1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-26 09:37:56 +00:00

(trunk libT) peer-io.c: remove dead code and get rid of a couple of GOTOs

This commit is contained in:
Charles Kerr 2008-12-22 04:55:07 +00:00
parent acdd8c860c
commit 1310fea91e

View file

@ -95,20 +95,18 @@ struct tr_peerIo
tr_session * session; tr_session * session;
tr_address addr; tr_address addr;
tr_list * output_datatypes; /* struct tr_datatype */
tr_can_read_cb canRead; tr_can_read_cb canRead;
tr_did_write_cb didWrite; tr_did_write_cb didWrite;
tr_net_error_cb gotError; tr_net_error_cb gotError;
void * userData; void * userData;
size_t bufferSize[2];
tr_bandwidth * bandwidth; tr_bandwidth * bandwidth;
tr_crypto * crypto; tr_crypto * crypto;
struct evbuffer * inbuf; struct evbuffer * inbuf;
struct evbuffer * outbuf; struct evbuffer * outbuf;
tr_list * outbuf_datatypes; /* struct tr_datatype */
struct event event_read; struct event event_read;
struct event event_write; struct event event_write;
@ -123,7 +121,7 @@ didWriteWrapper( tr_peerIo * io, size_t bytes_transferred )
{ {
while( bytes_transferred ) while( bytes_transferred )
{ {
struct tr_datatype * next = io->output_datatypes->data; struct tr_datatype * next = io->outbuf_datatypes->data;
const size_t payload = MIN( next->length, bytes_transferred ); const size_t payload = MIN( next->length, bytes_transferred );
const size_t overhead = getPacketOverhead( payload ); const size_t overhead = getPacketOverhead( payload );
@ -138,7 +136,7 @@ didWriteWrapper( tr_peerIo * io, size_t bytes_transferred )
bytes_transferred -= payload; bytes_transferred -= payload;
next->length -= payload; next->length -= payload;
if( !next->length ) if( !next->length )
tr_free( tr_list_pop_front( &io->output_datatypes ) ); tr_free( tr_list_pop_front( &io->outbuf_datatypes ) );
} }
} }
@ -211,7 +209,6 @@ static void
event_read_cb( int fd, short event UNUSED, void * vio ) event_read_cb( int fd, short event UNUSED, void * vio )
{ {
int res; int res;
short what = EVBUFFER_READ;
tr_peerIo * io = vio; tr_peerIo * io = vio;
const size_t howmuch = tr_bandwidthClamp( io->bandwidth, TR_DOWN, io->session->so_rcvbuf ); const size_t howmuch = tr_bandwidthClamp( io->bandwidth, TR_DOWN, io->session->so_rcvbuf );
const tr_direction dir = TR_DOWN; const tr_direction dir = TR_DOWN;
@ -227,33 +224,31 @@ event_read_cb( int fd, short event UNUSED, void * vio )
} }
res = evbuffer_read( io->inbuf, fd, howmuch ); res = evbuffer_read( io->inbuf, fd, howmuch );
if( res == -1 ) {
if( errno == EAGAIN || errno == EINTR )
goto reschedule;
/* error case */
what |= EVBUFFER_ERROR;
} else if( res == 0 ) {
/* eof case */
what |= EVBUFFER_EOF;
}
if( res <= 0 )
goto error;
if( res > 0 )
{
tr_peerIoSetEnabled( io, dir, TRUE ); tr_peerIoSetEnabled( io, dir, TRUE );
/* Invoke the user callback - must always be called last */ /* Invoke the user callback - must always be called last */
canReadWrapper( io ); canReadWrapper( io );
}
else
{
short what = EVBUFFER_READ;
return; if( res == 0 ) /* EOF */
what |= EVBUFFER_EOF;
reschedule: else if( res == -1 ) {
if( errno == EAGAIN || errno == EINTR ) {
tr_peerIoSetEnabled( io, dir, TRUE ); tr_peerIoSetEnabled( io, dir, TRUE );
return; return;
}
what |= EVBUFFER_ERROR;
}
error:
if( io->gotError != NULL ) if( io->gotError != NULL )
io->gotError( io, what, io->userData ); io->gotError( io, what, io->userData );
}
} }
static int static int
@ -341,13 +336,6 @@ event_write_cb( int fd, short event UNUSED, void * vio )
*** ***
**/ **/
static int
isFlag( int flag )
{
return( ( flag == 0 ) || ( flag == 1 ) );
}
static tr_peerIo* static tr_peerIo*
tr_peerIoNew( tr_session * session, tr_peerIoNew( tr_session * session,
const tr_address * addr, const tr_address * addr,
@ -374,9 +362,6 @@ tr_peerIoNew( tr_session * session,
io->outbuf = evbuffer_new( ); io->outbuf = evbuffer_new( );
event_set( &io->event_read, io->socket, EV_READ, event_read_cb, io ); event_set( &io->event_read, io->socket, EV_READ, event_read_cb, io );
event_set( &io->event_write, io->socket, EV_WRITE, event_write_cb, io ); event_set( &io->event_write, io->socket, EV_WRITE, event_write_cb, io );
#if 0
bufevNew( io );
#endif
tr_peerIoSetBandwidth( io, session->bandwidth ); tr_peerIoSetBandwidth( io, session->bandwidth );
return io; return io;
} }
@ -388,7 +373,7 @@ tr_peerIoNewIncoming( tr_session * session,
int socket ) int socket )
{ {
assert( session ); assert( session );
assert( addr ); assert( tr_isAddress( addr ) );
assert( socket >= 0 ); assert( socket >= 0 );
return tr_peerIoNew( session, addr, port, NULL, 1, socket ); return tr_peerIoNew( session, addr, port, NULL, 1, socket );
@ -403,7 +388,7 @@ tr_peerIoNewOutgoing( tr_session * session,
int socket; int socket;
assert( session ); assert( session );
assert( addr ); assert( tr_isAddress( addr ) );
assert( torrentHash ); assert( torrentHash );
socket = tr_netOpenTCP( session, addr, port ); socket = tr_netOpenTCP( session, addr, port );
@ -425,7 +410,7 @@ io_dtor( void * vio )
evbuffer_free( io->inbuf ); evbuffer_free( io->inbuf );
tr_netClose( io->socket ); tr_netClose( io->socket );
tr_cryptoFree( io->crypto ); tr_cryptoFree( io->crypto );
tr_list_free( &io->output_datatypes, tr_free ); tr_list_free( &io->outbuf_datatypes, tr_free );
io->magicNumber = 0xDEAD; io->magicNumber = 0xDEAD;
tr_free( io ); tr_free( io );
@ -515,12 +500,7 @@ tr_peerIoReconnect( tr_peerIo * io )
{ {
tr_bandwidth * bandwidth = io->bandwidth; tr_bandwidth * bandwidth = io->bandwidth;
tr_peerIoSetBandwidth( io, NULL ); tr_peerIoSetBandwidth( io, NULL );
tr_netSetTOS( io->socket, io->session->peerSocketTOS ); tr_netSetTOS( io->socket, io->session->peerSocketTOS );
#if 0
bufevNew( io );
#endif
tr_peerIoSetBandwidth( io, bandwidth ); tr_peerIoSetBandwidth( io, bandwidth );
return 0; return 0;
} }
@ -593,9 +573,9 @@ tr_peerIoEnableFEXT( tr_peerIo * io,
tr_bool flag ) tr_bool flag )
{ {
assert( tr_isPeerIo( io ) ); assert( tr_isPeerIo( io ) );
assert( isFlag( flag ) ); assert( _isBool( flag ) );
dbgmsg( io, "setting FEXT support flag to %d", (flag?1:0) ); dbgmsg( io, "setting FEXT support flag to %d", (flag!=0) );
io->fastExtensionSupported = flag; io->fastExtensionSupported = flag;
} }
@ -616,9 +596,9 @@ tr_peerIoEnableLTEP( tr_peerIo * io,
tr_bool flag ) tr_bool flag )
{ {
assert( tr_isPeerIo( io ) ); assert( tr_isPeerIo( io ) );
assert( isFlag( flag ) ); assert( _isBool( flag ) );
dbgmsg( io, "setting LTEP support flag to %d", (flag?1:0) ); dbgmsg( io, "setting LTEP support flag to %d", (flag!=0) );
io->extendedProtocolSupported = flag; io->extendedProtocolSupported = flag;
} }
@ -714,13 +694,14 @@ tr_peerIoWrite( tr_peerIo * io,
int isPieceData ) int isPieceData )
{ {
struct tr_datatype * datatype; struct tr_datatype * datatype;
assert( tr_amInEventThread( io->session ) ); assert( tr_amInEventThread( io->session ) );
dbgmsg( io, "adding %zu bytes into io->output", writemeLen ); dbgmsg( io, "adding %zu bytes into io->output", writemeLen );
datatype = tr_new( struct tr_datatype, 1 ); datatype = tr_new( struct tr_datatype, 1 );
datatype->isPieceData = isPieceData != 0; datatype->isPieceData = isPieceData != 0;
datatype->length = writemeLen; datatype->length = writemeLen;
tr_list_append( &io->output_datatypes, datatype ); tr_list_append( &io->outbuf_datatypes, datatype );
evbuffer_add( io->outbuf, writeme, writemeLen ); evbuffer_add( io->outbuf, writeme, writemeLen );
} }