use read_packet to replace duplicate code

This commit is contained in:
Andy2 2010-09-21 06:38:43 -07:00
parent e7b5923883
commit be23e06b60
2 changed files with 8 additions and 21 deletions

View file

@ -181,28 +181,13 @@ XWThreadPool::get_process_packet( int socket )
short packetSize;
assert( sizeof(packetSize) == 2 );
ssize_t nRead = recv( socket, &packetSize,
sizeof(packetSize), MSG_WAITALL );
if ( nRead != 2 ) {
EnqueueKill( socket, "nRead != 2" );
unsigned char buf[MAX_MSG_LEN];
int nRead = read_packet( socket, buf, sizeof(buf) );
if ( nRead < 0 ) {
EnqueueKill( socket, "bad packet" );
} else {
packetSize = ntohs( packetSize );
if ( packetSize < 0 || packetSize > MAX_MSG_LEN ) {
EnqueueKill( socket, "packetSize wrong" );
} else {
unsigned char buf[MAX_MSG_LEN];
nRead = recv( socket, buf, packetSize, MSG_WAITALL );
if ( nRead != packetSize ) {
EnqueueKill( socket, "nRead != packetSize" );
} else {
logf( XW_LOGINFO, "read %d bytes", nRead );
logf( XW_LOGINFO, "calling m_pFunc" );
success = (*m_pFunc)( buf, packetSize, socket );
}
}
logf( XW_LOGINFO, "calling m_pFunc" );
success = (*m_pFunc)( buf, nRead, socket );
}
return success;
} /* get_process_packet */

View file

@ -27,6 +27,8 @@ int GetNSpawns(void);
int make_socket( unsigned long addr, unsigned short port );
int read_packet( int sock, unsigned char* buf, int buflen );
const char* cmdToStr( XWRELAY_Cmd cmd );
extern class ListenerMgr g_listeners;