From 251de734feb2be2d414255dff8358045116e28e1 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Tue, 31 Oct 2006 11:01:43 +0000 Subject: 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. --- src/connection.cpp | 7 ++++-- src/sfile.cpp | 38 ++++++++++++++++++++++++++--- src/sfile.h | 7 +++++- src/stream.h | 7 +++++- src/tests/httpsrv/httpconnectionmonitor.cpp | 2 +- 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 st = ust = 0; } - *pnSecBack = st; - *pnUSecBack = ust; + if( pnSecBack ) + { + *pnSecBack = st; + *pnUSecBack = ust; + } //printf("New time: %d %d\n", *pnSecBack, *pnUSecBack ); 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() size_t SFile::read( char *pBuf, size_t nBytes ) { if( !fh ) - throw FileException("SFile not open."); + throw FileException("File not open."); return fread( pBuf, 1, nBytes, fh ); } -size_t SFile::write( char *pBuf, size_t nBytes ) +size_t SFile::write( const char *pBuf, size_t nBytes ) { if( !fh ) - throw FileException("SFile not open."); + throw FileException("File not open."); return fwrite( pBuf, 1, nBytes, fh ); } +long SFile::tell() +{ + if( !fh ) + throw FileException("File not open."); + + return ftell( fh ); +} + +void SFile::seek( long offset ) +{ + if( !fh ) + throw FileException("File not open."); + + fseek( fh, offset, SEEK_CUR ); +} + +void SFile::setPos( long pos ) +{ + if( !fh ) + throw FileException("File not open."); + + fseek( fh, pos, SEEK_SET ); +} + +void SFile::setPosEnd( long pos ) +{ + if( !fh ) + throw FileException("File not open."); + + fseek( fh, pos, SEEK_END ); +} + 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: virtual void close(); virtual size_t read( char *pBuf, size_t nBytes ); - virtual size_t write( char *pBuf, size_t nBytes ); + virtual size_t write( const char *pBuf, size_t nBytes ); + + virtual long tell(); + virtual void seek( long offset ); + virtual void setPos( long pos ); + virtual void setPosEnd( long pos ); private: 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: virtual void close() = 0; virtual size_t read( char *pBuf, size_t nBytes ) = 0; - virtual size_t write( char *pBuf, size_t nBytes ) = 0; + virtual size_t write( const char *pBuf, size_t nBytes ) = 0; + + virtual long tell() = 0; + virtual void seek( long offset ) = 0; + virtual void setPos( long pos ) = 0; + virtual void setPosEnd( long pos ) = 0; private: 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() bool HttpConnectionMonitor::onNewConnection( Connection *pCon, int nPort ) { printf("Got connection on port %d\n", nPort ); - Http hp( pCon ); pCon->readInput( 60, 0 ); printf("#######################\n%s\n#######################\n", pCon->getInput() ); + Http hp( pCon ); while( hp.parseRequest() == false ); printf("Done parsing.\n\n"); -- cgit v1.2.3