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
b0c1986a
Commit
b0c1986a
authored
Mar 04, 2015
by
Tatsuhiro Tsujikawa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
asio: Avoid shared_ptr for request and response
parent
9671eaa8
Changes
6
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
84 additions
and
128 deletions
+84
-128
examples/asio-sv.cc
examples/asio-sv.cc
+3
-4
examples/asio-sv2.cc
examples/asio-sv2.cc
+9
-9
src/asio_client_stream.cc
src/asio_client_stream.cc
+1
-2
src/asio_http2_handler.cc
src/asio_http2_handler.cc
+48
-84
src/asio_http2_handler.h
src/asio_http2_handler.h
+14
-17
src/includes/nghttp2/asio_http2.h
src/includes/nghttp2/asio_http2.h
+9
-12
No files found.
examples/asio-sv.cc
View file @
b0c1986a
...
...
@@ -62,10 +62,9 @@ int main(int argc, char *argv[]) {
server
.
tls
(
argv
[
3
],
argv
[
4
]);
}
server
.
listen
(
"*"
,
port
,
[](
const
std
::
shared_ptr
<
request
>
&
req
,
const
std
::
shared_ptr
<
response
>
&
res
)
{
res
->
write_head
(
200
,
{
header
{
"foo"
,
"bar"
}});
res
->
end
(
"hello, world"
);
server
.
listen
(
"*"
,
port
,
[](
const
request
&
req
,
const
response
&
res
)
{
res
.
write_head
(
200
,
{
header
{
"foo"
,
"bar"
}});
res
.
end
(
"hello, world"
);
});
}
catch
(
std
::
exception
&
e
)
{
std
::
cerr
<<
"exception: "
<<
e
.
what
()
<<
"
\n
"
;
...
...
examples/asio-sv2.cc
View file @
b0c1986a
...
...
@@ -66,12 +66,12 @@ int main(int argc, char *argv[]) {
server
.
tls
(
argv
[
4
],
argv
[
5
]);
}
server
.
listen
(
"*"
,
port
,
[
&
docroot
](
const
std
::
shared_ptr
<
request
>
&
req
,
const
std
::
shared_ptr
<
response
>
&
res
)
{
auto
path
=
percent_decode
(
req
->
path
());
server
.
listen
(
"*"
,
port
,
[
&
docroot
](
const
request
&
req
,
const
response
&
res
)
{
auto
path
=
percent_decode
(
req
.
path
());
if
(
!
check_path
(
path
))
{
res
->
write_head
(
404
);
res
->
end
();
res
.
write_head
(
404
);
res
.
end
();
return
;
}
...
...
@@ -82,8 +82,8 @@ int main(int argc, char *argv[]) {
path
=
docroot
+
path
;
auto
fd
=
open
(
path
.
c_str
(),
O_RDONLY
);
if
(
fd
==
-
1
)
{
res
->
write_head
(
404
);
res
->
end
();
res
.
write_head
(
404
);
res
.
end
();
return
;
}
...
...
@@ -95,8 +95,8 @@ int main(int argc, char *argv[]) {
header
{
"content-length"
,
std
::
to_string
(
stbuf
.
st_size
)});
headers
.
push_back
(
header
{
"last-modified"
,
http_date
(
stbuf
.
st_mtime
)});
}
res
->
write_head
(
200
,
std
::
move
(
headers
));
res
->
end
(
file_reader_from_fd
(
fd
));
res
.
write_head
(
200
,
std
::
move
(
headers
));
res
.
end
(
file_reader_from_fd
(
fd
));
});
}
catch
(
std
::
exception
&
e
)
{
std
::
cerr
<<
"exception: "
<<
e
.
what
()
<<
"
\n
"
;
...
...
src/asio_client_stream.cc
View file @
b0c1986a
...
...
@@ -32,8 +32,7 @@ namespace nghttp2 {
namespace
asio_http2
{
namespace
client
{
stream
::
stream
(
session_impl
*
sess
)
:
sess_
(
sess
),
stream_id_
(
0
)
{
stream
::
stream
(
session_impl
*
sess
)
:
sess_
(
sess
),
stream_id_
(
0
)
{
request_
.
impl
().
stream
(
this
);
}
...
...
src/asio_http2_handler.cc
View file @
b0c1986a
This diff is collapsed.
Click to expand it.
src/asio_http2_handler.h
View file @
b0c1986a
...
...
@@ -60,7 +60,6 @@ public:
std
::
vector
<
header
>
headers
=
{});
bool
pushed
()
const
;
bool
closed
()
const
;
void
on_data
(
data_cb
cb
);
void
on_end
(
void_cb
cb
);
...
...
@@ -73,12 +72,12 @@ public:
void
host
(
std
::
string
host
);
void
path
(
std
::
string
path
);
void
pushed
(
bool
f
);
void
handler
(
std
::
weak_ptr
<
http2_handler
>
h
);
void
stream
(
std
::
weak_ptr
<
http2_stream
>
s
);
void
stream
(
http2_stream
*
s
);
void
call_on_data
(
const
uint8_t
*
data
,
std
::
size_t
len
);
void
call_on_end
();
private:
http2_stream
*
stream_
;
std
::
vector
<
header
>
headers_
;
std
::
string
method_
;
std
::
string
scheme_
;
...
...
@@ -87,8 +86,6 @@ private:
std
::
string
path_
;
data_cb
on_data_cb_
;
void_cb
on_end_cb_
;
std
::
weak_ptr
<
http2_handler
>
handler_
;
std
::
weak_ptr
<
http2_stream
>
stream_
;
bool
pushed_
;
};
...
...
@@ -99,35 +96,35 @@ public:
void
end
(
std
::
string
data
=
""
);
void
end
(
read_cb
cb
);
void
resume
();
bool
closed
()
const
;
unsigned
int
status_code
()
const
;
const
std
::
vector
<
header
>
&
headers
()
const
;
bool
started
()
const
;
void
handler
(
std
::
weak_ptr
<
http2_handler
>
h
);
void
stream
(
std
::
weak_ptr
<
http2_stream
>
s
);
void
stream
(
http2_stream
*
s
);
read_cb
::
result_type
call_read
(
uint8_t
*
data
,
std
::
size_t
len
);
private:
http2_stream
*
stream_
;
std
::
vector
<
header
>
headers_
;
read_cb
read_cb_
;
std
::
weak_ptr
<
http2_handler
>
handler_
;
std
::
weak_ptr
<
http2_stream
>
stream_
;
unsigned
int
status_code_
;
bool
started_
;
};
class
http2_stream
{
public:
http2_stream
(
int32_t
stream_id
);
http2_stream
(
http2_handler
*
h
,
int32_t
stream_id
);
int32_t
get_stream_id
()
const
;
const
std
::
shared_ptr
<
request
>
&
get_request
();
const
std
::
shared_ptr
<
response
>
&
get_response
();
request
&
request
();
response
&
response
();
http2_handler
*
handler
()
const
;
private:
std
::
shared_ptr
<
request
>
request_
;
std
::
shared_ptr
<
response
>
response_
;
http2_handler
*
handler_
;
class
request
request_
;
class
response
response_
;
int32_t
stream_id_
;
};
...
...
@@ -148,9 +145,9 @@ public:
int
start
();
std
::
shared_ptr
<
http2_stream
>
create_stream
(
int32_t
stream_id
);
http2_stream
*
create_stream
(
int32_t
stream_id
);
void
close_stream
(
int32_t
stream_id
);
std
::
shared_ptr
<
http2_stream
>
find_stream
(
int32_t
stream_id
);
http2_stream
*
find_stream
(
int32_t
stream_id
);
void
call_on_request
(
http2_stream
&
stream
);
...
...
src/includes/nghttp2/asio_http2.h
View file @
b0c1986a
...
...
@@ -133,24 +133,21 @@ public:
const
std
::
string
&
path
()
const
;
// Sets callback when chunk of request body is received.
void
on_data
(
data_cb
cb
);
void
on_data
(
data_cb
cb
)
const
;
// Sets callback when request was completed.
void
on_end
(
void_cb
cb
);
void
on_end
(
void_cb
cb
)
const
;
// Pushes resource denoted by |path| using |method|. The additional
// headers can be given in |headers|. request_cb will be called for
// pushed resource later on. This function returns true if it
// succeeds, or false.
bool
push
(
std
::
string
method
,
std
::
string
path
,
std
::
vector
<
header
>
headers
=
{});
std
::
vector
<
header
>
headers
=
{})
const
;
// Returns true if this is pushed request.
bool
pushed
()
const
;
// Returns true if stream has been closed.
bool
closed
()
const
;
// Application must not call this directly.
request_impl
&
impl
();
...
...
@@ -165,18 +162,19 @@ public:
// Write response header using |status_code| (e.g., 200) and
// additional headers in |headers|.
void
write_head
(
unsigned
int
status_code
,
std
::
vector
<
header
>
headers
=
{});
void
write_head
(
unsigned
int
status_code
,
std
::
vector
<
header
>
headers
=
{})
const
;
// Sends |data| as request body. No further call of end() is
// allowed.
void
end
(
std
::
string
data
=
""
);
void
end
(
std
::
string
data
=
""
)
const
;
// Sets callback |cb| as a generator of the response body. No
// further call of end() is allowed.
void
end
(
read_cb
cb
);
void
end
(
read_cb
cb
)
const
;
// Resumes deferred response.
void
resume
();
void
resume
()
const
;
// Returns status code.
unsigned
int
status_code
()
const
;
...
...
@@ -193,8 +191,7 @@ private:
// This is so called request callback. Called every time request is
// received.
typedef
std
::
function
<
void
(
const
std
::
shared_ptr
<
request
>
&
,
const
std
::
shared_ptr
<
response
>
&
)
>
request_cb
;
typedef
std
::
function
<
void
(
const
request
&
,
const
response
&
)
>
request_cb
;
class
http2_impl
;
...
...
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