Changeset 10914


Ignore:
Timestamp:
Jun 30, 2010, 11:30:21 PM (12 years ago)
Author:
charles
Message:

(trunk third-party/dht) #3311 "mingw build of Transmission" -- use jch's upstream win32 portability fixes

Location:
trunk/third-party/dht
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/third-party/dht/CHANGES

    r10423 r10914  
     11 July 2010: dht-0.15
     2
     3  * Port to Windows, for the needs of Transmission.
     4
    1525 March 2010: dht-0.14
    26
  • trunk/third-party/dht/dht.c

    r10913 r10914  
    4040#include <fcntl.h>
    4141#include <sys/time.h>
     42
    4243#ifndef WIN32
    4344#include <arpa/inet.h>
     
    4748#else
    4849#include <w32api.h>
    49 #define WINVER  WindowsXP       /* freeaddrinfo(),getaddrinfo(),getnameinfo() */
     50#define WINVER WindowsXP
    5051#include <ws2tcpip.h>
    51 #define random  rand            /* int rand() since no long random() */
    52 extern const char *inet_ntop(int, const void *, char *, socklen_t); /* from libtransmission (utils.c) */
    53 #define EAFNOSUPPORT            WSAEAFNOSUPPORT
    5452#endif
    5553
     
    6462#ifndef MSG_CONFIRM
    6563#define MSG_CONFIRM 0
     64#endif
     65
     66#ifdef WIN32
     67
     68#define EAFNOSUPPORT WSAEAFNOSUPPORT
     69static int
     70set_nonblocking(int fd, int nonblocking)
     71{
     72    int rc;
     73
     74    unsigned long mode = !!nonblocking;
     75    rc = ioctlsocket(fd, FIONBIO, &mode);
     76    if(rc != 0)
     77        errno = WSAGetLastError();
     78    return (rc == 0 ? 0 : -1);
     79}
     80
     81static int
     82random(void)
     83{
     84    return rand();
     85}
     86extern const char *inet_ntop(int, const void *, char *, socklen_t);
     87
     88#else
     89
     90static int
     91set_nonblocking(int fd, int nonblocking)
     92{
     93    int rc;
     94    rc = fcntl(fd, F_GETFL, 0);
     95    if(rc < 0)
     96        return -1;
     97
     98    rc = fcntl(fd, F_SETFL, nonblocking?(rc | O_NONBLOCK):(rc & ~O_NONBLOCK));
     99    if(rc < 0)
     100        return -1;
     101
     102    return 0;
     103}
     104
    66105#endif
    67106
     
    15401579{
    15411580    int rc;
    1542 #ifdef WIN32
    1543     unsigned long flags = 1;
    1544 #endif
    1545 
    15461581
    15471582    if(dht_socket >= 0 || dht_socket6 >= 0 || buckets || buckets6) {
     
    15621597        buckets->af = AF_INET;
    15631598
    1564 #ifndef WIN32
    1565         rc = fcntl(s, F_GETFL, 0);
    1566         if(rc < 0)
    1567             goto fail;
    1568 
    1569         rc = fcntl(s, F_SETFL, (rc | O_NONBLOCK));
    1570 #else
    1571         rc = ioctlsocket(s, FIONBIO, &flags);
    1572 #endif
     1599        rc = set_nonblocking(s, 1);
    15731600        if(rc < 0)
    15741601            goto fail;
     
    15811608        buckets6->af = AF_INET6;
    15821609
    1583 #ifndef WIN32
    1584         rc = fcntl(s6, F_GETFL, 0);
    1585         if(rc < 0)
    1586             goto fail;
    1587 
    1588         rc = fcntl(s6, F_SETFL, (rc | O_NONBLOCK));
    1589 #else
    1590         rc = ioctlsocket(s6, FIONBIO, &flags);
    1591 #endif
     1610        rc = set_nonblocking(s6, 1);
    15921611        if(rc < 0)
    15931612            goto fail;
Note: See TracChangeset for help on using the changeset viewer.