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
dfce262f
Commit
dfce262f
authored
Feb 08, 2012
by
Tatsuhiro Tsujikawa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added non-blocking SPDY server spdyd. It only handles static contents.
parent
3bfe0553
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
1093 additions
and
8 deletions
+1093
-8
examples/Makefile.am
examples/Makefile.am
+3
-1
examples/spdyd.cc
examples/spdyd.cc
+946
-0
examples/spdylay_ssl.cc
examples/spdylay_ssl.cc
+77
-5
examples/spdylay_ssl.h
examples/spdylay_ssl.h
+12
-2
examples/util.cc
examples/util.cc
+27
-0
examples/util.h
examples/util.h
+28
-0
No files found.
examples/Makefile.am
View file @
dfce262f
...
...
@@ -26,6 +26,8 @@ AM_CPPFLAGS = -I$(srcdir)/../lib/includes -I$(builddir)/../lib/includes `pkg-con
AM_LDFLAGS
=
`
pkg-config
--libs
libssl libcrypto
`
LDADD
=
$(top_builddir)
/lib/libspdylay.la
bin_PROGRAMS
=
spdycat
bin_PROGRAMS
=
spdycat
spdyd
spdycat_SOURCES
=
uri.cc spdylay_ssl.cc util.cc spdycat.cc
spdyd_SOURCES
=
uri.cc spdylay_ssl.cc util.cc spdyd.cc
examples/spdyd.cc
0 → 100644
View file @
dfce262f
This diff is collapsed.
Click to expand it.
examples/spdylay_ssl.cc
View file @
dfce262f
...
...
@@ -159,6 +159,52 @@ int connect_to(const std::string& host, uint16_t port)
return
fd
;
}
int
make_listen_socket
(
uint16_t
port
)
{
addrinfo
hints
;
int
fd
=
-
1
;
int
r
;
char
service
[
10
];
snprintf
(
service
,
sizeof
(
service
),
"%u"
,
port
);
memset
(
&
hints
,
0
,
sizeof
(
addrinfo
));
hints
.
ai_family
=
AF_UNSPEC
;
hints
.
ai_socktype
=
SOCK_STREAM
;
hints
.
ai_flags
=
AI_ADDRCONFIG
|
AI_PASSIVE
;
addrinfo
*
res
,
*
rp
;
r
=
getaddrinfo
(
0
,
service
,
&
hints
,
&
res
);
if
(
r
!=
0
)
{
std
::
cerr
<<
"getaddrinfo: "
<<
gai_strerror
(
r
)
<<
std
::
endl
;
return
-
1
;
}
for
(
rp
=
res
;
rp
;
rp
=
rp
->
ai_next
)
{
fd
=
socket
(
rp
->
ai_family
,
rp
->
ai_socktype
,
rp
->
ai_protocol
);
if
(
fd
==
-
1
)
{
continue
;
}
int
val
=
1
;
if
(
setsockopt
(
fd
,
SOL_SOCKET
,
SO_REUSEADDR
,
&
val
,
static_cast
<
socklen_t
>
(
sizeof
(
val
)))
==
-
1
)
{
close
(
fd
);
continue
;
}
if
(
bind
(
fd
,
rp
->
ai_addr
,
rp
->
ai_addrlen
)
==
0
)
{
break
;
}
close
(
fd
);
}
freeaddrinfo
(
res
);
if
(
rp
==
0
)
{
return
-
1
;
}
else
{
if
(
listen
(
fd
,
16
)
==
-
1
)
{
close
(
fd
);
return
-
1
;
}
else
{
return
fd
;
}
}
}
int
make_non_block
(
int
fd
)
{
int
flags
,
r
;
...
...
@@ -173,6 +219,12 @@ int make_non_block(int fd)
return
0
;
}
int
set_tcp_nodelay
(
int
fd
)
{
int
val
=
1
;
return
setsockopt
(
fd
,
IPPROTO_TCP
,
TCP_NODELAY
,
&
val
,
(
socklen_t
)
sizeof
(
val
));
}
ssize_t
send_callback
(
spdylay_session
*
session
,
const
uint8_t
*
data
,
size_t
len
,
int
flags
,
void
*
user_data
)
...
...
@@ -250,6 +302,7 @@ void print_ctrl_hd(const spdylay_ctrl_hd& hd)
}
}
// namespace
namespace
{
void
print_frame
(
spdylay_frame_type
type
,
spdylay_frame
*
frame
)
{
printf
(
"%s frame "
,
ctrl_names
[
type
-
1
]);
...
...
@@ -300,6 +353,7 @@ void print_frame(spdylay_frame_type type, spdylay_frame *frame)
break
;
}
}
}
// namespace
void
on_ctrl_recv_callback
(
spdylay_session
*
session
,
spdylay_frame_type
type
,
spdylay_frame
*
frame
,
...
...
@@ -311,23 +365,41 @@ void on_ctrl_recv_callback
fflush
(
stdout
);
}
void
on_ctrl_send_callback
(
spdylay_session
*
session
,
spdylay_frame_type
type
,
spdylay_frame
*
frame
,
void
*
user_data
)
{
print_timer
();
printf
(
" send "
);
print_frame
(
type
,
frame
);
fflush
(
stdout
);
}
namespace
{
void
print_data_frame
(
uint8_t
flags
,
int32_t
stream_id
,
int32_t
length
)
{
printf
(
"DATA frame (stream_id=%d, flags=%d, length=%d)
\n
"
,
stream_id
,
flags
,
length
);
}
}
// namespace
void
on_data_recv_callback
(
spdylay_session
*
session
,
uint8_t
flags
,
int32_t
stream_id
,
int32_t
length
,
void
*
user_data
)
{
print_timer
();
printf
(
" recv
DATA frame (stream_id=%d, flags=%d, length=%d)
\n
"
,
stream_id
,
flags
,
length
);
printf
(
" recv
"
);
print_data_frame
(
flags
,
stream_id
,
length
);
fflush
(
stdout
);
}
void
on_
ctrl
_send_callback
(
spdylay_session
*
session
,
spdylay_frame_type
type
,
spdylay_frame
*
frame
,
void
on_
data
_send_callback
(
spdylay_session
*
session
,
uint8_t
flags
,
int32_t
stream_id
,
int32_t
length
,
void
*
user_data
)
{
print_timer
();
printf
(
" send "
);
print_
frame
(
type
,
frame
);
print_
data_frame
(
flags
,
stream_id
,
length
);
fflush
(
stdout
);
}
...
...
examples/spdylay_ssl.h
View file @
dfce262f
...
...
@@ -62,8 +62,12 @@ private:
int
connect_to
(
const
std
::
string
&
host
,
uint16_t
port
);
int
make_listen_socket
(
uint16_t
port
);
int
make_non_block
(
int
fd
);
int
set_tcp_nodelay
(
int
fd
);
ssize_t
send_callback
(
spdylay_session
*
session
,
const
uint8_t
*
data
,
size_t
len
,
int
flags
,
void
*
user_data
);
...
...
@@ -77,12 +81,16 @@ void on_ctrl_recv_callback
(
spdylay_session
*
session
,
spdylay_frame_type
type
,
spdylay_frame
*
frame
,
void
*
user_data
);
void
on_ctrl_send_callback
(
spdylay_session
*
session
,
spdylay_frame_type
type
,
spdylay_frame
*
frame
,
void
*
user_data
);
void
on_data_recv_callback
(
spdylay_session
*
session
,
uint8_t
flags
,
int32_t
stream_id
,
int32_t
length
,
void
*
user_data
);
void
on_
ctrl
_send_callback
(
spdylay_session
*
session
,
spdylay_frame_type
type
,
spdylay_frame
*
frame
,
void
on_
data
_send_callback
(
spdylay_session
*
session
,
uint8_t
flags
,
int32_t
stream_id
,
int32_t
length
,
void
*
user_data
);
void
ctl_poll
(
pollfd
*
pollfd
,
Spdylay
*
sc
);
...
...
@@ -100,6 +108,8 @@ void reset_timer();
void
get_timer
(
timeval
*
tv
);
void
print_timer
();
}
// namespace spdylay
#endif // SPDYLAY_SSL_H
examples/util.cc
View file @
dfce262f
...
...
@@ -24,7 +24,10 @@
*/
#include "util.h"
#include <time.h>
#include <cstdio>
#include <cstring>
namespace
spdylay
{
...
...
@@ -97,6 +100,30 @@ std::string percentDecode
return
result
;
}
std
::
string
http_date
(
time_t
t
)
{
char
buf
[
32
];
tm
*
tms
=
gmtime
(
&
t
);
// returned struct is statically allocated.
size_t
r
=
strftime
(
buf
,
sizeof
(
buf
),
"%a, %d %b %Y %H:%M:%S GMT"
,
tms
);
return
std
::
string
(
&
buf
[
0
],
&
buf
[
r
]);
}
time_t
parse_http_date
(
const
std
::
string
&
s
)
{
tm
tm
;
memset
(
&
tm
,
0
,
sizeof
(
tm
));
char
*
r
=
strptime
(
s
.
c_str
(),
"%a, %d %b %Y %H:%M:%S GMT"
,
&
tm
);
if
(
r
==
0
)
{
return
0
;
}
return
timegm
(
&
tm
);
}
bool
endsWith
(
const
std
::
string
&
a
,
const
std
::
string
&
b
)
{
return
endsWith
(
a
.
begin
(),
a
.
end
(),
b
.
begin
(),
b
.
end
());
}
}
// namespace util
}
// namespace spdylay
examples/util.h
View file @
dfce262f
...
...
@@ -28,6 +28,7 @@
#include <vector>
#include <string>
#include <algorithm>
#include <sstream>
namespace
spdylay
{
...
...
@@ -161,6 +162,33 @@ std::string percentEncode(const std::string& target);
std
::
string
percentDecode
(
std
::
string
::
const_iterator
first
,
std
::
string
::
const_iterator
last
);
std
::
string
http_date
(
time_t
t
);
time_t
parse_http_date
(
const
std
::
string
&
s
);
template
<
typename
T
>
std
::
string
to_str
(
T
value
)
{
std
::
stringstream
ss
;
ss
<<
value
;
return
ss
.
str
();
}
template
<
typename
InputIterator1
,
typename
InputIterator2
>
bool
endsWith
(
InputIterator1
first1
,
InputIterator1
last1
,
InputIterator2
first2
,
InputIterator2
last2
)
{
if
(
last1
-
first1
<
last2
-
first2
)
{
return
false
;
}
return
std
::
equal
(
first2
,
last2
,
last1
-
(
last2
-
first2
));
}
bool
endsWith
(
const
std
::
string
&
a
,
const
std
::
string
&
b
);
}
// namespace util
}
// 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