win32 cleanly compiles and starts now. (still doesn't atually *work*, but we're getting closer...)

This commit is contained in:
Charles Kerr 2007-08-02 19:43:29 +00:00
parent 65b81d09b6
commit 1fd5f90a77
10 changed files with 158 additions and 62 deletions

View File

@ -340,7 +340,7 @@ int tr_fdSocketCreate( int type, int priority )
if( priority || ( gFd->normal < gFd->normalMax ) )
if( ( s = socket( AF_INET, type, 0 ) ) < 0 )
tr_err( "Could not create socket (%s)", strerror( errno ) );
tr_err( "Could not create socket (%s)", strerror( sockerrno ) );
if( s > -1 )
{

View File

@ -602,7 +602,7 @@ pulsereq( tr_natpmp_t * pmp )
}
else
{
tr_inf( "error reading nat-pmp response (%s)", strerror( errno ) );
tr_inf( "error reading nat-pmp response (%s)", strerror( sockerrno ) );
}
return TR_NET_ERROR;
}
@ -657,7 +657,7 @@ sendreq( tr_natpmp_req_t * req )
}
if( TR_NET_CLOSE & res )
{
tr_err( "failed to send nat-pmp request (%s)", strerror( errno ) );
tr_err( "failed to send nat-pmp request (%s)", strerror( sockerrno ) );
return 1;
}
else if( !( TR_NET_BLOCK & res ) )

View File

@ -28,8 +28,11 @@
#include <string.h>
#include <sys/types.h>
#ifndef WIN32
#include <netdb.h>
#include <fcntl.h>
#endif
#include "transmission.h"
#include "fdlimit.h"
@ -38,6 +41,20 @@
#include "utils.h"
void
tr_netInit( void )
{
static int initialized = FALSE;
if( !initialized )
{
#ifdef WIN32
WSADATA wsaData;
WSAStartup(MAKEWORD(2,2), &wsaData);
#endif
initialized = TRUE;
}
}
/***********************************************************************
* DNS resolution
**********************************************************************/
@ -240,9 +257,9 @@ static void resolveFunc( void * arg UNUSED )
static int makeSocketNonBlocking( int s )
{
#ifdef SYS_WIN32
#ifdef WIN32
unsigned long flags = 1;
if( ioctlsocket( sock, FIONBIO, &flags) == SOCKET_ERROR )
if( ioctlsocket( s, FIONBIO, &flags) == SOCKET_ERROR )
#elif defined(SYS_BEOS)
int flags = 1;
if( setsockopt( s, SOL_SOCKET, SO_NONBLOCK,
@ -254,7 +271,7 @@ static int makeSocketNonBlocking( int s )
#endif
{
tr_err( "Could not set socket to non-blocking mode (%s)",
strerror( errno ) );
strerror( sockerrno ) );
tr_netClose( s );
return -1;
}
@ -293,7 +310,7 @@ tr_netOpen( const struct in_addr * addr, tr_port_t port,
sizeof( struct sockaddr_in ) ) < 0 &&
sockerrno != EINPROGRESS )
{
tr_err( "Could not connect socket (%s)", strerror( errno ) );
tr_err( "Could not connect socket (%s)", strerror( sockerrno ) );
tr_netClose( s );
return -1;
}
@ -328,9 +345,9 @@ int tr_netMcastOpen( int port, const struct in_addr * addr )
memset( &req, 0, sizeof( req ) );
req.imr_multiaddr.s_addr = addr->s_addr;
req.imr_interface.s_addr = htonl( INADDR_ANY );
if( setsockopt( fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, &req, sizeof ( req ) ) )
if( setsockopt( fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char*)&req, sizeof ( req ) ) )
{
tr_err( "Could not join multicast group (%s)", strerror( errno ) );
tr_err( "Could not join multicast group (%s)", strerror( sockerrno ) );
tr_netClose( fd );
return -1;
}
@ -360,7 +377,7 @@ tr_netBind( int port, int type )
#ifdef SO_REUSEADDR
optval = 1;
setsockopt( s, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof( optval ) );
setsockopt( s, SOL_SOCKET, SO_REUSEADDR, (char*)&optval, sizeof( optval ) );
#endif
#ifdef SO_REUSEPORT

