From 070374dde0f53bff26078550997f7682e84412e5 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Tue, 10 Apr 2007 20:16:19 +0000 Subject: I did it, the streams don't start with an S now. --- src/file.h | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/file.h (limited to 'src/file.h') diff --git a/src/file.h b/src/file.h new file mode 100644 index 0000000..bbc620c --- /dev/null +++ b/src/file.h @@ -0,0 +1,36 @@ +#ifndef FILE_H +#define FILE_H + +#include + +#include "stream.h" + +namespace Bu +{ + class File : public Bu::Stream + { + public: + File( const char *sName, const char *sFlags ); + virtual ~File(); + + virtual void close(); + virtual size_t read( void *pBuf, size_t nBytes ); + virtual size_t write( const void *pBuf, size_t nBytes ); + + virtual long tell(); + virtual void seek( long offset ); + virtual void setPos( long pos ); + virtual void setPosEnd( long pos ); + virtual bool isEOS(); + + virtual bool canRead(); + virtual bool canWrite(); + virtual bool canSeek(); + + private: + FILE *fh; + + }; +} + +#endif -- cgit v1.2.3 From e0e7932a122614a0ff566fbfd8de5776de8b9f6d Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Thu, 17 May 2007 05:56:26 +0000 Subject: Lots of cool new stuff, the Server class actually works for everything except actually interacting with clients, and the Client class is almost there, except that it doesn't really do anything yet. --- src/client.cpp | 9 +++++++ src/client.h | 23 +++++++++++++++++ src/file.cpp | 10 +++++++ src/file.h | 3 +++ src/list.h | 5 ++++ src/old/singleton.h | 59 ------------------------------------------ src/server.cpp | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/server.h | 49 +++++++++++++++++++++++++++++++++++ src/serversocket.cpp | 5 ++++ src/serversocket.h | 3 ++- src/singleton.h | 62 ++++++++++++++++++++++++++++++++++++++++++++ src/socket.cpp | 9 +++++++ src/socket.h | 3 ++- src/stream.h | 3 +++ src/tests/hash.cpp | 24 +++++++++++++++++ 15 files changed, 279 insertions(+), 61 deletions(-) create mode 100644 src/client.cpp create mode 100644 src/client.h delete mode 100644 src/old/singleton.h create mode 100644 src/server.cpp create mode 100644 src/server.h create mode 100644 src/singleton.h create mode 100644 src/tests/hash.cpp (limited to 'src/file.h') diff --git a/src/client.cpp b/src/client.cpp new file mode 100644 index 0000000..a048ca3 --- /dev/null +++ b/src/client.cpp @@ -0,0 +1,9 @@ +#include "client.h" + +Bu::Client::Client() +{ +} + +Bu::Client::~Client() +{ +} diff --git a/src/client.h b/src/client.h new file mode 100644 index 0000000..27fbad4 --- /dev/null +++ b/src/client.h @@ -0,0 +1,23 @@ +#ifndef CLIENT_H +#define CLIENT_H + +#include +#include "bu/socket.h" + +namespace Bu +{ + /** + * + */ + class Client + { + public: + Client(); + virtual ~Client(); + + private: + + }; +} + +#endif diff --git a/src/file.cpp b/src/file.cpp index 5de5f6c..26986a5 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -98,3 +98,13 @@ bool Bu::File::canSeek() return true; } +bool Bu::File::isBlocking() +{ + return true; +} + +void Bu::File::setBlocking( bool bBlocking ) +{ + return; +} + diff --git a/src/file.h b/src/file.h index bbc620c..ee3fdb3 100644 --- a/src/file.h +++ b/src/file.h @@ -27,6 +27,9 @@ namespace Bu virtual bool canWrite(); virtual bool canSeek(); + virtual bool isBlocking(); + virtual void setBlocking( bool bBlocking=true ); + private: FILE *fh; diff --git a/src/list.h b/src/list.h index 4d16872..6081ea5 100644 --- a/src/list.h +++ b/src/list.h @@ -217,6 +217,11 @@ namespace Bu { } + const_iterator( const iterator &i ) : + pLink( i.pLink ) + { + } + public: bool operator==( const const_iterator &oth ) const { diff --git a/src/old/singleton.h b/src/old/singleton.h deleted file mode 100644 index 47adbd5..0000000 --- a/src/old/singleton.h +++ /dev/null @@ -1,59 +0,0 @@ -#ifndef SINGLETON_H -#define SINGLETON_H - -#include - -/** - * Provides singleton functionality in a modular sort of way. Make this the - * base class of any other class and you immediately gain singleton - * functionality. Be sure to make your constructor and various functions use - * intellegent scoping. Cleanup and instantiation are performed automatically - * for you at first use and program exit. There are two things that you must - * do when using this template, first is to inherit from it with the name of - * your class filling in for T and then make this class a friend of your class. - *@code - * // Making the Single Singleton: - * class Single : public Singleton - * { - * friend class Singleton; - * protected: - * Single(); - * ... - * }; - @endcode - * You can still add public functions and variables to your new Singleton child - * class, but your constructor should be protected (hence the need for the - * friend decleration). - *@author Mike Buland - */ -template -class Singleton -{ -protected: - /** - * Private constructor. This constructor is empty but has a body so that - * you can make your own override of it. Be sure that you're override is - * also protected. - */ - Singleton() {}; - -private: - /** - * Copy constructor, defined so that you could write your own as well. - */ - Singleton( const Singleton& ); - -public: - /** - * Get a handle to the contained instance of the contained class. It is - * a reference. - *@returns A reference to the contained object. - */ - static T &getInstance() - { - static T i; - return i; - } -}; - -#endif diff --git a/src/server.cpp b/src/server.cpp new file mode 100644 index 0000000..f93238c --- /dev/null +++ b/src/server.cpp @@ -0,0 +1,73 @@ +#include "server.h" +#include + +Bu::Server::Server() : + nTimeoutSec( 0 ), + nTimeoutUSec( 0 ) +{ + FD_ZERO( &fdActive ); +} + +Bu::Server::~Server() +{ +} + +void Bu::Server::addPort( int nPort, int nPoolSize ) +{ + ServerSocket *s = new ServerSocket( nPort, nPoolSize ); + int nSocket = s->getSocket(); + FD_SET( nSocket, &fdActive ); + hServers.insert( nSocket, s ); +} + +void Bu::Server::addPort( const FString &sAddr, int nPort, int nPoolSize ) +{ + ServerSocket *s = new ServerSocket( sAddr, nPort, nPoolSize ); + int nSocket = s->getSocket(); + FD_SET( nSocket, &fdActive ); + hServers.insert( nSocket, s ); +} + +void Bu::Server::setTimeout( int nTimeoutSec, int nTimeoutUSec ) +{ + this->nTimeoutSec = nTimeoutSec; + this->nTimeoutUSec = nTimeoutUSec; +} + +void Bu::Server::scan() +{ + struct timeval xTimeout = { nTimeoutSec, nTimeoutUSec }; + + fd_set fdRead = fdActive; + fd_set fdWrite = fdActive; + fd_set fdException = fdActive; + + if( TEMP_FAILURE_RETRY( select( FD_SETSIZE, &fdRead, NULL, &fdException, &xTimeout ) ) < 0 ) + { + throw ExceptionBase("Error attempting to scan open connections."); + } + + for( int j = 0; j < FD_SETSIZE; j++ ) + { + if( FD_ISSET( j, &fdRead ) ) + { + if( hServers.has( j ) ) + { + addClient( hServers.get( j )->accept() ); + } + else + { + + } + } + } +} + +void Bu::Server::addClient( int nSocket ) +{ + FD_SET( nSocket, &fdActive ); + + Client *c = new Client(); + hClients.insert( nSocket, c ); +} + diff --git a/src/server.h b/src/server.h new file mode 100644 index 0000000..9f4f459 --- /dev/null +++ b/src/server.h @@ -0,0 +1,49 @@ +#ifndef SERVER_H +#define SERVER_H + +#include +#include "bu/serversocket.h" +#include "bu/list.h" +#include "bu/client.h" + +namespace Bu +{ + /** + * Core of a network server. This class is distinct from a ServerSocket in + * that a ServerSocket is one listening socket, nothing more. Socket will + * manage a pool of both ServerSockets and connected Sockets along with + * their protocols and buffers. + * + * To start serving on a new port, use the addPort functions. Each call to + * addPort creates a new ServerSocket, starts it listening, and adds it to + * the server pool. + * + * All of the real work is done by scan, which will wait for up + * to the timeout set by setTimeout before returning if there is no data + * pending. scan should probably be called in some sort of tight + * loop, possibly in it's own thread, or in the main control loop. + */ + class Server + { + public: + Server(); + virtual ~Server(); + + void addPort( int nPort, int nPoolSize=40 ); + void addPort( const FString &sAddr, int nPort, int nPoolSize=40 ); + + void scan(); + void setTimeout( int nTimeoutSec, int nTimeoutUSec=0 ); + + void addClient( int nSocket ); + + private: + int nTimeoutSec; + int nTimeoutUSec; + fd_set fdActive; + Hash hServers; + Hash hClients; + }; +} + +#endif diff --git a/src/serversocket.cpp b/src/serversocket.cpp index c53c80d..9c8f743 100644 --- a/src/serversocket.cpp +++ b/src/serversocket.cpp @@ -85,6 +85,11 @@ void Bu::ServerSocket::startServer( struct sockaddr_in &name, int nPoolSize ) FD_SET( nServer, &fdActive ); } +int Bu::ServerSocket::getSocket() +{ + return nServer; +} + int Bu::ServerSocket::accept( int nTimeoutSec, int nTimeoutUSec ) { fd_set fdRead = fdActive; diff --git a/src/serversocket.h b/src/serversocket.h index f146d91..d2601e4 100644 --- a/src/serversocket.h +++ b/src/serversocket.h @@ -23,7 +23,8 @@ namespace Bu ServerSocket( const FString &sAddr, int nPort, int nPoolSize=40 ); virtual ~ServerSocket(); - int accept( int nTimeoutSec, int nTimeoutUSec ); + int accept( int nTimeoutSec=0, int nTimeoutUSec=0 ); + int getSocket(); private: void startServer( struct sockaddr_in &name, int nPoolSize ); diff --git a/src/singleton.h b/src/singleton.h new file mode 100644 index 0000000..4976a61 --- /dev/null +++ b/src/singleton.h @@ -0,0 +1,62 @@ +#ifndef SINGLETON_H +#define SINGLETON_H + +#include + +namespace Bu +{ + /** + * Provides singleton functionality in a modular sort of way. Make this the + * base class of any other class and you immediately gain singleton + * functionality. Be sure to make your constructor and various functions use + * intellegent scoping. Cleanup and instantiation are performed automatically + * for you at first use and program exit. There are two things that you must + * do when using this template, first is to inherit from it with the name of + * your class filling in for T and then make this class a friend of your class. + *@code + * // Making the Single Singleton: + * class Single : public Singleton + * { + * friend class Singleton; + * protected: + * Single(); + * ... + * }; + @endcode + * You can still add public functions and variables to your new Singleton child + * class, but your constructor should be protected (hence the need for the + * friend decleration). + *@author Mike Buland + */ + template + class Singleton + { + protected: + /** + * Private constructor. This constructor is empty but has a body so that + * you can make your own override of it. Be sure that you're override is + * also protected. + */ + Singleton() {}; + + private: + /** + * Copy constructor, defined so that you could write your own as well. + */ + Singleton( const Singleton& ); + + public: + /** + * Get a handle to the contained instance of the contained class. It is + * a reference. + *@returns A reference to the contained object. + */ + static T &getInstance() + { + static T i; + return i; + } + }; +} + +#endif diff --git a/src/socket.cpp b/src/socket.cpp index 455b5c8..441678a 100644 --- a/src/socket.cpp +++ b/src/socket.cpp @@ -231,3 +231,12 @@ bool Bu::Socket::canSeek() return false; } +bool Bu::Socket::isBlocking() +{ + return false; +} + +void Bu::Socket::setBlocking( bool bBlocking ) +{ +} + diff --git a/src/socket.h b/src/socket.h index 568cad6..e65eb74 100644 --- a/src/socket.h +++ b/src/socket.h @@ -33,7 +33,8 @@ namespace Bu virtual bool canWrite(); virtual bool canSeek(); - + virtual bool isBlocking(); + virtual void setBlocking( bool bBlocking=true ); private: int nSocket; diff --git a/src/stream.h b/src/stream.h index e640959..5f586e6 100644 --- a/src/stream.h +++ b/src/stream.h @@ -36,6 +36,9 @@ namespace Bu virtual bool canWrite() = 0; virtual bool canSeek() = 0; + virtual bool isBlocking() = 0; + virtual void setBlocking( bool bBlocking=true ) = 0; + private: }; diff --git a/src/tests/hash.cpp b/src/tests/hash.cpp new file mode 100644 index 0000000..73cfb27 --- /dev/null +++ b/src/tests/hash.cpp @@ -0,0 +1,24 @@ +#include "bu/hash.h" +#include "bu/sptr.h" + +typedef struct Bob +{ + int nID; +} Bob; + +int main() +{ + Bu::Hash > lb; + for( int j = 0; j < 10; j++ ) + { + Bob *b = new Bob; + b->nID = j; + lb.insert( j, b ); + } + + for( int j = 0; j < 10; j++ ) + { + printf("%d\n", lb[j].value()->nID ); + } +} + -- cgit v1.2.3 From 5f39066a4f561e9a94a6cc9293ab9b978ebf1f81 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Sun, 10 Jun 2007 21:28:14 +0000 Subject: Bunch of maintenence type things. Minor tweaks and the like. The file class has a lot more helper functions and the like, the filters give more info back to the caller, minor updates to taf. --- src/bzip2.cpp | 41 ++++++++++++++++++++++++++++++++++------- src/bzip2.h | 2 +- src/file.cpp | 31 +++++++++++++++++++++++++++++++ src/file.h | 17 ++++++++++++++++- src/filter.cpp | 7 ++++++- src/filter.h | 4 +++- src/socket.cpp | 4 ++++ src/socket.h | 2 ++ src/stream.h | 2 ++ src/tafnode.cpp | 6 +++--- src/tafnode.h | 4 ++-- src/tests/taf.cpp | 2 +- 12 files changed, 105 insertions(+), 17 deletions(-) (limited to 'src/file.h') diff --git a/src/bzip2.cpp b/src/bzip2.cpp index 433fc91..5423a10 100644 --- a/src/bzip2.cpp +++ b/src/bzip2.cpp @@ -26,16 +26,18 @@ void Bu::BZip2::start() pBuf = new char[nBufSize]; } -void Bu::BZip2::stop() +size_t Bu::BZip2::stop() { if( bzState.state ) { if( bReading ) { BZ2_bzDecompressEnd( &bzState ); + return 0; } else { + size_t sTotal = 0; for(;;) { bzState.next_in = NULL; @@ -45,14 +47,16 @@ void Bu::BZip2::stop() int res = BZ2_bzCompress( &bzState, BZ_FINISH ); if( bzState.avail_out < nBufSize ) { - rNext.write( pBuf, nBufSize-bzState.avail_out ); + sTotal += rNext.write( pBuf, nBufSize-bzState.avail_out ); } if( res == BZ_STREAM_END ) break; } BZ2_bzCompressEnd( &bzState ); + return sTotal; } } + return 0; } void Bu::BZip2::bzError( int code ) @@ -63,13 +67,35 @@ void Bu::BZip2::bzError( int code ) return; case BZ_CONFIG_ERROR: - throw ExceptionBase("The bzip2 library has been miscompiled."); + throw ExceptionBase("BZip2: Library configured improperly, reinstall."); + + case BZ_SEQUENCE_ERROR: + throw ExceptionBase("BZip2: Functions were called in an invalid sequence."); case BZ_PARAM_ERROR: - throw ExceptionBase("bzip2 parameter error."); + throw ExceptionBase("BZip2: Invalid parameter was passed into a function."); case BZ_MEM_ERROR: - throw ExceptionBase("Not enough memory available for bzip2."); + throw ExceptionBase("BZip2: Couldn't allocate sufficient memory."); + + case BZ_DATA_ERROR: + throw ExceptionBase("BZip2: Data was corrupted before decompression."); + + case BZ_DATA_ERROR_MAGIC: + throw ExceptionBase("BZip2: Stream does not appear to be bzip2 data."); + + case BZ_IO_ERROR: + throw ExceptionBase("BZip2: File couldn't be read from / written to."); + + case BZ_UNEXPECTED_EOF: + throw ExceptionBase("BZip2: End of file encountered before end of stream."); + + case BZ_OUTBUFF_FULL: + throw ExceptionBase("BZip2: Buffer not large enough to accomidate data."); + + default: + throw ExceptionBase("BZip2: Unknown error encountered."); + } } @@ -124,6 +150,7 @@ size_t Bu::BZip2::write( const void *pData, size_t nBytes ) if( bReading == true ) throw ExceptionBase("This bzip2 filter is in reading mode, you can't write."); + size_t sTotalOut = 0; bzState.next_in = (char *)pData; bzState.avail_in = nBytes; for(;;) @@ -135,12 +162,12 @@ size_t Bu::BZip2::write( const void *pData, size_t nBytes ) if( bzState.avail_out < nBufSize ) { - rNext.write( pBuf, nBufSize-bzState.avail_out ); + sTotalOut += rNext.write( pBuf, nBufSize-bzState.avail_out ); } if( bzState.avail_in == 0 ) break; } - return 0; + return sTotalOut; } diff --git a/src/bzip2.h b/src/bzip2.h index 056f336..a23f07a 100644 --- a/src/bzip2.h +++ b/src/bzip2.h @@ -18,7 +18,7 @@ namespace Bu virtual ~BZip2(); virtual void start(); - virtual void stop(); + virtual size_t stop(); virtual size_t read( void *pBuf, size_t nBytes ); virtual size_t write( const void *pBuf, size_t nBytes ); diff --git a/src/file.cpp b/src/file.cpp index 26986a5..14b6e54 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -1,6 +1,8 @@ #include "file.h" #include "exceptions.h" #include +#include +#include Bu::File::File( const char *sName, const char *sFlags ) { @@ -11,6 +13,20 @@ Bu::File::File( const char *sName, const char *sFlags ) } } +Bu::File::File( const Bu::FString &sName, const char *sFlags ) +{ + fh = fopen( sName.getStr(), sFlags ); + if( fh == NULL ) + { + throw Bu::FileException( errno, strerror(errno) ); + } +} + +Bu::File::File( int fd, const char *sFlags ) +{ + fh = fdopen( fd, sFlags ); +} + Bu::File::~File() { close(); @@ -108,3 +124,18 @@ void Bu::File::setBlocking( bool bBlocking ) return; } +void Bu::File::truncate( long nSize ) +{ + ftruncate( fileno( fh ), nSize ); +} + +void Bu::File::flush() +{ + fflush( fh ); +} + +void Bu::File::chmod( mode_t t ) +{ + fchmod( fileno( fh ), t ); +} + diff --git a/src/file.h b/src/file.h index ee3fdb3..8107a1b 100644 --- a/src/file.h +++ b/src/file.h @@ -3,7 +3,8 @@ #include -#include "stream.h" +#include "bu/stream.h" +#include "bu/fstring.h" namespace Bu { @@ -11,6 +12,8 @@ namespace Bu { public: File( const char *sName, const char *sFlags ); + File( const Bu::FString &sName, const char *sFlags ); + File( int fd, const char *sFlags ); virtual ~File(); virtual void close(); @@ -23,6 +26,8 @@ namespace Bu virtual void setPosEnd( long pos ); virtual bool isEOS(); + virtual void flush(); + virtual bool canRead(); virtual bool canWrite(); virtual bool canSeek(); @@ -30,6 +35,16 @@ namespace Bu virtual bool isBlocking(); virtual void setBlocking( bool bBlocking=true ); + inline static Bu::File tempFile( Bu::FString &sName, const char *sFlags ) + { + int afh_d = mkstemp( sName.getStr() ); + + return Bu::File( afh_d, sFlags ); + } + + void truncate( long nSize ); + void chmod( mode_t t ); + private: FILE *fh; diff --git a/src/filter.cpp b/src/filter.cpp index d3faa00..693fb9f 100644 --- a/src/filter.cpp +++ b/src/filter.cpp @@ -7,7 +7,7 @@ Bu::Filter::Filter( Bu::Stream &rNext ) : Bu::Filter::~Filter() { - printf("-> Bu::Filter::~Filter()\n"); + //printf("-> Bu::Filter::~Filter()\n"); } /* void Bu::Filter::start() @@ -75,3 +75,8 @@ void Bu::Filter::setBlocking( bool bBlocking ) rNext.setBlocking( bBlocking ); } +void Bu::Filter::flush() +{ + rNext.flush(); +} + diff --git a/src/filter.h b/src/filter.h index b068206..088d46e 100644 --- a/src/filter.h +++ b/src/filter.h @@ -33,7 +33,7 @@ namespace Bu virtual ~Filter(); virtual void start()=0; - virtual void stop()=0; + virtual size_t stop()=0; virtual void close(); virtual long tell(); virtual void seek( long offset ); @@ -41,6 +41,8 @@ namespace Bu virtual void setPosEnd( long pos ); virtual bool isEOS(); + virtual void flush(); + virtual bool canRead(); virtual bool canWrite(); virtual bool canSeek(); diff --git a/src/socket.cpp b/src/socket.cpp index 441678a..1832898 100644 --- a/src/socket.cpp +++ b/src/socket.cpp @@ -240,3 +240,7 @@ void Bu::Socket::setBlocking( bool bBlocking ) { } +void Bu::Socket::flush() +{ +} + diff --git a/src/socket.h b/src/socket.h index e65eb74..30a43fb 100644 --- a/src/socket.h +++ b/src/socket.h @@ -29,6 +29,8 @@ namespace Bu virtual void setPosEnd( long pos ); virtual bool isEOS(); + virtual void flush(); + virtual bool canRead(); virtual bool canWrite(); virtual bool canSeek(); diff --git a/src/stream.h b/src/stream.h index fa0a606..a80586b 100644 --- a/src/stream.h +++ b/src/stream.h @@ -32,6 +32,8 @@ namespace Bu virtual void setPosEnd( long pos ) = 0; virtual bool isEOS() = 0; + virtual void flush() = 0; + virtual bool canRead() = 0; virtual bool canWrite() = 0; virtual bool canSeek() = 0; diff --git a/src/tafnode.cpp b/src/tafnode.cpp index 3060606..b9a4a24 100644 --- a/src/tafnode.cpp +++ b/src/tafnode.cpp @@ -45,7 +45,7 @@ const Bu::TafNode::PropList &Bu::TafNode::getProperties( const Bu::FString &sNam return hProp.get( sName ); } -const Bu::TafNode::NodeList &Bu::TafNode::getNodes( const Bu::FString &sName ) const +const Bu::TafNode::NodeList &Bu::TafNode::getChildren( const Bu::FString &sName ) const { return hChildren.get( sName ); } @@ -55,9 +55,9 @@ const Bu::FString &Bu::TafNode::getProperty( const Bu::FString &sName ) const return getProperties( sName ).first(); } -const Bu::TafNode *Bu::TafNode::getNode( const Bu::FString &sName ) const +const Bu::TafNode *Bu::TafNode::getChild( const Bu::FString &sName ) const { - return getNodes( sName ).first(); + return getChildren( sName ).first(); } void Bu::TafNode::setName( const Bu::FString &sName ) diff --git a/src/tafnode.h b/src/tafnode.h index 10232d2..08f78e8 100644 --- a/src/tafnode.h +++ b/src/tafnode.h @@ -28,9 +28,9 @@ namespace Bu void setProperty( Bu::FString sName, Bu::FString sValue ); const Bu::FString &getProperty( const Bu::FString &sName ) const; - const TafNode *getNode( const Bu::FString &sName ) const; const PropList &getProperties( const Bu::FString &sName ) const; - const NodeList &getNodes( const Bu::FString &sName ) const; + const TafNode *getChild( const Bu::FString &sName ) const; + const NodeList &getChildren( const Bu::FString &sName ) const; void addChild( TafNode *pNode ); private: diff --git a/src/tests/taf.cpp b/src/tests/taf.cpp index e7bad52..d135e78 100644 --- a/src/tests/taf.cpp +++ b/src/tests/taf.cpp @@ -8,7 +8,7 @@ int main() Bu::TafNode *pNode = tr.getNode(); - const Bu::TafNode *pStats = pNode->getNode("stats"); + const Bu::TafNode *pStats = pNode->getChild("stats"); printf("%s\n", pStats->getName().getStr() ); printf(" str = %s\n", pStats->getProperty("str").getStr() ); -- cgit v1.2.3 From 8b12972092777af56ae21f65b41f4c40d52c2367 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Mon, 18 Jun 2007 19:42:34 +0000 Subject: Added the protocol class. servers work, but don't send data, updated the streams to include many more state indicators and caps queries, and everything is working better in general. --- src/bzip2.cpp | 7 +++++- src/bzip2.h | 2 ++ src/client.cpp | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- src/client.h | 20 +++++++++++++--- src/file.cpp | 17 +++++++++++++- src/file.h | 6 ++++- src/filter.cpp | 19 ++++++++++++++-- src/filter.h | 6 ++++- src/protocol.cpp | 12 ++++++++++ src/protocol.h | 26 +++++++++++++++++++++ src/server.cpp | 11 ++++++--- src/server.h | 8 +++++-- src/socket.cpp | 48 ++++++++++++++++++++++++++++++++------- src/socket.h | 6 ++++- src/stream.h | 35 +++++++++++++++++++++++++++- 15 files changed, 266 insertions(+), 26 deletions(-) create mode 100644 src/protocol.cpp create mode 100644 src/protocol.h (limited to 'src/file.h') diff --git a/src/bzip2.cpp b/src/bzip2.cpp index d3f237a..66786e4 100644 --- a/src/bzip2.cpp +++ b/src/bzip2.cpp @@ -128,7 +128,7 @@ size_t Bu::BZip2::read( void *pData, size_t nBytes ) { if( bzState.avail_in > 0 ) { - if( rNext.canSeek() ) + if( rNext.isSeekable() ) { rNext.seek( -bzState.avail_in ); } @@ -185,3 +185,8 @@ size_t Bu::BZip2::write( const void *pData, size_t nBytes ) return sTotalOut; } +bool Bu::BZip2::isOpen() +{ + return (bzState.state != NULL); +} + diff --git a/src/bzip2.h b/src/bzip2.h index a23f07a..25f10c5 100644 --- a/src/bzip2.h +++ b/src/bzip2.h @@ -22,6 +22,8 @@ namespace Bu virtual size_t read( void *pBuf, size_t nBytes ); virtual size_t write( const void *pBuf, size_t nBytes ); + virtual bool isOpen(); + private: void bzError( int code ); bz_stream bzState; diff --git a/src/client.cpp b/src/client.cpp index a33cdc3..cf96424 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -1,6 +1,16 @@ -#include "client.h" +#include "bu/client.h" +#include "bu/socket.h" +#include +#include +#include "bu/exceptions.h" +#include "bu/protocol.h" -Bu::Client::Client() +/** Read buffer size. */ +#define RBS (1024*2) + +Bu::Client::Client( Bu::Socket *pSocket ) : + pSocket( pSocket ), + pProto( NULL ) { } @@ -8,3 +18,58 @@ Bu::Client::~Client() { } +void Bu::Client::processInput() +{ + char buf[RBS]; + size_t nRead, nTotal=0; + + for(;;) + { + nRead = pSocket->read( buf, nRead ); + if( nRead < 0 ) + { + throw Bu::ConnectionException( + excodeReadError, + "Read error: %s", + strerror( errno ) + ); + } + else if( nRead == 0 ) + { + break; + } + else + { + nTotal += nRead; + sReadBuf.append( buf, nRead ); + if( !pSocket->canRead() ) + break; + } + } + + if( pProto && nTotal ) + { + pProto->onNewData( this ); + } +} + +void Bu::Client::setProtocol( Protocol *pProto ) +{ + this->pProto = pProto; +} + +Bu::Protocol *Bu::Client::getProtocol() +{ + return pProto; +} + +void Bu::Client::clearProtocol() +{ + pProto = NULL; +} + +Bu::FString &Bu::Client::getInput() +{ + return sReadBuf; +} + diff --git a/src/client.h b/src/client.h index 27fbad4..1a189e2 100644 --- a/src/client.h +++ b/src/client.h @@ -2,21 +2,35 @@ #define CLIENT_H #include -#include "bu/socket.h" + +#include "bu/fstring.h" namespace Bu { + class Protocol; + class Socket; + /** * */ class Client { public: - Client(); + Client( Bu::Socket *pSocket ); virtual ~Client(); - private: + void processInput(); + Bu::FString &getInput(); + + void setProtocol( Protocol *pProto ); + Bu::Protocol *getProtocol(); + void clearProtocol(); + + private: + Bu::Socket *pSocket; + Bu::Protocol *pProto; + Bu::FString sReadBuf; }; } diff --git a/src/file.cpp b/src/file.cpp index 2965afa..368b788 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -109,7 +109,17 @@ bool Bu::File::canWrite() return true; } -bool Bu::File::canSeek() +bool Bu::File::isReadable() +{ + return true; +} + +bool Bu::File::isWritable() +{ + return true; +} + +bool Bu::File::isSeekable() { return true; } @@ -139,3 +149,8 @@ void Bu::File::chmod( mode_t t ) fchmod( fileno( fh ), t ); } +bool Bu::File::isOpen() +{ + return (fh != NULL); +} + diff --git a/src/file.h b/src/file.h index 8107a1b..fe8dbda 100644 --- a/src/file.h +++ b/src/file.h @@ -25,12 +25,16 @@ namespace Bu virtual void setPos( long pos ); virtual void setPosEnd( long pos ); virtual bool isEOS(); + virtual bool isOpen(); virtual void flush(); virtual bool canRead(); virtual bool canWrite(); - virtual bool canSeek(); + + virtual bool isReadable(); + virtual bool isWritable(); + virtual bool isSeekable(); virtual bool isBlocking(); virtual void setBlocking( bool bBlocking=true ); diff --git a/src/filter.cpp b/src/filter.cpp index 693fb9f..96a8694 100644 --- a/src/filter.cpp +++ b/src/filter.cpp @@ -50,6 +50,11 @@ bool Bu::Filter::isEOS() return rNext.isEOS(); } +bool Bu::Filter::isOpen() +{ + return rNext.isOpen(); +} + bool Bu::Filter::canRead() { return rNext.canRead(); @@ -60,9 +65,19 @@ bool Bu::Filter::canWrite() return rNext.canWrite(); } -bool Bu::Filter::canSeek() +bool Bu::Filter::isReadable() +{ + return rNext.isReadable(); +} + +bool Bu::Filter::isWritable() +{ + return rNext.isWritable(); +} + +bool Bu::Filter::isSeekable() { - return rNext.canSeek(); + return rNext.isSeekable(); } bool Bu::Filter::isBlocking() diff --git a/src/filter.h b/src/filter.h index 088d46e..7bb04bc 100644 --- a/src/filter.h +++ b/src/filter.h @@ -40,12 +40,16 @@ namespace Bu virtual void setPos( long pos ); virtual void setPosEnd( long pos ); virtual bool isEOS(); + virtual bool isOpen(); virtual void flush(); virtual bool canRead(); virtual bool canWrite(); - virtual bool canSeek(); + + virtual bool isReadable(); + virtual bool isWritable(); + virtual bool isSeekable(); virtual bool isBlocking(); virtual void setBlocking( bool bBlocking=true ); diff --git a/src/protocol.cpp b/src/protocol.cpp new file mode 100644 index 0000000..0976b3b --- /dev/null +++ b/src/protocol.cpp @@ -0,0 +1,12 @@ +#include "bu/protocol.h" + +using namespace Bu; + +Bu::Protocol::Protocol() +{ +} + +Bu::Protocol::~Protocol() +{ +} + diff --git a/src/protocol.h b/src/protocol.h new file mode 100644 index 0000000..3accd99 --- /dev/null +++ b/src/protocol.h @@ -0,0 +1,26 @@ +#ifndef PROTOCOL_H +#define PROTOCOL_H + +#include + +namespace Bu +{ + class Client; + + /** + * + */ + class Protocol + { + public: + Protocol(); + virtual ~Protocol(); + + virtual void onNewData( Bu::Client *pClient )=0; + + private: + + }; +} + +#endif diff --git a/src/server.cpp b/src/server.cpp index abf4c5b..bceeb81 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -1,5 +1,8 @@ -#include "server.h" +#include "bu/server.h" #include +#include "bu/serversocket.h" +#include "bu/client.h" +#include "bu/socket.h" Bu::Server::Server() : nTimeoutSec( 0 ), @@ -58,7 +61,7 @@ void Bu::Server::scan() } else { - + hClients.get( j )->processInput(); } } } @@ -68,7 +71,9 @@ void Bu::Server::addClient( int nSocket, int nPort ) { FD_SET( nSocket, &fdActive ); - Client *c = new Client(); + Client *c = new Client( + new Bu::Socket( nSocket ) + ); hClients.insert( nSocket, c ); onNewConnection( c, nPort ); diff --git a/src/server.h b/src/server.h index 942eb32..3331d2c 100644 --- a/src/server.h +++ b/src/server.h @@ -2,12 +2,16 @@ #define SERVER_H #include -#include "bu/serversocket.h" + +#include "bu/fstring.h" #include "bu/list.h" -#include "bu/client.h" namespace Bu { + class ServerSocket; + class Socket; + class Client; + /** * Core of a network server. This class is distinct from a ServerSocket in * that a ServerSocket is one listening socket, nothing more. Socket will diff --git a/src/socket.cpp b/src/socket.cpp index 1832898..bd05024 100644 --- a/src/socket.cpp +++ b/src/socket.cpp @@ -109,13 +109,6 @@ void Bu::Socket::close() ::close( nSocket ); } bActive = false; - //xInputBuf.clearData(); - //xOutputBuf.clearData(); - //if( pProtocol != NULL ) - //{ - // delete pProtocol; - // pProtocol = NULL; - //} } /* @@ -218,15 +211,49 @@ bool Bu::Socket::isEOS() bool Bu::Socket::canRead() { + fd_set rfds; + FD_ZERO(&rfds); + FD_SET(nSocket, &rfds); + struct timeval tv = { 0, 0 }; + int retval = select( nSocket+1, &rfds, NULL, NULL, &tv ); + if( retval == -1 ) + throw ConnectionException( + excodeBadReadError, + "Bad Read error" + ); + if( !FD_ISSET( nSocket, &rfds ) ) + return false; return true; } bool Bu::Socket::canWrite() { + fd_set wfds; + FD_ZERO(&wfds); + FD_SET(nSocket, &wfds); + struct timeval tv = { 0, 0 }; + int retval = select( nSocket+1, NULL, &wfds, NULL, &tv ); + if( retval == -1 ) + throw ConnectionException( + excodeBadReadError, + "Bad Read error" + ); + if( !FD_ISSET( nSocket, &wfds ) ) + return false; return true; } -bool Bu::Socket::canSeek() +bool Bu::Socket::isReadable() +{ + return true; +} + +bool Bu::Socket::isWritable() +{ + return true; +} + +bool Bu::Socket::isSeekable() { return false; } @@ -244,3 +271,8 @@ void Bu::Socket::flush() { } +bool Bu::Socket::isOpen() +{ + return bActive; +} + diff --git a/src/socket.h b/src/socket.h index 30a43fb..c9dbd8d 100644 --- a/src/socket.h +++ b/src/socket.h @@ -28,12 +28,16 @@ namespace Bu virtual void setPos( long pos ); virtual void setPosEnd( long pos ); virtual bool isEOS(); + virtual bool isOpen(); virtual void flush(); virtual bool canRead(); virtual bool canWrite(); - virtual bool canSeek(); + + virtual bool isReadable(); + virtual bool isWritable(); + virtual bool isSeekable(); virtual bool isBlocking(); virtual void setBlocking( bool bBlocking=true ); diff --git a/src/stream.h b/src/stream.h index a80586b..ba070d3 100644 --- a/src/stream.h +++ b/src/stream.h @@ -31,12 +31,45 @@ namespace Bu virtual void setPos( long pos ) = 0; virtual void setPosEnd( long pos ) = 0; virtual bool isEOS() = 0; + virtual bool isOpen() = 0; virtual void flush() = 0; + /** + * In non-blocking streams this indicates if a read operation will + * return data at the moment or not. In blocking streams this should + * return the same value as isEOS(). + */ virtual bool canRead() = 0; + + /** + * In non-blocking streams this indicates if a write operation will + * succeed or fail. In some cases writing is not allowed (e.g. + * internal buffers are full) temporarilly. In blocking streams this + * should return the same value as isWritable. + */ virtual bool canWrite() = 0; - virtual bool canSeek() = 0; + + /** + * Indicates if the stream is capable of read operations. This does not + * indicate if such operations will return useful data, see canRead for + * that. + */ + virtual bool isReadable() = 0; + + /** + * Indicates if the stream is capable of write operations. This does + * not indicate if such operations will succeed or fail, see canWrite + * for that. + */ + virtual bool isWritable() = 0; + + /** + * Indicates if the stream is capable of seek operations. This is + * generally false for non-blocking streams. Some buffered streams may + * support limited in-buffer seeking. + */ + virtual bool isSeekable() = 0; virtual bool isBlocking() = 0; virtual void setBlocking( bool bBlocking=true ) = 0; -- cgit v1.2.3 From 6f94639a3f5e20e1c635b2d8676086464d7cba2e Mon Sep 17 00:00:00 2001 From: David Date: Mon, 18 Jun 2007 20:45:45 +0000 Subject: david - did more documenting --- src/file.h | 18 ++++++++++++ src/list.h | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/sptr.h | 45 +++++++++++++++++++++++++++++ src/stream.h | 58 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 213 insertions(+) (limited to 'src/file.h') diff --git a/src/file.h b/src/file.h index fe8dbda..1a4421b 100644 --- a/src/file.h +++ b/src/file.h @@ -39,6 +39,14 @@ namespace Bu virtual bool isBlocking(); virtual void setBlocking( bool bBlocking=true ); + /** + * Create a temp file and return its handle + *@param sName (Bu::FString) Give in the form: "/tmp/tmpfileXXXXXXXX" + * It will alter your (sName) setting the 'X's to random + * characters. + *@param sFlags (const char *) Standard file flags 'rb'... etc.. + *@returns (Bu::File) A file object representing your temp file. + */ inline static Bu::File tempFile( Bu::FString &sName, const char *sFlags ) { int afh_d = mkstemp( sName.getStr() ); @@ -46,7 +54,17 @@ namespace Bu return Bu::File( afh_d, sFlags ); } + /** + * Set the size of the file to (nSize). You can either grow or shrink + * the file. + *@param nSize (long) The new size of the file. + */ void truncate( long nSize ); + + /** + * Change the file access permissions. + *@param t (mode_t) The new file access permissions. + */ void chmod( mode_t t ); private: diff --git a/src/list.h b/src/list.h index 9d1f904..314459e 100644 --- a/src/list.h +++ b/src/list.h @@ -115,6 +115,10 @@ namespace Bu } } + /** + * Prepend a value to the list. + *@param v (const value_type &) The value to prepend. + */ void prepend( const value &v ) { Link *pNew = la.allocate( 1 ); @@ -136,6 +140,9 @@ namespace Bu } } + /** + * An iterator to iterate through your list. + */ typedef struct iterator { friend class List; @@ -152,36 +159,67 @@ namespace Bu } public: + /** + * Equals comparison operator. + *@param oth (const iterator &) The iterator to compare to. + *@returns (bool) Are they equal? + */ bool operator==( const iterator &oth ) const { return ( pLink == oth.pLink ); } + /** + * Equals comparison operator. + *@param pOth (const Link *) The link to compare to. + *@returns (bool) Are they equal? + */ bool operator==( const Link *pOth ) const { return ( pLink == pOth ); } + /** + * Not equals comparison operator. + *@param oth (const iterator &) The iterator to compare to. + *@returns (bool) Are they not equal? + */ bool operator!=( const iterator &oth ) const { return ( pLink != oth.pLink ); } + /** + * Not equals comparison operator. + *@param pOth (const Link *) The link to compare to. + *@returns (bool) Are they not equal? + */ bool operator!=( const Link *pOth ) const { return ( pLink != pOth ); } + /** + * Dereference operator. + *@returns (value_type &) The value. + */ value &operator*() { return *(pLink->pValue); } + /** + * Pointer access operator. + *@returns (value_type *) A pointer to the value. + */ value *operator->() { return pLink->pValue; } + /** + * Increment operator. + */ iterator &operator++() { if( pLink != NULL ) @@ -189,6 +227,9 @@ namespace Bu return *this; } + /** + * Decrement operator. + */ iterator &operator--() { if( pLink != NULL ) @@ -196,6 +237,9 @@ namespace Bu return *this; } + /** + * Increment operator. + */ iterator &operator++( int ) { if( pLink != NULL ) @@ -203,6 +247,9 @@ namespace Bu return *this; } + /** + * Decrement operator. + */ iterator &operator--( int ) { if( pLink != NULL ) @@ -210,6 +257,11 @@ namespace Bu return *this; } + /** + * Assignment operator. + *@param oth (const iterator &) The other iterator to set this + * one to. + */ iterator &operator=( const iterator &oth ) { pLink = oth.pLink; @@ -217,6 +269,9 @@ namespace Bu } }; + /** + *@see iterator + */ typedef struct const_iterator { friend class List; @@ -309,21 +364,38 @@ namespace Bu } }; + /** + * Get an iterator pointing to the first item in the list. + *@returns (iterator) + */ iterator begin() { return iterator( pFirst ); } + /** + * Get a const iterator pointing to the first item in the list. + *@returns (const const_iterator) + */ const const_iterator begin() const { return const_iterator( pFirst ); } + /** + * Get an iterator pointing to a place just past the last item in + * the list. + *@returns (const Link *) + */ const Link *end() const { return NULL; } + /** + * Erase an item from the list. + *@param i (iterator) The item to erase. + */ void erase( iterator &i ) { Link *pCur = i.pLink; @@ -355,26 +427,46 @@ namespace Bu } } + /** + * Get the current size of the list. + *@returns (int) The current size of the list. + */ int getSize() const { return nSize; } + /** + * Get the first item in the list. + *@returns (value_type &) The first item in the list. + */ value &first() { return *pFirst->pValue; } + /** + * Get the first item in the list. + *@returns (const value_type &) The first item in the list. + */ const value &first() const { return *pFirst->pValue; } + /** + * Get the last item in the list. + *@returns (value_type &) The last item in the list. + */ value &last() { return *pLast->pValue; } + /** + * Get the last item in the list. + *@returns (const value_type &) The last item in the list. + */ const value &last() const { return *pLast->pValue; diff --git a/src/sptr.h b/src/sptr.h index faa8524..4baa697 100644 --- a/src/sptr.h +++ b/src/sptr.h @@ -45,31 +45,55 @@ namespace Bu } } + /** + * Get the number of references to this pointer. + *@returns (int32_t) The number of references to this pointer. + */ int32_t count() const { return *pRefCnt; } + /** + * Pointer access operator. + *@returns (const T *) + */ const T *operator->() const { return pData; } + /** + * Dereference operator. + *@returns (const T &) The value at the end of the pointer. + */ const T &operator*() const { return *pData; } + /** + * Pointer access operator. + *@returns (T *) + */ T *operator->() { return pData; } + /** + * Dereference operator. + *@returns (T &) The value at the end of the pointer. + */ T &operator*() { return *pData; } + /** + * Assignment operator. + *@param src (const SPtr &) + */ SPtr operator=( const SPtr &src ) { decCount(); @@ -81,6 +105,10 @@ namespace Bu return *this; } + /** + * Assignment operator. + *@param src (const SPtr &) + */ const SPtr operator=( const SPtr &src ) const { decCount(); @@ -92,21 +120,38 @@ namespace Bu return *this; } + /** + * Equals comparison operator. + *@param src (const SPtr &) The SPtr to compare to. + *@returns (bool) Are the equal? + */ bool operator==( const SPtr &src ) const { return pData == src.pData; } + /** + * Equals comparison operator. + *@param src (const T *) The pointer to compare to. + *@returns (bool) Are the equal? + */ bool operator==( const T *src ) const { return pData == src; } + /** + * Boolean cast operator. Do we have a pointer? + */ operator bool() const { return pRefCnt != NULL; } + /** + * Do we have a pointer? + *@returns (bool) Do we have a pointer? + */ bool isSet() const { return pRefCnt != NULL; diff --git a/src/stream.h b/src/stream.h index ba070d3..056de0c 100644 --- a/src/stream.h +++ b/src/stream.h @@ -22,17 +22,66 @@ namespace Bu Stream(); virtual ~Stream(); + /** + * Close the stream. + */ virtual void close() = 0; + + /** + * Read data from the stream into a buffer. + *@param pBuf (void *) Buffer which will be filled. + *@param nBytes (size_t) Max data to read. + *@returns (size_t) Amount of data read. + */ virtual size_t read( void *pBuf, size_t nBytes ) = 0; + + /** + * Write data to the stream. + *@param pBuf (const void *) The data to be written. + *@param nBytes (size_t) Amount of data to write from pBuf. + *@returns (size_t) Amount of data actually written. + */ virtual size_t write( const void *pBuf, size_t nBytes ) = 0; + /** + * Get the current position in the stream. + *@returns (long) The current position in the stream. + */ virtual long tell() = 0; + + /** + * Seek to a position in the stream relative to the current position. + *@param offset (long) Offset from current position to seek to. + */ virtual void seek( long offset ) = 0; + + /** + * Set position in the stream relative to the start of the stream. + *@param pos (long) The position. + */ virtual void setPos( long pos ) = 0; + + /** + * Set position in the stream relative to the end of the stream. + *@param pos (long) The position. + */ virtual void setPosEnd( long pos ) = 0; + + /** + * Are we at the end of the stream? + *@returns (bool) Are we at the end of the stream? + */ virtual bool isEOS() = 0; + + /** + * Is the stream open? + *@returns (bool) Is the stream open? + */ virtual bool isOpen() = 0; + /** + * Flush any data still held in buffers. + */ virtual void flush() = 0; /** @@ -71,7 +120,16 @@ namespace Bu */ virtual bool isSeekable() = 0; + /** + * Are we currently set to block mode? + *@returns (bool) + */ virtual bool isBlocking() = 0; + + /** + * Set stream to blocking or non-blocking mode. + *@param bBlocking (bool) Whether we should block or not. + */ virtual void setBlocking( bool bBlocking=true ) = 0; public: // Filters -- cgit v1.2.3 From 2b0fa89df615cb4789668014475ae64d99e773b5 Mon Sep 17 00:00:00 2001 From: David Date: Tue, 19 Jun 2007 06:05:55 +0000 Subject: david - got some things compiling on win32 (wine/devc++) --- fstringtest.dev | 59 ++++++++++++++ libbu++.dev | 209 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/file.cpp | 10 ++- src/file.h | 2 + src/tests/fstring.cpp | 10 +++ 5 files changed, 286 insertions(+), 4 deletions(-) create mode 100644 fstringtest.dev create mode 100644 libbu++.dev (limited to 'src/file.h') diff --git a/fstringtest.dev b/fstringtest.dev new file mode 100644 index 0000000..297242d --- /dev/null +++ b/fstringtest.dev @@ -0,0 +1,59 @@ +[Project] +FileName=fstringtest.dev +Name=fstringtest +UnitCount=1 +Type=1 +Ver=1 +ObjFiles= +Includes=z:\home\neonphog\wine_documents\libbu++\src\bu +Libs= +PrivateResource= +ResourceIncludes= +MakeIncludes= +Compiler= +CppCompiler=_@@_ +Linker=libbu++.a_@@_ +IsCpp=1 +Icon= +ExeOutput= +ObjectOutput= +OverrideOutput=0 +OverrideOutputName=fstringtest.exe +HostApplication= +Folders= +CommandLine= +UseCustomMakefile=0 +CustomMakefile= +IncludeVersionInfo=0 +SupportXPThemes=0 +CompilerSet=0 +CompilerSettings=0000000000000000000000 + +[VersionInfo] +Major=0 +Minor=1 +Release=1 +Build=1 +LanguageID=1033 +CharsetID=1252 +CompanyName= +FileVersion= +FileDescription=Developed using the Dev-C++ IDE +InternalName= +LegalCopyright= +LegalTrademarks= +OriginalFilename= +ProductName= +ProductVersion= +AutoIncBuildNr=0 + +[Unit1] +FileName=src\tests\fstring.cpp +CompileCpp=1 +Folder=fstringtest +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + diff --git a/libbu++.dev b/libbu++.dev new file mode 100644 index 0000000..2fb1ae9 --- /dev/null +++ b/libbu++.dev @@ -0,0 +1,209 @@ +[Project] +FileName=libbu++.dev +Name=libbu++ +UnitCount=16 +Type=2 +Ver=1 +ObjFiles= +Includes=z:\home\neonphog\wine_documents\libbu++\src\bu +Libs= +PrivateResource= +ResourceIncludes= +MakeIncludes= +Compiler= +CppCompiler= +Linker= +IsCpp=1 +Icon= +ExeOutput= +ObjectOutput= +OverrideOutput=0 +OverrideOutputName=libbu++.a +HostApplication= +Folders= +CommandLine= +UseCustomMakefile=0 +CustomMakefile= +IncludeVersionInfo=0 +SupportXPThemes=0 +CompilerSet=0 +CompilerSettings=0000000000000000000000 + +[Unit1] +FileName=src\stream.cpp +CompileCpp=1 +Folder=libbu++ +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[VersionInfo] +Major=0 +Minor=1 +Release=1 +Build=1 +LanguageID=1033 +CharsetID=1252 +CompanyName= +FileVersion= +FileDescription=Developed using the Dev-C++ IDE +InternalName= +LegalCopyright= +LegalTrademarks= +OriginalFilename= +ProductName= +ProductVersion= +AutoIncBuildNr=0 + +[Unit2] +FileName=src\stream.h +CompileCpp=1 +Folder=libbu++ +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit3] +FileName=src\file.cpp +CompileCpp=1 +Folder=libbu++ +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit4] +FileName=src\file.h +CompileCpp=1 +Folder=libbu++ +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit5] +FileName=src\fstring.h +CompileCpp=1 +Folder=libbu++ +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit6] +FileName=src\fstring.cpp +CompileCpp=1 +Folder=libbu++ +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit7] +FileName=src\archival.cpp +CompileCpp=1 +Folder=libbu++ +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit8] +FileName=src\archival.h +CompileCpp=1 +Folder=libbu++ +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit9] +FileName=src\archive.cpp +CompileCpp=1 +Folder=libbu++ +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit10] +FileName=src\archive.h +CompileCpp=1 +Folder=libbu++ +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit11] +FileName=src\hash.h +CompileCpp=1 +Folder=libbu++ +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit12] +FileName=src\hash.cpp +CompileCpp=1 +Folder=libbu++ +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit13] +FileName=src\exceptionbase.cpp +CompileCpp=1 +Folder=libbu++ +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit14] +FileName=src\exceptionbase.h +CompileCpp=1 +Folder=libbu++ +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit15] +FileName=src\list.cpp +CompileCpp=1 +Folder=libbu++ +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit16] +FileName=src\list.h +CompileCpp=1 +Folder=libbu++ +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + diff --git a/src/file.cpp b/src/file.cpp index 368b788..1a8bd08 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -134,19 +134,21 @@ void Bu::File::setBlocking( bool bBlocking ) return; } +#ifndef WIN32 void Bu::File::truncate( long nSize ) { ftruncate( fileno( fh ), nSize ); } -void Bu::File::flush() +void Bu::File::chmod( mode_t t ) { - fflush( fh ); + fchmod( fileno( fh ), t ); } +#endif -void Bu::File::chmod( mode_t t ) +void Bu::File::flush() { - fchmod( fileno( fh ), t ); + fflush( fh ); } bool Bu::File::isOpen() diff --git a/src/file.h b/src/file.h index 1a4421b..0f638a7 100644 --- a/src/file.h +++ b/src/file.h @@ -47,6 +47,7 @@ namespace Bu *@param sFlags (const char *) Standard file flags 'rb'... etc.. *@returns (Bu::File) A file object representing your temp file. */ +#ifndef WIN32 inline static Bu::File tempFile( Bu::FString &sName, const char *sFlags ) { int afh_d = mkstemp( sName.getStr() ); @@ -66,6 +67,7 @@ namespace Bu *@param t (mode_t) The new file access permissions. */ void chmod( mode_t t ); +#endif private: FILE *fh; diff --git a/src/tests/fstring.cpp b/src/tests/fstring.cpp index d600be6..48dfc5f 100644 --- a/src/tests/fstring.cpp +++ b/src/tests/fstring.cpp @@ -3,12 +3,22 @@ #include #include +#ifndef WIN32 inline double getTime() { struct timeval tv; gettimeofday( &tv, NULL ); return ((double)tv.tv_sec) + ((double)tv.tv_usec/1000000.0); } +#else +#include "windows.h" +#include "winbase.h" +inline double getTime() +{ + uint32_t t = (uint32_t) GetTickCount(); + return (double) t / 1000.0; +} +#endif Bu::FString genThing() { -- cgit v1.2.3 From 932677862376e9642a496a15b7f09f1106f495a5 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Thu, 28 Jun 2007 20:49:39 +0000 Subject: Many minor changes, hopefully the header fixes will keep future header macro conflicts from happening. And, from now on, other projects should do -Ilibbu++ not -Ilibbu++/src so we can get ready for an installed version of libbu++. --- bu | 1 + src/archival.h | 4 ++-- src/archive.h | 4 ++-- src/atom.h | 4 ++-- src/bzip2.h | 4 ++-- src/client.h | 4 ++-- src/exceptionbase.h | 4 ++-- src/exceptions.h | 4 ++-- src/file.h | 4 ++-- src/filter.h | 4 ++-- src/fstring.h | 4 ++-- src/hash.h | 4 ++-- src/ito.h | 4 ++-- src/itoatom.h | 4 ++-- src/itocondition.h | 4 ++-- src/itomutex.h | 4 ++-- src/itoqueue.h | 4 ++-- src/linkmessage.h | 4 ++-- src/list.h | 4 ++-- src/membuf.h | 4 ++-- src/paramproc.h | 4 ++-- src/plugger.h | 4 ++-- src/programchain.h | 4 ++-- src/programlink.h | 4 ++-- src/protocol.h | 4 ++-- src/ringbuffer.h | 4 ++-- src/server.h | 4 ++-- src/serversocket.h | 4 ++-- src/singleton.h | 4 ++-- src/socket.h | 4 ++-- src/sptr.h | 4 ++-- src/stream.h | 4 ++-- src/unitsuite.h | 4 ++-- 33 files changed, 65 insertions(+), 64 deletions(-) create mode 120000 bu (limited to 'src/file.h') diff --git a/bu b/bu new file mode 120000 index 0000000..02b8847 --- /dev/null +++ b/bu @@ -0,0 +1 @@ +src/bu/ \ No newline at end of file diff --git a/src/archival.h b/src/archival.h index e2c803c..8be3308 100644 --- a/src/archival.h +++ b/src/archival.h @@ -1,5 +1,5 @@ -#ifndef ARCHIVAL_H -#define ARCHIVAL_H +#ifndef BU_ARCHIVAL_H +#define BU_ARCHIVAL_H namespace Bu { diff --git a/src/archive.h b/src/archive.h index 05c6f57..6c0c1df 100644 --- a/src/archive.h +++ b/src/archive.h @@ -1,5 +1,5 @@ -#ifndef ARCHIVE_H -#define ARCHIVE_H +#ifndef BU_ARCHIVE_H +#define BU_ARCHIVE_H #include #include diff --git a/src/atom.h b/src/atom.h index a0469b6..fad47eb 100644 --- a/src/atom.h +++ b/src/atom.h @@ -1,5 +1,5 @@ -#ifndef ATOM_H -#define ATOM_H +#ifndef BU_ATOM_H +#define BU_ATOM_H #include #include diff --git a/src/bzip2.h b/src/bzip2.h index 25f10c5..0a111e8 100644 --- a/src/bzip2.h +++ b/src/bzip2.h @@ -1,5 +1,5 @@ -#ifndef B_ZIP2_H -#define B_ZIP2_H +#ifndef BU_BZIP2_H +#define BU_BZIP2_H #include #include diff --git a/src/client.h b/src/client.h index 02ba077..cee558d 100644 --- a/src/client.h +++ b/src/client.h @@ -1,5 +1,5 @@ -#ifndef CLIENT_H -#define CLIENT_H +#ifndef BU_CLIENT_H +#define BU_CLIENT_H #include diff --git a/src/exceptionbase.h b/src/exceptionbase.h index fd78089..24e4bbf 100644 --- a/src/exceptionbase.h +++ b/src/exceptionbase.h @@ -1,5 +1,5 @@ -#ifndef EXCEPTION_BASE_H -#define EXCEPTION_BASE_H +#ifndef BU_EXCEPTION_BASE_H +#define BU_EXCEPTION_BASE_H #include #include diff --git a/src/exceptions.h b/src/exceptions.h index d5a9d39..b824b91 100644 --- a/src/exceptions.h +++ b/src/exceptions.h @@ -1,5 +1,5 @@ -#ifndef EXCEPTIONS_H -#define EXCEPTIONS_H +#ifndef BU_EXCEPTIONS_H +#define BU_EXCEPTIONS_H #include "exceptionbase.h" #include diff --git a/src/file.h b/src/file.h index 0f638a7..d4e43eb 100644 --- a/src/file.h +++ b/src/file.h @@ -1,5 +1,5 @@ -#ifndef FILE_H -#define FILE_H +#ifndef BU_FILE_H +#define BU_FILE_H #include diff --git a/src/filter.h b/src/filter.h index 7bb04bc..bd557b2 100644 --- a/src/filter.h +++ b/src/filter.h @@ -1,5 +1,5 @@ -#ifndef FILTER_H -#define FILTER_H +#ifndef BU_FILTER_H +#define BU_FILTER_H #include diff --git a/src/fstring.h b/src/fstring.h index 7180f5f..bf6518b 100644 --- a/src/fstring.h +++ b/src/fstring.h @@ -1,5 +1,5 @@ -#ifndef F_STRING_H -#define F_STRING_H +#ifndef BU_F_STRING_H +#define BU_F_STRING_H #include #include diff --git a/src/hash.h b/src/hash.h index 6c4a443..0fa3af7 100644 --- a/src/hash.h +++ b/src/hash.h @@ -1,5 +1,5 @@ -#ifndef HASH_H -#define HASH_H +#ifndef BU_HASH_H +#define BU_HASH_H #include #include diff --git a/src/ito.h b/src/ito.h index 01253f5..c062052 100644 --- a/src/ito.h +++ b/src/ito.h @@ -1,5 +1,5 @@ -#ifndef ITO_H -#define ITO_H +#ifndef BU_ITO_H +#define BU_ITO_H #include diff --git a/src/itoatom.h b/src/itoatom.h index 96090f2..7fc9090 100644 --- a/src/itoatom.h +++ b/src/itoatom.h @@ -1,5 +1,5 @@ -#ifndef ITO_QUEUE_H -#define ITO_QUEUE_H +#ifndef BU_ITO_QUEUE_H +#define BU_ITO_QUEUE_H #include diff --git a/src/itocondition.h b/src/itocondition.h index 4771b22..1793f81 100644 --- a/src/itocondition.h +++ b/src/itocondition.h @@ -1,5 +1,5 @@ -#ifndef ITO_CONDITION_H -#define ITO_CONDITION_H +#ifndef BU_ITO_CONDITION_H +#define BU_ITO_CONDITION_H #include diff --git a/src/itomutex.h b/src/itomutex.h index 80956b8..9c9d205 100644 --- a/src/itomutex.h +++ b/src/itomutex.h @@ -1,5 +1,5 @@ -#ifndef ITO_MUTEX_H -#define ITO_MUTEX_H +#ifndef BU_ITO_MUTEX_H +#define BU_ITO_MUTEX_H #include diff --git a/src/itoqueue.h b/src/itoqueue.h index 322698d..75a2f27 100644 --- a/src/itoqueue.h +++ b/src/itoqueue.h @@ -1,5 +1,5 @@ -#ifndef ITO_QUEUE_H -#define ITO_QUEUE_H +#ifndef BU_ITO_QUEUE_H +#define BU_ITO_QUEUE_H #include diff --git a/src/linkmessage.h b/src/linkmessage.h index 64b8bc2..baa22a6 100644 --- a/src/linkmessage.h +++ b/src/linkmessage.h @@ -1,8 +1,8 @@ /**\file linkmessage.h */ -#ifndef LINKMESSAGE_H -#define LINKMESSAGE_H +#ifndef BU_LINKMESSAGE_H +#define BU_LINKMESSAGE_H namespace Bu { diff --git a/src/list.h b/src/list.h index 314459e..6235619 100644 --- a/src/list.h +++ b/src/list.h @@ -1,5 +1,5 @@ -#ifndef LIST_H -#define LIST_H +#ifndef BU_LIST_H +#define BU_LIST_H #include #include "bu/exceptionbase.h" diff --git a/src/membuf.h b/src/membuf.h index 877b35e..b82f943 100644 --- a/src/membuf.h +++ b/src/membuf.h @@ -1,5 +1,5 @@ -#ifndef MEM_BUF_H -#define MEM_BUF_H +#ifndef BU_MEM_BUF_H +#define BU_MEM_BUF_H #include diff --git a/src/paramproc.h b/src/paramproc.h index beee4a0..2bca588 100644 --- a/src/paramproc.h +++ b/src/paramproc.h @@ -1,5 +1,5 @@ -#ifndef PARAM_PROC_H -#define PARAM_PROC_H +#ifndef BU_PARAM_PROC_H +#define BU_PARAM_PROC_H #include #include diff --git a/src/plugger.h b/src/plugger.h index 4d2e7af..79a3271 100644 --- a/src/plugger.h +++ b/src/plugger.h @@ -1,5 +1,5 @@ -#ifndef PLUGGER_H -#define PLUGGER_H +#ifndef BU_PLUGGER_H +#define BU_PLUGGER_H #include "bu/hash.h" diff --git a/src/programchain.h b/src/programchain.h index e73d659..336a9f1 100644 --- a/src/programchain.h +++ b/src/programchain.h @@ -1,5 +1,5 @@ -#ifndef PROGRAMCHAIN_H -#define PROGRAMCHAIN_H +#ifndef BU_PROGRAMCHAIN_H +#define BU_PROGRAMCHAIN_H #include "bu/list.h" #include "bu/linkmessage.h" diff --git a/src/programlink.h b/src/programlink.h index 7c31a18..07d7489 100644 --- a/src/programlink.h +++ b/src/programlink.h @@ -1,5 +1,5 @@ -#ifndef PROGRAMLINK_H -#define PROGRAMLINK_H +#ifndef BU_PROGRAMLINK_H +#define BU_PROGRAMLINK_H #include "bu/linkmessage.h" #include "bu/programchain.h" diff --git a/src/protocol.h b/src/protocol.h index 3accd99..c7a9275 100644 --- a/src/protocol.h +++ b/src/protocol.h @@ -1,5 +1,5 @@ -#ifndef PROTOCOL_H -#define PROTOCOL_H +#ifndef BU_PROTOCOL_H +#define BU_PROTOCOL_H #include diff --git a/src/ringbuffer.h b/src/ringbuffer.h index 625f65b..be80e2f 100644 --- a/src/ringbuffer.h +++ b/src/ringbuffer.h @@ -1,5 +1,5 @@ -#ifndef RING_BUFFER_H -#define RING_BUFFER_H +#ifndef BU_RING_BUFFER_H +#define BU_RING_BUFFER_H #include #include "bu/exceptionbase.h" diff --git a/src/server.h b/src/server.h index 07eef95..302b6e3 100644 --- a/src/server.h +++ b/src/server.h @@ -1,5 +1,5 @@ -#ifndef SERVER_H -#define SERVER_H +#ifndef BU_SERVER_H +#define BU_SERVER_H #include diff --git a/src/serversocket.h b/src/serversocket.h index cb86078..b4ee247 100644 --- a/src/serversocket.h +++ b/src/serversocket.h @@ -1,5 +1,5 @@ -#ifndef SERVER_SOCKET_H -#define SERVER_SOCKET_H +#ifndef BU_SERVER_SOCKET_H +#define BU_SERVER_SOCKET_H #include #include "bu/fstring.h" diff --git a/src/singleton.h b/src/singleton.h index 4976a61..c43d71b 100644 --- a/src/singleton.h +++ b/src/singleton.h @@ -1,5 +1,5 @@ -#ifndef SINGLETON_H -#define SINGLETON_H +#ifndef BU_SINGLETON_H +#define BU_SINGLETON_H #include diff --git a/src/socket.h b/src/socket.h index c9dbd8d..0ccee3b 100644 --- a/src/socket.h +++ b/src/socket.h @@ -1,5 +1,5 @@ -#ifndef SOCKET_H -#define SOCKET_H +#ifndef BU_SOCKET_H +#define BU_SOCKET_H #include diff --git a/src/sptr.h b/src/sptr.h index 4baa697..75851a6 100644 --- a/src/sptr.h +++ b/src/sptr.h @@ -1,5 +1,5 @@ -#ifndef SPTR_H -#define SPTR_H +#ifndef BU_SPTR_H +#define BU_SPTR_H #include #include diff --git a/src/stream.h b/src/stream.h index 056de0c..1e236a6 100644 --- a/src/stream.h +++ b/src/stream.h @@ -1,5 +1,5 @@ -#ifndef STREAM_H -#define STREAM_H +#ifndef BU_STREAM_H +#define BU_STREAM_H #include #include diff --git a/src/unitsuite.h b/src/unitsuite.h index 6e9270a..578b4cc 100644 --- a/src/unitsuite.h +++ b/src/unitsuite.h @@ -1,5 +1,5 @@ -#ifndef UNIT_SUITE_H -#define UNIT_SUITE_H +#ifndef BU_UNIT_SUITE_H +#define BU_UNIT_SUITE_H #include #include -- cgit v1.2.3