mirror of
https://github.com/transmission/transmission
synced 2025-03-03 10:15:45 +00:00
get the socket/net code working on win32 too
This commit is contained in:
parent
ae6e82a1a5
commit
ba3dc008fc
8 changed files with 53 additions and 35 deletions
|
@ -116,7 +116,7 @@ case $host_os in
|
|||
*cygwin|*mingw32*)
|
||||
msw="yes"
|
||||
CXXFLAGS="$CXXFLAGS -mms-bitfields -mwin32 -mwindows"
|
||||
CPPFLAGS="$CPPFLAGS -D__MINGW__ -DWIN32_LEAN_AND_MEAN"
|
||||
CPPFLAGS="$CPPFLAGS -DWIN32 -DWIN32_LEAN_AND_MEAN"
|
||||
LIBS="$LIBS -lshell32 -lws2_32"
|
||||
transmissionlocaledir="locale"
|
||||
if test -z "$host_alias"; then
|
||||
|
|
|
@ -33,16 +33,8 @@ extern int vasprintf( char **, const char *, va_list );
|
|||
#include <signal.h>
|
||||
#endif
|
||||
|
||||
#ifdef SYS_BEOS
|
||||
# define socklen_t uint32_t
|
||||
#endif
|
||||
|
||||
#define TR_NAME "Transmission"
|
||||
|
||||
#ifndef INADDR_NONE
|
||||
#define INADDR_NONE 0xffffffff
|
||||
#endif
|
||||
|
||||
#ifdef __GNUC__
|
||||
#define UNUSED __attribute__((unused))
|
||||
#else
|
||||
|
|
|
@ -595,7 +595,7 @@ pulsereq( tr_natpmp_t * pmp )
|
|||
}
|
||||
else if( TR_NET_CLOSE & res )
|
||||
{
|
||||
if( ECONNRESET == errno || ECONNREFUSED == errno )
|
||||
if( ECONNRESET == sockerrno || ECONNREFUSED == sockerrno )
|
||||
{
|
||||
tr_dbg( "nat-pmp not supported by device" );
|
||||
req->nobodyhome = 1;
|
||||
|
@ -651,7 +651,7 @@ sendreq( tr_natpmp_req_t * req )
|
|||
}
|
||||
|
||||
res = tr_netSend( req->fd, buf, sizeof( buf ) );
|
||||
if( TR_NET_CLOSE & res && EHOSTUNREACH == errno )
|
||||
if( TR_NET_CLOSE & res && EHOSTUNREACH == sockerrno )
|
||||
{
|
||||
res = TR_NET_BLOCK;
|
||||
}
|
||||
|
|
|
@ -80,7 +80,7 @@ struct tr_resolve_s
|
|||
* Initializes the static variables used for resolution and launch the
|
||||
* gethostbyname thread.
|
||||
**********************************************************************/
|
||||
void tr_netResolveThreadInit()
|
||||
void tr_netResolveThreadInit( void )
|
||||
{
|
||||
resolveDie = 0;
|
||||
resolveQueue = NULL;
|
||||
|
@ -96,7 +96,7 @@ void tr_netResolveThreadInit()
|
|||
* wait until it does, in case it is stuck in a resolution: we let it
|
||||
* die and clean itself up.
|
||||
**********************************************************************/
|
||||
void tr_netResolveThreadClose()
|
||||
void tr_netResolveThreadClose( void )
|
||||
{
|
||||
tr_lockLock( resolveLock );
|
||||
resolveDie = 1;
|
||||
|
@ -289,7 +289,7 @@ tr_netOpen( const struct in_addr * addr, tr_port_t port,
|
|||
|
||||
if( connect( s, (struct sockaddr *) &sock,
|
||||
sizeof( struct sockaddr_in ) ) < 0 &&
|
||||
errno != EINPROGRESS )
|
||||
sockerrno != EINPROGRESS )
|
||||
{
|
||||
tr_err( "Could not connect socket (%s)", strerror( errno ) );
|
||||
tr_netClose( s );
|
||||
|
@ -415,7 +415,7 @@ tr_netSend( int s, const void * buf, int size )
|
|||
if( ret >= 0 )
|
||||
return ret;
|
||||
|
||||
if( errno == ENOTCONN || errno == EAGAIN || errno == EWOULDBLOCK )
|
||||
if( sockerrno == ENOTCONN || sockerrno == EAGAIN || sockerrno == EWOULDBLOCK )
|
||||
return TR_NET_BLOCK;
|
||||
|
||||
return TR_NET_CLOSE;
|
||||
|
@ -430,7 +430,7 @@ int tr_netRecvFrom( int s, uint8_t * buf, int size, struct sockaddr_in * addr )
|
|||
ret = recvfrom( s, buf, size, 0, ( struct sockaddr * ) addr, &len );
|
||||
if( ret < 0 )
|
||||
{
|
||||
if( errno == EAGAIN || errno == EWOULDBLOCK )
|
||||
if( sockerrno == EAGAIN || sockerrno == EWOULDBLOCK )
|
||||
{
|
||||
ret = TR_NET_BLOCK;
|
||||
}
|
||||
|
|
|
@ -25,12 +25,38 @@
|
|||
#ifndef _TR_NET_H_
|
||||
#define _TR_NET_H_
|
||||
|
||||
#if defined(BEOS_NETSERVER) || defined(__MINGW__)
|
||||
#include <stdint.h>
|
||||
typedef uint16_t tr_port_t;
|
||||
#ifdef WIN32
|
||||
#include <stdint.h>
|
||||
#include <winsock2.h>
|
||||
typedef uint16_t tr_port_t;
|
||||
#else
|
||||
#include <arpa/inet.h>
|
||||
typedef in_port_t tr_port_t;
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
typedef in_port_t tr_port_t;
|
||||
#endif
|
||||
|
||||
#ifdef SYS_BEOS
|
||||
#include <stdint.h>
|
||||
typedef uint32_t socklen_t;
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
#define EAGAIN WSAEAGAIN
|
||||
#define ECONNREFUSED WSAECONNREFUSED
|
||||
#define ECONNRESET WSAECONNRESET
|
||||
#define EHOSTUNREACH WSAEHOSTUNREACH
|
||||
#define EINPROGRESS WSAEINPROGRESS
|
||||
#define ENOTCONN WSAENOTCONN
|
||||
#define EWOULDBLOCK WSAEWOULDBLOCK
|
||||
#define sockerrno WSAGetLastError( )
|
||||
#else
|
||||
#include <errno.h>
|
||||
#define sockerrno errno
|
||||
#endif
|
||||
|
||||
#ifndef INADDR_NONE
|
||||
#define INADDR_NONE 0xffffffff
|
||||
#endif
|
||||
|
||||
struct in_addr;
|
||||
|
@ -42,8 +68,8 @@ struct sockaddr_in;
|
|||
int tr_netResolve( const char *, struct in_addr * );
|
||||
|
||||
typedef struct tr_resolve_s tr_resolve_t;
|
||||
void tr_netResolveThreadInit();
|
||||
void tr_netResolveThreadClose();
|
||||
void tr_netResolveThreadInit( void );
|
||||
void tr_netResolveThreadClose( void );
|
||||
tr_resolve_t * tr_netResolveInit( const char * address );
|
||||
tr_tristate_t tr_netResolvePulse( tr_resolve_t *, struct in_addr * );
|
||||
void tr_netResolveClose( tr_resolve_t * );
|
||||
|
@ -52,13 +78,13 @@ void tr_netResolveClose( tr_resolve_t * );
|
|||
/***********************************************************************
|
||||
* TCP and UDP sockets
|
||||
**********************************************************************/
|
||||
int tr_netOpenTCP ( const struct in_addr * addr, tr_port_t port, int priority );
|
||||
int tr_netOpenUDP ( const struct in_addr * addr, tr_port_t port, int priority );
|
||||
int tr_netOpenTCP ( const struct in_addr * addr, tr_port_t port, int priority );
|
||||
int tr_netOpenUDP ( const struct in_addr * addr, tr_port_t port, int priority );
|
||||
int tr_netMcastOpen( int port, const struct in_addr * addr );
|
||||
int tr_netBindTCP ( int port );
|
||||
int tr_netBindUDP ( int port );
|
||||
int tr_netAccept ( int s, struct in_addr *, tr_port_t * );
|
||||
void tr_netClose ( int s );
|
||||
int tr_netBindTCP ( int port );
|
||||
int tr_netBindUDP ( int port );
|
||||
int tr_netAccept ( int s, struct in_addr *, tr_port_t * );
|
||||
void tr_netClose ( int s );
|
||||
|
||||
#define TR_NET_BLOCK 0x80000000
|
||||
#define TR_NET_CLOSE 0x40000000
|
||||
|
|
|
@ -845,10 +845,10 @@ getroute( int fd, unsigned int * buflen )
|
|||
res = recvfrom( fd, buf, len, 0, (struct sockaddr *) &snl, &slen );
|
||||
if( 0 > res )
|
||||
{
|
||||
if( EAGAIN != errno )
|
||||
if( EAGAIN != sockerrno )
|
||||
{
|
||||
tr_err( "failed to read from routing socket (%s)",
|
||||
strerror( errno ) );
|
||||
strerror( sockerrno ) );
|
||||
}
|
||||
free( buf );
|
||||
*buflen = 0;
|
||||
|
|
|
@ -52,7 +52,7 @@ extern "C" {
|
|||
#define INET_ADDRSTRLEN 16
|
||||
#endif
|
||||
|
||||
#if defined(__MINGW__)
|
||||
#if defined(WIN32)
|
||||
#define TR_PATH_DELIMITER '\\'
|
||||
#define TR_PATH_DELIMITER_STR "\\"
|
||||
#else
|
||||
|
|
|
@ -400,10 +400,10 @@ sendSSDP( int fd )
|
|||
if( 0 > sendto( fd, buf, len, 0,
|
||||
(struct sockaddr*) &sin, sizeof( sin ) ) )
|
||||
{
|
||||
if( EAGAIN != errno )
|
||||
if( EAGAIN != sockerrno )
|
||||
{
|
||||
tr_err( "Could not send SSDP discover message (%s)",
|
||||
strerror( errno ) );
|
||||
strerror( sockerrno ) );
|
||||
}
|
||||
killSock( &fd );
|
||||
return -1;
|
||||
|
@ -507,7 +507,7 @@ recvSSDP( int fd, char * buf, int * len )
|
|||
}
|
||||
else if( TR_NET_CLOSE & *len )
|
||||
{
|
||||
tr_err( "Could not receive SSDP message (%s)", strerror( errno ) );
|
||||
tr_err( "Could not receive SSDP message (%s)", strerror( sockerrno ) );
|
||||
return TR_NET_ERROR;
|
||||
}
|
||||
else
|
||||
|
|
Loading…
Reference in a new issue