Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StreamSocket::receiveBytes(FIFOBuffer&) and sendBytes(FIFOBuffer&) are not thread safe #402

Closed
dmeehan1968 opened this issue Mar 9, 2014 · 0 comments
Assignees
Milestone

Comments

@dmeehan1968
Copy link

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;
}
@aleks-f aleks-f added the bug label Aug 16, 2014
@aleks-f aleks-f added this to the Release 1.6.0 milestone Aug 16, 2014
@aleks-f aleks-f self-assigned this Aug 16, 2014
@aleks-f aleks-f changed the title StreamSocket::receiveBytes(FIFOBuffer&) and sendBytes(FIFOBuffer&) with not thread safe StreamSocket::receiveBytes(FIFOBuffer&) and sendBytes(FIFOBuffer&) are not thread safe Oct 3, 2014
aleks-f added a commit that referenced this issue Oct 3, 2014
- StreamSocket::receiveBytes(FIFOBuffer&) and sendBytes(FIFOBuffer&) are
  not thread safe #402
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants