prevent copying of buffers
This commit is contained in:
parent
1f5f641d8b
commit
71eba4c5d3
|
|
@ -348,7 +348,7 @@ public:
|
||||||
*
|
*
|
||||||
* @param buffer the buffer with data to send
|
* @param buffer the buffer with data to send
|
||||||
*/
|
*/
|
||||||
bool send(const CopiedBuffer &buffer);
|
bool send(CopiedBuffer &&buffer);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a channel by its identifier
|
* Get a channel by its identifier
|
||||||
|
|
|
||||||
|
|
@ -82,17 +82,10 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copy constructor
|
* Disabled copy constructor to prevent expensive copy operations
|
||||||
* @param that
|
* @param that
|
||||||
*/
|
*/
|
||||||
CopiedBuffer(const CopiedBuffer &that) :
|
CopiedBuffer(const CopiedBuffer &that) = delete;
|
||||||
_capacity(that._capacity),
|
|
||||||
_buffer((char *)malloc(_capacity)),
|
|
||||||
_size(that._size)
|
|
||||||
{
|
|
||||||
// copy the data
|
|
||||||
memcpy(_buffer, that._buffer, _size);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Move constructor
|
* Move constructor
|
||||||
|
|
|
||||||
|
|
@ -727,15 +727,15 @@ void ChannelImpl::onSynchronized()
|
||||||
while (_connection && !_synchronous && !_queue.empty())
|
while (_connection && !_synchronous && !_queue.empty())
|
||||||
{
|
{
|
||||||
// retrieve the first buffer and synchronous
|
// retrieve the first buffer and synchronous
|
||||||
const auto &pair = _queue.front();
|
auto &pair = _queue.front();
|
||||||
|
|
||||||
// mark as synchronous if necessary
|
// mark as synchronous if necessary
|
||||||
_synchronous = pair.first;
|
_synchronous = pair.first;
|
||||||
|
|
||||||
// send it over the connection
|
// send it over the connection
|
||||||
_connection->send(pair.second);
|
_connection->send(std::move(pair.second));
|
||||||
|
|
||||||
// the user space handler may have destructed the channel
|
// the user space handler may have destructed this channel object
|
||||||
if (!monitor.valid()) return;
|
if (!monitor.valid()) return;
|
||||||
|
|
||||||
// remove from the list
|
// remove from the list
|
||||||
|
|
|
||||||
|
|
@ -353,7 +353,7 @@ bool ConnectionImpl::send(const Frame &frame)
|
||||||
*
|
*
|
||||||
* @param buffer the buffer with data to send
|
* @param buffer the buffer with data to send
|
||||||
*/
|
*/
|
||||||
bool ConnectionImpl::send(const CopiedBuffer &buffer)
|
bool ConnectionImpl::send(CopiedBuffer &&buffer)
|
||||||
{
|
{
|
||||||
// this only works when we are already connected
|
// this only works when we are already connected
|
||||||
if (_state != state_connected) return false;
|
if (_state != state_connected) return false;
|
||||||
|
|
@ -367,7 +367,7 @@ bool ConnectionImpl::send(const CopiedBuffer &buffer)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// add to the list of waiting buffers
|
// add to the list of waiting buffers
|
||||||
_queue.push(buffer);
|
_queue.emplace(std::move(buffer));
|
||||||
}
|
}
|
||||||
|
|
||||||
// done
|
// done
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue