Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
nghttp2
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
nghttp2
Commits
4e192493
Commit
4e192493
authored
13 years ago
by
Tatsuhiro Tsujikawa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use gettimeofday instead of clock_gettime and use poll instead of epoll for portability.
parent
9785b999
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
46 deletions
+38
-46
examples/spdycat.cc
examples/spdycat.cc
+18
-21
examples/spdylay_ssl.cc
examples/spdylay_ssl.cc
+16
-22
examples/spdylay_ssl.h
examples/spdylay_ssl.h
+4
-3
No files found.
examples/spdycat.cc
View file @
4e192493
...
@@ -27,11 +27,11 @@
...
@@ -27,11 +27,11 @@
#include <netdb.h>
#include <netdb.h>
#include <unistd.h>
#include <unistd.h>
#include <fcntl.h>
#include <fcntl.h>
#include <sys/epoll.h>
#include <netinet/in.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <netinet/tcp.h>
#include <signal.h>
#include <signal.h>
#include <getopt.h>
#include <getopt.h>
#include <poll.h>
#include <cassert>
#include <cassert>
#include <cstdio>
#include <cstdio>
...
@@ -159,11 +159,10 @@ int communicate(const std::string& host, uint16_t port,
...
@@ -159,11 +159,10 @@ int communicate(const std::string& host, uint16_t port,
}
}
make_non_block
(
fd
);
make_non_block
(
fd
);
Spdylay
sc
(
fd
,
ssl
,
callbacks
);
Spdylay
sc
(
fd
,
ssl
,
callbacks
);
int
epollfd
=
epoll_create
(
1
);
if
(
epollfd
==
-
1
)
{
nfds_t
npollfds
=
1
;
perror
(
"epoll_create"
);
pollfd
pollfds
[
1
];
return
-
1
;
}
for
(
int
i
=
0
,
n
=
reqvec
.
size
();
i
<
n
;
++
i
)
{
for
(
int
i
=
0
,
n
=
reqvec
.
size
();
i
<
n
;
++
i
)
{
uri
::
UriStruct
&
us
=
reqvec
[
i
].
us
;
uri
::
UriStruct
&
us
=
reqvec
[
i
].
us
;
std
::
string
path
=
us
.
dir
+
us
.
file
+
us
.
query
;
std
::
string
path
=
us
.
dir
+
us
.
file
+
us
.
query
;
...
@@ -171,33 +170,31 @@ int communicate(const std::string& host, uint16_t port,
...
@@ -171,33 +170,31 @@ int communicate(const std::string& host, uint16_t port,
assert
(
r
==
0
);
assert
(
r
==
0
);
path2req
[
path
]
=
&
reqvec
[
i
];
path2req
[
path
]
=
&
reqvec
[
i
];
}
}
ctl_epollev
(
epollfd
,
EPOLL_CTL_ADD
,
&
sc
)
;
pollfds
[
0
].
fd
=
fd
;
static
const
size_t
MAX_EVENTS
=
1
;
ctl_poll
(
pollfds
,
&
sc
)
;
epoll_event
events
[
MAX_EVENTS
];
bool
ok
=
true
;
bool
ok
=
true
;
while
(
sc
.
want_read
()
||
sc
.
want_write
())
{
while
(
sc
.
want_read
()
||
sc
.
want_write
())
{
int
nfds
=
epoll_wait
(
epollfd
,
events
,
MAX_EVENTS
,
-
1
);
int
nfds
=
poll
(
pollfds
,
npollfds
,
-
1
);
if
(
nfds
==
-
1
)
{
if
(
nfds
==
-
1
)
{
perror
(
"
epoll_wait
"
);
perror
(
"
poll
"
);
return
-
1
;
return
-
1
;
}
}
for
(
int
n
=
0
;
n
<
nfds
;
++
n
)
{
if
(((
pollfds
[
0
].
revents
&
POLLIN
)
&&
sc
.
recv
()
!=
0
)
||
if
(((
events
[
n
].
events
&
EPOLLIN
)
&&
sc
.
recv
()
!=
0
)
||
((
pollfds
[
0
].
revents
&
POLLOUT
)
&&
sc
.
send
()
!=
0
))
{
((
events
[
n
].
events
&
EPOLLOUT
)
&&
sc
.
send
()
!=
0
))
{
ok
=
false
;
ok
=
false
;
std
::
cout
<<
"Fatal"
<<
std
::
endl
;
std
::
cout
<<
"Fatal"
<<
std
::
endl
;
break
;
break
;
}
}
if
((
events
[
n
].
events
&
EPOLLHUP
)
||
(
events
[
n
].
events
&
E
POLLERR
))
{
if
((
pollfds
[
0
].
revents
&
POLLHUP
)
||
(
pollfds
[
0
].
revents
&
POLLERR
))
{
std
::
cout
<<
"HUP"
<<
std
::
endl
;
std
::
cout
<<
"HUP"
<<
std
::
endl
;
ok
=
false
;
ok
=
false
;
break
;
break
;
}
}
}
if
(
!
ok
)
{
if
(
!
ok
)
{
break
;
break
;
}
}
ctl_
epollev
(
epollfd
,
EPOLL_CTL_MOD
,
&
sc
);
ctl_
poll
(
pollfds
,
&
sc
);
}
}
SSL_shutdown
(
ssl
);
SSL_shutdown
(
ssl
);
...
...
This diff is collapsed.
Click to expand it.
examples/spdylay_ssl.cc
View file @
4e192493
...
@@ -27,7 +27,6 @@
...
@@ -27,7 +27,6 @@
#include <netdb.h>
#include <netdb.h>
#include <unistd.h>
#include <unistd.h>
#include <fcntl.h>
#include <fcntl.h>
#include <sys/epoll.h>
#include <netinet/in.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <netinet/tcp.h>
...
@@ -227,9 +226,9 @@ void print_nv(char **nv)
...
@@ -227,9 +226,9 @@ void print_nv(char **nv)
void
print_timer
()
void
print_timer
()
{
{
time
spec
ts
;
time
val
tv
;
get_timer
(
&
t
s
);
get_timer
(
&
t
v
);
printf
(
"[%3ld.%03ld]"
,
t
s
.
tv_sec
,
ts
.
tv_nsec
/
1000
000
);
printf
(
"[%3ld.%03ld]"
,
t
v
.
tv_sec
,
tv
.
tv_usec
/
1
000
);
}
}
void
print_frame
(
spdylay_frame_type
type
,
spdylay_frame
*
frame
)
void
print_frame
(
spdylay_frame_type
type
,
spdylay_frame
*
frame
)
...
@@ -291,19 +290,14 @@ void on_ctrl_send_callback
...
@@ -291,19 +290,14 @@ void on_ctrl_send_callback
fflush
(
stdout
);
fflush
(
stdout
);
}
}
void
ctl_
epollev
(
int
epollfd
,
int
op
,
Spdylay
*
sc
)
void
ctl_
poll
(
pollfd
*
pollfd
,
Spdylay
*
sc
)
{
{
epoll_event
ev
;
pollfd
->
events
=
0
;
memset
(
&
ev
,
0
,
sizeof
(
ev
));
if
(
sc
->
want_read
())
{
if
(
sc
->
want_read
())
{
ev
.
events
|=
E
POLLIN
;
pollfd
->
events
|=
POLLIN
;
}
}
if
(
sc
->
want_write
())
{
if
(
sc
->
want_write
())
{
ev
.
events
|=
EPOLLOUT
;
pollfd
->
events
|=
POLLOUT
;
}
if
(
epoll_ctl
(
epollfd
,
op
,
sc
->
fd
(),
&
ev
)
==
-
1
)
{
perror
(
"epoll_ctl"
);
exit
(
EXIT_FAILURE
);
}
}
}
}
...
@@ -357,22 +351,22 @@ int ssl_handshake(SSL *ssl, int fd)
...
@@ -357,22 +351,22 @@ int ssl_handshake(SSL *ssl, int fd)
}
}
namespace
{
namespace
{
time
spec
basets
;
time
val
base_tv
;
}
// namespace
}
// namespace
void
reset_timer
()
void
reset_timer
()
{
{
clock_gettime
(
CLOCK_MONOTONIC_RAW
,
&
basets
);
gettimeofday
(
&
base_tv
,
0
);
}
}
void
get_timer
(
time
spec
*
ts
)
void
get_timer
(
time
val
*
tv
)
{
{
clock_gettime
(
CLOCK_MONOTONIC_RAW
,
ts
);
gettimeofday
(
tv
,
0
);
t
s
->
tv_nsec
-=
basets
.
tv_n
sec
;
t
v
->
tv_usec
-=
base_tv
.
tv_u
sec
;
t
s
->
tv_sec
-=
basets
.
tv_sec
;
t
v
->
tv_sec
-=
base_tv
.
tv_sec
;
if
(
t
s
->
tv_n
sec
<
0
)
{
if
(
t
v
->
tv_u
sec
<
0
)
{
t
s
->
tv_nsec
+=
1000
000000
;
t
v
->
tv_usec
+=
1
000000
;
--
t
s
->
tv_sec
;
--
t
v
->
tv_sec
;
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
examples/spdylay_ssl.h
View file @
4e192493
...
@@ -27,7 +27,8 @@
...
@@ -27,7 +27,8 @@
#include <stdint.h>
#include <stdint.h>
#include <cstdlib>
#include <cstdlib>
#include <time.h>
#include <sys/time.h>
#include <poll.h>
#include <openssl/ssl.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
#include <openssl/err.h>
...
@@ -83,7 +84,7 @@ void on_ctrl_send_callback
...
@@ -83,7 +84,7 @@ void on_ctrl_send_callback
(
spdylay_session
*
session
,
spdylay_frame_type
type
,
spdylay_frame
*
frame
,
(
spdylay_session
*
session
,
spdylay_frame_type
type
,
spdylay_frame
*
frame
,
void
*
user_data
);
void
*
user_data
);
void
ctl_
epollev
(
int
epollfd
,
int
op
,
Spdylay
*
sc
);
void
ctl_
poll
(
pollfd
*
pollfd
,
Spdylay
*
sc
);
int
select_next_proto_cb
(
SSL
*
ssl
,
int
select_next_proto_cb
(
SSL
*
ssl
,
unsigned
char
**
out
,
unsigned
char
*
outlen
,
unsigned
char
**
out
,
unsigned
char
*
outlen
,
...
@@ -96,7 +97,7 @@ int ssl_handshake(SSL *ssl, int fd);
...
@@ -96,7 +97,7 @@ int ssl_handshake(SSL *ssl, int fd);
void
reset_timer
();
void
reset_timer
();
void
get_timer
(
time
spec
*
ts
);
void
get_timer
(
time
val
*
tv
);
}
// namespace spdylay
}
// namespace spdylay
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment