aboutsummaryrefslogtreecommitdiff
path: root/src/stable
diff options
context:
space:
mode:
Diffstat (limited to 'src/stable')
-rw-r--r--src/stable/archive.cpp2
-rw-r--r--src/stable/myriad.cpp1
-rw-r--r--src/stable/myriadstream.cpp10
-rw-r--r--src/stable/server.cpp8
-rw-r--r--src/stable/server.h14
-rw-r--r--src/stable/tcpserversocket.cpp14
-rw-r--r--src/stable/tcpserversocket.h13
-rw-r--r--src/stable/tcpsocket.cpp4
-rw-r--r--src/stable/thread.cpp5
-rw-r--r--src/stable/util.h21
10 files changed, 53 insertions, 39 deletions
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 )
35 if( nSize == 0 || pData == NULL ) 35 if( nSize == 0 || pData == NULL )
36 return; 36 return;
37 37
38 if( rStream.read( (char *)pData, nSize ) < nSize ) 38 if( (size_t)rStream.read( (char *)pData, nSize ) < nSize )
39 throw Bu::ExceptionBase("Insufficient data to unarchive object."); 39 throw Bu::ExceptionBase("Insufficient data to unarchive object.");
40} 40}
41 41
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 @@
5 * terms of the license contained in the file LICENSE. 5 * terms of the license contained in the file LICENSE.
6 */ 6 */
7 7
8#include "bu/config.h"
8#include "bu/myriad.h" 9#include "bu/myriad.h"
9#include "bu/stream.h" 10#include "bu/stream.h"
10#include "bu/myriadstream.h" 11#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 )
84 pCurBlock = rMyriad.getBlock( iCurBlock ); 84 pCurBlock = rMyriad.getBlock( iCurBlock );
85 } 85 }
86 86
87 int iAmnt = Bu::min( 87 int iAmnt = Bu::buMin(
88 Bu::min( 88 Bu::buMin(
89 rMyriad.iBlockSize - iPos%rMyriad.iBlockSize, 89 rMyriad.iBlockSize - iPos%rMyriad.iBlockSize,
90 iLeft 90 iLeft
91 ), 91 ),
@@ -165,8 +165,8 @@ Bu::size Bu::MyriadStream::write( const void *pBuf, Bu::size nBytes )
165 // happens when creating a new stream. 165 // happens when creating a new stream.
166 if( iPos < pStream->iSize ) 166 if( iPos < pStream->iSize )
167 { 167 {
168 int iAmnt = Bu::min( 168 int iAmnt = Bu::buMin(
169 Bu::min( 169 Bu::buMin(
170 rMyriad.iBlockSize - iPos%rMyriad.iBlockSize, 170 rMyriad.iBlockSize - iPos%rMyriad.iBlockSize,
171 iLeft 171 iLeft
172 ), 172 ),
@@ -189,7 +189,7 @@ Bu::size Bu::MyriadStream::write( const void *pBuf, Bu::size nBytes )
189 } 189 }
190 else 190 else
191 { 191 {
192 int iAmnt = Bu::min( 192 int iAmnt = Bu::buMin(
193 rMyriad.iBlockSize - iPos%rMyriad.iBlockSize, 193 rMyriad.iBlockSize - iPos%rMyriad.iBlockSize,
194 iLeft 194 iLeft
195 ); 195 );
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()
29void Bu::Server::addPort( int nPort, int nPoolSize ) 29void Bu::Server::addPort( int nPort, int nPoolSize )
30{ 30{
31 TcpServerSocket *s = new TcpServerSocket( nPort, nPoolSize ); 31 TcpServerSocket *s = new TcpServerSocket( nPort, nPoolSize );
32 int nSocket = s->getSocket(); 32 socket_t nSocket = s->getSocket();
33 FD_SET( nSocket, &fdActive ); 33 FD_SET( nSocket, &fdActive );
34 hServers.insert( nSocket, s ); 34 hServers.insert( nSocket, s );
35} 35}
@@ -37,7 +37,7 @@ void Bu::Server::addPort( int nPort, int nPoolSize )
37void Bu::Server::addPort( const String &sAddr, int nPort, int nPoolSize ) 37void Bu::Server::addPort( const String &sAddr, int nPort, int nPoolSize )
38{ 38{
39 TcpServerSocket *s = new TcpServerSocket( sAddr, nPort, nPoolSize ); 39 TcpServerSocket *s = new TcpServerSocket( sAddr, nPort, nPoolSize );
40 int nSocket = s->getSocket(); 40 socket_t nSocket = s->getSocket();
41 FD_SET( nSocket, &fdActive ); 41 FD_SET( nSocket, &fdActive );
42 hServers.insert( nSocket, s ); 42 hServers.insert( nSocket, s );
43} 43}
@@ -131,7 +131,7 @@ void Bu::Server::scan()
131 tick(); 131 tick();
132} 132}
133 133
134void Bu::Server::addClient( int nSocket, int nPort ) 134void Bu::Server::addClient( socket_t nSocket, int nPort )
135{ 135{
136 FD_SET( nSocket, &fdActive ); 136 FD_SET( nSocket, &fdActive );
137 137
@@ -202,7 +202,7 @@ void Bu::Server::shutdown()
202 hClients.clear(); 202 hClients.clear();
203} 203}
204 204
205void Bu::Server::closeClient( int iSocket ) 205void Bu::Server::closeClient( socket_t iSocket )
206{ 206{
207 Bu::Client *pClient = hClients.get( iSocket ); 207 Bu::Client *pClient = hClients.get( iSocket );
208 onClosedConnection( pClient ); 208 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
55 Server(); 55 Server();
56 virtual ~Server(); 56 virtual ~Server();
57 57
58#ifdef WIN32
59 typedef unsigned int socket_t;
60#else
61 typedef int socket_t;
62#endif
63
58 void addPort( int nPort, int nPoolSize=40 ); 64 void addPort( int nPort, int nPoolSize=40 );
59 void addPort( const String &sAddr, int nPort, int nPoolSize=40 ); 65 void addPort( const String &sAddr, int nPort, int nPoolSize=40 );
60 66
61 virtual void scan(); 67 virtual void scan();
62 void setTimeout( int nTimeoutSec, int nTimeoutUSec=0 ); 68 void setTimeout( int nTimeoutSec, int nTimeoutUSec=0 );
63 69
64 void addClient( int nSocket, int nPort ); 70 void addClient( socket_t nSocket, int nPort );
65 71
66 void setAutoTick( bool bEnable=true ); 72 void setAutoTick( bool bEnable=true );
67 void tick(); 73 void tick();
@@ -72,7 +78,7 @@ namespace Bu
72 void shutdown(); 78 void shutdown();
73 79
74 private: 80 private:
75 void closeClient( int iSocket ); 81 void closeClient( socket_t iSocket );
76 class SrvClientLink : public Bu::ClientLink 82 class SrvClientLink : public Bu::ClientLink
77 { 83 {
78 public: 84 public:
@@ -97,9 +103,9 @@ namespace Bu
97 int nTimeoutSec; 103 int nTimeoutSec;
98 int nTimeoutUSec; 104 int nTimeoutUSec;
99 fd_set fdActive; 105 fd_set fdActive;
100 typedef Hash<int,TcpServerSocket *> SrvHash; 106 typedef Hash<socket_t,TcpServerSocket *> SrvHash;
101 SrvHash hServers; 107 SrvHash hServers;
102 typedef Hash<int,Client *> ClientHash; 108 typedef Hash<socket_t,Client *> ClientHash;
103 ClientHash hClients; 109 ClientHash hClients;
104 bool bAutoTick; 110 bool bAutoTick;
105 }; 111 };
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 @@
5 * terms of the license contained in the file LICENSE. 5 * terms of the license contained in the file LICENSE.
6 */ 6 */
7 7
8#include "bu/config.h"
9
8#ifndef WIN32 10#ifndef WIN32
9 #include <sys/socket.h> 11 #include <sys/socket.h>
10 #include <netinet/in.h> 12 #include <netinet/in.h>
@@ -23,8 +25,6 @@
23#include <fcntl.h> 25#include <fcntl.h>
24#include "bu/tcpserversocket.h" 26#include "bu/tcpserversocket.h"
25 27
26#include "bu/config.h"
27
28namespace Bu { subExceptionDef( TcpServerSocketException ) } 28namespace Bu { subExceptionDef( TcpServerSocketException ) }
29 29
30Bu::TcpServerSocket::TcpServerSocket( int nPort, int nPoolSize ) : 30Bu::TcpServerSocket::TcpServerSocket( int nPort, int nPoolSize ) :
@@ -72,7 +72,7 @@ Bu::TcpServerSocket::TcpServerSocket(const String &sAddr,int nPort, int nPoolSiz
72 startServer( name, nPoolSize ); 72 startServer( name, nPoolSize );
73} 73}
74 74
75Bu::TcpServerSocket::TcpServerSocket( int nServer, bool bInit, int nPoolSize ) : 75Bu::TcpServerSocket::TcpServerSocket( socket_t nServer, bool bInit, int nPoolSize ) :
76 nServer( nServer ), 76 nServer( nServer ),
77 nPort( 0 ) 77 nPort( 0 )
78{ 78{
@@ -109,7 +109,11 @@ Bu::TcpServerSocket::TcpServerSocket( const TcpServerSocket &rSrc )
109 109
110Bu::TcpServerSocket::~TcpServerSocket() 110Bu::TcpServerSocket::~TcpServerSocket()
111{ 111{
112#ifdef WIN32
113 if( nServer != INVALID_SOCKET )
114#else
112 if( nServer > -1 ) 115 if( nServer > -1 )
116#endif
113 ::close( nServer ); 117 ::close( nServer );
114} 118}
115 119
@@ -118,7 +122,11 @@ void Bu::TcpServerSocket::startServer( struct sockaddr_in &name, int nPoolSize )
118 /* Create the socket. */ 122 /* Create the socket. */
119 nServer = bu_socket( PF_INET, SOCK_STREAM, 0 ); 123 nServer = bu_socket( PF_INET, SOCK_STREAM, 0 );
120 124
125#ifdef WIN32
126 if( nServer == INVALID_SOCKET )
127#else
121 if( nServer < 0 ) 128 if( nServer < 0 )
129#endif
122 { 130 {
123 throw Bu::TcpServerSocketException("Couldn't create a listen socket."); 131 throw Bu::TcpServerSocketException("Couldn't create a listen socket.");
124 } 132 }
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
37 class TcpServerSocket 37 class TcpServerSocket
38 { 38 {
39 public: 39 public:
40#ifdef WIN32
41 typedef unsigned int socket_t;
42#else
43 typedef int socket_t;
44#endif
40 TcpServerSocket( int nPort, int nPoolSize=40 ); 45 TcpServerSocket( int nPort, int nPoolSize=40 );
41 TcpServerSocket( const String &sAddr, int nPort, int nPoolSize=40 ); 46 TcpServerSocket( const String &sAddr, int nPort, int nPoolSize=40 );
42 TcpServerSocket( int nSocket, bool bInit, int nPoolSize=40 ); 47 TcpServerSocket( socket_t nSocket, bool bInit, int nPoolSize=40 );
43 TcpServerSocket( const TcpServerSocket &rSrc ); 48 TcpServerSocket( const TcpServerSocket &rSrc );
44 virtual ~TcpServerSocket(); 49 virtual ~TcpServerSocket();
45 50
@@ -52,11 +57,7 @@ namespace Bu
52 void initServer( struct sockaddr_in &name, int nPoolSize ); 57 void initServer( struct sockaddr_in &name, int nPoolSize );
53 58
54 fd_set fdActive; 59 fd_set fdActive;
55#ifdef WIN32 60 socket_t nServer;
56 unsigned int nServer;
57#else
58 int nServer;
59#endif
60 int nPort; 61 int nPort;
61 }; 62 };
62} 63}
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,
55 /* Create the socket. */ 55 /* Create the socket. */
56 nTcpSocket = bu_socket( PF_INET, SOCK_STREAM, 0 ); 56 nTcpSocket = bu_socket( PF_INET, SOCK_STREAM, 0 );
57 57
58#ifdef WIN32
59 if( nTcpSocket == INVALID_SOCKET )
60#else
58 if( nTcpSocket < 0 ) 61 if( nTcpSocket < 0 )
62#endif
59 { 63 {
60 throw ExceptionBase("Couldn't create socket.\n"); 64 throw ExceptionBase("Couldn't create socket.\n");
61 } 65 }
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 @@
5 * terms of the license contained in the file LICENSE. 5 * terms of the license contained in the file LICENSE.
6 */ 6 */
7 7
8#include "bu/thread.h"
9
10#include "bu/config.h" 8#include "bu/config.h"
9#include "bu/thread.h"
11 10
12namespace Bu { subExceptionDef( ThreadException ); } 11namespace Bu { subExceptionDef( ThreadException ); }
13 12
@@ -78,7 +77,7 @@ void Bu::Thread::yield()
78#ifndef WIN32 77#ifndef WIN32
79 pthread_yield(); 78 pthread_yield();
80#else 79#else
81 #warning Bu::Thread::yield IS A STUB for WIN32!!!! 80 sched_yield();
82#endif 81#endif
83} 82}
84 83
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
39 b = tmp; 39 b = tmp;
40 } 40 }
41 41
42#ifdef WIN32
43 #warning: removing min and max win32 macros because of compile conflict
44 #undef min
45 #undef max
46#endif
47 /** 42 /**
48 * Finds the lesser of the two objects, objects passed in must be 43 * Finds the lesser of the two objects, objects passed in must be
49 * less-than-comparable. 44 * less-than-comparable.
@@ -52,7 +47,7 @@ namespace Bu
52 *@returns A reference to the lesser of a or b. 47 *@returns A reference to the lesser of a or b.
53 */ 48 */
54 template<typename item> 49 template<typename item>
55 const item &min( const item &a, const item &b ) 50 const item &buMin( const item &a, const item &b )
56 { 51 {
57 return a<b?a:b; 52 return a<b?a:b;
58 } 53 }
@@ -65,7 +60,7 @@ namespace Bu
65 *@returns A reference to the lesser of a or b. 60 *@returns A reference to the lesser of a or b.
66 */ 61 */
67 template<typename item> 62 template<typename item>
68 item &min( item &a, item &b ) 63 item &buMin( item &a, item &b )
69 { 64 {
70 return a<b?a:b; 65 return a<b?a:b;
71 } 66 }
@@ -78,7 +73,7 @@ namespace Bu
78 *@returns A reference to the greater of a or b. 73 *@returns A reference to the greater of a or b.
79 */ 74 */
80 template<typename item> 75 template<typename item>
81 const item &max( const item &a, const item &b ) 76 const item &buMax( const item &a, const item &b )
82 { 77 {
83 return b<a?a:b; 78 return b<a?a:b;
84 } 79 }
@@ -91,7 +86,7 @@ namespace Bu
91 *@returns A reference to the greater of a or b. 86 *@returns A reference to the greater of a or b.
92 */ 87 */
93 template<typename item> 88 template<typename item>
94 item &max( item &a, item &b ) 89 item &buMax( item &a, item &b )
95 { 90 {
96 return b<a?a:b; 91 return b<a?a:b;
97 } 92 }
@@ -104,9 +99,9 @@ namespace Bu
104 *@returns A reference to the mid-value of a, b, and c. 99 *@returns A reference to the mid-value of a, b, and c.
105 */ 100 */
106 template<typename item> 101 template<typename item>
107 const item &mid( const item &a, const item &b, const item &c ) 102 const item &buMid( const item &a, const item &b, const item &c )
108 { 103 {
109 return min( max( a, b ), c ); 104 return buMin( buMax( a, b ), c );
110 } 105 }
111 106
112 /** 107 /**
@@ -117,9 +112,9 @@ namespace Bu
117 *@returns A reference to the mid-value of a, b, and c. 112 *@returns A reference to the mid-value of a, b, and c.
118 */ 113 */
119 template<typename item> 114 template<typename item>
120 item &mid( item &a, item &b, item &c ) 115 item &buMid( item &a, item &b, item &c )
121 { 116 {
122 return min( max( a, b ), c ); 117 return buMin( buMax( a, b ), c );
123 } 118 }
124 119
125 // 120 //