diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/exceptionbase.h | 2 | ||||
-rw-r--r-- | src/plugger.h | 4 | ||||
-rw-r--r-- | src/socket.cpp | 23 | ||||
-rw-r--r-- | src/socket.h | 3 | ||||
-rw-r--r-- | src/tests/fstrstd.cpp | 9 | ||||
-rw-r--r-- | src/tests/socketblock.cpp | 50 |
6 files changed, 83 insertions, 8 deletions
diff --git a/src/exceptionbase.h b/src/exceptionbase.h index 33e79b2..0a251e4 100644 --- a/src/exceptionbase.h +++ b/src/exceptionbase.h | |||
@@ -81,7 +81,7 @@ namespace Bu | |||
81 | } | 81 | } |
82 | 82 | ||
83 | #define subExceptionDecl( name ) \ | 83 | #define subExceptionDecl( name ) \ |
84 | class name : public Bu::ExceptionBase \ | 84 | class name : public Bu::ExceptionBase \ |
85 | { \ | 85 | { \ |
86 | public: \ | 86 | public: \ |
87 | name( const char *sFormat, ... ) throw (); \ | 87 | name( const char *sFormat, ... ) throw (); \ |
diff --git a/src/plugger.h b/src/plugger.h index 2124b7a..88628a9 100644 --- a/src/plugger.h +++ b/src/plugger.h | |||
@@ -158,9 +158,7 @@ namespace Bu | |||
158 | 158 | ||
159 | bool hasPlugin( const char *lpName ) | 159 | bool hasPlugin( const char *lpName ) |
160 | { | 160 | { |
161 | if( hPlugin[lpName] == NULL ) | 161 | return hPlugin.has( lpName ); |
162 | return false; | ||
163 | return true; | ||
164 | } | 162 | } |
165 | 163 | ||
166 | void destroy( T *pPlug ) | 164 | void destroy( T *pPlug ) |
diff --git a/src/socket.cpp b/src/socket.cpp index e567061..221d4c2 100644 --- a/src/socket.cpp +++ b/src/socket.cpp | |||
@@ -174,9 +174,26 @@ size_t Bu::Socket::read( void *pBuf, size_t nBytes ) | |||
174 | return nRead; | 174 | return nRead; |
175 | } | 175 | } |
176 | 176 | ||
177 | //size_t Bu::Socket::read( void *pBuf, size_t nBytes, uint32_t nTimeout ) | 177 | size_t Bu::Socket::read( void *pBuf, size_t nBytes, |
178 | //{ | 178 | uint32_t nSec, uint32_t nUSec ) |
179 | //} | 179 | { |
180 | fd_set rfds; | ||
181 | FD_ZERO(&rfds); | ||
182 | FD_SET(nSocket, &rfds); | ||
183 | struct timeval tv = { nSec, nUSec }; | ||
184 | int retval = select( nSocket+1, &rfds, NULL, NULL, &tv ); | ||
185 | if( retval == -1 ) | ||
186 | throw ConnectionException( | ||
187 | excodeBadReadError, | ||
188 | "Bad Read error" | ||
189 | ); | ||
190 | if( !FD_ISSET( nSocket, &rfds ) ) | ||
191 | throw ConnectionException( | ||
192 | excodeSocketTimeout, | ||
193 | "Socket timout on read" | ||
194 | ); | ||
195 | return read( pBuf, nBytes ); | ||
196 | } | ||
180 | 197 | ||
181 | size_t Bu::Socket::write( const void *pBuf, size_t nBytes ) | 198 | size_t Bu::Socket::write( const void *pBuf, size_t nBytes ) |
182 | { | 199 | { |
diff --git a/src/socket.h b/src/socket.h index c291549..9f82456 100644 --- a/src/socket.h +++ b/src/socket.h | |||
@@ -21,7 +21,8 @@ namespace Bu | |||
21 | virtual void close(); | 21 | virtual void close(); |
22 | //virtual void read(); | 22 | //virtual void read(); |
23 | virtual size_t read( void *pBuf, size_t nBytes ); | 23 | virtual size_t read( void *pBuf, size_t nBytes ); |
24 | virtual size_t read( void *pBuf, size_t nBytes, uint32_t nTimeout ); | 24 | virtual size_t read( void *pBuf, size_t nBytes, |
25 | uint32_t nSec, uint32_t nUSec=0 ); | ||
25 | virtual size_t write( const void *pBuf, size_t nBytes ); | 26 | virtual size_t write( const void *pBuf, size_t nBytes ); |
26 | 27 | ||
27 | virtual long tell(); | 28 | virtual long tell(); |
diff --git a/src/tests/fstrstd.cpp b/src/tests/fstrstd.cpp new file mode 100644 index 0000000..8dffcb6 --- /dev/null +++ b/src/tests/fstrstd.cpp | |||
@@ -0,0 +1,9 @@ | |||
1 | #include <iostream> | ||
2 | #include "bu/fstring.h" | ||
3 | |||
4 | int main() | ||
5 | { | ||
6 | Bu::FString s("Hey there, dude.\n"); | ||
7 | |||
8 | std::cout << s << 5; | ||
9 | } | ||
diff --git a/src/tests/socketblock.cpp b/src/tests/socketblock.cpp new file mode 100644 index 0000000..443b07e --- /dev/null +++ b/src/tests/socketblock.cpp | |||
@@ -0,0 +1,50 @@ | |||
1 | #include "bu/ito.h" | ||
2 | #include "bu/socket.h" | ||
3 | #include "bu/serversocket.h" | ||
4 | #include <stdio.h> | ||
5 | |||
6 | class TstServer : public Bu::Ito | ||
7 | { | ||
8 | public: | ||
9 | TstServer() : | ||
10 | s( 55678 ) | ||
11 | { | ||
12 | } | ||
13 | |||
14 | virtual void *run() | ||
15 | { | ||
16 | Bu::Socket c = s.accept( 45, 0 ); | ||
17 | printf("TstServer: Accetped connection.\n"); fflush( stdout ); | ||
18 | |||
19 | sleep( 1 ); | ||
20 | printf("TstServer: Trying to read 10 bytes...\n"); fflush( stdout ); | ||
21 | |||
22 | char buf[10]; | ||
23 | size_t nRead = c.read( buf, 10 ); | ||
24 | printf("TstServer: Got %d bytes...\n", nRead ); fflush( stdout ); | ||
25 | |||
26 | printf("TstServer: Closing connection...\n"); fflush( stdout ); | ||
27 | c.close(); | ||
28 | |||
29 | return NULL; | ||
30 | } | ||
31 | |||
32 | Bu::ServerSocket s; | ||
33 | }; | ||
34 | |||
35 | int main() | ||
36 | { | ||
37 | TstServer ts; | ||
38 | |||
39 | ts.start(); | ||
40 | |||
41 | printf("main: Connecting to server.\n"); fflush( stdout ); | ||
42 | Bu::Socket s( "localhost", 55678 ); | ||
43 | |||
44 | printf("main: Sending 4 bytes.\n"); fflush( stdout ); | ||
45 | s.write( "aoeu", 4 ); | ||
46 | |||
47 | printf("main: Sleeping 10 seconds for good measure.\n"); fflush( stdout ); | ||
48 | sleep( 10 ); | ||
49 | } | ||
50 | |||