Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions src/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ bool Server::Connect(int port)
bool Server::PollSockets()
{
static struct timeval tv;

Socket* sclose = NULL;
// copy the permanent descriptor set
memcpy(&rSet, &fSet, sizeof(fd_set));

Expand All @@ -92,13 +92,27 @@ bool Server::PollSockets()
for (Socket* sock: socketList)
{

// if previous socket marked for close, then close it
if (sclose)
{
CloseSocket(sclose);
sclose = NULL; //reset close pointer
}
// attempt to read from this socket if pending incoming data
if (FD_ISSET(sock->GetControl(), &rSet))
{

// if read fails, close the connection
// if read fails, close the connection, after iterater advances
if (sock->Read() == false)
CloseSocket(sock);
{
if(sock == socketList.back())
{
CloseSocket(sock);
}
else
{
sclose = sock;
}
}
}

Expand Down