aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKen Brown <kbrown@cornell.edu>2021-05-17 15:54:14 -0400
committerKen Brown <kbrown@cornell.edu>2021-06-04 12:36:46 -0400
commit37b102057aed7ff87ef79584f8d4983238029cec (patch)
tree75de86d2317fe410e438d3652d531c2eb891a422
parent7720ea9679e9c0952edee5aaa3bd4d77e4cbbd33 (diff)
downloadnewlib-37b102057aed7ff87ef79584f8d4983238029cec.zip
newlib-37b102057aed7ff87ef79584f8d4983238029cec.tar.gz
newlib-37b102057aed7ff87ef79584f8d4983238029cec.tar.bz2
Cygwin: AF_UNIX: adapt shutdown to mqueues
-rw-r--r--winsup/cygwin/fhandler_socket_unix.cc26
1 files changed, 16 insertions, 10 deletions
diff --git a/winsup/cygwin/fhandler_socket_unix.cc b/winsup/cygwin/fhandler_socket_unix.cc
index 6071061..2178c38 100644
--- a/winsup/cygwin/fhandler_socket_unix.cc
+++ b/winsup/cygwin/fhandler_socket_unix.cc
@@ -1671,14 +1671,18 @@ fhandler_socket_unix::getpeername (struct sockaddr *name, int *namelen)
int
fhandler_socket_unix::shutdown (int how)
{
- NTSTATUS status = STATUS_SUCCESS;
- IO_STATUS_BLOCK io;
+ int ret;
if (how < SHUT_RD || how > SHUT_RDWR)
{
set_errno (EINVAL);
return -1;
}
+ if (connect_state () != connected)
+ {
+ set_errno (ENOTCONN);
+ return -1;
+ }
/* Convert SHUT_RD/SHUT_WR/SHUT_RDWR to _SHUT_RECV/_SHUT_SEND bits. */
++how;
state_lock ();
@@ -1687,23 +1691,25 @@ fhandler_socket_unix::shutdown (int how)
if (new_shutdown_mask != old_shutdown_mask)
saw_shutdown (new_shutdown_mask);
state_unlock ();
- if (new_shutdown_mask != old_shutdown_mask)
+ if (new_shutdown_mask != old_shutdown_mask
+ && get_socket_type () == SOCK_STREAM)
{
/* Send shutdown info to peer. Note that it's not necessarily fatal
if the info isn't sent here. The info will be reproduced by any
followup package sent to the peer. */
af_unix_pkt_hdr_t packet (true, (shut_state) new_shutdown_mask, 0, 0, 0);
io_lock ();
- set_pipe_non_blocking (true);
- status = NtWriteFile (get_handle (), NULL, NULL, NULL, &io, &packet,
- packet.pckt_len, NULL, NULL);
- set_pipe_non_blocking (is_nonblocking ());
+ set_mqueue_non_blocking (get_mqd_out (), true);
+ ret = mq_send (get_mqd_out (), (const char *) &packet, packet.pckt_len,
+ af_un_prio_admin);
+ set_mqueue_non_blocking (get_mqd_out (), is_nonblocking ());
io_unlock ();
}
- if (!NT_SUCCESS (status))
+ if (ret < 0)
{
- debug_printf ("Couldn't send shutdown info: NtWriteFile: %y", status);
- return -1;
+ debug_printf ("Couldn't send shutdown info, %E");
+ if (get_errno () != EAGAIN)
+ return -1;
}
return 0;
}