From 411cdf39fc2b961a970a0ae91b9059614251247e Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Tue, 28 Aug 2012 17:42:54 +0000 Subject: Loads of win32 compilation issues fixed. Most are fairly minor unsigned/signed mismatches because of socket handles, but there were also some order-of-definition issues that were fixed in the FD_SETSIZE definition code. Fixed a few things that just never worked on windows, like Bu::Thread::yield(). --- src/stable/archive.cpp | 2 +- src/stable/myriad.cpp | 1 + src/stable/myriadstream.cpp | 10 +++++----- src/stable/server.cpp | 8 ++++---- src/stable/server.h | 14 ++++++++++---- src/stable/tcpserversocket.cpp | 14 +++++++++++--- src/stable/tcpserversocket.h | 13 +++++++------ src/stable/tcpsocket.cpp | 4 ++++ src/stable/thread.cpp | 5 ++--- src/stable/util.h | 21 ++++++++------------- 10 files changed, 53 insertions(+), 39 deletions(-) (limited to 'src/stable') diff --git a/src/stable/archive.cpp b/src/stable/archive.cpp index 3a88b55..13480e1 100644 --- a/src/stable/archive.cpp +++ b/src/stable/archive.cpp @@ -35,7 +35,7 @@ void Bu::Archive::read( void *pData, size_t nSize ) if( nSize == 0 || pData == NULL ) return; - if( rStream.read( (char *)pData, nSize ) < nSize ) + if( (size_t)rStream.read( (char *)pData, nSize ) < nSize ) throw Bu::ExceptionBase("Insufficient data to unarchive object."); } diff --git a/src/stable/myriad.cpp b/src/stable/myriad.cpp index 4f65583..4be82f0 100644 --- a/src/stable/myriad.cpp +++ b/src/stable/myriad.cpp @@ -5,6 +5,7 @@ * terms of the license contained in the file LICENSE. */ +#include "bu/config.h" #include "bu/myriad.h" #include "bu/stream.h" #include "bu/myriadstream.h" diff --git a/src/stable/myriadstream.cpp b/src/stable/myriadstream.cpp index cb81355..58d3936 100644 --- a/src/stable/myriadstream.cpp +++ b/src/stable/myriadstream.cpp @@ -84,8 +84,8 @@ Bu::size Bu::MyriadStream::read( void *pBuf, Bu::size nBytes ) pCurBlock = rMyriad.getBlock( iCurBlock ); } - int iAmnt = Bu::min( - Bu::min( + int iAmnt = Bu::buMin( + Bu::buMin( rMyriad.iBlockSize - iPos%rMyriad.iBlockSize, iLeft ), @@ -165,8 +165,8 @@ Bu::size Bu::MyriadStream::write( const void *pBuf, Bu::size nBytes ) // happens when creating a new stream. if( iPos < pStream->iSize ) { - int iAmnt = Bu::min( - Bu::min( + int iAmnt = Bu::buMin( + Bu::buMin( rMyriad.iBlockSize - iPos%rMyriad.iBlockSize, iLeft ), @@ -189,7 +189,7 @@ Bu::size Bu::MyriadStream::write( const void *pBuf, Bu::size nBytes ) } else { - int iAmnt = Bu::min( + int iAmnt = Bu::buMin( rMyriad.iBlockSize - iPos%rMyriad.iBlockSize, iLeft ); diff --git a/src/stable/server.cpp b/src/stable/server.cpp index e4769a5..39ff7bb 100644 --- a/src/stable/server.cpp +++ b/src/stable/server.cpp @@ -29,7 +29,7 @@ Bu::Server::~Server() void Bu::Server::addPort( int nPort, int nPoolSize ) { TcpServerSocket *s = new TcpServerSocket( nPort, nPoolSize ); - int nSocket = s->getSocket(); + socket_t nSocket = s->getSocket(); FD_SET( nSocket, &fdActive ); hServers.insert( nSocket, s ); } @@ -37,7 +37,7 @@ void Bu::Server::addPort( int nPort, int nPoolSize ) void Bu::Server::addPort( const String &sAddr, int nPort, int nPoolSize ) { TcpServerSocket *s = new TcpServerSocket( sAddr, nPort, nPoolSize ); - int nSocket = s->getSocket(); + socket_t nSocket = s->getSocket(); FD_SET( nSocket, &fdActive ); hServers.insert( nSocket, s ); } @@ -131,7 +131,7 @@ void Bu::Server::scan() tick(); } -void Bu::Server::addClient( int nSocket, int nPort ) +void Bu::Server::addClient( socket_t nSocket, int nPort ) { FD_SET( nSocket, &fdActive ); @@ -202,7 +202,7 @@ void Bu::Server::shutdown() hClients.clear(); } -void Bu::Server::closeClient( int iSocket ) +void Bu::Server::closeClient( socket_t iSocket ) { Bu::Client *pClient = hClients.get( iSocket ); onClosedConnection( pClient ); diff --git a/src/stable/server.h b/src/stable/server.h index 68e5205..5a414d9 100644 --- a/src/stable/server.h +++ b/src/stable/server.h @@ -55,13 +55,19 @@ namespace Bu Server(); virtual ~Server(); +#ifdef WIN32 + typedef unsigned int socket_t; +#else + typedef int socket_t; +#endif + void addPort( int nPort, int nPoolSize=40 ); void addPort( const String &sAddr, int nPort, int nPoolSize=40 ); virtual void scan(); void setTimeout( int nTimeoutSec, int nTimeoutUSec=0 ); - void addClient( int nSocket, int nPort ); + void addClient( socket_t nSocket, int nPort ); void setAutoTick( bool bEnable=true ); void tick(); @@ -72,7 +78,7 @@ namespace Bu void shutdown(); private: - void closeClient( int iSocket ); + void closeClient( socket_t iSocket ); class SrvClientLink : public Bu::ClientLink { public: @@ -97,9 +103,9 @@ namespace Bu int nTimeoutSec; int nTimeoutUSec; fd_set fdActive; - typedef Hash SrvHash; + typedef Hash SrvHash; SrvHash hServers; - typedef Hash ClientHash; + typedef Hash ClientHash; ClientHash hClients; bool bAutoTick; }; diff --git a/src/stable/tcpserversocket.cpp b/src/stable/tcpserversocket.cpp index daedcd1..91da199 100644 --- a/src/stable/tcpserversocket.cpp +++ b/src/stable/tcpserversocket.cpp @@ -5,6 +5,8 @@ * terms of the license contained in the file LICENSE. */ +#include "bu/config.h" + #ifndef WIN32 #include #include @@ -23,8 +25,6 @@ #include #include "bu/tcpserversocket.h" -#include "bu/config.h" - namespace Bu { subExceptionDef( TcpServerSocketException ) } Bu::TcpServerSocket::TcpServerSocket( int nPort, int nPoolSize ) : @@ -72,7 +72,7 @@ Bu::TcpServerSocket::TcpServerSocket(const String &sAddr,int nPort, int nPoolSiz startServer( name, nPoolSize ); } -Bu::TcpServerSocket::TcpServerSocket( int nServer, bool bInit, int nPoolSize ) : +Bu::TcpServerSocket::TcpServerSocket( socket_t nServer, bool bInit, int nPoolSize ) : nServer( nServer ), nPort( 0 ) { @@ -109,7 +109,11 @@ Bu::TcpServerSocket::TcpServerSocket( const TcpServerSocket &rSrc ) Bu::TcpServerSocket::~TcpServerSocket() { +#ifdef WIN32 + if( nServer != INVALID_SOCKET ) +#else if( nServer > -1 ) +#endif ::close( nServer ); } @@ -118,7 +122,11 @@ void Bu::TcpServerSocket::startServer( struct sockaddr_in &name, int nPoolSize ) /* Create the socket. */ nServer = bu_socket( PF_INET, SOCK_STREAM, 0 ); +#ifdef WIN32 + if( nServer == INVALID_SOCKET ) +#else if( nServer < 0 ) +#endif { throw Bu::TcpServerSocketException("Couldn't create a listen socket."); } diff --git a/src/stable/tcpserversocket.h b/src/stable/tcpserversocket.h index 0f56bd6..9776668 100644 --- a/src/stable/tcpserversocket.h +++ b/src/stable/tcpserversocket.h @@ -37,9 +37,14 @@ namespace Bu class TcpServerSocket { public: +#ifdef WIN32 + typedef unsigned int socket_t; +#else + typedef int socket_t; +#endif TcpServerSocket( int nPort, int nPoolSize=40 ); TcpServerSocket( const String &sAddr, int nPort, int nPoolSize=40 ); - TcpServerSocket( int nSocket, bool bInit, int nPoolSize=40 ); + TcpServerSocket( socket_t nSocket, bool bInit, int nPoolSize=40 ); TcpServerSocket( const TcpServerSocket &rSrc ); virtual ~TcpServerSocket(); @@ -52,11 +57,7 @@ namespace Bu void initServer( struct sockaddr_in &name, int nPoolSize ); fd_set fdActive; -#ifdef WIN32 - unsigned int nServer; -#else - int nServer; -#endif + socket_t nServer; int nPort; }; } diff --git a/src/stable/tcpsocket.cpp b/src/stable/tcpsocket.cpp index 7ea6ca1..fa79a36 100644 --- a/src/stable/tcpsocket.cpp +++ b/src/stable/tcpsocket.cpp @@ -55,7 +55,11 @@ Bu::TcpSocket::TcpSocket( const Bu::String &sAddr, int nPort, int nTimeout, /* Create the socket. */ nTcpSocket = bu_socket( PF_INET, SOCK_STREAM, 0 ); +#ifdef WIN32 + if( nTcpSocket == INVALID_SOCKET ) +#else if( nTcpSocket < 0 ) +#endif { throw ExceptionBase("Couldn't create socket.\n"); } diff --git a/src/stable/thread.cpp b/src/stable/thread.cpp index 1bd2040..141f54a 100644 --- a/src/stable/thread.cpp +++ b/src/stable/thread.cpp @@ -5,9 +5,8 @@ * terms of the license contained in the file LICENSE. */ -#include "bu/thread.h" - #include "bu/config.h" +#include "bu/thread.h" namespace Bu { subExceptionDef( ThreadException ); } @@ -78,7 +77,7 @@ void Bu::Thread::yield() #ifndef WIN32 pthread_yield(); #else - #warning Bu::Thread::yield IS A STUB for WIN32!!!! + sched_yield(); #endif } diff --git a/src/stable/util.h b/src/stable/util.h index 087af6e..4514281 100644 --- a/src/stable/util.h +++ b/src/stable/util.h @@ -39,11 +39,6 @@ namespace Bu b = tmp; } -#ifdef WIN32 - #warning: removing min and max win32 macros because of compile conflict - #undef min - #undef max -#endif /** * Finds the lesser of the two objects, objects passed in must be * less-than-comparable. @@ -52,7 +47,7 @@ namespace Bu *@returns A reference to the lesser of a or b. */ template - const item &min( const item &a, const item &b ) + const item &buMin( const item &a, const item &b ) { return a - item &min( item &a, item &b ) + item &buMin( item &a, item &b ) { return a - const item &max( const item &a, const item &b ) + const item &buMax( const item &a, const item &b ) { return b - item &max( item &a, item &b ) + item &buMax( item &a, item &b ) { return b - const item &mid( const item &a, const item &b, const item &c ) + const item &buMid( const item &a, const item &b, const item &c ) { - return min( max( a, b ), c ); + return buMin( buMax( a, b ), c ); } /** @@ -117,9 +112,9 @@ namespace Bu *@returns A reference to the mid-value of a, b, and c. */ template - item &mid( item &a, item &b, item &c ) + item &buMid( item &a, item &b, item &c ) { - return min( max( a, b ), c ); + return buMin( buMax( a, b ), c ); } // -- cgit v1.2.3