properly support MSG_TRUNC. we don't even have to trim the buffer, just try to fill the user buffers as much as possible

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20582 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Hugo Santos 2007-04-05 16:05:07 +00:00
parent 17b77c3b92
commit abe1ec18ac
4 changed files with 21 additions and 21 deletions

View File

@ -187,11 +187,6 @@ RawSocket::Read(size_t numBytes, uint32 flags, bigtime_t timeout,
if (status < B_OK)
return status;
if (numBytes < buffer->size) {
// discard any data behind the amount requested
gBufferModule->trim(buffer, numBytes);
}
*_buffer = buffer;
return B_OK;
}

View File

@ -849,12 +849,6 @@ UdpEndpoint::FetchData(size_t numBytes, uint32 flags, net_buffer **_buffer)
if (status < B_OK)
return status;
if (numBytes < buffer->size) {
// discard any data behind the amount requested
gBufferModule->trim(buffer, numBytes);
// TODO: we should indicate MSG_TRUNC to application!
}
TRACE(("FetchData() returns buffer with %ld data bytes\n", buffer->size));
*_buffer = buffer;
return B_OK;

View File

@ -337,11 +337,6 @@ link_read_data(net_protocol *_protocol, size_t numBytes, uint32 flags,
if (status < B_OK)
return status;
if (numBytes < buffer->size) {
// discard any data behind the amount requested
gNetBufferModule.trim(buffer, numBytes);
}
*_buffer = buffer;
return B_OK;
}

View File

@ -230,8 +230,18 @@ status_t
socket_receive_data(net_socket *socket, size_t length, uint32 flags,
net_buffer **_buffer)
{
return socket->first_info->read_data(socket->first_protocol,
status_t status = socket->first_info->read_data(socket->first_protocol,
length, flags, _buffer);
if (status < B_OK)
return status;
if (*_buffer && length < (*_buffer)->size) {
// discard any data behind the amount requested
gNetBufferModule.trim(*_buffer, length);
}
return status;
}
@ -761,9 +771,7 @@ socket_receive(net_socket *socket, msghdr *header, void *data, size_t length,
if (status < B_OK)
return status;
// TODO: - datagram based protocols should return the
// full datagram so we can cut it here with MSG_TRUNC
// - returning a NULL buffer when received 0 bytes
// TODO: - returning a NULL buffer when received 0 bytes
// may not make much sense as we still need the address
// - gNetBufferModule.read() uses memcpy() instead of user_memcpy
@ -814,8 +822,16 @@ socket_receive(net_socket *socket, msghdr *header, void *data, size_t length,
gNetBufferModule.free(buffer);
if (bytesCopied < bytesReceived)
if (bytesCopied < bytesReceived) {
if (flags & MSG_TRUNC) {
if (header)
header->msg_flags = MSG_TRUNC;
return bytesReceived;
}
return ENOBUFS;
}
return bytesCopied;
}