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
992c14e3
Commit
992c14e3
authored
Mar 06, 2015
by
Tatsuhiro Tsujikawa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
asio: Rename *_reader as *_generator and read_cb as generator_cb
parent
529fc937
Changes
14
Show whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
46 additions
and
45 deletions
+46
-45
examples/asio-sv2.cc
examples/asio-sv2.cc
+1
-1
src/asio_client_request_impl.cc
src/asio_client_request_impl.cc
+6
-5
src/asio_client_request_impl.h
src/asio_client_request_impl.h
+4
-4
src/asio_client_session.cc
src/asio_client_session.cc
+3
-3
src/asio_client_session_impl.cc
src/asio_client_session_impl.cc
+1
-1
src/asio_client_session_impl.h
src/asio_client_session_impl.h
+1
-1
src/asio_common.cc
src/asio_common.cc
+7
-7
src/asio_common.h
src/asio_common.h
+3
-3
src/asio_server_response.cc
src/asio_server_response.cc
+1
-1
src/asio_server_response_impl.cc
src/asio_server_response_impl.cc
+9
-9
src/asio_server_response_impl.h
src/asio_server_response_impl.h
+4
-4
src/includes/nghttp2/asio_http2.h
src/includes/nghttp2/asio_http2.h
+4
-4
src/includes/nghttp2/asio_http2_client.h
src/includes/nghttp2/asio_http2_client.h
+1
-1
src/includes/nghttp2/asio_http2_server.h
src/includes/nghttp2/asio_http2_server.h
+1
-1
No files found.
examples/asio-sv2.cc
View file @
992c14e3
...
...
@@ -96,7 +96,7 @@ int main(int argc, char *argv[]) {
header_value
{
http_date
(
stbuf
.
st_mtime
)});
}
res
.
write_head
(
200
,
std
::
move
(
header
));
res
.
end
(
file_
reade
r_from_fd
(
fd
));
res
.
end
(
file_
generato
r_from_fd
(
fd
));
});
server
.
listen
(
"*"
,
port
);
...
...
src/asio_client_request_impl.cc
View file @
992c14e3
...
...
@@ -63,12 +63,13 @@ void request_impl::call_on_close(uint32_t error_code) {
}
}
void
request_impl
::
on_read
(
read_cb
cb
)
{
read
_cb_
=
std
::
move
(
cb
);
}
void
request_impl
::
on_read
(
generator_cb
cb
)
{
generator
_cb_
=
std
::
move
(
cb
);
}
read_cb
::
result_type
request_impl
::
call_on_read
(
uint8_t
*
buf
,
std
::
size_t
len
,
generator_cb
::
result_type
request_impl
::
call_on_read
(
uint8_t
*
buf
,
std
::
size_t
len
,
uint32_t
*
data_flags
)
{
if
(
read
_cb_
)
{
return
read
_cb_
(
buf
,
len
,
data_flags
);
if
(
generator
_cb_
)
{
return
generator
_cb_
(
buf
,
len
,
data_flags
);
}
*
data_flags
|=
NGHTTP2_DATA_FLAG_EOF
;
...
...
src/asio_client_request_impl.h
View file @
992c14e3
...
...
@@ -54,8 +54,8 @@ public:
void
on_close
(
close_cb
cb
);
void
call_on_close
(
uint32_t
error_code
);
void
on_read
(
read
_cb
cb
);
read
_cb
::
result_type
call_on_read
(
uint8_t
*
buf
,
std
::
size_t
len
,
void
on_read
(
generator
_cb
cb
);
generator
_cb
::
result_type
call_on_read
(
uint8_t
*
buf
,
std
::
size_t
len
,
uint32_t
*
data_flags
);
void
resume
();
...
...
@@ -78,7 +78,7 @@ private:
response_cb
response_cb_
;
request_cb
push_request_cb_
;
close_cb
close_cb_
;
read_cb
read
_cb_
;
generator_cb
generator
_cb_
;
class
stream
*
strm_
;
uri_ref
uri_
;
std
::
string
method_
;
...
...
src/asio_client_session.cc
View file @
992c14e3
...
...
@@ -64,20 +64,20 @@ boost::asio::io_service &session::io_service() const {
const
request
*
session
::
submit
(
boost
::
system
::
error_code
&
ec
,
const
std
::
string
&
method
,
const
std
::
string
&
uri
,
header_map
h
)
const
{
return
impl_
->
submit
(
ec
,
method
,
uri
,
read
_cb
(),
std
::
move
(
h
));
return
impl_
->
submit
(
ec
,
method
,
uri
,
generator
_cb
(),
std
::
move
(
h
));
}
const
request
*
session
::
submit
(
boost
::
system
::
error_code
&
ec
,
const
std
::
string
&
method
,
const
std
::
string
&
uri
,
std
::
string
data
,
header_map
h
)
const
{
return
impl_
->
submit
(
ec
,
method
,
uri
,
string_
reade
r
(
std
::
move
(
data
)),
return
impl_
->
submit
(
ec
,
method
,
uri
,
string_
generato
r
(
std
::
move
(
data
)),
std
::
move
(
h
));
}
const
request
*
session
::
submit
(
boost
::
system
::
error_code
&
ec
,
const
std
::
string
&
method
,
const
std
::
string
&
uri
,
read
_cb
cb
,
const
std
::
string
&
uri
,
generator
_cb
cb
,
header_map
h
)
const
{
return
impl_
->
submit
(
ec
,
method
,
uri
,
std
::
move
(
cb
),
std
::
move
(
h
));
}
...
...
src/asio_client_session_impl.cc
View file @
992c14e3
...
...
@@ -364,7 +364,7 @@ std::unique_ptr<stream> session_impl::create_stream() {
const
request
*
session_impl
::
submit
(
boost
::
system
::
error_code
&
ec
,
const
std
::
string
&
method
,
const
std
::
string
&
uri
,
read
_cb
cb
,
const
std
::
string
&
uri
,
generator
_cb
cb
,
header_map
h
)
{
ec
.
clear
();
...
...
src/asio_client_session_impl.h
View file @
992c14e3
...
...
@@ -63,7 +63,7 @@ public:
const
request
*
submit
(
boost
::
system
::
error_code
&
ec
,
const
std
::
string
&
method
,
const
std
::
string
&
uri
,
read
_cb
cb
,
header_map
h
);
generator
_cb
cb
,
header_map
h
);
virtual
void
start_connect
(
tcp
::
resolver
::
iterator
endpoint_it
)
=
0
;
virtual
tcp
::
socket
&
socket
()
=
0
;
...
...
src/asio_common.cc
View file @
992c14e3
...
...
@@ -47,7 +47,7 @@ boost::system::error_code make_error_code(nghttp2_error ev) {
return
boost
::
system
::
error_code
(
static_cast
<
int
>
(
ev
),
nghttp2_category
());
}
read_cb
string_reade
r
(
std
::
string
data
)
{
generator_cb
string_generato
r
(
std
::
string
data
)
{
auto
strio
=
std
::
make_shared
<
std
::
pair
<
std
::
string
,
size_t
>>
(
std
::
move
(
data
),
data
.
size
());
return
[
strio
](
uint8_t
*
buf
,
size_t
len
,
uint32_t
*
data_flags
)
{
...
...
@@ -63,7 +63,7 @@ read_cb string_reader(std::string data) {
};
}
read_cb
deferred_reade
r
()
{
generator_cb
deferred_generato
r
()
{
return
[](
uint8_t
*
buf
,
size_t
len
,
uint32_t
*
data_flags
)
{
return
NGHTTP2_ERR_DEFERRED
;
};
}
...
...
@@ -74,20 +74,20 @@ std::shared_ptr<Defer<F, T...>> defer_shared(F &&f, T &&... t) {
std
::
forward
<
T
>
(
t
)...);
}
read_cb
file_reade
r
(
const
std
::
string
&
path
)
{
generator_cb
file_generato
r
(
const
std
::
string
&
path
)
{
auto
fd
=
open
(
path
.
c_str
(),
O_RDONLY
);
if
(
fd
==
-
1
)
{
return
read
_cb
();
return
generator
_cb
();
}
return
file_
reade
r_from_fd
(
fd
);
return
file_
generato
r_from_fd
(
fd
);
}
read_cb
file_reade
r_from_fd
(
int
fd
)
{
generator_cb
file_generato
r_from_fd
(
int
fd
)
{
auto
d
=
defer_shared
(
close
,
fd
);
return
[
fd
,
d
](
uint8_t
*
buf
,
size_t
len
,
uint32_t
*
data_flags
)
->
read
_cb
::
result_type
{
->
generator
_cb
::
result_type
{
ssize_t
n
;
while
((
n
=
read
(
fd
,
buf
,
len
))
==
-
1
&&
errno
==
EINTR
)
;
...
...
src/asio_common.h
View file @
992c14e3
...
...
@@ -39,10 +39,10 @@ namespace asio_http2 {
boost
::
system
::
error_code
make_error_code
(
nghttp2_error
ev
);
read_cb
string_reade
r
(
std
::
string
data
);
generator_cb
string_generato
r
(
std
::
string
data
);
// Returns
read
_cb, which just returns NGHTTP2_ERR_DEFERRED
read_cb
deferred_reade
r
();
// Returns
generator
_cb, which just returns NGHTTP2_ERR_DEFERRED
generator_cb
deferred_generato
r
();
template
<
typename
InputIt
>
void
split_path
(
uri_ref
&
dst
,
InputIt
first
,
InputIt
last
)
{
...
...
src/asio_server_response.cc
View file @
992c14e3
...
...
@@ -44,7 +44,7 @@ void response::write_head(unsigned int status_code, header_map h) const {
void
response
::
end
(
std
::
string
data
)
const
{
impl_
->
end
(
std
::
move
(
data
));
}
void
response
::
end
(
read
_cb
cb
)
const
{
impl_
->
end
(
std
::
move
(
cb
));
}
void
response
::
end
(
generator
_cb
cb
)
const
{
impl_
->
end
(
std
::
move
(
cb
));
}
void
response
::
on_close
(
close_cb
cb
)
const
{
impl_
->
on_close
(
std
::
move
(
cb
));
}
...
...
src/asio_server_response_impl.cc
View file @
992c14e3
...
...
@@ -33,7 +33,7 @@ namespace asio_http2 {
namespace
server
{
response_impl
::
response_impl
()
:
strm_
(
nullptr
),
read_cb_
(
deferred_reade
r
()),
status_code_
(
200
),
:
strm_
(
nullptr
),
generator_cb_
(
deferred_generato
r
()),
status_code_
(
200
),
state_
(
response_state
::
INITIAL
),
pushed_
(
false
),
push_promise_sent_
(
false
)
{}
...
...
@@ -57,20 +57,20 @@ void response_impl::write_head(unsigned int status_code, header_map h) {
}
void
response_impl
::
end
(
std
::
string
data
)
{
end
(
string_
reade
r
(
std
::
move
(
data
)));
end
(
string_
generato
r
(
std
::
move
(
data
)));
}
void
response_impl
::
end
(
read
_cb
cb
)
{
void
response_impl
::
end
(
generator
_cb
cb
)
{
if
(
state_
==
response_state
::
BODY_STARTED
)
{
return
;
}
read
_cb_
=
std
::
move
(
cb
);
generator
_cb_
=
std
::
move
(
cb
);
if
(
state_
==
response_state
::
INITIAL
)
{
write_head
(
status_code_
);
}
else
{
//
read
_cb is changed, start writing in case it is deferred.
//
generator
_cb is changed, start writing in case it is deferred.
auto
handler
=
strm_
->
handler
();
handler
->
resume
(
*
strm_
);
}
...
...
@@ -133,10 +133,10 @@ const header_map &response_impl::header() const { return header_; }
void
response_impl
::
stream
(
class
stream
*
s
)
{
strm_
=
s
;
}
read_cb
::
result_type
response_impl
::
call_read
(
uint8_t
*
data
,
std
::
size_t
len
,
uint32_t
*
data_flags
)
{
if
(
read
_cb_
)
{
return
read
_cb_
(
data
,
len
,
data_flags
);
generator_cb
::
result_type
response_impl
::
call_read
(
uint8_t
*
data
,
std
::
size_t
len
,
uint32_t
*
data_flags
)
{
if
(
generator
_cb_
)
{
return
generator
_cb_
(
data
,
len
,
data_flags
);
}
*
data_flags
|=
NGHTTP2_DATA_FLAG_EOF
;
...
...
src/asio_server_response_impl.h
View file @
992c14e3
...
...
@@ -48,7 +48,7 @@ public:
response_impl
();
void
write_head
(
unsigned
int
status_code
,
header_map
h
=
{});
void
end
(
std
::
string
data
=
""
);
void
end
(
read
_cb
cb
);
void
end
(
generator
_cb
cb
);
void
on_close
(
close_cb
cb
);
void
resume
();
...
...
@@ -66,14 +66,14 @@ public:
void
pushed
(
bool
f
);
void
push_promise_sent
();
void
stream
(
class
stream
*
s
);
read
_cb
::
result_type
call_read
(
uint8_t
*
data
,
std
::
size_t
len
,
generator
_cb
::
result_type
call_read
(
uint8_t
*
data
,
std
::
size_t
len
,
uint32_t
*
data_flags
);
void
call_on_close
(
uint32_t
error_code
);
private:
class
stream
*
strm_
;
header_map
header_
;
read_cb
read
_cb_
;
generator_cb
generator
_cb_
;
close_cb
close_cb_
;
unsigned
int
status_code_
;
response_state
state_
;
...
...
src/includes/nghttp2/asio_http2.h
View file @
992c14e3
...
...
@@ -100,16 +100,16 @@ typedef std::function<void(uint32_t)> close_cb;
// of the error and request/response must be closed, return
// NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE.
typedef
std
::
function
<
ssize_t
(
uint8_t
*
buf
,
std
::
size_t
len
,
uint32_t
*
data_flags
)
>
read
_cb
;
ssize_t
(
uint8_t
*
buf
,
std
::
size_t
len
,
uint32_t
*
data_flags
)
>
generator
_cb
;
// Convenient function to create function to read file denoted by
// |path|. This can be passed to response::end().
read_cb
file_reade
r
(
const
std
::
string
&
path
);
generator_cb
file_generato
r
(
const
std
::
string
&
path
);
// Like file_
reade
r(const std::string&), but it takes opened file
// Like file_
generato
r(const std::string&), but it takes opened file
// descriptor. The passed descriptor will be closed when returned
// function object is destroyed.
read_cb
file_reade
r_from_fd
(
int
fd
);
generator_cb
file_generato
r_from_fd
(
int
fd
);
// Validates path so that it does not contain directory traversal
// vector. Returns true if path is safe. The |path| must start with
...
...
src/includes/nghttp2/asio_http2_client.h
View file @
992c14e3
...
...
@@ -165,7 +165,7 @@ public:
// nullptr and |ec| contains error message.
const
request
*
submit
(
boost
::
system
::
error_code
&
ec
,
const
std
::
string
&
method
,
const
std
::
string
&
uri
,
read
_cb
cb
,
header_map
h
=
{})
const
;
generator
_cb
cb
,
header_map
h
=
{})
const
;
private:
std
::
unique_ptr
<
session_impl
>
impl_
;
...
...
src/includes/nghttp2/asio_http2_server.h
View file @
992c14e3
...
...
@@ -79,7 +79,7 @@ public:
// Sets callback as a generator of the response body. No further
// call of end() is allowed.
void
end
(
read
_cb
cb
)
const
;
void
end
(
generator
_cb
cb
)
const
;
// Sets callback which is invoked when this request and response are
// finished. After the invocation of this callback, the application
...
...
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