aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2007-06-29 00:48:32 +0000
committerMike Buland <eichlan@xagasoft.com>2007-06-29 00:48:32 +0000
commitec8ed8b4b44c7b039e87faaa50bb4d503393d336 (patch)
tree7ea933f72bf2186f12658f96a30e451622fc485a /src
parent76ea96f91115585f7c6b49d11ba60ec15bee12e6 (diff)
downloadlibbu++-ec8ed8b4b44c7b039e87faaa50bb4d503393d336.tar.gz
libbu++-ec8ed8b4b44c7b039e87faaa50bb4d503393d336.tar.bz2
libbu++-ec8ed8b4b44c7b039e87faaa50bb4d503393d336.tar.xz
libbu++-ec8ed8b4b44c7b039e87faaa50bb4d503393d336.zip
A few changes here and there, mainly related to getting the new Server system
working in optimal condition...
Diffstat (limited to '')
-rw-r--r--src/client.cpp35
-rw-r--r--src/client.h11
-rw-r--r--src/fstring.cpp2
-rw-r--r--src/fstring.h2
-rw-r--r--src/membuf.cpp11
-rw-r--r--src/membuf.h3
6 files changed, 57 insertions, 7 deletions
diff --git a/src/client.cpp b/src/client.cpp
index 2f293b7..8077b3d 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -99,9 +99,9 @@ bool Bu::Client::isOpen()
99 return pSocket->isOpen(); 99 return pSocket->isOpen();
100} 100}
101 101
102void Bu::Client::write( const char *pData, int nBytes ) 102void Bu::Client::write( const void *pData, int nBytes )
103{ 103{
104 sWriteBuf.append( pData, nBytes ); 104 sWriteBuf.append( (const char *)pData, nBytes );
105} 105}
106 106
107void Bu::Client::write( int8_t nData ) 107void Bu::Client::write( int8_t nData )
@@ -144,7 +144,7 @@ void Bu::Client::write( uint64_t nData )
144 sWriteBuf.append( (const char *)&nData, sizeof(nData) ); 144 sWriteBuf.append( (const char *)&nData, sizeof(nData) );
145} 145}
146 146
147void Bu::Client::read( char *pData, int nBytes ) 147void Bu::Client::read( void *pData, int nBytes )
148{ 148{
149 memcpy( pData, sReadBuf.getStr()+nRBOffset, nBytes ); 149 memcpy( pData, sReadBuf.getStr()+nRBOffset, nBytes );
150 nRBOffset += nBytes; 150 nRBOffset += nBytes;
@@ -165,6 +165,31 @@ void Bu::Client::read( char *pData, int nBytes )
165 } 165 }
166} 166}
167 167
168void Bu::Client::peek( void *pData, int nBytes )
169{
170 memcpy( pData, sReadBuf.getStr()+nRBOffset, nBytes );
171}
172
173void Bu::Client::seek( int nBytes )
174{
175 nRBOffset += nBytes;
176 if( sReadBuf.getSize()-nRBOffset == 0 )
177 {
178 sReadBuf.clear();
179 nRBOffset = 0;
180 }
181 // This is an experimental threshold, maybe I'll make this configurable
182 // later on.
183 else if(
184 (sReadBuf.getSize() >= 1024 && nRBOffset >= sReadBuf.getSize()/2) ||
185 (nRBOffset >= sReadBuf.getSize()/4)
186 )
187 {
188 sReadBuf.trimFront( nRBOffset );
189 nRBOffset = 0;
190 }
191}
192
168long Bu::Client::getInputSize() 193long Bu::Client::getInputSize()
169{ 194{
170 return sReadBuf.getSize()-nRBOffset; 195 return sReadBuf.getSize()-nRBOffset;
@@ -175,3 +200,7 @@ const Bu::Socket *Bu::Client::getSocket() const
175 return pSocket; 200 return pSocket;
176} 201}
177 202
203void Bu::Client::disconnect()
204{
205}
206
diff --git a/src/client.h b/src/client.h
index 1253dcd..5947521 100644
--- a/src/client.h
+++ b/src/client.h
@@ -24,7 +24,7 @@ namespace Bu
24 24
25 Bu::FString &getInput(); 25 Bu::FString &getInput();
26 Bu::FString &getOutput(); 26 Bu::FString &getOutput();
27 void write( const char *pData, int nBytes ); 27 void write( const void *pData, int nBytes );
28 void write( int8_t nData ); 28 void write( int8_t nData );
29 void write( int16_t nData ); 29 void write( int16_t nData );
30 void write( int32_t nData ); 30 void write( int32_t nData );
@@ -33,7 +33,9 @@ namespace Bu
33 void write( uint16_t nData ); 33 void write( uint16_t nData );
34 void write( uint32_t nData ); 34 void write( uint32_t nData );
35 void write( uint64_t nData ); 35 void write( uint64_t nData );
36 void read( char *pData, int nBytes ); 36 void read( void *pData, int nBytes );
37 void peek( void *pData, int nBytes );
38 void seek( int nBytes );
37 long getInputSize(); 39 long getInputSize();
38 40
39 void setProtocol( Protocol *pProto ); 41 void setProtocol( Protocol *pProto );
@@ -44,6 +46,11 @@ namespace Bu
44 46
45 const Bu::Socket *getSocket() const; 47 const Bu::Socket *getSocket() const;
46 48
49 /**
50 *@todo Make this not suck.
51 */
52 void disconnect();
53
47 private: 54 private:
48 Bu::Socket *pSocket; 55 Bu::Socket *pSocket;
49 Bu::Protocol *pProto; 56 Bu::Protocol *pProto;
diff --git a/src/fstring.cpp b/src/fstring.cpp
index 0b5a970..f71d6c1 100644
--- a/src/fstring.cpp
+++ b/src/fstring.cpp
@@ -12,7 +12,7 @@ template<> bool Bu::__cmpHashKeys<Bu::FString>(
12 return a == b; 12 return a == b;
13} 13}
14 14
15std::ostream& operator<< (std::ostream &os, Bu::FString &val ) 15std::basic_ostream<char>& operator<< (std::basic_ostream<char> &os, const Bu::FString &val )
16{ 16{
17 os.write( val.getStr(), val.getSize() ); 17 os.write( val.getStr(), val.getSize() );
18 return os; 18 return os;
diff --git a/src/fstring.h b/src/fstring.h
index 1f21b5f..f06c362 100644
--- a/src/fstring.h
+++ b/src/fstring.h
@@ -897,6 +897,6 @@ namespace Bu
897} 897}
898 898
899#include <ostream> 899#include <ostream>
900std::ostream& operator<< (std::ostream &os, Bu::FString &val ); 900std::basic_ostream<char>& operator<< (std::basic_ostream<char> &os, const Bu::FString &val );
901 901
902#endif 902#endif
diff --git a/src/membuf.cpp b/src/membuf.cpp
index 3c394b0..45ff5bd 100644
--- a/src/membuf.cpp
+++ b/src/membuf.cpp
@@ -7,6 +7,12 @@ Bu::MemBuf::MemBuf() :
7{ 7{
8} 8}
9 9
10Bu::MemBuf::MemBuf( const Bu::FString &str ) :
11 sBuf( str ),
12 nPos( 0 )
13{
14}
15
10Bu::MemBuf::~MemBuf() 16Bu::MemBuf::~MemBuf()
11{ 17{
12} 18}
@@ -107,3 +113,8 @@ void Bu::MemBuf::setBlocking( bool bBlocking )
107{ 113{
108} 114}
109 115
116Bu::FString &Bu::MemBuf::getString()
117{
118 return sBuf;
119}
120
diff --git a/src/membuf.h b/src/membuf.h
index b82f943..8f53d4b 100644
--- a/src/membuf.h
+++ b/src/membuf.h
@@ -15,6 +15,7 @@ namespace Bu
15 { 15 {
16 public: 16 public:
17 MemBuf(); 17 MemBuf();
18 MemBuf( const Bu::FString &str );
18 virtual ~MemBuf(); 19 virtual ~MemBuf();
19 20
20 virtual void close(); 21 virtual void close();
@@ -41,6 +42,8 @@ namespace Bu
41 virtual bool isBlocking(); 42 virtual bool isBlocking();
42 virtual void setBlocking( bool bBlocking=true ); 43 virtual void setBlocking( bool bBlocking=true );
43 44
45 Bu::FString &getString();
46
44 private: 47 private:
45 Bu::FString sBuf; 48 Bu::FString sBuf;
46 long nPos; 49 long nPos;