* TCPConnection::SendData() now waits until there is enough free space in

the send queue (however, if the buffer sent is larger than the maximum
  buffer, it will just hang for now...). The check is also not thread-safe.
* BufferQueue::Get() did not correctly maintain the fFirstSequence member
  in remove mode.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19403 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2006-11-30 22:36:45 +00:00
parent 1d891ef80b
commit 7e85d85e7a
2 changed files with 20 additions and 4 deletions
@@ -287,10 +287,9 @@ BufferQueue::Get(size_t bytes, bool remove, net_buffer **_buffer)
} else {
// we can reuse this buffer
bytesLeft -= buffer->size;
fList.Remove(buffer);
fFirstSequence += buffer->size;
if (fList.First() != NULL)
fFirstSequence = fList.First()->sequence;
fList.Remove(buffer);
}
// clone/copy the remaining data
@@ -311,11 +310,15 @@ BufferQueue::Get(size_t bytes, bool remove, net_buffer **_buffer)
// remove either the whole buffer or only the part we cloned
fFirstSequence += size;
if (size == source->size) {
iterator.Remove();
gBufferModule->free(source);
} else
} else {
gBufferModule->remove_header(source, size);
source->sequence += size;
}
}
if (status == B_OK) {
@@ -384,6 +384,19 @@ TCPConnection::SendData(net_buffer *buffer)
{
TRACE(("TCP:%p.SendData()\n", this));
// TODO: hangs if the buffer size is larger than the maximum!
while (fSendQueue.Free() < buffer->size) {
status_t status = acquire_sem_etc(fSendLock, 1,
B_RELATIVE_TIMEOUT | B_CAN_INTERRUPT, socket->send.timeout);
if (status < B_OK)
return status;
}
// TODO: check state!
if (buffer->size == 0)
return B_OK;
RecursiveLocker locker(fLock);
fSendQueue.Add(buffer);
return _SendQueued();