Fixed player disconnects (again).

This commit is contained in:
lotodore
2007-06-15 20:56:31 +00:00
parent 0f04c39a5b
commit 4e6a78dcb5
5 changed files with 44 additions and 24 deletions
+22 -6
View File
@@ -92,9 +92,17 @@ SenderThread::Main()
int selectResult = select(m_curSocket + 1, NULL, &writeSet, NULL, &timeout); int selectResult = select(m_curSocket + 1, NULL, &writeSet, NULL, &timeout);
if (!IS_VALID_SELECT(selectResult)) if (!IS_VALID_SELECT(selectResult))
{ {
m_callback.SignalNetError(m_curSocket, ERR_SOCK_SELECT_FAILED, SOCKET_ERRNO()); // Never assume that this is a fatal error.
// Assume that this is a fatal error, terminate thread. int errCode = SOCKET_ERRNO();
return; 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 if (selectResult > 0) // send is possible
{ {
@@ -103,9 +111,17 @@ SenderThread::Main()
if (!IS_VALID_SEND(bytesSent)) if (!IS_VALID_SEND(bytesSent))
{ {
m_callback.SignalNetError(m_curSocket, ERR_SOCK_SEND_FAILED, SOCKET_ERRNO()); // Never assume that this is a fatal error.
// Assume that this is a fatal error, terminate thread. int errCode = SOCKET_ERRNO();
return; 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) else if ((unsigned)bytesSent < m_tmpOutBufSize)
{ {
+4 -2
View File
@@ -426,8 +426,9 @@ ServerRecvStateStartHand::Process(ServerRecvThread &server)
// Send cards to all players. // Send cards to all players.
for (int i = 0; i < curGame.getStartQuantityPlayers(); i++) 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]; int cards[2];
playerArray[i]->getMyCards(cards); playerArray[i]->getMyCards(cards);
boost::shared_ptr<NetPacket> notifyCards(new NetPacketHandStart); boost::shared_ptr<NetPacket> notifyCards(new NetPacketHandStart);
@@ -438,6 +439,7 @@ ServerRecvStateStartHand::Process(ServerRecvThread &server)
server.GetSender().Send(playerArray[i]->getNetSessionData()->GetSocket(), notifyCards); server.GetSender().Send(playerArray[i]->getNetSessionData()->GetSocket(), notifyCards);
} }
}
// Start hand. // Start hand.
curGame.startHand(); curGame.startHand();
+1 -3
View File
@@ -476,13 +476,11 @@ ServerRecvThread::RemoveDisconnectedPlayers()
for (int i = 0; i < m_game->getStartQuantityPlayers(); i++) for (int i = 0; i < m_game->getStartQuantityPlayers(); i++)
{ {
PlayerInterface *tmpPlayer = m_game->getPlayerArray()[i]; PlayerInterface *tmpPlayer = m_game->getPlayerArray()[i];
if (tmpPlayer->getMyActiveStatus())
{
if (!IsPlayerConnected(tmpPlayer->getMyUniqueID())) if (!IsPlayerConnected(tmpPlayer->getMyUniqueID()))
{ {
tmpPlayer->setMyCash(0); tmpPlayer->setMyCash(0);
tmpPlayer->setMyActiveStatus(false); tmpPlayer->setMyActiveStatus(false);
} tmpPlayer->setNetSessionData(boost::shared_ptr<SessionData>());
} }
} }
} }
+2 -2
View File
@@ -30,8 +30,8 @@
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>
#define SENDER_THREAD_TERMINATE_TIMEOUT 200 #define SENDER_THREAD_TERMINATE_TIMEOUT 200
#define SEND_TIMEOUT_MSEC 50 #define SEND_TIMEOUT_MSEC 10
#define SEND_QUEUE_SIZE 200 #define SEND_QUEUE_SIZE 500
class SenderThread : public Thread class SenderThread : public Thread
{ {
+4
View File
@@ -32,6 +32,8 @@
#define IOCTLSOCKET ioctlsocket #define IOCTLSOCKET ioctlsocket
#define SOCKET_ERRNO() WSAGetLastError() #define SOCKET_ERRNO() WSAGetLastError()
#define SOCKET_ERR_WOULDBLOCK WSAEWOULDBLOCK #define SOCKET_ERR_WOULDBLOCK WSAEWOULDBLOCK
#define SOCKET_ERR_NOTCONN WSAENOTCONN
#define SOCKET_ERR_NOTSOCK WSAENOTSOCK
typedef unsigned __int16 u_int16_t; typedef unsigned __int16 u_int16_t;
typedef unsigned __int32 u_int32_t; typedef unsigned __int32 u_int32_t;
@@ -47,6 +49,8 @@ typedef unsigned char u_char;
#define SOCKET_ERRNO() errno #define SOCKET_ERRNO() errno
#define IOCTLSOCKET ioctl #define IOCTLSOCKET ioctl
#define SOCKET_ERR_WOULDBLOCK EINPROGRESS #define SOCKET_ERR_WOULDBLOCK EINPROGRESS
#define SOCKET_ERR_NOTCONN ENOTCONN
#define SOCKET_ERR_NOTSOCK ENOTSOCK
#endif #endif