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:
parent
17b77c3b92
commit
abe1ec18ac
|
@ -187,11 +187,6 @@ RawSocket::Read(size_t numBytes, uint32 flags, bigtime_t timeout,
|
||||||
if (status < B_OK)
|
if (status < B_OK)
|
||||||
return status;
|
return status;
|
||||||
|
|
||||||
if (numBytes < buffer->size) {
|
|
||||||
// discard any data behind the amount requested
|
|
||||||
gBufferModule->trim(buffer, numBytes);
|
|
||||||
}
|
|
||||||
|
|
||||||
*_buffer = buffer;
|
*_buffer = buffer;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
|
@ -849,12 +849,6 @@ UdpEndpoint::FetchData(size_t numBytes, uint32 flags, net_buffer **_buffer)
|
||||||
if (status < B_OK)
|
if (status < B_OK)
|
||||||
return status;
|
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));
|
TRACE(("FetchData() returns buffer with %ld data bytes\n", buffer->size));
|
||||||
*_buffer = buffer;
|
*_buffer = buffer;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
|
|
|
@ -337,11 +337,6 @@ link_read_data(net_protocol *_protocol, size_t numBytes, uint32 flags,
|
||||||
if (status < B_OK)
|
if (status < B_OK)
|
||||||
return status;
|
return status;
|
||||||
|
|
||||||
if (numBytes < buffer->size) {
|
|
||||||
// discard any data behind the amount requested
|
|
||||||
gNetBufferModule.trim(buffer, numBytes);
|
|
||||||
}
|
|
||||||
|
|
||||||
*_buffer = buffer;
|
*_buffer = buffer;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
|
@ -230,8 +230,18 @@ status_t
|
||||||
socket_receive_data(net_socket *socket, size_t length, uint32 flags,
|
socket_receive_data(net_socket *socket, size_t length, uint32 flags,
|
||||||
net_buffer **_buffer)
|
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);
|
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)
|
if (status < B_OK)
|
||||||
return status;
|
return status;
|
||||||
|
|
||||||
// TODO: - datagram based protocols should return the
|
// TODO: - returning a NULL buffer when received 0 bytes
|
||||||
// full datagram so we can cut it here with MSG_TRUNC
|
|
||||||
// - returning a NULL buffer when received 0 bytes
|
|
||||||
// may not make much sense as we still need the address
|
// may not make much sense as we still need the address
|
||||||
// - gNetBufferModule.read() uses memcpy() instead of user_memcpy
|
// - 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);
|
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 ENOBUFS;
|
||||||
|
}
|
||||||
|
|
||||||
return bytesCopied;
|
return bytesCopied;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue