}
/* -------------------------------------------------------------------
- * Receieve data from the (connected) TCP/UDP socket.
+ * Receive data from the (connected) socket.
* Sends termination flag several times at the end.
* Does not close the socket.
* ------------------------------------------------------------------- */
void Server::Run( void ) {
long currLen;
- struct UDP_datagram* mBuf_UDP = (struct UDP_datagram*) mBuf;
+ struct dgram_record* dgram_rec = (struct dgram_record*) mBuf;
ReportStruct *reportstruct = NULL;
// perform read
currLen = recv( mSettings->mSock, mBuf, mSettings->mBufLen, 0 );
- if ( isUDP( mSettings ) ) {
+ if ( isPacketOriented( mSettings ) ) {
// read the datagram ID and sentTime out of the buffer
- reportstruct->packetID = ntohl( mBuf_UDP->id );
- reportstruct->sentTime.tv_sec = ntohl( mBuf_UDP->tv_sec );
- reportstruct->sentTime.tv_usec = ntohl( mBuf_UDP->tv_usec );
+ reportstruct->packetID = ntohl( dgram_rec->id );
+ reportstruct->sentTime.tv_sec = ntohl( dgram_rec->tv_sec );
+ reportstruct->sentTime.tv_usec = ntohl( dgram_rec->tv_usec );
}
reportstruct->packetLen = currLen;
// the datagram ID should be correct, just negated
if ( reportstruct->packetID < 0 ) {
reportstruct->packetID = -reportstruct->packetID;
+ // Don't count the FIN message in connection-oriented protocols.
+ if (!isConnectionLess(mSettings))
+ break;
currLen = -1;
}
ReportPacket( mSettings->reporthdr, reportstruct );
gettimeofday( &(reportstruct->packetTime), NULL );
CloseReport( mSettings->reporthdr, reportstruct );
+ // send back an acknowledgement of the terminating datagram
// send a acknowledgement back only if we're NOT receiving multicast
- if ( isUDP( mSettings ) && !isMulticast( mSettings ) ) {
- // send back an acknowledgement of the terminating datagram
- write_UDP_AckFIN( );
- }
+ if ( isPacketOriented( mSettings ) && !isMulticast( mSettings ) )
+ write_dgram_AckFin( );
} else {
FAIL(1, "Out of memory! Closing server thread\n", mSettings);
}
* termination datagrams, so re-transmit our AckFIN.
* ------------------------------------------------------------------- */
-void Server::write_UDP_AckFIN( ) {
+void Server::write_dgram_AckFin( ) {
int rc;
while ( count < 10 ) {
count++;
- UDP_datagram *UDP_Hdr;
+ dgram_record *dgram_rec;
server_hdr *hdr;
- UDP_Hdr = (UDP_datagram*) mBuf;
+ dgram_rec = (dgram_record*) mBuf;
- if ( mSettings->mBufLen > (int) ( sizeof( UDP_datagram )
+ if ( mSettings->mBufLen > (int) ( sizeof( dgram_record )
+ sizeof( server_hdr ) ) ) {
Transfer_Info *stats = GetReport( mSettings->reporthdr );
- hdr = (server_hdr*) (UDP_Hdr+1);
+ hdr = (server_hdr*) (dgram_rec+1);
hdr->flags = htonl( HEADER_VERSION1 );
hdr->total_len1 = htonl( (long) (stats->TotalLen >> 32) );
fprintf( stderr, warn_ack_failed, mSettings->mSock, count );
}
-// end write_UDP_AckFIN
-