don't try to read from socket after it's been closed

This commit is contained in:
Eric House 2013-07-04 12:37:55 -07:00
parent e6248210a5
commit 4b5af7ebdf

View file

@ -1055,6 +1055,7 @@ linux_close_socket( CommonGlobals* cGlobals )
int
blocking_read( int fd, unsigned char* buf, const int len )
{
assert( -1 != fd );
int nRead = 0;
while ( nRead < len ) {
ssize_t siz = read( fd, buf + nRead, len - nRead );
@ -1073,9 +1074,11 @@ blocking_read( int fd, unsigned char* buf, const int len )
int
linux_relay_receive( CommonGlobals* cGlobals, unsigned char* buf, int bufSize )
{
ssize_t nRead = -1;
int sock = cGlobals->socket;
if ( -1 != sock ) {
unsigned short tmp;
ssize_t nRead = blocking_read( sock, (unsigned char*)&tmp, sizeof(tmp) );
nRead = blocking_read( sock, (unsigned char*)&tmp, sizeof(tmp) );
if ( nRead != 2 ) {
nRead = -1;
} else {
@ -1113,7 +1116,7 @@ linux_relay_receive( CommonGlobals* cGlobals, unsigned char* buf, int bufSize )
linux_close_socket( cGlobals );
comms_transportFailed( cGlobals->game.comms );
}
}
XP_LOGF( "%s=>%d", __func__, nRead );
return nRead;
} /* linux_relay_receive */