network: Migrate SIGPIPE generation into the socket module.
This removes the burden of determining whether to and then actually sending SIGPIPE from the protocol modules, meaning the MSG_NOSIGNAL flag can now be implemented entirely in the socket module and not even passed further down the chain. Change-Id: I9ba976c4aff60d533cb4b390bbba1560c0de423f Reviewed-on: https://review.haiku-os.org/c/haiku/+/7124 Reviewed-by: Jérôme Duval <jerome.duval@gmail.com> Reviewed-by: waddlesplash <waddlesplash@gmail.com>
This commit is contained in:
parent
da2f2c65b7
commit
973f6d3320
@ -814,19 +814,15 @@ TCPEndpoint::SendData(net_buffer *buffer)
|
|||||||
T(APICall(this, "senddata"));
|
T(APICall(this, "senddata"));
|
||||||
|
|
||||||
const uint32 flags = buffer->flags;
|
const uint32 flags = buffer->flags;
|
||||||
if ((flags & ~(MSG_NOSIGNAL | MSG_DONTWAIT | MSG_OOB | MSG_EOF)) != 0)
|
if ((flags & ~(MSG_DONTWAIT | MSG_OOB | MSG_EOF)) != 0)
|
||||||
return EOPNOTSUPP;
|
return EOPNOTSUPP;
|
||||||
|
|
||||||
if (fState == CLOSED)
|
if (fState == CLOSED)
|
||||||
return ENOTCONN;
|
return ENOTCONN;
|
||||||
if (fState == LISTEN)
|
if (fState == LISTEN)
|
||||||
return EDESTADDRREQ;
|
return EDESTADDRREQ;
|
||||||
if (!is_writable(fState) && !is_establishing(fState)) {
|
if (!is_writable(fState) && !is_establishing(fState))
|
||||||
// we only send signals when called from userland
|
|
||||||
if (gStackModule->is_syscall() && (flags & MSG_NOSIGNAL) == 0)
|
|
||||||
send_signal(find_thread(NULL), SIGPIPE);
|
|
||||||
return EPIPE;
|
return EPIPE;
|
||||||
}
|
|
||||||
|
|
||||||
size_t left = buffer->size;
|
size_t left = buffer->size;
|
||||||
|
|
||||||
@ -849,12 +845,8 @@ TCPEndpoint::SendData(net_buffer *buffer)
|
|||||||
return posix_error(status);
|
return posix_error(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_writable(fState) && !is_establishing(fState)) {
|
if (!is_writable(fState) && !is_establishing(fState))
|
||||||
// we only send signals when called from userland
|
|
||||||
if (gStackModule->is_syscall() && (flags & MSG_NOSIGNAL) == 0)
|
|
||||||
send_signal(find_thread(NULL), SIGPIPE);
|
|
||||||
return EPIPE;
|
return EPIPE;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t size = fSendQueue.Free();
|
size_t size = fSendQueue.Free();
|
||||||
|
@ -215,7 +215,7 @@ UnixDatagramEndpoint::Send(const iovec* vecs, size_t vecCount,
|
|||||||
TRACE("[%" B_PRId32 "] %p->UnixDatagramEndpoint::Send()\n",
|
TRACE("[%" B_PRId32 "] %p->UnixDatagramEndpoint::Send()\n",
|
||||||
find_thread(NULL), this);
|
find_thread(NULL), this);
|
||||||
|
|
||||||
if ((flags & ~(MSG_DONTWAIT | MSG_NOSIGNAL)) != 0)
|
if ((flags & ~(MSG_DONTWAIT)) != 0)
|
||||||
return EOPNOTSUPP;
|
return EOPNOTSUPP;
|
||||||
|
|
||||||
bigtime_t timeout = 0;
|
bigtime_t timeout = 0;
|
||||||
@ -307,8 +307,7 @@ UnixDatagramEndpoint::Send(const iovec* vecs, size_t vecCount,
|
|||||||
|
|
||||||
switch (result) {
|
switch (result) {
|
||||||
case EPIPE:
|
case EPIPE:
|
||||||
if (gStackModule->is_syscall() && (flags & MSG_NOSIGNAL) == 0)
|
// The socket module will generate SIGPIPE for us, if necessary.
|
||||||
send_signal(find_thread(NULL), SIGPIPE);
|
|
||||||
break;
|
break;
|
||||||
case B_TIMED_OUT:
|
case B_TIMED_OUT:
|
||||||
if (timeout == 0)
|
if (timeout == 0)
|
||||||
|
@ -379,7 +379,7 @@ UnixStreamEndpoint::Send(const iovec* vecs, size_t vecCount,
|
|||||||
TRACE("[%" B_PRId32 "] %p->UnixStreamEndpoint::Send(%p, %ld, %p)\n",
|
TRACE("[%" B_PRId32 "] %p->UnixStreamEndpoint::Send(%p, %ld, %p)\n",
|
||||||
find_thread(NULL), this, vecs, vecCount, ancillaryData);
|
find_thread(NULL), this, vecs, vecCount, ancillaryData);
|
||||||
|
|
||||||
if ((flags & ~(MSG_DONTWAIT | MSG_NOSIGNAL)) != 0)
|
if ((flags & ~(MSG_DONTWAIT)) != 0)
|
||||||
return EOPNOTSUPP;
|
return EOPNOTSUPP;
|
||||||
|
|
||||||
bigtime_t timeout = 0;
|
bigtime_t timeout = 0;
|
||||||
@ -452,10 +452,7 @@ UnixStreamEndpoint::Send(const iovec* vecs, size_t vecCount,
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case EPIPE:
|
case EPIPE:
|
||||||
// The peer closed connection or shutdown its read side. Reward
|
// The socket module will generate SIGPIPE for us, if necessary.
|
||||||
// the caller with a SIGPIPE.
|
|
||||||
if (gStackModule->is_syscall() && (flags & MSG_NOSIGNAL) == 0)
|
|
||||||
send_signal(find_thread(NULL), SIGPIPE);
|
|
||||||
break;
|
break;
|
||||||
case B_TIMED_OUT:
|
case B_TIMED_OUT:
|
||||||
// Translate non-blocking timeouts to the correct error code.
|
// Translate non-blocking timeouts to the correct error code.
|
||||||
|
@ -1333,6 +1333,9 @@ socket_send(net_socket* socket, msghdr* header, const void* data, size_t length,
|
|||||||
socklen_t addressLength = 0;
|
socklen_t addressLength = 0;
|
||||||
size_t bytesLeft = length;
|
size_t bytesLeft = length;
|
||||||
|
|
||||||
|
const bool nosignal = ((flags & MSG_NOSIGNAL) != 0);
|
||||||
|
flags &= ~MSG_NOSIGNAL;
|
||||||
|
|
||||||
if (length > SSIZE_MAX)
|
if (length > SSIZE_MAX)
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
@ -1398,6 +1401,11 @@ socket_send(net_socket* socket, msghdr* header, const void* data, size_t length,
|
|||||||
ssize_t written = socket->first_info->send_data_no_buffer(
|
ssize_t written = socket->first_info->send_data_no_buffer(
|
||||||
socket->first_protocol, vecs, vecCount, ancillaryData, address,
|
socket->first_protocol, vecs, vecCount, ancillaryData, address,
|
||||||
addressLength, flags);
|
addressLength, flags);
|
||||||
|
|
||||||
|
// we only send signals when called from userland
|
||||||
|
if (written == EPIPE && is_syscall() && !nosignal)
|
||||||
|
send_signal(find_thread(NULL), SIGPIPE);
|
||||||
|
|
||||||
if (written > 0)
|
if (written > 0)
|
||||||
ancillaryDataDeleter.Detach();
|
ancillaryDataDeleter.Detach();
|
||||||
return written;
|
return written;
|
||||||
@ -1473,6 +1481,10 @@ socket_send(net_socket* socket, msghdr* header, const void* data, size_t length,
|
|||||||
|
|
||||||
status = socket->first_info->send_data(socket->first_protocol, buffer);
|
status = socket->first_info->send_data(socket->first_protocol, buffer);
|
||||||
if (status != B_OK) {
|
if (status != B_OK) {
|
||||||
|
// we only send signals when called from userland
|
||||||
|
if (status == EPIPE && is_syscall() && !nosignal)
|
||||||
|
send_signal(find_thread(NULL), SIGPIPE);
|
||||||
|
|
||||||
size_t sizeAfterSend = buffer->size;
|
size_t sizeAfterSend = buffer->size;
|
||||||
gNetBufferModule.free(buffer);
|
gNetBufferModule.free(buffer);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user