Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ISC Open Source Projects
Kea
Commits
43394f76
Commit
43394f76
authored
Apr 25, 2017
by
Marcin Siodelski
Browse files
[master] Merge branch 'trac5260'
parents
b30f1095
10eaa838
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/lib/http/connection.cc
View file @
43394f76
...
...
@@ -34,10 +34,6 @@ HttpConnection:: HttpConnection(asiolink::IOService& io_service,
:
request_timer_
(
io_service
),
request_timeout_
(
request_timeout
),
socket_
(
io_service
),
socket_callback_
(
boost
::
bind
(
&
HttpConnection
::
socketReadCallback
,
this
,
_1
,
_2
)),
socket_write_callback_
(
boost
::
bind
(
&
HttpConnection
::
socketWriteCallback
,
this
,
_1
,
_2
)),
acceptor_
(
acceptor
),
connection_pool_
(
connection_pool
),
response_creator_
(
response_creator
),
...
...
@@ -54,6 +50,7 @@ HttpConnection::~HttpConnection() {
void
HttpConnection
::
close
()
{
request_timer_
.
cancel
();
socket_
.
close
();
}
...
...
@@ -71,8 +68,12 @@ HttpConnection::stopThisConnection() {
void
HttpConnection
::
asyncAccept
()
{
// Create instance of the callback. It is safe to pass the local instance
// of the callback, because the underlying boost functions make copies
// as needed.
HttpAcceptorCallback
cb
=
boost
::
bind
(
&
HttpConnection
::
acceptorCallback
,
this
,
_1
);
shared_from_this
(),
boost
::
asio
::
placeholders
::
error
);
try
{
acceptor_
.
asyncAccept
(
socket_
,
cb
);
...
...
@@ -86,8 +87,15 @@ void
HttpConnection
::
doRead
()
{
try
{
TCPEndpoint
endpoint
;
// Create instance of the callback. It is safe to pass the local instance
// of the callback, because the underlying boost functions make copies
// as needed.
SocketCallback
cb
(
boost
::
bind
(
&
HttpConnection
::
socketReadCallback
,
shared_from_this
(),
boost
::
asio
::
placeholders
::
error
,
boost
::
asio
::
placeholders
::
bytes_transferred
));
socket_
.
asyncReceive
(
static_cast
<
void
*>
(
buf_
.
data
()),
buf_
.
size
(),
0
,
&
endpoint
,
socket_callback_
);
0
,
&
endpoint
,
cb
);
}
catch
(
const
std
::
exception
&
ex
)
{
stopThisConnection
();
...
...
@@ -98,9 +106,16 @@ void
HttpConnection
::
doWrite
()
{
try
{
if
(
!
output_buf_
.
empty
())
{
// Create instance of the callback. It is safe to pass the local instance
// of the callback, because the underlying boost functions make copies
// as needed.
SocketCallback
cb
(
boost
::
bind
(
&
HttpConnection
::
socketWriteCallback
,
shared_from_this
(),
boost
::
asio
::
placeholders
::
error
,
boost
::
asio
::
placeholders
::
bytes_transferred
));
socket_
.
asyncSend
(
output_buf_
.
data
(),
output_buf_
.
length
(),
socket_write_callback_
);
cb
);
}
else
{
stopThisConnection
();
}
...
...
@@ -133,7 +148,8 @@ HttpConnection::acceptorCallback(const boost::system::error_code& ec) {
HTTP_REQUEST_RECEIVE_START
)
.
arg
(
getRemoteEndpointAddressAsText
())
.
arg
(
static_cast
<
unsigned
>
(
request_timeout_
/
1000
));
request_timer_
.
setup
(
boost
::
bind
(
&
HttpConnection
::
requestTimeoutCallback
,
this
),
request_timer_
.
setup
(
boost
::
bind
(
&
HttpConnection
::
requestTimeoutCallback
,
shared_from_this
()),
request_timeout_
,
IntervalTimer
::
ONE_SHOT
);
doRead
();
}
...
...
src/lib/http/connection.h
View file @
43394f76
...
...
@@ -187,12 +187,6 @@ private:
/// @brief Socket used by this connection.
asiolink
::
TCPSocket
<
SocketCallback
>
socket_
;
/// @brief Callback invoked when data received over the socket.
SocketCallback
socket_callback_
;
/// @brief Callback invoked when data sent over the socket.
SocketCallback
socket_write_callback_
;
/// @brief Reference to the TCP acceptor used to accept new connections.
HttpAcceptor
&
acceptor_
;
...
...
src/lib/http/tests/listener_unittests.cc
View file @
43394f76
...
...
@@ -168,10 +168,21 @@ public:
[
this
,
request
](
const
boost
::
system
::
error_code
&
ec
,
std
::
size_t
bytes_transferred
)
mutable
{
if
(
ec
)
{
ADD_FAILURE
()
<<
"error occurred while connecting: "
<<
ec
.
message
();
io_service_
.
stop
();
return
;
if
(
ec
.
value
()
==
boost
::
asio
::
error
::
operation_aborted
)
{
return
;
}
else
if
((
ec
.
value
()
==
boost
::
asio
::
error
::
try_again
)
||
(
ec
.
value
()
==
boost
::
asio
::
error
::
would_block
))
{
// If we should try again make sure there is no garbage in the
// bytes_transferred.
bytes_transferred
=
0
;
}
else
{
ADD_FAILURE
()
<<
"error occurred while connecting: "
<<
ec
.
message
();
io_service_
.
stop
();
return
;
}
}
// Remove the part of the request which has been sent.
...
...
@@ -199,14 +210,21 @@ public:
std
::
size_t
bytes_transferred
)
{
if
(
ec
)
{
// IO service stopped so simply return.
if
(
ec
==
boost
::
asio
::
error
::
operation_aborted
)
{
if
(
ec
.
value
()
==
boost
::
asio
::
error
::
operation_aborted
)
{
return
;
}
// Error occurred, bail...
ADD_FAILURE
()
<<
"error occurred while receiving HTTP"
" response from the server: "
<<
ec
.
message
();
io_service_
.
stop
();
}
else
if
((
ec
.
value
()
==
boost
::
asio
::
error
::
try_again
)
||
(
ec
.
value
()
==
boost
::
asio
::
error
::
would_block
))
{
// If we should try again, make sure that there is no garbage
// in the bytes_transferred.
bytes_transferred
=
0
;
}
else
{
// Error occurred, bail...
ADD_FAILURE
()
<<
"error occurred while receiving HTTP"
" response from the server: "
<<
ec
.
message
();
io_service_
.
stop
();
}
}
if
(
bytes_transferred
>
0
)
{
...
...
Write
Preview
Supports
Markdown
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