diff --git a/src/net/common/senderthread.cpp b/src/net/common/senderthread.cpp index e064c3fc..49bd1628 100644 --- a/src/net/common/senderthread.cpp +++ b/src/net/common/senderthread.cpp @@ -92,9 +92,17 @@ SenderThread::Main() int selectResult = select(m_curSocket + 1, NULL, &writeSet, NULL, &timeout); if (!IS_VALID_SELECT(selectResult)) { - m_callback.SignalNetError(m_curSocket, ERR_SOCK_SELECT_FAILED, SOCKET_ERRNO()); - // Assume that this is a fatal error, terminate thread. - return; + // Never assume that this is a fatal error. + int errCode = SOCKET_ERRNO(); + if (errCode != SOCKET_ERR_WOULDBLOCK) + { + // Skip this packet - this is bad, and is therefore reported. + // Ignore invalid or not connected sockets. + if (errCode != SOCKET_ERR_NOTCONN && errCode != SOCKET_ERR_NOTSOCK) + m_callback.SignalNetError(m_curSocket, ERR_SOCK_SELECT_FAILED, errCode); + m_tmpOutBufSize = 0; + } + Msleep(SEND_TIMEOUT_MSEC); } if (selectResult > 0) // send is possible { @@ -103,9 +111,17 @@ SenderThread::Main() if (!IS_VALID_SEND(bytesSent)) { - m_callback.SignalNetError(m_curSocket, ERR_SOCK_SEND_FAILED, SOCKET_ERRNO()); - // Assume that this is a fatal error, terminate thread. - return; + // Never assume that this is a fatal error. + int errCode = SOCKET_ERRNO(); + if (errCode != SOCKET_ERR_WOULDBLOCK) + { + // Skip this packet - this is bad, and is therefore reported. + // Ignore invalid or not connected sockets. + if (errCode != SOCKET_ERR_NOTCONN && errCode != SOCKET_ERR_NOTSOCK) + m_callback.SignalNetError(m_curSocket, ERR_SOCK_SEND_FAILED, errCode); + m_tmpOutBufSize = 0; + } + Msleep(SEND_TIMEOUT_MSEC); } else if ((unsigned)bytesSent < m_tmpOutBufSize) { diff --git a/src/net/common/serverrecvstate.cpp b/src/net/common/serverrecvstate.cpp index 613d1b56..91e912fb 100644 --- a/src/net/common/serverrecvstate.cpp +++ b/src/net/common/serverrecvstate.cpp @@ -426,17 +426,19 @@ ServerRecvStateStartHand::Process(ServerRecvThread &server) // Send cards to all players. for (int i = 0; i < curGame.getStartQuantityPlayers(); i++) { - assert(playerArray[i]->getNetSessionData().get()); // TODO throw exception + // also send to inactive players, but not to disconnected players. + if (playerArray[i]->getNetSessionData().get()) + { + int cards[2]; + playerArray[i]->getMyCards(cards); + boost::shared_ptr notifyCards(new NetPacketHandStart); + NetPacketHandStart::Data handStartData; + handStartData.yourCards[0] = static_cast(cards[0]); + handStartData.yourCards[1] = static_cast(cards[1]); + static_cast(notifyCards.get())->SetData(handStartData); - int cards[2]; - playerArray[i]->getMyCards(cards); - boost::shared_ptr notifyCards(new NetPacketHandStart); - NetPacketHandStart::Data handStartData; - handStartData.yourCards[0] = static_cast(cards[0]); - handStartData.yourCards[1] = static_cast(cards[1]); - static_cast(notifyCards.get())->SetData(handStartData); - - server.GetSender().Send(playerArray[i]->getNetSessionData()->GetSocket(), notifyCards); + server.GetSender().Send(playerArray[i]->getNetSessionData()->GetSocket(), notifyCards); + } } // Start hand. diff --git a/src/net/common/serverrecvthread.cpp b/src/net/common/serverrecvthread.cpp index 6331014b..d7e83a55 100644 --- a/src/net/common/serverrecvthread.cpp +++ b/src/net/common/serverrecvthread.cpp @@ -476,13 +476,11 @@ ServerRecvThread::RemoveDisconnectedPlayers() for (int i = 0; i < m_game->getStartQuantityPlayers(); i++) { PlayerInterface *tmpPlayer = m_game->getPlayerArray()[i]; - if (tmpPlayer->getMyActiveStatus()) + if (!IsPlayerConnected(tmpPlayer->getMyUniqueID())) { - if (!IsPlayerConnected(tmpPlayer->getMyUniqueID())) - { - tmpPlayer->setMyCash(0); - tmpPlayer->setMyActiveStatus(false); - } + tmpPlayer->setMyCash(0); + tmpPlayer->setMyActiveStatus(false); + tmpPlayer->setNetSessionData(boost::shared_ptr()); } } } diff --git a/src/net/senderthread.h b/src/net/senderthread.h index ed09a030..bd74c7af 100644 --- a/src/net/senderthread.h +++ b/src/net/senderthread.h @@ -30,8 +30,8 @@ #include #define SENDER_THREAD_TERMINATE_TIMEOUT 200 -#define SEND_TIMEOUT_MSEC 50 -#define SEND_QUEUE_SIZE 200 +#define SEND_TIMEOUT_MSEC 10 +#define SEND_QUEUE_SIZE 500 class SenderThread : public Thread { diff --git a/src/net/socket_helper.h b/src/net/socket_helper.h index a05b390a..aef409c0 100644 --- a/src/net/socket_helper.h +++ b/src/net/socket_helper.h @@ -32,6 +32,8 @@ #define IOCTLSOCKET ioctlsocket #define SOCKET_ERRNO() WSAGetLastError() #define SOCKET_ERR_WOULDBLOCK WSAEWOULDBLOCK +#define SOCKET_ERR_NOTCONN WSAENOTCONN +#define SOCKET_ERR_NOTSOCK WSAENOTSOCK typedef unsigned __int16 u_int16_t; typedef unsigned __int32 u_int32_t; @@ -47,6 +49,8 @@ typedef unsigned char u_char; #define SOCKET_ERRNO() errno #define IOCTLSOCKET ioctl #define SOCKET_ERR_WOULDBLOCK EINPROGRESS +#define SOCKET_ERR_NOTCONN ENOTCONN +#define SOCKET_ERR_NOTSOCK ENOTSOCK #endif