Changeset 10913


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

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

Location:
trunk
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/configure.ac

    r10899 r10913  
    8686if test "x$GCC" = "xyes" ; then
    8787
    88     CFLAGS="$CFLAGS -std=gnu99 -ggdb3 -Wall -W -Wpointer-arith -Wformat-security -Wcast-align -Wundef -Wcast-align -Wstrict-prototypes -Wmissing-declarations -Wmissing-format-attribute -Wredundant-decls -Wnested-externs -Wunused-parameter -Wwrite-strings"
     88    CFLAGS="$CFLAGS -std=gnu99 -ggdb3 -Wall -W -Wpointer-arith -Wformat-security -Wcast-align -Wundef -Wcast-align -Wstrict-prototypes -Wmissing-declarations -Wmissing-format-attribute -Wredundant-decls -Wnested-externs -Wunused-parameter -Wwrite-strings -Wvariadic-macros -Waggregate-return -Wvla -Winline -Wfloat-equal"
    8989
    9090    dnl figure out gcc version
  • trunk/libtransmission/net.c

    r10858 r10913  
    148148}
    149149
     150char *
     151tr_net_strerror( char * buf, size_t buflen, int err )
     152{
     153    *buf = '\0';
     154#ifdef WIN32
     155    FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM, NULL, e, 0, buf, buflen, NULL );
     156#else
     157    tr_strlcpy( buf, tr_strerror( err ), buflen );
     158#endif
     159    return buf;
     160}
     161
    150162const char *
    151163tr_ntop( const tr_address * src, char * dst, int size )
  • trunk/libtransmission/net.h

    r10858 r10913  
    123123void tr_netInit( void );
    124124
     125/**
     126 * @brief get a human-representable string representing the network error.
     127 * @param err an errno on Unix/Linux and an WSAError on win32)
     128 */
     129char* tr_net_strerror( char * buf, size_t buflen, int err );
     130
    125131const unsigned char *tr_globalIPv6( void );
    126132
  • 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 )
  • trunk/libtransmission/tr-dht.c

    r10816 r10913  
    8888
    8989static void
    90 nap( int roughly )
    91 {
    92     struct timeval tv;
    93     tv.tv_sec = roughly / 2 + tr_cryptoWeakRandInt( roughly );
    94     tv.tv_usec = tr_cryptoWeakRandInt( 1000000 );
    95     select( 0, NULL, NULL, NULL, &tv );
     90nap( int roughly_sec )
     91{
     92    const int roughly_msec = roughly_sec * 1000;
     93    const int msec = roughly_msec/2 + tr_cryptoWeakRandInt(roughly_msec);
     94    tr_wait_msec( msec );
    9695}
    9796
  • trunk/libtransmission/tr-lpd.c

    r10912 r10913  
    2626
    2727/* posix */
    28 #include <netinet/in.h> /* sockaddr_in */
    2928#include <signal.h> /* sig_atomic_t */
    3029#include <sys/time.h>
    31 #include <sys/types.h>
    32 #include <sys/socket.h> /* socket(), bind() */
    3330#include <unistd.h> /* close() */
    3431#include <fcntl.h> /* fcntl(), O_NONBLOCK */
    3532#include <ctype.h> /* toupper() */
     33#ifdef WIN32
     34  #include <w32api.h>
     35  #define WINDOWS  WindowsXP  /* freeaddrinfo(),getaddrinfo(),getnameinfo() */
     36  #include <inttypes.h>
     37  #include <ws2tcpip.h>
     38  typedef uint16_t in_port_t;                   /* all missing */
     39  extern int fcntl (int fd, int cmd, ...);
     40  #define O_NONBLOCK    04000
     41#else
     42  #include <sys/types.h>
     43  #include <sys/socket.h> /* socket(), bind() */
     44  #include <netinet/in.h> /* sockaddr_in */
     45#endif
    3646
    3747/* third party */
     
    247257static inline int lpd_configureSocket( int sock, int add )
    248258{
     259#ifdef WIN32
     260    unsigned long flags = 1;
     261
     262    if (add != O_NONBLOCK)
     263        return -1;              /* not supported */
     264    if (ioctlsocket(sock, FIONBIO, &flags) == SOCKET_ERROR)
     265        return -1;
     266#else
    249267    /* read-modify-write socket flags */
    250268    int flags = fcntl( sock, F_GETFL );
     
    255273    if( fcntl( sock, F_SETFL, add | flags ) == -1 )
    256274        return -1;
     275#endif
    257276
    258277    return add;
  • trunk/libtransmission/trevent.c

    r10858 r10913  
    9696{
    9797    int ret = recv(s, buf, len, 0);
    98     int werror = 0;
    9998
    10099    if (ret < 0) {
    101         werror= WSAGetLastError();
     100        const int werror= WSAGetLastError();
    102101        switch(werror) {
    103102          /* simplified error mapping (not valid for connect) */
  • trunk/libtransmission/web.c

    r10858 r10913  
    241241}
    242242
     243/**
     244 * Portability wrapper for select().
     245 *
     246 * http://msdn.microsoft.com/en-us/library/ms740141%28VS.85%29.aspx
     247 * On win32, any two of the parameters, readfds, writefds, or exceptfds,
     248 * can be given as null. At least one must be non-null, and any non-null
     249 * descriptor set must contain at least one handle to a socket.
     250 */
     251static void
     252tr_select( int nfds,
     253           fd_set * r_fd_set, fd_set * w_fd_set, fd_set * c_fd_set,
     254           struct timeval  * t )
     255{
     256#ifdef WIN32
     257    if( !r_fd_set->fd_count && !w_fd_set->fd_count && !c_fd_set->fd_count )
     258    {
     259        tr_wait_msec( msec );
     260    }
     261    else if( select( 0, r_fd_set->fd_count ? r_fd_set : NULL,
     262                        w_fd_set->fd_count ? w_fd_set : NULL,
     263                        c_fd_set->fd_count ? c_fd_set : NULL, t ) < 0 )
     264    {
     265        char errstr[512];
     266        const int e = EVUTIL_SOCKET_ERROR( );
     267        tr_net_strerror( errstr, sizeof( errstr ), e );
     268        dbgmsg( "Error: select (%d) %s", e, errstr );
     269    }
     270#else
     271    select( nfds, r_fd_set, w_fd_set, c_fd_set, t );
     272#endif
     273}
     274
    243275static void
    244276tr_webThreadFunc( void * vsession )
     
    309341            t.tv_usec = usec % 1000000;
    310342
    311 #ifdef WIN32
    312             /* see ticket #3311, comments 16-18 */
    313             if( !r_fd_set.fd_count && !w_fd_set.fd_count && !c_fd_set.fd_count )
    314                 tr_wait_msec( msec );
    315             else
    316                 select( 0, r_fd_set.fd_count ? &r_fd_set : NULL,
    317                            w_fd_set.fd_count ? &w_fd_set : NULL,
    318                            c_fd_set.fd_count ? &c_fd_set : NULL, &t );
    319 #else
    320             select( max_fd+1, &r_fd_set, &w_fd_set, &c_fd_set, &t );
    321 #endif
     343            tr_select( max_fd+1, &r_fd_set, &w_fd_set, &c_fd_set, &t );
    322344        }
    323345
  • trunk/third-party/dht/dht.c

    r10423 r10913  
    4040#include <fcntl.h>
    4141#include <sys/time.h>
     42#ifndef WIN32
    4243#include <arpa/inet.h>
    4344#include <sys/types.h>
    4445#include <sys/socket.h>
    4546#include <netinet/in.h>
     47#else
     48#include <w32api.h>
     49#define WINVER  WindowsXP       /* freeaddrinfo(),getaddrinfo(),getnameinfo() */
     50#include <ws2tcpip.h>
     51#define random  rand            /* int rand() since no long random() */
     52extern const char *inet_ntop(int, const void *, char *, socklen_t); /* from libtransmission (utils.c) */
     53#define EAFNOSUPPORT            WSAEAFNOSUPPORT
     54#endif
    4655
    4756#include "dht.h"
     
    15311540{
    15321541    int rc;
     1542#ifdef WIN32
     1543    unsigned long flags = 1;
     1544#endif
     1545
    15331546
    15341547    if(dht_socket >= 0 || dht_socket6 >= 0 || buckets || buckets6) {
     
    15491562        buckets->af = AF_INET;
    15501563
     1564#ifndef WIN32
    15511565        rc = fcntl(s, F_GETFL, 0);
    15521566        if(rc < 0)
     
    15541568
    15551569        rc = fcntl(s, F_SETFL, (rc | O_NONBLOCK));
     1570#else
     1571        rc = ioctlsocket(s, FIONBIO, &flags);
     1572#endif
    15561573        if(rc < 0)
    15571574            goto fail;
     
    15641581        buckets6->af = AF_INET6;
    15651582
     1583#ifndef WIN32
    15661584        rc = fcntl(s6, F_GETFL, 0);
    15671585        if(rc < 0)
     
    15691587
    15701588        rc = fcntl(s6, F_SETFL, (rc | O_NONBLOCK));
     1589#else
     1590        rc = ioctlsocket(s6, FIONBIO, &flags);
     1591#endif
    15711592        if(rc < 0)
    15721593            goto fail;
  • trunk/third-party/miniupnp/miniupnpc.c

    r10739 r10913  
    2525#include <ws2tcpip.h>
    2626#include <io.h>
    27 #include <IPHlpApi.h>
     27#include <iphlpapi.h>
    2828#define snprintf _snprintf
    2929#if defined(_MSC_VER) && (_MSC_VER >= 1400)
Note: See TracChangeset for help on using the changeset viewer.