diff options
Diffstat (limited to '')
-rw-r--r-- | src/stable/client.cpp | 32 | ||||
-rw-r--r-- | src/stable/client.h | 2 | ||||
-rw-r--r-- | src/stable/multiserver.cpp | 6 | ||||
-rw-r--r-- | src/stable/string.cpp | 10 |
4 files changed, 44 insertions, 6 deletions
diff --git a/src/stable/client.cpp b/src/stable/client.cpp index ca86f37..43ae83b 100644 --- a/src/stable/client.cpp +++ b/src/stable/client.cpp | |||
@@ -25,11 +25,13 @@ Bu::Client::Client( Bu::TcpSocket *pSocket, | |||
25 | bWantsDisconnect( false ), | 25 | bWantsDisconnect( false ), |
26 | pfLink( pfLink ) | 26 | pfLink( pfLink ) |
27 | { | 27 | { |
28 | Bu::ReadWriteMutex::WriteLocker lGlobal( mGlobal ); | ||
28 | lFilts.prepend( pSocket ); | 29 | lFilts.prepend( pSocket ); |
29 | } | 30 | } |
30 | 31 | ||
31 | Bu::Client::~Client() | 32 | Bu::Client::~Client() |
32 | { | 33 | { |
34 | Bu::ReadWriteMutex::WriteLocker lGlobal( mGlobal ); | ||
33 | for( FilterList::iterator i = lFilts.begin(); i; i++ ) | 35 | for( FilterList::iterator i = lFilts.begin(); i; i++ ) |
34 | { | 36 | { |
35 | delete *i; | 37 | delete *i; |
@@ -40,6 +42,7 @@ Bu::Client::~Client() | |||
40 | 42 | ||
41 | void Bu::Client::processInput() | 43 | void Bu::Client::processInput() |
42 | { | 44 | { |
45 | Bu::ReadWriteMutex::ReadLocker lGlobal( mGlobal ); | ||
43 | mRead.lock(); | 46 | mRead.lock(); |
44 | char buf[RBS]; | 47 | char buf[RBS]; |
45 | Bu::size nRead, nTotal=0; | 48 | Bu::size nRead, nTotal=0; |
@@ -85,6 +88,7 @@ void Bu::Client::processInput() | |||
85 | 88 | ||
86 | void Bu::Client::processOutput() | 89 | void Bu::Client::processOutput() |
87 | { | 90 | { |
91 | Bu::ReadWriteMutex::ReadLocker lGlobal( mGlobal ); | ||
88 | mWrite.lock(); | 92 | mWrite.lock(); |
89 | char buf[RBS]; | 93 | char buf[RBS]; |
90 | if( qbWrite.getSize() > 0 ) | 94 | if( qbWrite.getSize() > 0 ) |
@@ -100,17 +104,20 @@ void Bu::Client::processOutput() | |||
100 | 104 | ||
101 | void Bu::Client::setProtocol( Protocol *pProto ) | 105 | void Bu::Client::setProtocol( Protocol *pProto ) |
102 | { | 106 | { |
107 | Bu::ReadWriteMutex::ReadLocker lGlobal( mGlobal ); | ||
103 | this->pProto = pProto; | 108 | this->pProto = pProto; |
104 | this->pProto->onNewConnection( this ); | 109 | this->pProto->onNewConnection( this ); |
105 | } | 110 | } |
106 | 111 | ||
107 | Bu::Protocol *Bu::Client::getProtocol() | 112 | Bu::Protocol *Bu::Client::getProtocol() |
108 | { | 113 | { |
114 | Bu::ReadWriteMutex::ReadLocker lGlobal( mGlobal ); | ||
109 | return pProto; | 115 | return pProto; |
110 | } | 116 | } |
111 | 117 | ||
112 | void Bu::Client::clearProtocol() | 118 | void Bu::Client::clearProtocol() |
113 | { | 119 | { |
120 | Bu::ReadWriteMutex::ReadLocker lGlobal( mGlobal ); | ||
114 | pProto = NULL; | 121 | pProto = NULL; |
115 | } | 122 | } |
116 | /* | 123 | /* |
@@ -127,127 +134,149 @@ Bu::String &Bu::Client::getOutput() | |||
127 | 134 | ||
128 | bool Bu::Client::isOpen() | 135 | bool Bu::Client::isOpen() |
129 | { | 136 | { |
137 | Bu::ReadWriteMutex::ReadLocker lGlobal( mGlobal ); | ||
130 | if( !pTopStream ) return false; | 138 | if( !pTopStream ) return false; |
131 | return pTopStream->isOpen(); | 139 | return pTopStream->isOpen(); |
132 | } | 140 | } |
133 | 141 | ||
134 | Bu::size Bu::Client::write( const Bu::String &sData ) | 142 | Bu::size Bu::Client::write( const Bu::String &sData ) |
135 | { | 143 | { |
144 | Bu::ReadWriteMutex::ReadLocker lGlobal( mGlobal ); | ||
136 | Bu::MutexLocker l( mWrite ); | 145 | Bu::MutexLocker l( mWrite ); |
137 | return qbWrite.write( sData.getStr(), sData.getSize() ); | 146 | return qbWrite.write( sData.getStr(), sData.getSize() ); |
138 | } | 147 | } |
139 | 148 | ||
140 | Bu::size Bu::Client::write( const void *pData, Bu::size nBytes ) | 149 | Bu::size Bu::Client::write( const void *pData, Bu::size nBytes ) |
141 | { | 150 | { |
151 | Bu::ReadWriteMutex::ReadLocker lGlobal( mGlobal ); | ||
142 | Bu::MutexLocker l( mWrite ); | 152 | Bu::MutexLocker l( mWrite ); |
143 | return qbWrite.write( pData, nBytes ); | 153 | return qbWrite.write( pData, nBytes ); |
144 | } | 154 | } |
145 | 155 | ||
146 | Bu::size Bu::Client::write( int8_t nData ) | 156 | Bu::size Bu::Client::write( int8_t nData ) |
147 | { | 157 | { |
158 | Bu::ReadWriteMutex::ReadLocker lGlobal( mGlobal ); | ||
148 | Bu::MutexLocker l( mWrite ); | 159 | Bu::MutexLocker l( mWrite ); |
149 | return qbWrite.write( (const char *)&nData, sizeof(nData) ); | 160 | return qbWrite.write( (const char *)&nData, sizeof(nData) ); |
150 | } | 161 | } |
151 | 162 | ||
152 | Bu::size Bu::Client::write( int16_t nData ) | 163 | Bu::size Bu::Client::write( int16_t nData ) |
153 | { | 164 | { |
165 | Bu::ReadWriteMutex::ReadLocker lGlobal( mGlobal ); | ||
154 | Bu::MutexLocker l( mWrite ); | 166 | Bu::MutexLocker l( mWrite ); |
155 | return qbWrite.write( (const char *)&nData, sizeof(nData) ); | 167 | return qbWrite.write( (const char *)&nData, sizeof(nData) ); |
156 | } | 168 | } |
157 | 169 | ||
158 | Bu::size Bu::Client::write( int32_t nData ) | 170 | Bu::size Bu::Client::write( int32_t nData ) |
159 | { | 171 | { |
172 | Bu::ReadWriteMutex::ReadLocker lGlobal( mGlobal ); | ||
160 | Bu::MutexLocker l( mWrite ); | 173 | Bu::MutexLocker l( mWrite ); |
161 | return qbWrite.write( (const char *)&nData, sizeof(nData) ); | 174 | return qbWrite.write( (const char *)&nData, sizeof(nData) ); |
162 | } | 175 | } |
163 | 176 | ||
164 | Bu::size Bu::Client::write( int64_t nData ) | 177 | Bu::size Bu::Client::write( int64_t nData ) |
165 | { | 178 | { |
179 | Bu::ReadWriteMutex::ReadLocker lGlobal( mGlobal ); | ||
166 | Bu::MutexLocker l( mWrite ); | 180 | Bu::MutexLocker l( mWrite ); |
167 | return qbWrite.write( (const char *)&nData, sizeof(nData) ); | 181 | return qbWrite.write( (const char *)&nData, sizeof(nData) ); |
168 | } | 182 | } |
169 | 183 | ||
170 | Bu::size Bu::Client::write( uint8_t nData ) | 184 | Bu::size Bu::Client::write( uint8_t nData ) |
171 | { | 185 | { |
186 | Bu::ReadWriteMutex::ReadLocker lGlobal( mGlobal ); | ||
172 | Bu::MutexLocker l( mWrite ); | 187 | Bu::MutexLocker l( mWrite ); |
173 | return qbWrite.write( (const char *)&nData, sizeof(nData) ); | 188 | return qbWrite.write( (const char *)&nData, sizeof(nData) ); |
174 | } | 189 | } |
175 | 190 | ||
176 | Bu::size Bu::Client::write( uint16_t nData ) | 191 | Bu::size Bu::Client::write( uint16_t nData ) |
177 | { | 192 | { |
193 | Bu::ReadWriteMutex::ReadLocker lGlobal( mGlobal ); | ||
178 | Bu::MutexLocker l( mWrite ); | 194 | Bu::MutexLocker l( mWrite ); |
179 | return qbWrite.write( (const char *)&nData, sizeof(nData) ); | 195 | return qbWrite.write( (const char *)&nData, sizeof(nData) ); |
180 | } | 196 | } |
181 | 197 | ||
182 | Bu::size Bu::Client::write( uint32_t nData ) | 198 | Bu::size Bu::Client::write( uint32_t nData ) |
183 | { | 199 | { |
200 | Bu::ReadWriteMutex::ReadLocker lGlobal( mGlobal ); | ||
184 | Bu::MutexLocker l( mWrite ); | 201 | Bu::MutexLocker l( mWrite ); |
185 | return qbWrite.write( (const char *)&nData, sizeof(nData) ); | 202 | return qbWrite.write( (const char *)&nData, sizeof(nData) ); |
186 | } | 203 | } |
187 | 204 | ||
188 | Bu::size Bu::Client::write( uint64_t nData ) | 205 | Bu::size Bu::Client::write( uint64_t nData ) |
189 | { | 206 | { |
207 | Bu::ReadWriteMutex::ReadLocker lGlobal( mGlobal ); | ||
190 | Bu::MutexLocker l( mWrite ); | 208 | Bu::MutexLocker l( mWrite ); |
191 | return qbWrite.write( (const char *)&nData, sizeof(nData) ); | 209 | return qbWrite.write( (const char *)&nData, sizeof(nData) ); |
192 | } | 210 | } |
193 | 211 | ||
194 | Bu::size Bu::Client::read( void *pData, Bu::size nBytes ) | 212 | Bu::size Bu::Client::read( void *pData, Bu::size nBytes ) |
195 | { | 213 | { |
214 | Bu::ReadWriteMutex::ReadLocker lGlobal( mGlobal ); | ||
196 | Bu::MutexLocker l( mWrite ); | 215 | Bu::MutexLocker l( mWrite ); |
197 | return qbRead.read( pData, nBytes ); | 216 | return qbRead.read( pData, nBytes ); |
198 | } | 217 | } |
199 | 218 | ||
200 | Bu::size Bu::Client::peek( void *pData, int nBytes, int nOffset ) | 219 | Bu::size Bu::Client::peek( void *pData, int nBytes, int nOffset ) |
201 | { | 220 | { |
221 | Bu::ReadWriteMutex::ReadLocker lGlobal( mGlobal ); | ||
202 | Bu::MutexLocker l( mWrite ); | 222 | Bu::MutexLocker l( mWrite ); |
203 | return qbRead.peek( pData, nBytes, nOffset ); | 223 | return qbRead.peek( pData, nBytes, nOffset ); |
204 | } | 224 | } |
205 | 225 | ||
206 | Bu::size Bu::Client::getInputSize() | 226 | Bu::size Bu::Client::getInputSize() |
207 | { | 227 | { |
228 | Bu::ReadWriteMutex::ReadLocker lGlobal( mGlobal ); | ||
208 | Bu::MutexLocker l( mWrite ); | 229 | Bu::MutexLocker l( mWrite ); |
209 | return qbRead.getSize(); | 230 | return qbRead.getSize(); |
210 | } | 231 | } |
211 | 232 | ||
212 | Bu::size Bu::Client::getOutputSize() | 233 | Bu::size Bu::Client::getOutputSize() |
213 | { | 234 | { |
235 | Bu::ReadWriteMutex::ReadLocker lGlobal( mGlobal ); | ||
214 | Bu::MutexLocker l( mWrite ); | 236 | Bu::MutexLocker l( mWrite ); |
215 | return qbWrite.getSize(); | 237 | return qbWrite.getSize(); |
216 | } | 238 | } |
217 | 239 | ||
218 | const Bu::TcpSocket *Bu::Client::getSocket() const | 240 | const Bu::TcpSocket *Bu::Client::getSocket() const |
219 | { | 241 | { |
242 | Bu::ReadWriteMutex::ReadLocker lGlobal( mGlobal ); | ||
220 | return pSocket; | 243 | return pSocket; |
221 | } | 244 | } |
222 | 245 | ||
223 | void Bu::Client::disconnect() | 246 | void Bu::Client::disconnect() |
224 | { | 247 | { |
248 | Bu::ReadWriteMutex::ReadLocker lGlobal( mGlobal ); | ||
225 | bWantsDisconnect = true; | 249 | bWantsDisconnect = true; |
226 | } | 250 | } |
227 | 251 | ||
228 | bool Bu::Client::wantsDisconnect() | 252 | bool Bu::Client::wantsDisconnect() |
229 | { | 253 | { |
254 | Bu::ReadWriteMutex::ReadLocker lGlobal( mGlobal ); | ||
230 | return bWantsDisconnect; | 255 | return bWantsDisconnect; |
231 | } | 256 | } |
232 | 257 | ||
233 | void Bu::Client::close() | 258 | void Bu::Client::close() |
234 | { | 259 | { |
260 | Bu::ReadWriteMutex::ReadLocker lGlobal( mGlobal ); | ||
235 | pTopStream->close(); | 261 | pTopStream->close(); |
236 | } | 262 | } |
237 | 263 | ||
238 | Bu::ClientLink *Bu::Client::getLink() | 264 | Bu::ClientLink *Bu::Client::getLink() |
239 | { | 265 | { |
266 | Bu::ReadWriteMutex::ReadLocker lGlobal( mGlobal ); | ||
240 | return pfLink->createLink( this ); | 267 | return pfLink->createLink( this ); |
241 | } | 268 | } |
242 | 269 | ||
243 | void Bu::Client::onMessage( const Bu::String &sMsg ) | 270 | void Bu::Client::onMessage( const Bu::String &sMsg ) |
244 | { | 271 | { |
272 | Bu::ReadWriteMutex::ReadLocker lGlobal( mGlobal ); | ||
245 | if( pProto ) | 273 | if( pProto ) |
246 | pProto->onMessage( this, sMsg ); | 274 | pProto->onMessage( this, sMsg ); |
247 | } | 275 | } |
248 | 276 | ||
249 | void Bu::Client::tick() | 277 | void Bu::Client::tick() |
250 | { | 278 | { |
279 | Bu::ReadWriteMutex::ReadLocker lGlobal( mGlobal ); | ||
251 | if( pProto ) | 280 | if( pProto ) |
252 | pProto->onTick( this ); | 281 | pProto->onTick( this ); |
253 | } | 282 | } |
@@ -259,6 +288,7 @@ Bu::size Bu::Client::tell() | |||
259 | 288 | ||
260 | void Bu::Client::seek( Bu::size offset ) | 289 | void Bu::Client::seek( Bu::size offset ) |
261 | { | 290 | { |
291 | Bu::ReadWriteMutex::ReadLocker lGlobal( mGlobal ); | ||
262 | Bu::MutexLocker l( mRead ); | 292 | Bu::MutexLocker l( mRead ); |
263 | return qbRead.seek( offset ); | 293 | return qbRead.seek( offset ); |
264 | } | 294 | } |
@@ -280,11 +310,13 @@ bool Bu::Client::isEos() | |||
280 | 310 | ||
281 | void Bu::Client::flush() | 311 | void Bu::Client::flush() |
282 | { | 312 | { |
313 | Bu::ReadWriteMutex::ReadLocker lGlobal( mGlobal ); | ||
283 | processOutput(); | 314 | processOutput(); |
284 | } | 315 | } |
285 | 316 | ||
286 | bool Bu::Client::canRead() | 317 | bool Bu::Client::canRead() |
287 | { | 318 | { |
319 | Bu::ReadWriteMutex::ReadLocker lGlobal( mGlobal ); | ||
288 | Bu::MutexLocker l( mRead ); | 320 | Bu::MutexLocker l( mRead ); |
289 | return qbRead.getSize() > 0; | 321 | return qbRead.getSize() > 0; |
290 | } | 322 | } |
diff --git a/src/stable/client.h b/src/stable/client.h index ac882eb..6492a6e 100644 --- a/src/stable/client.h +++ b/src/stable/client.h | |||
@@ -14,6 +14,7 @@ | |||
14 | #include "bu/string.h" | 14 | #include "bu/string.h" |
15 | #include "bu/queuebuf.h" | 15 | #include "bu/queuebuf.h" |
16 | #include "bu/mutex.h" | 16 | #include "bu/mutex.h" |
17 | #include "bu/readwritemutex.h" | ||
17 | 18 | ||
18 | namespace Bu | 19 | namespace Bu |
19 | { | 20 | { |
@@ -130,6 +131,7 @@ namespace Bu | |||
130 | class Bu::ClientLinkFactory *pfLink; | 131 | class Bu::ClientLinkFactory *pfLink; |
131 | Bu::Mutex mRead; | 132 | Bu::Mutex mRead; |
132 | Bu::Mutex mWrite; | 133 | Bu::Mutex mWrite; |
134 | mutable Bu::ReadWriteMutex mGlobal; | ||
133 | }; | 135 | }; |
134 | } | 136 | } |
135 | 137 | ||
diff --git a/src/stable/multiserver.cpp b/src/stable/multiserver.cpp index 6fd7ff3..c9e86cf 100644 --- a/src/stable/multiserver.cpp +++ b/src/stable/multiserver.cpp | |||
@@ -11,6 +11,8 @@ | |||
11 | 11 | ||
12 | #include "bu/config.h" | 12 | #include "bu/config.h" |
13 | 13 | ||
14 | #include "bu/sio.h" | ||
15 | |||
14 | Bu::MultiServer::MultiServer() | 16 | Bu::MultiServer::MultiServer() |
15 | { | 17 | { |
16 | } | 18 | } |
@@ -40,7 +42,9 @@ void Bu::MultiServer::onNewConnection( Bu::Client *pClient, int nPort ) | |||
40 | 42 | ||
41 | void Bu::MultiServer::onClosedConnection( Bu::Client *pClient ) | 43 | void Bu::MultiServer::onClosedConnection( Bu::Client *pClient ) |
42 | { | 44 | { |
43 | delete pClient->getProtocol(); | 45 | Bu::Protocol *pProto = pClient->getProtocol(); |
46 | pClient->clearProtocol(); | ||
47 | delete pProto; | ||
44 | } | 48 | } |
45 | 49 | ||
46 | void Bu::MultiServer::shutdown() | 50 | void Bu::MultiServer::shutdown() |
diff --git a/src/stable/string.cpp b/src/stable/string.cpp index 1579826..ce679fe 100644 --- a/src/stable/string.cpp +++ b/src/stable/string.cpp | |||
@@ -201,7 +201,7 @@ void Bu::String::append( const char *pData, long nStart, long nLen ) | |||
201 | 201 | ||
202 | _hardCopy(); | 202 | _hardCopy(); |
203 | 203 | ||
204 | if( core->pLast && core->pLast->nLength < nMinSize ) | 204 | if( core->pLast && core->pLast->nLength+1 < nMinSize ) |
205 | { | 205 | { |
206 | int nAmnt = nMinSize - core->pLast->nLength; | 206 | int nAmnt = nMinSize - core->pLast->nLength; |
207 | if( nAmnt > nLen ) | 207 | if( nAmnt > nLen ) |
@@ -228,9 +228,9 @@ void Bu::String::append( const char *pData, long nStart, long nLen ) | |||
228 | 228 | ||
229 | void Bu::String::append( const char &cData ) | 229 | void Bu::String::append( const char &cData ) |
230 | { | 230 | { |
231 | if( core->pLast && core->pLast->nLength < nMinSize ) | 231 | _hardCopy(); |
232 | if( core->pLast && core->pLast->nLength+1 < nMinSize ) | ||
232 | { | 233 | { |
233 | _hardCopy(); | ||
234 | core->pLast->pData[core->pLast->nLength] = cData; | 234 | core->pLast->pData[core->pLast->nLength] = cData; |
235 | ++core->pLast->nLength; ++core->nLength; | 235 | ++core->pLast->nLength; ++core->nLength; |
236 | // pLast->pData[pLast->nLength] = (char)0; | 236 | // pLast->pData[pLast->nLength] = (char)0; |
@@ -615,9 +615,9 @@ Bu::String &Bu::String::operator+=( const Bu::String::const_iterator &i ) | |||
615 | 615 | ||
616 | Bu::String &Bu::String::operator+=( const char cData ) | 616 | Bu::String &Bu::String::operator+=( const char cData ) |
617 | { | 617 | { |
618 | if( core->pLast && core->pLast->nLength < nMinSize ) | ||
619 | { | ||
620 | _hardCopy(); | 618 | _hardCopy(); |
619 | if( core->pLast && core->pLast->nLength+1 < nMinSize ) | ||
620 | { | ||
621 | core->pLast->pData[core->pLast->nLength] = cData; | 621 | core->pLast->pData[core->pLast->nLength] = cData; |
622 | ++core->pLast->nLength; ++core->nLength; | 622 | ++core->pLast->nLength; ++core->nLength; |
623 | // pLast->pData[pLast->nLength] = (char)0; | 623 | // pLast->pData[pLast->nLength] = (char)0; |