Changeset 10816


Ignore:
Timestamp:
Jun 22, 2010, 12:12:52 AM (12 years ago)
Author:
charles
Message:

(trunk) more win32 fixes from rb07 in #3311

Location:
trunk
Files:
2 added
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/configure.ac

    r10783 r10816  
    408408     CXXFLAGS="$CXXFLAGS -mms-bitfields -mwin32 -mwindows"
    409409     CPPFLAGS="$CPPFLAGS -DWIN32 -D_WIN32 -DWIN32_LEAN_AND_MEAN"
    410      LIBS="$LIBS -lshell32 -lws2_32"
     410     LIBS="$LIBS -liphlpapi -lshell32 -lws2_32"
    411411     transmissionlocaledir="locale"
    412412     if test -z "$host_alias"; then
  • trunk/libtransmission/bencode.c

    r10814 r10816  
    1919#include <string.h>
    2020
    21 #ifdef WIN32
     21#ifdef WIN32 /* tr_mkstemp() */
    2222 #include <fcntl.h>
    23  #define fsync(fd) _commit(fd)
     23 #define _S_IREAD 256
     24 #define _S_IWRITE 128
    2425#endif
    2526
     
    16341635}
    16351636
     1637/* portability wrapper for mkstemp(). */
     1638static int
     1639tr_mkstemp( char * template )
     1640{
     1641#ifdef WIN32
     1642    const int flags = O_RDWR | O_BINARY | O_CREAT | O_EXCL | _O_SHORT_LIVED;
     1643    const mode_t mode = _S_IREAD | _S_IWRITE;
     1644    mktemp( template );
     1645    return open( template, flags, mode );
     1646#else
     1647    return mkstemp( template );
     1648#endif
     1649}
     1650
     1651/* portability wrapper for fsync(). */
     1652static void
     1653tr_fsync( int fd )
     1654{
     1655#ifdef WIN32
     1656    _commit( fd );
     1657#else
     1658    fsync( fd );
     1659#endif
     1660}
     1661
    16361662int
    16371663tr_bencToFile( const tr_benc * top, tr_fmt_mode mode, const char * filename )
     
    16431669
    16441670    /* follow symlinks to find the "real" file, to make sure the temporary
    1645      * we build with mkstemp() is created on the right partition */
     1671     * we build with tr_mkstemp() is created on the right partition */
    16461672    if( tr_realpath( filename, buf ) != NULL )
    16471673        filename = buf;
     
    16491675    /* if the file already exists, try to move it out of the way & keep it as a backup */
    16501676    tmp = tr_strdup_printf( "%s.tmp.XXXXXX", filename );
    1651     fd = mkstemp( tmp );
     1677    fd = tr_mkstemp( tmp );
    16521678    if( fd >= 0 )
    16531679    {
     
    16581684        if( write( fd, str, len ) == (ssize_t)len )
    16591685        {
    1660             fsync( fd );
     1686            tr_fsync( fd );
    16611687            close( fd );
    16621688
     
    17291755    return err;
    17301756}
     1757
  • trunk/libtransmission/blocklist.c

    r10754 r10816  
    1616
    1717#ifdef WIN32
     18 #include <w32api.h>
     19 #define WINVER  WindowsXP
    1820 #include <windows.h>
    1921#endif
     
    3436#include "utils.h"
    3537
     38#ifndef O_BINARY
     39 #define O_BINARY 0
     40#endif
     41
    3642
    3743/***
     
    8187        return;
    8288
    83     fd = open( b->filename, O_RDONLY );
     89    fd = open( b->filename, O_RDONLY | O_BINARY );
    8490    if( fd == -1 )
    8591    {
     
    8894    }
    8995
    90 #ifndef WIN32
    9196    b->rules = mmap( NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0 );
    92 #else
    93     b->rules = mmap( NULL, st.st_size, 0, 0, fd, 0 );
    94 #endif
    9597    if( !b->rules )
    9698    {
     
    316318    }
    317319
    318     in = fopen( filename, "r" );
     320    in = fopen( filename, "rb" );
    319321    if( !in )
    320322    {
     
    363365    {
    364366        char * base = tr_basename( b->filename );
    365         tr_inf( _( "Blocklist \"%1$s\" updated with %2$'d entries" ), base, outCount );
     367        tr_inf( _( "Blocklist \"%s\" updated with %'d entries" ), base, outCount );
    366368        tr_free( base );
    367369    }
  • trunk/libtransmission/net.c

    r10753 r10816  
    3333
    3434#ifdef WIN32
    35  #include <winsock2.h> /* inet_addr */
    36  #include <WS2tcpip.h>
     35 #define _WIN32_WINNT   0x0501
     36 #include <ws2tcpip.h>
    3737#else
    3838 #include <sys/socket.h>
  • trunk/libtransmission/net.h

    r10508 r10816  
    3232#ifdef WIN32
    3333 #include <inttypes.h>
    34  #include <winsock2.h>
    35  #include <WS2tcpip.h>
    36  typedef int socklen_t;
     34 #include <ws2tcpip.h>
    3735#else
    3836 #include <sys/types.h>
     
    4341
    4442#ifdef WIN32
     43 #define EADDRINUSE              WSAEADDRINUSE
    4544 #define ECONNREFUSED            WSAECONNREFUSED
    4645 #define ECONNRESET              WSAECONNRESET
  • trunk/libtransmission/torrent.c

    r10800 r10816  
    16591659}
    16601660
     1661static void
     1662tr_setenv( const char * name, const char * value, tr_bool override )
     1663{
     1664#ifdef WIN32
     1665    putenv( tr_strdup_printf( "%s=%s", name, value ) ); /* leaks memory... */
     1666#else
     1667    setenv( name, value, override );
     1668#endif
     1669}
    16611670
    16621671static void
     
    16741683#endif
    16751684
    1676         setenv( "TR_APP_VERSION", SHORT_VERSION_STRING, 1 );
     1685        tr_setenv( "TR_APP_VERSION", SHORT_VERSION_STRING, 1 );
    16771686
    16781687        tr_snprintf( buf, sizeof( buf ), "%d", tr_torrentId( tor ) );
    1679         setenv( "TR_TORRENT_ID", buf, 1 );
    1680         setenv( "TR_TORRENT_NAME", tr_torrentName( tor ), 1 );
    1681         setenv( "TR_TORRENT_DIR", tor->currentDir, 1 );
    1682         setenv( "TR_TORRENT_HASH", tor->info.hashString, 1 );
     1688        tr_setenv( "TR_TORRENT_ID", buf, 1 );
     1689        tr_setenv( "TR_TORRENT_NAME", tr_torrentName( tor ), 1 );
     1690        tr_setenv( "TR_TORRENT_DIR", tor->currentDir, 1 );
     1691        tr_setenv( "TR_TORRENT_HASH", tor->info.hashString, 1 );
    16831692        tr_strlcpy( buf, ctime( &now ), sizeof( buf ) );
    16841693        *strchr( buf,'\n' ) = '\0';
    1685         setenv( "TR_TIME_LOCALTIME", buf, 1 );
     1694        tr_setenv( "TR_TIME_LOCALTIME", buf, 1 );
    16861695        tr_torinf( tor, "Calling script \"%s\"", script );
    16871696        system( script );
  • trunk/libtransmission/tr-dht.c

    r10814 r10816  
    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() */
    33 #include <netdb.h>
    3430#include <unistd.h> /* close() */
     31#ifdef WIN32
     32  #include <inttypes.h>
     33  #define _WIN32_WINNT  0x0501  /* freeaddrinfo(),getaddrinfo(),getnameinfo() */
     34  #include <ws2tcpip.h>
     35#else
     36  #include <sys/types.h>
     37  #include <sys/socket.h> /* socket(), bind() */
     38  #include <netdb.h>
     39  #include <netinet/in.h> /* sockaddr_in */
     40#endif
    3541
    3642/* third party */
  • trunk/libtransmission/trevent.c

    r9992 r10816  
    2727#ifdef WIN32
    2828
    29 #include <WinSock2.h>
     29#include "utils.h"
     30#include <winsock2.h>
    3031
    3132static int
    3233pgpipe( int handles[2] )
    3334{
    34         SOCKET s;
    35         struct sockaddr_in serv_addr;
    36         int len = sizeof( serv_addr );
    37 
    38         handles[0] = handles[1] = INVALID_SOCKET;
    39 
    40         if ( ( s = socket( AF_INET, SOCK_STREAM, 0 ) ) == INVALID_SOCKET )
    41         {
    42 /*              ereport(LOG, (errmsg_internal("pgpipe failed to create socket: %ui", WSAGetLastError()))); */
    43                 return -1;
    44         }
    45 
    46         memset( &serv_addr, 0, sizeof( serv_addr ) );
    47         serv_addr.sin_family = AF_INET;
    48         serv_addr.sin_port = htons(0);
    49         serv_addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
    50         if (bind(s, (SOCKADDR *) & serv_addr, len) == SOCKET_ERROR)
    51         {
    52 /*              ereport(LOG, (errmsg_internal("pgpipe failed to bind: %ui", WSAGetLastError()))); */
    53                 closesocket(s);
    54                 return -1;
    55         }
    56         if (listen(s, 1) == SOCKET_ERROR)
    57         {
    58 /*              ereport(LOG, (errmsg_internal("pgpipe failed to listen: %ui", WSAGetLastError()))); */
    59                 closesocket(s);
    60                 return -1;
    61         }
    62         if (getsockname(s, (SOCKADDR *) & serv_addr, &len) == SOCKET_ERROR)
    63         {
    64 /*              ereport(LOG, (errmsg_internal("pgpipe failed to getsockname: %ui", WSAGetLastError()))); */
    65                 closesocket(s);
    66                 return -1;
    67         }
    68         if ((handles[1] = socket(PF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET)
    69         {
    70 /*              ereport(LOG, (errmsg_internal("pgpipe failed to create socket 2: %ui", WSAGetLastError()))); */
    71                 closesocket(s);
    72                 return -1;
    73         }
    74 
    75         if (connect(handles[1], (SOCKADDR *) & serv_addr, len) == SOCKET_ERROR)
    76         {
    77 /*              ereport(LOG, (errmsg_internal("pgpipe failed to connect socket: %ui", WSAGetLastError()))); */
    78                 closesocket(s);
    79                 return -1;
    80         }
    81         if ((handles[0] = accept(s, (SOCKADDR *) & serv_addr, &len)) == INVALID_SOCKET)
    82         {
    83 /*              ereport(LOG, (errmsg_internal("pgpipe failed to accept socket: %ui", WSAGetLastError()))); */
    84                 closesocket(handles[1]);
    85                 handles[1] = INVALID_SOCKET;
    86                 closesocket(s);
    87                 return -1;
    88         }
    89         closesocket(s);
    90         return 0;
     35    SOCKET s;
     36    struct sockaddr_in serv_addr;
     37    int len = sizeof( serv_addr );
     38
     39    handles[0] = handles[1] = INVALID_SOCKET;
     40
     41    if ( ( s = socket( AF_INET, SOCK_STREAM, 0 ) ) == INVALID_SOCKET )
     42    {
     43        tr_dbg("pgpipe failed to create socket: %ui", WSAGetLastError());
     44        return -1;
     45    }
     46
     47    memset( &serv_addr, 0, sizeof( serv_addr ) );
     48    serv_addr.sin_family = AF_INET;
     49    serv_addr.sin_port = htons(0);
     50    serv_addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
     51    if (bind(s, (SOCKADDR *) & serv_addr, len) == SOCKET_ERROR)
     52    {
     53        tr_dbg("pgpipe failed to bind: %ui", WSAGetLastError());
     54        closesocket(s);
     55        return -1;
     56    }
     57    if (listen(s, 1) == SOCKET_ERROR)
     58    {
     59        tr_ndbg("event","pgpipe failed to listen: %ui", WSAGetLastError());
     60        closesocket(s);
     61        return -1;
     62    }
     63    if (getsockname(s, (SOCKADDR *) & serv_addr, &len) == SOCKET_ERROR)
     64    {
     65        tr_dbg("pgpipe failed to getsockname: %ui", WSAGetLastError());
     66        closesocket(s);
     67        return -1;
     68    }
     69    if ((handles[1] = socket(PF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET)
     70    {
     71        tr_dbg("pgpipe failed to create socket 2: %ui", WSAGetLastError());
     72        closesocket(s);
     73        return -1;
     74    }
     75
     76    if (connect(handles[1], (SOCKADDR *) & serv_addr, len) == SOCKET_ERROR)
     77    {
     78        tr_dbg("pgpipe failed to connect socket: %ui", WSAGetLastError());
     79        closesocket(s);
     80        return -1;
     81    }
     82    if ((handles[0] = accept(s, (SOCKADDR *) & serv_addr, &len)) == INVALID_SOCKET)
     83    {
     84        tr_dbg("pgpipe failed to accept socket: %ui", WSAGetLastError());
     85        closesocket(handles[1]);
     86        handles[1] = INVALID_SOCKET;
     87        closesocket(s);
     88        return -1;
     89    }
     90    closesocket(s);
     91    return 0;
    9192}
    9293
     
    9495piperead( int s, char *buf, int len )
    9596{
    96         int ret = recv(s, buf, len, 0);
    97 
    98         if (ret < 0 && WSAGetLastError() == WSAECONNRESET)
    99                 /* EOF on the pipe! (win32 socket based implementation) */
    100                 ret = 0;
    101         return ret;
     97    int ret = recv(s, buf, len, 0);
     98    int werror = 0;
     99
     100    if (ret < 0) {
     101        werror= WSAGetLastError();
     102        switch(werror) {
     103          /* simplified error mapping (not valid for connect) */
     104            case WSAEWOULDBLOCK:
     105                errno = EAGAIN;
     106                break;
     107            case WSAECONNRESET:
     108                /* EOF on the pipe! (win32 socket based implementation) */
     109                ret = 0;
     110                /* fall through */
     111            default:
     112                errno = werror;
     113                break;
     114        }
     115    } else
     116        errno = 0;
     117    return ret;
    102118}
    103119
  • trunk/qt/qtr.pro

    r10815 r10816  
    1010CONFIG += qt qdbus thread debug link_pkgconfig
    1111QT += network
    12 PKGCONFIG = fontconfig libcurl openssl
     12PKGCONFIG = fontconfig libcurl openssl dbus-1
    1313
    1414TRANSMISSION_TOP = ..
     
    1818LIBS += $${TRANSMISSION_TOP}/third-party/miniupnp/libminiupnp.a
    1919LIBS += $${TRANSMISSION_TOP}/third-party/libnatpmp/libnatpmp.a
    20 LIBS += -levent
     20unix: LIBS += -levent
     21win32:DEFINES += QT_DBUS
     22win32:LIBS += -levent -lws2_32 -lintl
     23win32:LIBS += -lidn -liconv -lwldap32 -liphlpapi
    2124
    2225TRANSLATIONS += transmission_en.ts transmission_ru.ts
     
    3336HEADERS += speed.h types.h
    3437
     38win32:RC_FILE = qtr.rc
  • trunk/qt/utils.cc

    r10726 r10816  
    7777        {
    7878            displayed_size = (double)size / MEGABYTE_FACTOR;
    79             str = tr( "%L1 MiB" ).arg( displayed_size,  0, 'f', 1 );
     79            str = tr( "%L1 MiB" ).arg( displayed_size,  0, 'f', 2 );
    8080        }
    8181        else
    8282        {
    8383            displayed_size = (double) size / GIGABYTE_FACTOR;
    84             str = tr( "%L1 GiB" ).arg( displayed_size,  0, 'f', 1 );
     84            str = tr( "%L1 GiB" ).arg( displayed_size,  0, 'f', 3 );
    8585        }
    8686    }
Note: See TracChangeset for help on using the changeset viewer.