| ... | @@ -619,60 +619,6 @@ pub fn socketpair(domain: u32, socket_type: u32, protocol: u32) SocketError![2]s | ... | @@ -619,60 +619,6 @@ pub fn socketpair(domain: u32, socket_type: u32, protocol: u32) SocketError![2]s |
| 619 | } | 619 | } |
| 620 | } | 620 | } |
| 621 | | 621 | |
| 622 | pub const ShutdownError = error{ | | |
| 623 | ConnectionAborted, | | |
| 624 | | | |
| 625 | /// Connection was reset by peer, application should close socket as it is no longer usable. | | |
| 626 | ConnectionResetByPeer, | | |
| 627 | BlockingOperationInProgress, | | |
| 628 | | | |
| 629 | /// The network subsystem has failed. | | |
| 630 | NetworkDown, | | |
| 631 | | | |
| 632 | /// The socket is not connected (connection-oriented sockets only). | | |
| 633 | SocketUnconnected, | | |
| 634 | SystemResources, | | |
| 635 | } || UnexpectedError; | | |
| 636 | | | |
| 637 | pub const ShutdownHow = enum { recv, send, both }; | | |
| 638 | | | |
| 639 | /// Shutdown socket send/receive operations | | |
| 640 | pub fn shutdown(sock: socket_t, how: ShutdownHow) ShutdownError!void { | | |
| 641 | if (native_os == .windows) { | | |
| 642 | const result = windows.ws2_32.shutdown(sock, switch (how) { | | |
| 643 | .recv => windows.ws2_32.SD_RECEIVE, | | |
| 644 | .send => windows.ws2_32.SD_SEND, | | |
| 645 | .both => windows.ws2_32.SD_BOTH, | | |
| 646 | }); | | |
| 647 | if (0 != result) switch (windows.ws2_32.WSAGetLastError()) { | | |
| 648 | .ECONNABORTED => return error.ConnectionAborted, | | |
| 649 | .ECONNRESET => return error.ConnectionResetByPeer, | | |
| 650 | .EINPROGRESS => return error.BlockingOperationInProgress, | | |
| 651 | .EINVAL => unreachable, | | |
| 652 | .ENETDOWN => return error.NetworkDown, | | |
| 653 | .ENOTCONN => return error.SocketUnconnected, | | |
| 654 | .ENOTSOCK => unreachable, | | |
| 655 | .NOTINITIALISED => unreachable, | | |
| 656 | else => |err| return windows.unexpectedWSAError(err), | | |
| 657 | }; | | |
| 658 | } else { | | |
| 659 | const rc = system.shutdown(sock, switch (how) { | | |
| 660 | .recv => SHUT.RD, | | |
| 661 | .send => SHUT.WR, | | |
| 662 | .both => SHUT.RDWR, | | |
| 663 | }); | | |
| 664 | switch (errno(rc)) { | | |
| 665 | .SUCCESS => return, | | |
| 666 | .BADF => unreachable, | | |
| 667 | .INVAL => unreachable, | | |
| 668 | .NOTCONN => return error.SocketUnconnected, | | |
| 669 | .NOTSOCK => unreachable, | | |
| 670 | .NOBUFS => return error.SystemResources, | | |
| 671 | else => |err| return unexpectedErrno(err), | | |
| 672 | } | | |
| 673 | } | | |
| 674 | } | | |
| 675 | | | |
| 676 | pub const BindError = error{ | 622 | pub const BindError = error{ |
| 677 | SymLinkLoop, | 623 | SymLinkLoop, |
| 678 | NameTooLong, | 624 | NameTooLong, |