Skip to content

Commit

Permalink
bug fix for multiple socket closes
Browse files Browse the repository at this point in the history
  • Loading branch information
Niall Ryan authored and Niall Ryan committed Mar 7, 2011
1 parent dbc992e commit 0e9704b
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions Cpp/Source/ProtoBufRemote/SocketRpcChannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace ProtoBufRemote {

SocketRpcChannel::SocketRpcChannel(RpcController* controller, SOCKET socket)
: RpcChannel(controller), m_socket(socket)
: RpcChannel(controller), m_socket(socket), m_thread(0)
{
m_sendEvent = WSACreateEvent();
m_terminateEvent = WSACreateEvent();
Expand All @@ -29,14 +29,22 @@ SocketRpcChannel::~SocketRpcChannel()

void SocketRpcChannel::Start()
{
m_thread = reinterpret_cast<HANDLE>(_beginthreadex(NULL, 0, &SocketRpcChannel::ThreadRun, this, 0, NULL));
if (!m_thread)
{
m_thread = reinterpret_cast<HANDLE>(_beginthreadex(NULL, 0, &SocketRpcChannel::ThreadRun, this, 0, NULL));
}
}

void SocketRpcChannel::CloseAndJoin()
{
WSASetEvent(m_terminateEvent);
WaitForSingleObject(m_thread, INFINITE);
CloseHandle(m_thread);
if (m_thread)
{
WSASetEvent(m_terminateEvent);
WaitForSingleObject(m_thread, INFINITE);
WSAResetEvent(m_terminateEvent);
CloseHandle(m_thread);
m_thread = 0;
}
}

unsigned int SocketRpcChannel::GetAndClearBytesRead()
Expand Down

0 comments on commit 0e9704b

Please sign in to comment.