Ignore:
Timestamp:
Jun 30, 2010, 9:24:36 PM (11 years ago)
Author:
charles
Message:

(trunk) #3311 "MingW build of Transmission" -- apply more of rb07's diffs, though edited to lessen the inevitable #ifdefs

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/peer-io.c

    r10912 r10913  
    3838
    3939#define MAGIC_NUMBER 206745
     40
     41#ifdef WIN32
     42 #define EAGAIN       WSAEWOULDBLOCK
     43 #define EINTR        WSAEINTR
     44 #define EINPROGRESS  WSAEINPROGRESS
     45 #define EPIPE        WSAECONNRESET
     46#endif
    4047
    4148static size_t
     
    222229    }
    223230
    224     errno = 0;
     231    EVUTIL_SET_SOCKET_ERROR( 0 );
    225232    res = evbuffer_read( io->inbuf, fd, howmuch );
    226     e = errno;
     233    e = EVUTIL_SOCKET_ERROR( );
    227234
    228235    if( res > 0 )
     
    235242    else
    236243    {
     244        char errstr[512];
    237245        short what = EVBUFFER_READ;
    238246
     
    247255        }
    248256
    249         dbgmsg( io, "event_read_cb got an error. res is %d, what is %hd, errno is %d (%s)", res, what, e, strerror( e ) );
     257        tr_net_strerror( errstr, sizeof( errstr ), e );
     258        dbgmsg( io, "event_read_cb got an error. res is %d, what is %hd, errno is %d (%s)", res, what, e, errstr );
    250259
    251260        if( io->gotError != NULL )
     
    259268    int e;
    260269    int n;
     270    char errstr[256];
    261271    struct evbuffer * buffer = io->outbuf;
    262272
    263273    howmuch = MIN( EVBUFFER_LENGTH( buffer ), howmuch );
    264274
    265     errno = 0;
     275    EVUTIL_SET_SOCKET_ERROR( 0 );
    266276#ifdef WIN32
    267277    n = (int) send(fd, buffer->buffer, howmuch,  0 );
     
    269279    n = (int) write(fd, buffer->buffer, howmuch );
    270280#endif
    271     e = errno;
    272     dbgmsg( io, "wrote %d to peer (%s)", n, (n==-1?strerror(e):"") );
     281    e = EVUTIL_SOCKET_ERROR( );
     282    dbgmsg( io, "wrote %d to peer (%s)", n, (n==-1?tr_net_strerror(errstr,sizeof(errstr),e):"") );
    273283
    274284    if( n > 0 )
     
    311321    }
    312322
    313     errno = 0;
     323    EVUTIL_SET_SOCKET_ERROR( 0 );
    314324    res = tr_evbuffer_write( io, fd, howmuch );
    315     e = errno;
     325    e = EVUTIL_SOCKET_ERROR( );
    316326
    317327    if (res == -1) {
    318 #ifndef WIN32
    319 /*todo. evbuffer uses WriteFile when WIN32 is set. WIN32 system calls do not
    320  *  *set errno. thus this error checking is not portable*/
    321328        if (e == EAGAIN || e == EINTR || e == EINPROGRESS)
    322329            goto reschedule;
    323330        /* error case */
    324331        what |= EVBUFFER_ERROR;
    325 
    326 #else
    327         goto reschedule;
    328 #endif
    329 
    330332    } else if (res == 0) {
    331333        /* eof case */
     
    879881    {
    880882        int e;
    881         errno = 0;
     883
     884        EVUTIL_SET_SOCKET_ERROR( 0 );
    882885        res = evbuffer_read( io->inbuf, io->socket, howmuch );
    883         e = errno;
     886        e = EVUTIL_SOCKET_ERROR( );
    884887
    885888        dbgmsg( io, "read %d from peer (%s)", res, (res==-1?strerror(e):"") );
     
    890893        if( ( res <= 0 ) && ( io->gotError ) && ( e != EAGAIN ) && ( e != EINTR ) && ( e != EINPROGRESS ) )
    891894        {
     895            char errstr[512];
    892896            short what = EVBUFFER_READ | EVBUFFER_ERROR;
    893897            if( res == 0 )
    894898                what |= EVBUFFER_EOF;
    895             dbgmsg( io, "tr_peerIoTryRead got an error. res is %d, what is %hd, errno is %d (%s)", res, what, e, strerror( e ) );
     899            tr_net_strerror( errstr, sizeof( errstr ), e );
     900            dbgmsg( io, "tr_peerIoTryRead got an error. res is %d, what is %hd, errno is %d (%s)", res, what, e, errstr );
    896901            io->gotError( io, what, io->userData );
    897902        }
     
    909914    {
    910915        int e;
    911         errno = 0;
     916        EVUTIL_SET_SOCKET_ERROR( 0 );
    912917        n = tr_evbuffer_write( io, io->socket, howmuch );
    913         e = errno;
     918        e = EVUTIL_SOCKET_ERROR( );
    914919
    915920        if( n > 0 )
     
    918923        if( ( n < 0 ) && ( io->gotError ) && ( e != EPIPE ) && ( e != EAGAIN ) && ( e != EINTR ) && ( e != EINPROGRESS ) )
    919924        {
     925            char errstr[512];
    920926            const short what = EVBUFFER_WRITE | EVBUFFER_ERROR;
    921             dbgmsg( io, "tr_peerIoTryWrite got an error. res is %d, what is %hd, errno is %d (%s)", n, what, e, strerror( e ) );
     927
     928            tr_net_strerror( errstr, sizeof( errstr ), e );
     929            dbgmsg( io, "tr_peerIoTryWrite got an error. res is %d, what is %hd, errno is %d (%s)", n, what, e, errstr );
    922930
    923931            if( io->gotError != NULL )
Note: See TracChangeset for help on using the changeset viewer.