aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/client.cpp4
-rw-r--r--src/logger.cpp13
-rw-r--r--src/socket.cpp66
-rw-r--r--src/socket.h2
4 files changed, 68 insertions, 17 deletions
diff --git a/src/client.cpp b/src/client.cpp
index b546deb..f69ea24 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -68,8 +68,8 @@ void Bu::Client::processOutput()
68 if( sWriteBuf.getSize() > 0 ) 68 if( sWriteBuf.getSize() > 0 )
69 { 69 {
70 int nAmnt = (sWriteBuf.getSize()<2048)?(sWriteBuf.getSize()):(2048); 70 int nAmnt = (sWriteBuf.getSize()<2048)?(sWriteBuf.getSize()):(2048);
71 pSocket->write( sWriteBuf.getStr(), nAmnt ); 71 int nReal = pSocket->write( sWriteBuf.getStr(), nAmnt );
72 sWriteBuf.trimFront( nAmnt ); 72 sWriteBuf.trimFront( nReal );
73 //sWriteBuf.clear(); 73 //sWriteBuf.clear();
74 } 74 }
75} 75}
diff --git a/src/logger.cpp b/src/logger.cpp
index fe6a916..91679ff 100644
--- a/src/logger.cpp
+++ b/src/logger.cpp
@@ -20,7 +20,11 @@ void Bu::Logger::log( uint32_t nLevel, const char *sFile, const char *sFunction,
20 va_list ap; 20 va_list ap;
21 va_start( ap, sFormat ); 21 va_start( ap, sFormat );
22 char *text; 22 char *text;
23 vasprintf( &text, sFormat, ap ); 23 if( vasprintf( &text, sFormat, ap ) < 0 )
24 {
25 printf("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! WTF?\n");
26 return;
27 }
24 va_end(ap); 28 va_end(ap);
25 29
26 time_t t = time(NULL); 30 time_t t = time(NULL);
@@ -152,6 +156,11 @@ void Bu::Logger::hexDump( uint32_t nLevel, const char *sFile,
152 Bu::FString sLine; 156 Bu::FString sLine;
153 for(;;) 157 for(;;)
154 { 158 {
159 {
160 char buf[15];
161 sprintf( buf, "%010d| ", j );
162 sLine += buf;
163 }
155 int kmax = 8; 164 int kmax = 8;
156 if( nDataLen-j < 8 ) kmax = nDataLen-j; 165 if( nDataLen-j < 8 ) kmax = nDataLen-j;
157 for(int k = 0; k < 8; k++ ) 166 for(int k = 0; k < 8; k++ )
@@ -171,7 +180,7 @@ void Bu::Logger::hexDump( uint32_t nLevel, const char *sFile,
171 for(int k = 0; k < kmax; k++ ) 180 for(int k = 0; k < kmax; k++ )
172 { 181 {
173 char buf[3]; 182 char buf[3];
174 sprintf( buf, "%c ", (pData[j+k]>32 && pData[j+k]<=128)?(pData[j+k]):('.') ); 183 sprintf( buf, "%c", (pData[j+k]>32 && pData[j+k]<=128)?(pData[j+k]):('.') );
175 sLine += buf; 184 sLine += buf;
176 } 185 }
177 log( nLevel, sFile, sFunction, nLine, sLine.getStr() ); 186 log( nLevel, sFile, sFunction, nLine, sLine.getStr() );
diff --git a/src/socket.cpp b/src/socket.cpp
index 1874fd2..73d52e4 100644
--- a/src/socket.cpp
+++ b/src/socket.cpp
@@ -179,22 +179,32 @@ size_t Bu::Socket::read( void *pBuf, size_t nBytes )
179size_t Bu::Socket::read( void *pBuf, size_t nBytes, 179size_t Bu::Socket::read( void *pBuf, size_t nBytes,
180 uint32_t nSec, uint32_t nUSec ) 180 uint32_t nSec, uint32_t nUSec )
181{ 181{
182 struct timeval tv, nt, ct;
183 size_t nRead = 0;
184
182 fd_set rfds; 185 fd_set rfds;
183 FD_ZERO(&rfds); 186 FD_ZERO(&rfds);
184 FD_SET(nSocket, &rfds); 187 FD_SET(nSocket, &rfds);
185 struct timeval tv = { nSec, nUSec }; 188
186 int retval = select( nSocket+1, &rfds, NULL, NULL, &tv ); 189 gettimeofday( &nt, NULL );
187 if( retval == -1 ) 190 nt.tv_sec += nSec;
188 throw ConnectionException( 191 nt.tv_usec += nUSec;
189 excodeBadReadError, 192
190 "Bad Read error" 193 for(;;)
191 ); 194 {
192 if( !FD_ISSET( nSocket, &rfds ) ) 195 tv.tv_sec = nSec;
193 throw ConnectionException( 196 tv.tv_usec = nUSec;
194 excodeSocketTimeout, 197 select( nSocket+1, &rfds, NULL, NULL, &tv );
195 "Socket timout on read" 198 nRead += read( ((char *)pBuf)+nRead, nBytes-nRead );
196 ); 199 if( nRead >= nBytes )
197 return read( pBuf, nBytes ); 200 break;
201 gettimeofday( &ct, NULL );
202 if( (ct.tv_sec > nt.tv_sec) ||
203 (ct.tv_sec == nt.tv_sec &&
204 ct.tv_usec >= nt.tv_usec) )
205 break;
206 }
207 return nRead;
198} 208}
199 209
200size_t Bu::Socket::write( const void *pBuf, size_t nBytes ) 210size_t Bu::Socket::write( const void *pBuf, size_t nBytes )
@@ -208,6 +218,36 @@ size_t Bu::Socket::write( const void *pBuf, size_t nBytes )
208 return nWrote; 218 return nWrote;
209} 219}
210 220
221size_t Bu::Socket::write( const void *pBuf, size_t nBytes, uint32_t nSec, uint32_t nUSec )
222{
223 struct timeval tv, nt, ct;
224 size_t nWrote = 0;
225
226 fd_set wfds;
227 FD_ZERO(&wfds);
228 FD_SET(nSocket, &wfds);
229
230 gettimeofday( &nt, NULL );
231 nt.tv_sec += nSec;
232 nt.tv_usec += nUSec;
233
234 for(;;)
235 {
236 tv.tv_sec = nSec;
237 tv.tv_usec = nUSec;
238 select( nSocket+1, NULL, &wfds, NULL, &tv );
239 nWrote += write( ((char *)pBuf)+nWrote, nBytes-nWrote );
240 if( nWrote >= nBytes )
241 break;
242 gettimeofday( &ct, NULL );
243 if( (ct.tv_sec > nt.tv_sec) ||
244 (ct.tv_sec == nt.tv_sec &&
245 ct.tv_usec >= nt.tv_usec) )
246 break;
247 }
248 return nWrote;
249}
250
211long Bu::Socket::tell() 251long Bu::Socket::tell()
212{ 252{
213 throw UnsupportedException(); 253 throw UnsupportedException();
diff --git a/src/socket.h b/src/socket.h
index 95271f8..96cfeb9 100644
--- a/src/socket.h
+++ b/src/socket.h
@@ -25,6 +25,8 @@ namespace Bu
25 virtual size_t read( void *pBuf, size_t nBytes, 25 virtual size_t read( void *pBuf, size_t nBytes,
26 uint32_t nSec, uint32_t nUSec=0 ); 26 uint32_t nSec, uint32_t nUSec=0 );
27 virtual size_t write( const void *pBuf, size_t nBytes ); 27 virtual size_t write( const void *pBuf, size_t nBytes );
28 virtual size_t write( const void *pBuf, size_t nBytes,
29 uint32_t nSec, uint32_t nUSec=0 );
28 30
29 virtual long tell(); 31 virtual long tell();
30 virtual void seek( long offset ); 32 virtual void seek( long offset );