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
Jan 31, 2012
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 @@
#include <netdb.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/epoll.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <signal.h>
#include <getopt.h>
#include <poll.h>
#include <cassert>
#include <cstdio>
...
...
@@ -159,11 +159,10 @@ int communicate(const std::string& host, uint16_t port,
}
make_non_block
(
fd
);
Spdylay
sc
(
fd
,
ssl
,
callbacks
);
int
epollfd
=
epoll_create
(
1
);
if
(
epollfd
==
-
1
)
{
perror
(
"epoll_create"
);
return
-
1
;
}
nfds_t
npollfds
=
1
;
pollfd
pollfds
[
1
];
for
(
int
i
=
0
,
n
=
reqvec
.
size
();
i
<
n
;
++
i
)
{
uri
::
UriStruct
&
us
=
reqvec
[
i
].
us
;
std
::
string
path
=
us
.
dir
+
us
.
file
+
us
.
query
;
...
...
@@ -171,33 +170,31 @@ int communicate(const std::string& host, uint16_t port,
assert
(
r
==
0
);
path2req
[
path
]
=
&
reqvec
[
i
];
}
ctl_epollev
(
epollfd
,
EPOLL_CTL_ADD
,
&
sc
)
;
static
const
size_t
MAX_EVENTS
=
1
;
epoll_event
events
[
MAX_EVENTS
];
pollfds
[
0
].
fd
=
fd
;
ctl_poll
(
pollfds
,
&
sc
)
;
bool
ok
=
true
;
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
)
{
perror
(
"
epoll_wait
"
);
perror
(
"
poll
"
);
return
-
1
;
}
for
(
int
n
=
0
;
n
<
nfds
;
++
n
)
{
if
(((
events
[
n
].
events
&
EPOLLIN
)
&&
sc
.
recv
()
!=
0
)
||
((
events
[
n
].
events
&
EPOLLOUT
)
&&
sc
.
send
()
!=
0
))
{
if
(((
pollfds
[
0
].
revents
&
POLLIN
)
&&
sc
.
recv
()
!=
0
)
||
((
pollfds
[
0
].
revents
&
POLLOUT
)
&&
sc
.
send
()
!=
0
))
{
ok
=
false
;
std
::
cout
<<
"Fatal"
<<
std
::
endl
;
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
;
ok
=
false
;
break
;
}
}
if
(
!
ok
)
{
break
;
}
ctl_
epollev
(
epollfd
,
EPOLL_CTL_MOD
,
&
sc
);
ctl_
poll
(
pollfds
,
&
sc
);
}
SSL_shutdown
(
ssl
);
...
...
examples/spdylay_ssl.cc
View file @
4e192493
...
...
@@ -27,7 +27,6 @@
#include <netdb.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/epoll.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
...
...
@@ -227,9 +226,9 @@ void print_nv(char **nv)
void
print_timer
()
{
time
spec
ts
;
get_timer
(
&
t
s
);
printf
(
"[%3ld.%03ld]"
,
t
s
.
tv_sec
,
ts
.
tv_nsec
/
1000
000
);
time
val
tv
;
get_timer
(
&
t
v
);
printf
(
"[%3ld.%03ld]"
,
t
v
.
tv_sec
,
tv
.
tv_usec
/
1
000
);
}
void
print_frame
(
spdylay_frame_type
type
,
spdylay_frame
*
frame
)
...
...
@@ -291,19 +290,14 @@ void on_ctrl_send_callback
fflush
(
stdout
);
}
void
ctl_
epollev
(
int
epollfd
,
int
op
,
Spdylay
*
sc
)
void
ctl_
poll
(
pollfd
*
pollfd
,
Spdylay
*
sc
)
{
epoll_event
ev
;
memset
(
&
ev
,
0
,
sizeof
(
ev
));
pollfd
->
events
=
0
;
if
(
sc
->
want_read
())
{
ev
.
events
|=
E
POLLIN
;
pollfd
->
events
|=
POLLIN
;
}
if
(
sc
->
want_write
())
{
ev
.
events
|=
EPOLLOUT
;
}
if
(
epoll_ctl
(
epollfd
,
op
,
sc
->
fd
(),
&
ev
)
==
-
1
)
{
perror
(
"epoll_ctl"
);
exit
(
EXIT_FAILURE
);
pollfd
->
events
|=
POLLOUT
;
}
}
...
...
@@ -357,22 +351,22 @@ int ssl_handshake(SSL *ssl, int fd)
}
namespace
{
time
spec
basets
;
time
val
base_tv
;
}
// namespace
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
);
t
s
->
tv_nsec
-=
basets
.
tv_n
sec
;
t
s
->
tv_sec
-=
basets
.
tv_sec
;
if
(
t
s
->
tv_n
sec
<
0
)
{
t
s
->
tv_nsec
+=
1000
000000
;
--
t
s
->
tv_sec
;
gettimeofday
(
tv
,
0
);
t
v
->
tv_usec
-=
base_tv
.
tv_u
sec
;
t
v
->
tv_sec
-=
base_tv
.
tv_sec
;
if
(
t
v
->
tv_u
sec
<
0
)
{
t
v
->
tv_usec
+=
1
000000
;
--
t
v
->
tv_sec
;
}
}
...
...
examples/spdylay_ssl.h
View file @
4e192493
...
...
@@ -27,7 +27,8 @@
#include <stdint.h>
#include <cstdlib>
#include <time.h>
#include <sys/time.h>
#include <poll.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
...
...
@@ -83,7 +84,7 @@ void on_ctrl_send_callback
(
spdylay_session
*
session
,
spdylay_frame_type
type
,
spdylay_frame
*
frame
,
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
,
unsigned
char
**
out
,
unsigned
char
*
outlen
,
...
...
@@ -96,7 +97,7 @@ int ssl_handshake(SSL *ssl, int fd);
void
reset_timer
();
void
get_timer
(
time
spec
*
ts
);
void
get_timer
(
time
val
*
tv
);
}
// namespace spdylay
...
...
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