View File

@ -94,6 +94,8 @@ int tr_netRecvFrom( int s, uint8_t * buf, int size, struct sockaddr_in * );
void tr_netNtop( const struct in_addr * addr, char * buf, int len );
void tr_netInit ( void );
#define tr_addrcmp( aa, bb ) memcmp( ( void * )(aa), ( void * )(bb), 4)

View File

@ -33,6 +33,8 @@
#include <kernel/OS.h>
#define BEOS_MAX_THREADS 256
#elif defined(WIN32)
#include <windows.h>
#include <shlobj.h> /* for CSIDL_APPDATA, CSIDL_PROFILE */
#else
#include <pthread.h>
#endif
@ -43,6 +45,7 @@
#include <unistd.h> /* getuid getpid close */
#include "transmission.h"
#include "list.h"
#include "net.h"
#include "platform.h"
#include "utils.h"
@ -111,7 +114,7 @@ tr_threadNew( void (*func)(void *),
t->thread = spawn_thread( (void*)ThreadFunc, name, B_NORMAL_PRIORITY, t );
resume_thread( t->thread );
#elif defined(WIN32)
t->thread = (HANDLE) _beginthreadex( NULL, 0, &ThreadFunc, NULL, 0, NULL );
t->thread = (HANDLE) _beginthreadex( NULL, 0, &ThreadFunc, t, 0, NULL );
#else
pthread_create( &t->thread, NULL, (void * (*) (void *)) ThreadFunc, t );
#endif
@ -216,7 +219,7 @@ tr_lockUnlock( tr_lock_t * l )
#ifdef SYS_BEOS
release_sem( l->lock );
#elif defined(WIN32)
DeleteCriticalSection( &l->lock );
LeaveCriticalSection( &l->lock );
#else
pthread_mutex_unlock( &l->lock );
#endif
@ -343,12 +346,26 @@ struct tr_cond_s
thread_id threads[BEOS_MAX_THREADS];
int start, end;
#elif defined(WIN32)
CONDITION_VARIABLE cond;
tr_list_t * events;
tr_lock_t * lock;
#else
pthread_cond_t cond;
#endif
};
#ifdef WIN32
static DWORD getContEventTLS( void )
{
static int inited = FALSE;
static DWORD event_tls;
if( !inited ) {
inited = TRUE;
event_tls = TlsAlloc();
}
return event_tls;
}
#endif
tr_cond_t*
tr_condNew( void )
{
@ -358,16 +375,19 @@ tr_condNew( void )
c->start = 0;
c->end = 0;
#elif defined(WIN32)
InitializeConditionVariable( &c->cond );
c->events = NULL;
c->lock = tr_lockNew( );
#else
pthread_cond_init( &c->cond, NULL );
#endif
return c;
}
void tr_condWait( tr_cond_t * c, tr_lock_t * l )
void
tr_condWait( tr_cond_t * c, tr_lock_t * l )
{
#ifdef SYS_BEOS
/* Keep track of that thread */
acquire_sem( c->sem );
c->threads[c->end] = find_thread( NULL );
@ -378,10 +398,36 @@ void tr_condWait( tr_cond_t * c, tr_lock_t * l )
release_sem( *l );
suspend_thread( find_thread( NULL ) ); /* Wait for signal */
acquire_sem( *l );
#elif defined(WIN32)
SleepConditionVariableCS( &c->cond, &l->lock, INFINITE );
/* get this thread's cond event */
DWORD key = getContEventTLS ( );
HANDLE hEvent = TlsGetValue( key );
if( !hEvent ) {
hEvent = CreateEvent( 0, FALSE, FALSE, 0 );
TlsSetValue( key, hEvent );
}
/* add it to the list of events waiting to be signaled */
tr_lockLock( c->lock );
c->events = tr_list_append( c->events, hEvent );
tr_lockUnlock( c->lock );
/* now wait for it to be signaled */
tr_lockUnlock( l );
WaitForSingleObject( hEvent, INFINITE );
tr_lockLock( l );
/* remove it from the list of events waiting to be signaled */
tr_lockLock( c->lock );
c->events = tr_list_remove_data( c->events, hEvent );
tr_lockUnlock( c->lock );
#else
pthread_cond_wait( &c->cond, &l->lock );
#endif
}
@ -409,28 +455,50 @@ static int condTrySignal( tr_cond_t * c )
return 0;
}
#endif
void tr_condSignal( tr_cond_t * c )
void
tr_condSignal( tr_cond_t * c )
{
#ifdef SYS_BEOS
acquire_sem( c->sem );
condTrySignal( c );
release_sem( c->sem );
#elif defined(WIN32)
WakeConditionVariable( &c->cond );
tr_lockLock( c->lock );
if( c->events != NULL )
SetEvent( (HANDLE)c->events->data );
tr_lockUnlock( c->lock );
#else
pthread_cond_signal( &c->cond );
#endif
}
void tr_condBroadcast( tr_cond_t * c )
void
tr_condBroadcast( tr_cond_t * c )
{
#ifdef SYS_BEOS
acquire_sem( c->sem );
while( !condTrySignal( c ) );
release_sem( c->sem );
#elif defined(WIN32)
WakeAllConditionVariable( &c->cond );
tr_list_t * l;
tr_lockLock( c->lock );
for( l=c->events; l!=NULL; l=l->next )
SetEvent( (HANDLE)l->data );
tr_lockUnlock( c->lock );
#else
pthread_cond_broadcast( &c->cond );
#endif
}
@ -440,7 +508,8 @@ tr_condFree( tr_cond_t * c )
#ifdef SYS_BEOS
delete_sem( c->sem );
#elif defined(WIN32)
/* a no-op, apparently */
tr_list_free( c->events );
tr_lockFree( c->lock );
#else
pthread_cond_destroy( &c->cond );
#endif
@ -452,52 +521,40 @@ tr_condFree( tr_cond_t * c )
**** PATHS
***/
#if !defined( SYS_BEOS ) && !defined( __AMIGAOS4__ )
#if !defined(WIN32) && !defined(SYS_BEOS) && !defined(__AMIGAOS4__)
#include <pwd.h>
#endif
const char *
tr_getHomeDirectory( void )
{
static char homeDirectory[MAX_PATH_LENGTH];
static int init = 0;
char * envHome;
struct passwd * pw;
static char buf[MAX_PATH_LENGTH];
static int init = 0;
const char * envHome;
if( init )
{
return homeDirectory;
}
return buf;
envHome = getenv( "HOME" );
if( NULL == envHome )
{
pw = getpwuid( getuid() );
if( envHome )
snprintf( buf, sizeof(buf), "%s", envHome );
else {
#ifdef WIN32
SHGetFolderPath( NULL, CSIDL_PROFILE, NULL, 0, buf );
#elif defined(SYS_BEOS) || defined(__AMIGAOS4__)
*buf = '\0';
#else
struct passwd * pw = getpwuid( getuid() );
endpwent();
if( NULL == pw )
{
/* XXX need to handle this case */
return NULL;
}
envHome = pw->pw_dir;
if( pw != NULL )
snprintf( buf, sizeof(buf), "%s", pw->pw_dir );
#endif
}
snprintf( homeDirectory, MAX_PATH_LENGTH, "%s", envHome );
init = 1;
return homeDirectory;
return buf;
}
#else
const char *
tr_getHomeDirectory( void )
{
/* XXX */
return "";
}
#endif /* !SYS_BEOS && !__AMIGAOS4__ */
static void
tr_migrateResume( const char *oldDirectory, const char *newDirectory )
@ -545,6 +602,13 @@ tr_getPrefsDirectory( void )
"Library", "Application Support", "Transmission", NULL );
#elif defined(__AMIGAOS4__)
snprintf( buf, buflen, "PROGDIR:.transmission" );
#elif defined(WIN32)
{
char tmp[MAX_PATH_LENGTH];
SHGetFolderPath( NULL, CSIDL_APPDATA, NULL, 0, tmp );
tr_buildPath( buf, sizeof(buf), tmp, "Transmission", NULL );
buflen = strlen( buf );
}
#else
tr_buildPath ( buf, buflen, h, ".transmission", NULL );
#endif
@ -574,7 +638,7 @@ tr_getCacheDirectory( void )
return buf;
p = tr_getPrefsDirectory();
#ifdef SYS_BEOS
#if defined(SYS_BEOS) || defined(WIN32)
tr_buildPath( buf, buflen, p, "Cache", NULL );
#elif defined( SYS_DARWIN )
tr_buildPath( buf, buflen, tr_getHomeDirectory(),
@ -605,7 +669,7 @@ tr_getTorrentsDirectory( void )
p = tr_getPrefsDirectory ();
#ifdef SYS_BEOS
#if defined(SYS_BEOS) || defined(WIN32)
tr_buildPath( buf, buflen, p, "Torrents", NULL );
#elif defined( SYS_DARWIN )
tr_buildPath( buf, buflen, p, "Torrents", NULL );

View File

@ -30,7 +30,6 @@
#include "transmission.h"
#include "bencode.h"
#include "bsdqueue.h"
#include "completion.h"
#include "http.h"
#include "net.h"
@ -38,6 +37,11 @@
#include "tracker.h"
#include "utils.h"
#ifdef WIN32
#undef SLIST_ENTRY
#endif
#include "bsdqueue.h"
/* Users aren't allowed to make a manual announce more often than this. */
static const int MANUAL_ANNOUNCE_INTERVAL_MSEC = (60*1000);

View File

@ -73,6 +73,7 @@ tr_handle_t * tr_init( const char * tag )
int i;
tr_msgInit();
tr_netInit();
tr_netResolveThreadInit();
h = calloc( 1, sizeof( tr_handle_t ) );
@ -101,8 +102,10 @@ tr_handle_t * tr_init( const char * tag )
h->azId[i] = tr_rand( 0xff );
}
#ifndef WIN32
/* Don't exit when writing on a broken socket */
signal( SIGPIPE, SIG_IGN );
#endif
/* Initialize rate and file descripts controls */
h->upload = tr_rcInit();

