Core/Socket: Removed unused synchronous read method

This commit is contained in:
Shauren
2015-04-24 00:10:04 +02:00
parent 15a5eb4e35
commit 59e9bcf0bf
3 changed files with 6 additions and 23 deletions

View File

@@ -81,8 +81,8 @@ void WorldSocket::Start()
initializer.Write(&header, sizeof(header.Setup.Size));
initializer.Write(ServerConnectionInitialize.c_str(), ServerConnectionInitialize.length());
std::unique_lock<std::mutex> dummy(_writeLock, std::defer_lock);
QueuePacket(std::move(initializer), dummy);
std::unique_lock<std::mutex> guard(_writeLock);
QueuePacket(std::move(initializer), guard);
}
void WorldSocket::HandleSendAuthSession()

View File

@@ -50,6 +50,7 @@ public:
virtual ~Socket()
{
_closed = true;
boost::system::error_code error;
_socket.close(error);
}
@@ -97,26 +98,6 @@ public:
std::bind(&Socket<T>::ReadHandlerInternal, this->shared_from_this(), std::placeholders::_1, std::placeholders::_2));
}
void ReadData(std::size_t size)
{
if (!IsOpen())
return;
boost::system::error_code error;
std::size_t bytesRead = boost::asio::read(_socket, boost::asio::buffer(_readBuffer.GetWritePointer(), size), error);
_readBuffer.WriteCompleted(bytesRead);
if (error || bytesRead != size)
{
TC_LOG_DEBUG("network", "Socket::ReadData: %s errored with: %i (%s)", GetRemoteIpAddress().to_string().c_str(), error.value(),
error.message().c_str());
CloseSocket();
}
}
void QueuePacket(MessageBuffer&& buffer, std::unique_lock<std::mutex>& guard)
{
_writeQueue.push(std::move(buffer));

View File

@@ -70,7 +70,9 @@ public:
{
std::unique_lock<std::mutex> lock(_queueLock);
_condition.wait(lock, [this]() { return !_queue.empty() || _shutdown; });
// we could be using .wait(lock, predicate) overload here but some threading error analysis tools produce false positives
while (_queue.empty() && !_shutdown)
_condition.wait(lock);
if (_queue.empty() || _shutdown)
return;