-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Closed
Description
Both of these methods bypass FIFOBuffer's thread safety by using methods on FIFOBuffer to return memory addresses and sizes to take/receive network data.
FIFOBuffer does not expose its mutex, so the only way to implement this is with a temporary char buffer.
Alternatively, FIFOBuffer could be extended to take a StreamSocket to read/write from, but probably makes FIFOBuffer less generic.
This problem affects use of FIFOBuffer in conjunction with SocketReactor, for which samples show their use. When an additional thread is introduced that can also process FIFO content, you will get issues with concurrent access.
// Poco/Net/src/StreamSocket.cpp
int StreamSocket::receiveBytes(FIFOBuffer& fifoBuf)
{
// writing to the address returned by next() is not thread safe. available() could also change
int ret = impl()->receiveBytes(fifoBuf.next(), (int) fifoBuf.available());
if (ret > 0) fifoBuf.advance(ret);
return ret;
}
int StreamSocket::sendBytes(FIFOBuffer& fifoBuf)
{
// reading from the address returned by buffer() is not thread safe. used() may also change
int ret = impl()->sendBytes(&fifoBuf.buffer()[0], (int) fifoBuf.used());
if (ret > 0) fifoBuf.drain(ret);
return ret;
}Reactions are currently unavailable