View File

@ -1478,7 +1478,7 @@ main( int argc, char * argv[] )
if( 0 > stat( argv[2], &sb ) )
{
tr_err( "failed to stat file %s: %s", argv[2], strerror( errno ) );
tr_err( "failed to stat file %s: %s", argv[2], strerror( sockerrno ) );
return 1;
}
@ -1492,7 +1492,7 @@ main( int argc, char * argv[] )
fd = open( argv[2], O_RDONLY );
if( 0 > fd )
{
tr_err( "failed to open file %s: %s", argv[2], strerror( errno ) );
tr_err( "failed to open file %s: %s", argv[2], strerror( sockerrno ) );
free( data );
return 1;
}
@ -1501,7 +1501,7 @@ main( int argc, char * argv[] )
if( sb.st_size > res )
{
tr_err( "failed to read file %s: %s", argv[2],
( 0 > res ? strerror( errno ) : "short read count" ) );
( 0 > res ? strerror( sockerrno ) : "short read count" ) );
close( fd );
free( data );
return 1;

View File

@ -35,6 +35,10 @@
#include <sys/stat.h>
#include <unistd.h> /* usleep, stat */
#ifdef WIN32
#include <windows.h> /* for Sleep */
#endif
#include "transmission.h"
#include "trcompat.h"
#include "utils.h"
@ -707,11 +711,13 @@ tr_date( void )
}
void
tr_wait( uint64_t delay_msec )
tr_wait( uint64_t delay_milliseconds )
{
#ifdef SYS_BEOS
snooze( 1000 * delay_msec );
snooze( 1000 * delay_milliseconds );
#elif defined(WIN32)
Sleep( (DWORD)delay_milliseconds );
#else
usleep( 1000 * delay_msec );
usleep( 1000 * delay_milliseconds );
#endif
}

View File

@ -15,8 +15,8 @@
#include "speed-stats.h"
BEGIN_EVENT_TABLE( SpeedStats, wxPanel )
EVT_PAINT( SpeedStats::OnPaint )
END_EVENT_TABLE()
//EVT_PAINT( SpeedStats::OnPaint )
SpeedStats :: SpeedStats( wxWindow * parent,
wxWindowID id,