Changeset 7487 for branches/1.4x
- Timestamp:
- Dec 24, 2008, 2:50:09 AM (14 years ago)
- Location:
- branches/1.4x/libtransmission
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/1.4x/libtransmission/peer-io.c
r7459 r7487 209 209 { 210 210 int res; 211 int e; 211 212 tr_peerIo * io = vio; 212 const size_t howmuch = tr_bandwidthClamp( io->bandwidth, TR_DOWN, io->session->so_rcvbuf ); 213 214 /* Limit the input buffer to 256K, so it doesn't grow too large */ 215 size_t howmuch; 213 216 const tr_direction dir = TR_DOWN; 217 const size_t max = 256 * 1024; 218 const size_t curlen = EVBUFFER_LENGTH( io->inbuf ); 219 220 howmuch = curlen >= max ? 0 : max - curlen; 221 howmuch = tr_bandwidthClamp( io->bandwidth, TR_DOWN, howmuch ); 214 222 215 223 assert( tr_isPeerIo( io ) ); … … 223 231 } 224 232 233 errno = 0; 225 234 res = evbuffer_read( io->inbuf, fd, howmuch ); 235 e = errno; 226 236 227 237 if( res > 0 ) … … 239 249 what |= EVBUFFER_EOF; 240 250 else if( res == -1 ) { 241 if( e rrno == EAGAIN || errno== EINTR ) {251 if( e == EAGAIN || e == EINTR ) { 242 252 tr_peerIoSetEnabled( io, dir, TRUE ); 243 253 return; … … 246 256 } 247 257 258 dbgmsg( io, "event_read_cb got an error. res is %d, what is %hd, errno is %d (%s)", res, what, e, strerror( e ) ); 259 248 260 if( io->gotError != NULL ) 249 261 io->gotError( io, what, io->userData ); … … 256 268 struct evbuffer * buffer = io->outbuf; 257 269 int n = MIN( EVBUFFER_LENGTH( buffer ), howmuch ); 258 270 int e; 271 272 errno = 0; 259 273 #ifdef WIN32 260 274 n = send(fd, buffer->buffer, n, 0 ); … … 262 276 n = write(fd, buffer->buffer, n ); 263 277 #endif 264 dbgmsg( io, "wrote %d to peer (%s)", n, (n==-1?strerror(errno):"") ); 278 e = errno; 279 dbgmsg( io, "wrote %d to peer (%s)", n, (n==-1?strerror(e):"") ); 265 280 266 281 if( n == -1 ) … … 277 292 { 278 293 int res = 0; 294 int e; 279 295 short what = EVBUFFER_WRITE; 280 296 tr_peerIo * io = vio; … … 286 302 dbgmsg( io, "libevent says this peer is ready to write" ); 287 303 288 howmuch = MIN( (size_t)io->session->so_sndbuf, EVBUFFER_LENGTH( io->outbuf ) ); 289 howmuch = tr_bandwidthClamp( io->bandwidth, dir, howmuch ); 304 /* Write as much as possible, since the socket is non-blocking, write() will 305 * return if it can't write any more data without blocking */ 306 howmuch = tr_bandwidthClamp( io->bandwidth, dir, EVBUFFER_LENGTH( io->outbuf ) ); 290 307 291 308 /* if we don't have any bandwidth left, stop writing */ … … 295 312 } 296 313 314 errno = 0; 297 315 res = tr_evbuffer_write( io, fd, howmuch ); 316 e = errno; 317 298 318 if (res == -1) { 299 319 #ifndef WIN32 300 320 /*todo. evbuffer uses WriteFile when WIN32 is set. WIN32 system calls do not 301 321 * *set errno. thus this error checking is not portable*/ 302 if (e rrno == EAGAIN || errno == EINTR || errno== EINPROGRESS)322 if (e == EAGAIN || e == EINTR || e == EINPROGRESS) 303 323 goto reschedule; 304 324 /* error case */ … … 328 348 329 349 error: 350 351 dbgmsg( io, "event_write_cb got an error. res is %d, what is %hd, errno is %d (%s)", res, what, e, strerror( e ) ); 352 330 353 if( io->gotError != NULL ) 331 354 io->gotError( io, what, io->userData ); … … 860 883 tr_peerIoTryRead( tr_peerIo * io, size_t howmuch ) 861 884 { 862 int res; 863 864 assert( tr_isPeerIo( io ) ); 865 866 howmuch = tr_bandwidthClamp( io->bandwidth, TR_DOWN, howmuch ); 867 868 res = howmuch ? evbuffer_read( io->inbuf, io->socket, howmuch ) : 0; 869 870 dbgmsg( io, "read %d from peer (%s)", res, (res==-1?strerror(errno):"") ); 871 872 if( EVBUFFER_LENGTH( io->inbuf ) ) 873 canReadWrapper( io ); 874 875 if( ( res <= 0 ) && ( io->gotError ) && ( errno != EAGAIN ) && ( errno != EINTR ) && ( errno != EINPROGRESS ) ) 885 int res = 0; 886 887 assert( tr_isPeerIo( io ) ); 888 889 if(( howmuch = tr_bandwidthClamp( io->bandwidth, TR_DOWN, howmuch ))) 876 890 { 877 short what = EVBUFFER_READ | EVBUFFER_ERROR; 878 if( res == 0 ) 879 what |= EVBUFFER_EOF; 880 io->gotError( io, what, io->userData ); 891 int e; 892 errno = 0; 893 res = evbuffer_read( io->inbuf, io->socket, howmuch ); 894 e = errno; 895 896 dbgmsg( io, "read %d from peer (%s)", res, (res==-1?strerror(e):"") ); 897 898 if( EVBUFFER_LENGTH( io->inbuf ) ) 899 canReadWrapper( io ); 900 901 if( ( res <= 0 ) && ( io->gotError ) && ( e != EAGAIN ) && ( e != EINTR ) && ( e != EINPROGRESS ) ) 902 { 903 short what = EVBUFFER_READ | EVBUFFER_ERROR; 904 if( res == 0 ) 905 what |= EVBUFFER_EOF; 906 dbgmsg( io, "tr_peerIoTryRead got an error. res is %d, what is %hd, errno is %d (%s)", res, what, e, strerror( e ) ); 907 io->gotError( io, what, io->userData ); 908 } 881 909 } 882 910 … … 891 919 assert( tr_isPeerIo( io ) ); 892 920 893 howmuch = tr_bandwidthClamp( io->bandwidth, TR_UP, howmuch ); 894 895 n = tr_evbuffer_write( io, io->socket, (int)howmuch ); 896 897 if( n > 0 ) 898 didWriteWrapper( io, n ); 899 900 if( ( n < 0 ) && ( io->gotError ) && ( errno != EPIPE ) && ( errno != EAGAIN ) && ( errno != EINTR ) && ( errno != EINPROGRESS ) ) { 901 short what = EVBUFFER_WRITE | EVBUFFER_ERROR; 902 io->gotError( io, what, io->userData ); 921 if(( howmuch = tr_bandwidthClamp( io->bandwidth, TR_UP, howmuch ))) 922 { 923 int e; 924 errno = 0; 925 n = tr_evbuffer_write( io, io->socket, (int)howmuch ); 926 e = errno; 927 928 if( n > 0 ) 929 didWriteWrapper( io, n ); 930 931 if( ( n < 0 ) && ( io->gotError ) && ( e != EPIPE ) && ( e != EAGAIN ) && ( e != EINTR ) && ( e != EINPROGRESS ) ) 932 { 933 const short what = EVBUFFER_WRITE | EVBUFFER_ERROR; 934 dbgmsg( io, "tr_peerIoTryWrite got an error. res is %d, what is %hd, errno is %d (%s)", n, what, e, strerror( e ) ); 935 io->gotError( io, what, io->userData ); 936 } 903 937 } 904 938 -
branches/1.4x/libtransmission/peer-mgr.c
r7455 r7487 913 913 atom->myflags |= MYFLAG_BANNED; 914 914 peer->doPurge = 1; 915 tordbg( t, "banning peer %s", 916 tr_peerIoAddrStr( &atom->addr, atom->port ) ); 915 tordbg( t, "banning peer %s", tr_peerIoAddrStr( &atom->addr, atom->port ) ); 917 916 } 918 917 } … … 1140 1139 addStrike( t, peer ); 1141 1140 peer->doPurge = 1; 1142 tordbg( t, "setting doPurge because we got an EINVAL error");1141 tordbg( t, "setting %s doPurge flag because we got an EINVAL error", tr_peerIoAddrStr( &peer->addr, peer->port ) ); 1143 1142 } 1144 1143 else if( ( e->err == ERANGE ) … … 1148 1147 /* some protocol error from the peer */ 1149 1148 peer->doPurge = 1; 1150 tordbg( t, "setting doPurge because we got an ERANGE, EMSGSIZE, or ENOTCONN error");1149 tordbg( t, "setting %s doPurge flag because we got an ERANGE, EMSGSIZE, or ENOTCONN error", tr_peerIoAddrStr( &peer->addr, peer->port ) ); 1151 1150 } 1152 1151 else /* a local error, such as an IO error */
Note: See TracChangeset
for help on using the changeset viewer.