aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2006-10-31 11:01:43 +0000
committerMike Buland <eichlan@xagasoft.com>2006-10-31 11:01:43 +0000
commit251de734feb2be2d414255dff8358045116e28e1 (patch)
tree02a98b01c398c8c77ba7c73f15a034d72591530b
parentbdd4bdd8615b1587974312a92219cbeab0068a7a (diff)
downloadlibbu++-251de734feb2be2d414255dff8358045116e28e1.tar.gz
libbu++-251de734feb2be2d414255dff8358045116e28e1.tar.bz2
libbu++-251de734feb2be2d414255dff8358045116e28e1.tar.xz
libbu++-251de734feb2be2d414255dff8358045116e28e1.zip
Expanded the scope of the stream system to include positional functions. Updated
the Connection class so that it won't die horribly if you don't provide the pointers to updatable memory for the amount of time not spent waiting for data during a read. Also fiddled with the http test, as you can see...nothing important.
-rw-r--r--src/connection.cpp7
-rw-r--r--src/sfile.cpp38
-rw-r--r--src/sfile.h7
-rw-r--r--src/stream.h7
-rw-r--r--src/tests/httpsrv/httpconnectionmonitor.cpp2
5 files changed, 53 insertions, 8 deletions
diff --git a/src/connection.cpp b/src/connection.cpp
index 748d56d..bf687ec 100644
--- a/src/connection.cpp
+++ b/src/connection.cpp
@@ -292,8 +292,11 @@ bool Connection::readInput( int nSec, int nUSec, int *pnSecBack, int *pnUSecBack
292 st = ust = 0; 292 st = ust = 0;
293 } 293 }
294 294
295 *pnSecBack = st; 295 if( pnSecBack )
296 *pnUSecBack = ust; 296 {
297 *pnSecBack = st;
298 *pnUSecBack = ust;
299 }
297 300
298 //printf("New time: %d %d\n", *pnSecBack, *pnUSecBack ); 301 //printf("New time: %d %d\n", *pnSecBack, *pnUSecBack );
299 302
diff --git a/src/sfile.cpp b/src/sfile.cpp
index 9c5f830..3f5144d 100644
--- a/src/sfile.cpp
+++ b/src/sfile.cpp
@@ -22,16 +22,48 @@ void SFile::close()
22size_t SFile::read( char *pBuf, size_t nBytes ) 22size_t SFile::read( char *pBuf, size_t nBytes )
23{ 23{
24 if( !fh ) 24 if( !fh )
25 throw FileException("SFile not open."); 25 throw FileException("File not open.");
26 26
27 return fread( pBuf, 1, nBytes, fh ); 27 return fread( pBuf, 1, nBytes, fh );
28} 28}
29 29
30size_t SFile::write( char *pBuf, size_t nBytes ) 30size_t SFile::write( const char *pBuf, size_t nBytes )
31{ 31{
32 if( !fh ) 32 if( !fh )
33 throw FileException("SFile not open."); 33 throw FileException("File not open.");
34 34
35 return fwrite( pBuf, 1, nBytes, fh ); 35 return fwrite( pBuf, 1, nBytes, fh );
36} 36}
37 37
38long SFile::tell()
39{
40 if( !fh )
41 throw FileException("File not open.");
42
43 return ftell( fh );
44}
45
46void SFile::seek( long offset )
47{
48 if( !fh )
49 throw FileException("File not open.");
50
51 fseek( fh, offset, SEEK_CUR );
52}
53
54void SFile::setPos( long pos )
55{
56 if( !fh )
57 throw FileException("File not open.");
58
59 fseek( fh, pos, SEEK_SET );
60}
61
62void SFile::setPosEnd( long pos )
63{
64 if( !fh )
65 throw FileException("File not open.");
66
67 fseek( fh, pos, SEEK_END );
68}
69
diff --git a/src/sfile.h b/src/sfile.h
index f94aef7..f276ad2 100644
--- a/src/sfile.h
+++ b/src/sfile.h
@@ -13,7 +13,12 @@ public:
13 13
14 virtual void close(); 14 virtual void close();
15 virtual size_t read( char *pBuf, size_t nBytes ); 15 virtual size_t read( char *pBuf, size_t nBytes );
16 virtual size_t write( char *pBuf, size_t nBytes ); 16 virtual size_t write( const char *pBuf, size_t nBytes );
17
18 virtual long tell();
19 virtual void seek( long offset );
20 virtual void setPos( long pos );
21 virtual void setPosEnd( long pos );
17 22
18private: 23private:
19 FILE *fh; 24 FILE *fh;
diff --git a/src/stream.h b/src/stream.h
index 086e4a1..32e5432 100644
--- a/src/stream.h
+++ b/src/stream.h
@@ -12,7 +12,12 @@ public:
12 12
13 virtual void close() = 0; 13 virtual void close() = 0;
14 virtual size_t read( char *pBuf, size_t nBytes ) = 0; 14 virtual size_t read( char *pBuf, size_t nBytes ) = 0;
15 virtual size_t write( char *pBuf, size_t nBytes ) = 0; 15 virtual size_t write( const char *pBuf, size_t nBytes ) = 0;
16
17 virtual long tell() = 0;
18 virtual void seek( long offset ) = 0;
19 virtual void setPos( long pos ) = 0;
20 virtual void setPosEnd( long pos ) = 0;
16 21
17private: 22private:
18 23
diff --git a/src/tests/httpsrv/httpconnectionmonitor.cpp b/src/tests/httpsrv/httpconnectionmonitor.cpp
index ee1eab3..451478e 100644
--- a/src/tests/httpsrv/httpconnectionmonitor.cpp
+++ b/src/tests/httpsrv/httpconnectionmonitor.cpp
@@ -13,11 +13,11 @@ HttpConnectionMonitor::~HttpConnectionMonitor()
13bool HttpConnectionMonitor::onNewConnection( Connection *pCon, int nPort ) 13bool HttpConnectionMonitor::onNewConnection( Connection *pCon, int nPort )
14{ 14{
15 printf("Got connection on port %d\n", nPort ); 15 printf("Got connection on port %d\n", nPort );
16 Http hp( pCon );
17 16
18 pCon->readInput( 60, 0 ); 17 pCon->readInput( 60, 0 );
19 printf("#######################\n%s\n#######################\n", pCon->getInput() ); 18 printf("#######################\n%s\n#######################\n", pCon->getInput() );
20 19
20 Http hp( pCon );
21 while( hp.parseRequest() == false ); 21 while( hp.parseRequest() == false );
22 printf("Done parsing.\n\n"); 22 printf("Done parsing.\n\n");
23 23