Skip to content

Commit

Permalink
WT-12461: Correctly use WAsioWrapper
Browse files Browse the repository at this point in the history
Implementations that use a standalone asio (like the Windows builder for
releases) require the use of WAsioWrapper, instead of calling
boost::asio.
  • Loading branch information
matthias committed Oct 2, 2024
1 parent ae39464 commit 66e6df4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
16 changes: 6 additions & 10 deletions src/Wt/WWebSocketConnection.C
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ bool WebSocketConnection::doAsyncWrite(OpCode type, const std::vector<char>& fra
writeBuffer_.append(data.data(), data.size());

// Put data into asio::buffer actual write buffer
using namespace boost::asio;
using namespace AsioWrapper::asio;

std::vector<const_buffer> buffer;
writeBuffer_.asioBuffers(buffer);
Expand Down Expand Up @@ -482,7 +482,7 @@ void WebSocketConnection::doControlFrameWrite(const std::vector<char>& frameHead
// Put data into asio::buffer actual write buffer
writeBuffer_.append(frameHeader.data(), frameHeader.size());

using namespace boost::asio;
using namespace AsioWrapper::asio;

std::vector<const_buffer> buffer;
writeBuffer_.asioBuffers(buffer);
Expand Down Expand Up @@ -603,12 +603,10 @@ void WebSocketTcpConnection::doClose()

void WebSocketTcpConnection::doSocketRead(char* buffer, size_t size)
{
using namespace boost::asio;

socket_->async_read_some(boost::asio::buffer(buffer, size), strand_.wrap(std::bind(&WebSocketTcpConnection::handleAsyncRead, shared_from_this(), std::placeholders::_1, std::placeholders::_2)));
socket_->async_read_some(AsioWrapper::asio::buffer(buffer, size), strand_.wrap(std::bind(&WebSocketTcpConnection::handleAsyncRead, shared_from_this(), std::placeholders::_1, std::placeholders::_2)));
}

void WebSocketTcpConnection::doSocketWrite(const std::vector<boost::asio::const_buffer>& buffer, OpCode type)
void WebSocketTcpConnection::doSocketWrite(const std::vector<AsioWrapper::asio::const_buffer>& buffer, OpCode type)
{
async_write(socket(), buffer, strand_.wrap(std::bind(&WebSocketTcpConnection::handleAsyncWritten, shared_from_this(), type, std::placeholders::_1, std::placeholders::_2)));
}
Expand Down Expand Up @@ -661,12 +659,10 @@ void WebSocketSslConnection::stopTcpSocket(const AsioWrapper::error_code& e)

void WebSocketSslConnection::doSocketRead(char* buffer, size_t size)
{
using namespace boost::asio;

socket_->async_read_some(boost::asio::buffer(buffer, size), strand_.wrap(std::bind(&WebSocketSslConnection::handleAsyncRead, shared_from_this(), std::placeholders::_1, std::placeholders::_2)));
socket_->async_read_some(AsioWrapper::asio::buffer(buffer, size), strand_.wrap(std::bind(&WebSocketSslConnection::handleAsyncRead, shared_from_this(), std::placeholders::_1, std::placeholders::_2)));
}

void WebSocketSslConnection::doSocketWrite(const std::vector<boost::asio::const_buffer>& buffer, OpCode type)
void WebSocketSslConnection::doSocketWrite(const std::vector<AsioWrapper::asio::const_buffer>& buffer, OpCode type)
{
async_write(*socket_, buffer, strand_.wrap(std::bind(&WebSocketSslConnection::handleAsyncWritten, shared_from_this(), type, std::placeholders::_1, std::placeholders::_2)));
}
Expand Down
12 changes: 6 additions & 6 deletions src/Wt/WWebSocketConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class WT_API WebSocketConnection : public std::enable_shared_from_this<WebSocket

virtual void doSocketRead(char* buffer, size_t size) = 0;
// Performs an async write to the socket, inside the write-done loop.
virtual void doSocketWrite(const std::vector<boost::asio::const_buffer>& buffer, OpCode type) = 0;
virtual void doSocketWrite(const std::vector<AsioWrapper::asio::const_buffer>& buffer, OpCode type) = 0;

private:
// Buffer & parsing
Expand Down Expand Up @@ -174,9 +174,9 @@ class WT_API WebSocketConnection : public std::enable_shared_from_this<WebSocket
bool hasPendingPingWrite_;
bool hasPendingPongWrite_;
OpCode pendingWriteDataType_;
std::vector<boost::asio::const_buffer> pendingWritePingBuffer_;
std::vector<boost::asio::const_buffer> pendingWritePongBuffer_;
std::vector<boost::asio::const_buffer> pendingWriteDataBuffer_;
std::vector<AsioWrapper::asio::const_buffer> pendingWritePingBuffer_;
std::vector<AsioWrapper::asio::const_buffer> pendingWritePongBuffer_;
std::vector<AsioWrapper::asio::const_buffer> pendingWriteDataBuffer_;

std::function<void()> hasDataReadCallback_;
std::function<void(const AsioWrapper::error_code&, std::size_t)> hasDataWrittenCallback_;
Expand All @@ -199,7 +199,7 @@ class WT_API WebSocketTcpConnection final : public WebSocketConnection

protected:
void doSocketRead(char* input, size_t offset) final;
void doSocketWrite(const std::vector<boost::asio::const_buffer>& buffer, OpCode type) final;
void doSocketWrite(const std::vector<AsioWrapper::asio::const_buffer>& buffer, OpCode type) final;

private:
std::unique_ptr<Socket> socket_;
Expand All @@ -219,7 +219,7 @@ class WT_API WebSocketSslConnection final : public WebSocketConnection

protected:
void doSocketRead(char* input, size_t offset) final;
void doSocketWrite(const std::vector<boost::asio::const_buffer>& buffer, OpCode type) final;
void doSocketWrite(const std::vector<AsioWrapper::asio::const_buffer>& buffer, OpCode type) final;

private:
std::unique_ptr<SSLSocket> socket_;
Expand Down

0 comments on commit 66e6df4

Please sign in to comment.