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
f3a43f9c
Commit
f3a43f9c
authored
Jan 11, 2017
by
Marcin Siodelski
Browse files
[5099] Implemented asyncSend variant without the 2-byte count.
parent
dba214ec
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/lib/asiolink/tcp_socket.h
View file @
f3a43f9c
...
...
@@ -113,6 +113,19 @@ public:
virtual
void
asyncSend
(
const
void
*
data
,
size_t
length
,
const
IOEndpoint
*
endpoint
,
C
&
callback
);
/// \brief Send Asynchronously without count.
///
/// This variant of the method sends data over the TCP socket without
/// preceding the data with a data count. Eventually, we should migrate
/// the virtual method to not insert the count but there are existing
/// classes using the count. Once this migration is done, the existing
/// virtual method should be replaced by this method.
///
/// \param data Data to send
/// \param length Length of data to send
/// \param callback Callback object.
void
asyncSend
(
const
void
*
data
,
size_t
length
,
C
&
callback
);
/// \brief Receive Asynchronously
///
/// Calls the underlying socket's async_receive() method to read a packet
...
...
@@ -248,6 +261,30 @@ TCPSocket<C>::open(const IOEndpoint* endpoint, C& callback) {
// Send a message. Should never do this if the socket is not open, so throw
// an exception if this is the case.
template
<
typename
C
>
void
TCPSocket
<
C
>::
asyncSend
(
const
void
*
data
,
size_t
length
,
C
&
callback
)
{
if
(
socket_
.
is_open
())
{
try
{
send_buffer_
.
reset
(
new
isc
::
util
::
OutputBuffer
(
length
));
send_buffer_
->
writeData
(
data
,
length
);
// Send the data.
socket_
.
async_send
(
boost
::
asio
::
buffer
(
send_buffer_
->
getData
(),
send_buffer_
->
getLength
()),
callback
);
}
catch
(
boost
::
numeric
::
bad_numeric_cast
&
)
{
isc_throw
(
BufferTooLarge
,
"attempt to send buffer larger than 64kB"
);
}
}
else
{
isc_throw
(
SocketNotOpen
,
"attempt to send on a TCP socket that is not open"
);
}
}
template
<
typename
C
>
void
TCPSocket
<
C
>::
asyncSend
(
const
void
*
data
,
size_t
length
,
const
IOEndpoint
*
,
C
&
callback
)
...
...
@@ -262,7 +299,8 @@ TCPSocket<C>::asyncSend(const void* data, size_t length,
uint16_t
count
=
boost
::
numeric_cast
<
uint16_t
>
(
length
);
// Copy data into a buffer preceded by the count field.
send_buffer_
.
reset
(
new
isc
::
util
::
OutputBuffer
(
length
));
send_buffer_
.
reset
(
new
isc
::
util
::
OutputBuffer
(
length
+
2
));
send_buffer_
->
writeUint16
(
count
);
send_buffer_
->
writeData
(
data
,
length
);
// ... and send it
...
...
src/lib/http/connection.cc
View file @
f3a43f9c
...
...
@@ -67,9 +67,8 @@ HttpConnection::doRead() {
void
HttpConnection
::
doWrite
()
{
if
(
!
output_buf_
.
empty
())
{
TCPEndpoint
endpoint
;
socket_
.
asyncSend
(
output_buf_
.
data
(),
output_buf_
.
length
(),
&
endpoint
,
output_buf_
.
length
(),
socket_write_callback_
);
}
}
...
...
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