aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2012-08-28 17:42:54 +0000
committerMike Buland <eichlan@xagasoft.com>2012-08-28 17:42:54 +0000
commit411cdf39fc2b961a970a0ae91b9059614251247e (patch)
tree935afa56c11aef0fb769e63659970e7d033a99e8
parentfc5132d68ae9e6afdbd0b5a687ba81c88fc84826 (diff)
downloadlibbu++-411cdf39fc2b961a970a0ae91b9059614251247e.tar.gz
libbu++-411cdf39fc2b961a970a0ae91b9059614251247e.tar.bz2
libbu++-411cdf39fc2b961a970a0ae91b9059614251247e.tar.xz
libbu++-411cdf39fc2b961a970a0ae91b9059614251247e.zip
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().
-rw-r--r--src/compat/win32.cpp4
-rw-r--r--src/compat/win32.h2
-rw-r--r--src/experimental/cipher.h4
-rw-r--r--src/experimental/fastcgi.cpp2
-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
-rw-r--r--src/tools/viewcsv.cpp8
-rw-r--r--src/unstable/itoserver.cpp13
-rw-r--r--src/unstable/itoserver.h18
-rw-r--r--src/unstable/myriadfs.cpp5
18 files changed, 84 insertions, 64 deletions
diff --git a/src/compat/win32.cpp b/src/compat/win32.cpp
index 6488d5f..e1151b0 100644
--- a/src/compat/win32.cpp
+++ b/src/compat/win32.cpp
@@ -12,7 +12,7 @@
12#define deffunc( name ) \ 12#define deffunc( name ) \
13 Bu::Winsock2::FNDEF_DYN_ ##name Bu::Winsock2::_fnptr_ ##name = NULL 13 Bu::Winsock2::FNDEF_DYN_ ##name Bu::Winsock2::_fnptr_ ##name = NULL
14 14
15char Bu::Winsock2::scode[15]; 15char Bu::Winsock2::scode[32];
16 16
17deffunc( WSAStartup ); 17deffunc( WSAStartup );
18deffunc( WSACleanup ); 18deffunc( WSACleanup );
@@ -85,7 +85,7 @@ Bu::Winsock2::~Winsock2()
85 85
86char *Bu::Winsock2::gai_strerror( int iCode ) 86char *Bu::Winsock2::gai_strerror( int iCode )
87{ 87{
88 sprintf( scode, "%d", Bu::Winsock2::WSAGetLastError() ); 88 sprintf( scode, "%d (%d)", iCode, Bu::Winsock2::WSAGetLastError() );
89 return scode; 89 return scode;
90} 90}
91 91
diff --git a/src/compat/win32.h b/src/compat/win32.h
index 512e6d3..7e44c13 100644
--- a/src/compat/win32.h
+++ b/src/compat/win32.h
@@ -87,7 +87,7 @@ namespace Bu
87 decltype( int, send, SOCKET s, const char *buf, int len, int flags ); 87 decltype( int, send, SOCKET s, const char *buf, int len, int flags );
88 decltype( int, __WSAFDIsSet, SOCKET s, fd_set *set ); 88 decltype( int, __WSAFDIsSet, SOCKET s, fd_set *set );
89 89
90 static char scode[15]; 90 static char scode[32];
91 static char *gai_strerror( int iCode ); 91 static char *gai_strerror( int iCode );
92 }; 92 };
93 93
diff --git a/src/experimental/cipher.h b/src/experimental/cipher.h
index 74f5124..5d5cb07 100644
--- a/src/experimental/cipher.h
+++ b/src/experimental/cipher.h
@@ -61,7 +61,7 @@ namespace Bu
61 61
62 if( iReadBufFill == iBlockSize ) 62 if( iReadBufFill == iBlockSize )
63 { 63 {
64 int iCpy = Bu::min( (int)(iBytes-iRead), iBlockSize-iReadBufPos ); 64 int iCpy = Bu::buMin( (int)(iBytes-iRead), iBlockSize-iReadBufPos );
65 memcpy( ((char *)pBuf)+iRead, aReadBuf+iReadBufPos, iCpy ); 65 memcpy( ((char *)pBuf)+iRead, aReadBuf+iReadBufPos, iCpy );
66 iRead += iCpy; 66 iRead += iCpy;
67 iReadBufPos += iCpy; 67 iReadBufPos += iCpy;
@@ -81,7 +81,7 @@ namespace Bu
81 81
82 while( iPos < iBytes ) 82 while( iPos < iBytes )
83 { 83 {
84 int iLeft = Bu::min((int)(iBytes-iPos),iBlockSize-iWriteBufFill); 84 int iLeft = Bu::buMin((int)(iBytes-iPos),iBlockSize-iWriteBufFill);
85 memcpy( aWriteBuf+iWriteBufFill, (char *)pBuf+iPos, iLeft ); 85 memcpy( aWriteBuf+iWriteBufFill, (char *)pBuf+iPos, iLeft );
86 iPos += iLeft; 86 iPos += iLeft;
87 iWriteBufFill += iLeft; 87 iWriteBufFill += iLeft;
diff --git a/src/experimental/fastcgi.cpp b/src/experimental/fastcgi.cpp
index 1f945a3..7068fa8 100644
--- a/src/experimental/fastcgi.cpp
+++ b/src/experimental/fastcgi.cpp
@@ -24,7 +24,7 @@ Bu::FastCgi::FastCgi() :
24 pSrv( NULL ), 24 pSrv( NULL ),
25 bRunning( true ) 25 bRunning( true )
26{ 26{
27 pSrv = new Bu::TcpServerSocket( STDIN_FILENO, false ); 27 pSrv = new Bu::TcpServerSocket( (Bu::TcpServerSocket::socket_t)STDIN_FILENO, false );
28} 28}
29 29
30Bu::FastCgi::FastCgi( int iPort ) : 30Bu::FastCgi::FastCgi( int iPort ) :
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 //
diff --git a/src/tools/viewcsv.cpp b/src/tools/viewcsv.cpp
index 46db319..5009ea8 100644
--- a/src/tools/viewcsv.cpp
+++ b/src/tools/viewcsv.cpp
@@ -105,8 +105,8 @@ public:
105 int maxx, maxy; 105 int maxx, maxy;
106 getmaxyx( stdscr, maxy, maxx ); 106 getmaxyx( stdscr, maxy, maxx );
107 107
108 int iRows = min( (int)doc.sgData.getSize(), maxy-((bHeaderRow)?(4):(3)) ); 108 int iRows = buMin( (int)doc.sgData.getSize(), maxy-((bHeaderRow)?(4):(3)) );
109 int iCols = min( doc.iMaxCols, (int)maxx-1 ); 109 int iCols = buMin( doc.iMaxCols, (int)maxx-1 );
110 110
111 int iHdrHeight = 1; 111 int iHdrHeight = 1;
112 if( bHeaderRow ) 112 if( bHeaderRow )
@@ -129,7 +129,7 @@ public:
129 { 129 {
130 if( iXPos >= maxx ) 130 if( iXPos >= maxx )
131 break; 131 break;
132 int iWidth = min( doc.aWidths[iCol+iXOff], maxx-iXPos-1 ); 132 int iWidth = buMin( doc.aWidths[iCol+iXOff], maxx-iXPos-1 );
133 char buf[6]; 133 char buf[6];
134 snprintf( buf, 6, "%d", iCol+iXOff ); 134 snprintf( buf, 6, "%d", iCol+iXOff );
135 mvaddch( 0, iXPos, ACS_VLINE ); 135 mvaddch( 0, iXPos, ACS_VLINE );
@@ -165,7 +165,7 @@ public:
165 { 165 {
166 if( iXPos >= maxx ) 166 if( iXPos >= maxx )
167 break; 167 break;
168 int iWidth = min( doc.aWidths[iCol+iXOff], maxx-iXPos-1 ); 168 int iWidth = buMin( doc.aWidths[iCol+iXOff], maxx-iXPos-1 );
169 mvaddch( iRow+iHdrHeight+1, iXPos, ACS_VLINE ); 169 mvaddch( iRow+iHdrHeight+1, iXPos, ACS_VLINE );
170 mvaddnstr( iRow+iHdrHeight+1, iXPos+1, 170 mvaddnstr( iRow+iHdrHeight+1, iXPos+1,
171 doc.sgData[iRow+iYOff][iCol+iXOff].getStr(), iWidth ); 171 doc.sgData[iRow+iYOff][iCol+iXOff].getStr(), iWidth );
diff --git a/src/unstable/itoserver.cpp b/src/unstable/itoserver.cpp
index 5b3b5a2..7dbce6c 100644
--- a/src/unstable/itoserver.cpp
+++ b/src/unstable/itoserver.cpp
@@ -5,14 +5,13 @@
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/itoserver.h" 9#include "bu/itoserver.h"
9#include <errno.h> 10#include <errno.h>
10#include "bu/tcpserversocket.h" 11#include "bu/tcpserversocket.h"
11#include "bu/client.h" 12#include "bu/client.h"
12#include "bu/tcpsocket.h" 13#include "bu/tcpsocket.h"
13 14
14#include "bu/config.h"
15
16Bu::ItoServer::ItoServer() : 15Bu::ItoServer::ItoServer() :
17 nTimeoutSec( 1 ), 16 nTimeoutSec( 1 ),
18 nTimeoutUSec( 0 ) 17 nTimeoutUSec( 0 )
@@ -42,7 +41,7 @@ Bu::ItoServer::~ItoServer()
42void Bu::ItoServer::addPort( int nPort, int nPoolSize ) 41void Bu::ItoServer::addPort( int nPort, int nPoolSize )
43{ 42{
44 TcpServerSocket *s = new TcpServerSocket( nPort, nPoolSize ); 43 TcpServerSocket *s = new TcpServerSocket( nPort, nPoolSize );
45 int nSocket = s->getSocket(); 44 socket_t nSocket = s->getSocket();
46 FD_SET( nSocket, &fdActive ); 45 FD_SET( nSocket, &fdActive );
47 hServers.insert( nSocket, s ); 46 hServers.insert( nSocket, s );
48} 47}
@@ -50,7 +49,7 @@ void Bu::ItoServer::addPort( int nPort, int nPoolSize )
50void Bu::ItoServer::addPort( const String &sAddr, int nPort, int nPoolSize ) 49void Bu::ItoServer::addPort( const String &sAddr, int nPort, int nPoolSize )
51{ 50{
52 TcpServerSocket *s = new TcpServerSocket( sAddr, nPort, nPoolSize ); 51 TcpServerSocket *s = new TcpServerSocket( sAddr, nPort, nPoolSize );
53 int nSocket = s->getSocket(); 52 socket_t nSocket = s->getSocket();
54 FD_SET( nSocket, &fdActive ); 53 FD_SET( nSocket, &fdActive );
55 hServers.insert( nSocket, s ); 54 hServers.insert( nSocket, s );
56} 55}
@@ -61,7 +60,7 @@ void Bu::ItoServer::setTimeout( int nTimeoutSec, int nTimeoutUSec )
61 this->nTimeoutUSec = nTimeoutUSec; 60 this->nTimeoutUSec = nTimeoutUSec;
62} 61}
63 62
64void Bu::ItoServer::addClient( int nSocket, int nPort ) 63void Bu::ItoServer::addClient( socket_t nSocket, int nPort )
65{ 64{
66 ItoClient *pC = new ItoClient( *this, nSocket, nPort, nTimeoutSec, 65 ItoClient *pC = new ItoClient( *this, nSocket, nPort, nTimeoutSec,
67 nTimeoutUSec ); 66 nTimeoutUSec );
@@ -106,7 +105,7 @@ void Bu::ItoServer::run()
106 } 105 }
107} 106}
108 107
109void Bu::ItoServer::clientCleanup( int iSocket ) 108void Bu::ItoServer::clientCleanup( socket_t iSocket )
110{ 109{
111 imClients.lock(); 110 imClients.lock();
112 ItoClient *pCli = hClients.get( iSocket ); 111 ItoClient *pCli = hClients.get( iSocket );
@@ -114,7 +113,7 @@ void Bu::ItoServer::clientCleanup( int iSocket )
114 qClientCleanup.enqueue( pCli ); 113 qClientCleanup.enqueue( pCli );
115} 114}
116 115
117Bu::ItoServer::ItoClient::ItoClient( ItoServer &rSrv, int iSocket, int iPort, 116Bu::ItoServer::ItoClient::ItoClient( ItoServer &rSrv, Bu::ItoServer::socket_t iSocket, int iPort,
118 int nTimeoutSec, int nTimeoutUSec ) : 117 int nTimeoutSec, int nTimeoutUSec ) :
119 rSrv( rSrv ), 118 rSrv( rSrv ),
120 iSocket( iSocket ), 119 iSocket( iSocket ),
diff --git a/src/unstable/itoserver.h b/src/unstable/itoserver.h
index 57fece3..6a0df56 100644
--- a/src/unstable/itoserver.h
+++ b/src/unstable/itoserver.h
@@ -58,13 +58,19 @@ namespace Bu
58 ItoServer(); 58 ItoServer();
59 virtual ~ItoServer(); 59 virtual ~ItoServer();
60 60
61#ifdef WIN32
62 typedef unsigned int socket_t;
63#else
64 typedef int socket_t;
65#endif
66
61 void addPort( int nPort, int nPoolSize=40 ); 67 void addPort( int nPort, int nPoolSize=40 );
62 void addPort( const String &sAddr, int nPort, int nPoolSize=40 ); 68 void addPort( const String &sAddr, int nPort, int nPoolSize=40 );
63 69
64 //void scan(); 70 //void scan();
65 void setTimeout( int nTimeoutSec, int nTimeoutUSec=0 ); 71 void setTimeout( int nTimeoutSec, int nTimeoutUSec=0 );
66 72
67 void addClient( int nSocket, int nPort ); 73 void addClient( socket_t nSocket, int nPort );
68 74
69 virtual void onNewConnection( Client *pClient, int nPort )=0; 75 virtual void onNewConnection( Client *pClient, int nPort )=0;
70 virtual void onClosedConnection( Client *pClient )=0; 76 virtual void onClosedConnection( Client *pClient )=0;
@@ -78,7 +84,7 @@ namespace Bu
78 { 84 {
79 friend class Bu::ItoServer::SrvClientLink; 85 friend class Bu::ItoServer::SrvClientLink;
80 public: 86 public:
81 ItoClient( ItoServer &rSrv, int nSocket, int nPort, 87 ItoClient( ItoServer &rSrv, socket_t nSocket, int nPort,
82 int nTimeoutSec, int nTimeoutUSec ); 88 int nTimeoutSec, int nTimeoutUSec );
83 virtual ~ItoClient(); 89 virtual ~ItoClient();
84 90
@@ -92,7 +98,7 @@ namespace Bu
92 ItoServer &rSrv; 98 ItoServer &rSrv;
93 Client *pClient; 99 Client *pClient;
94 fd_set fdActive; 100 fd_set fdActive;
95 int iSocket; 101 socket_t iSocket;
96 int iPort; 102 int iPort;
97 int nTimeoutSec; 103 int nTimeoutSec;
98 int nTimeoutUSec; 104 int nTimeoutUSec;
@@ -126,15 +132,15 @@ namespace Bu
126 int nTimeoutSec; 132 int nTimeoutSec;
127 int nTimeoutUSec; 133 int nTimeoutUSec;
128 fd_set fdActive; 134 fd_set fdActive;
129 typedef Hash<int,TcpServerSocket *> ServerHash; 135 typedef Hash<socket_t,TcpServerSocket *> ServerHash;
130 ServerHash hServers; 136 ServerHash hServers;
131 typedef Hash<int,ItoClient *> ClientHash; 137 typedef Hash<socket_t,ItoClient *> ClientHash;
132 typedef SynchroQueue<ItoClient *> ClientQueue; 138 typedef SynchroQueue<ItoClient *> ClientQueue;
133 ClientHash hClients; 139 ClientHash hClients;
134 ClientQueue qClientCleanup; 140 ClientQueue qClientCleanup;
135 Mutex imClients; 141 Mutex imClients;
136 142
137 void clientCleanup( int iSocket ); 143 void clientCleanup( socket_t iSocket );
138 }; 144 };
139} 145}
140 146
diff --git a/src/unstable/myriadfs.cpp b/src/unstable/myriadfs.cpp
index 32e1ad6..6ed176d 100644
--- a/src/unstable/myriadfs.cpp
+++ b/src/unstable/myriadfs.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/myriadfs.h" 9#include "bu/myriadfs.h"
9#include "bu/myriadstream.h" 10#include "bu/myriadstream.h"
10 11
@@ -434,7 +435,7 @@ int32_t Bu::MyriadFs::lookupInode( Bu::String::const_iterator iStart,
434void Bu::MyriadFs::readInode( int32_t iNode, RawStat &rs, MyriadStream &rIs ) 435void Bu::MyriadFs::readInode( int32_t iNode, RawStat &rs, MyriadStream &rIs )
435{ 436{
436 rIs.setPos( hNodeIndex.get( iNode )*sizeof(RawStat) ); 437 rIs.setPos( hNodeIndex.get( iNode )*sizeof(RawStat) );
437 if( rIs.read( &rs, sizeof(RawStat) ) < sizeof(RawStat) ) 438 if( rIs.read( &rs, sizeof(RawStat) ) < (int)sizeof(RawStat) )
438 throw Bu::MyriadFsException("Filesystem corruption detected."); 439 throw Bu::MyriadFsException("Filesystem corruption detected.");
439 if( rs.iNode != iNode ) 440 if( rs.iNode != iNode )
440 throw Bu::MyriadFsException("Filesystem corruption detected."); 441 throw Bu::MyriadFsException("Filesystem corruption detected.");
@@ -451,7 +452,7 @@ void Bu::MyriadFs::writeInode( const RawStat &rs,
451{ 452{
452 rOs.setSize( hNodeIndex.getSize()*sizeof(RawStat) ); 453 rOs.setSize( hNodeIndex.getSize()*sizeof(RawStat) );
453 rOs.setPos( hNodeIndex.get( rs.iNode )*sizeof(RawStat) ); 454 rOs.setPos( hNodeIndex.get( rs.iNode )*sizeof(RawStat) );
454 if( rOs.write( &rs, sizeof(RawStat) ) < sizeof(RawStat) ) 455 if( rOs.write( &rs, sizeof(RawStat) ) < (int)sizeof(RawStat) )
455 throw Bu::MyriadFsException("Error writing inode to header stream."); 456 throw Bu::MyriadFsException("Error writing inode to header stream.");
456} 457}
457 458