SHUTDOWN(2)

✨ shutdown(2) ✨

okay so bestie, welcome to shutdown(2) β€” the System Calls Manual page you didn't know you needed πŸ’… no cap.


🌸 NAME 🌸

shutdown β€” disable sends and/or receives on a socket πŸš«πŸ“€πŸ“₯

πŸ“š LIBRARY πŸ“š

Standard C Library (libc, -lc) 🫢

✨ SYNOPSIS ✨

#include <sys/types.h>
#include <sys/socket.h>

int
shutdown(int s, int how);

πŸ’– DESCRIPTION πŸ’–

The shutdown() system call disables sends or receives on a socket. Like, it's giving "we're done here" energy to one direction or both πŸŽ€

The how argument specifies the type of shutdown. Possible values are:

  • SHUT_RD β€” further receives will be disallowed. bye bye incoming data πŸ’Œ
  • SHUT_WR β€” further sends will be disallowed. This may cause actions specific to the protocol family of the socket s to happen; see β€œIMPLEMENTATION NOTES”. lowkey this one has side quests πŸ‘€
  • SHUT_RDWR β€” further sends and receives will be disallowed. Implies SHUT_WR. both directions? gone. periodt.

If the file descriptor s is associated with a SOCK_STREAM socket, all or part of the full-duplex connection will be shut down. iconic behavior honestly 🌈


🧚 IMPLEMENTATION NOTES 🧚

The following protocol specific actions apply to the use of SHUT_WR (and potentially also SHUT_RDWR), based on the properties of the socket associated with the file descriptor s.

Like, the vibe check depends on your domain + type + protocol combo, so here's the whole roster πŸ¦‹:

  • Domain PF_INET, Type SOCK_DGRAM, Protocol IPPROTO_SCTP β€” failure, as socket is not connected. πŸ’€
  • Domain PF_INET, Type SOCK_DGRAM, Protocol IPPROTO_UDP β€” failure, as socket is not connected. πŸ’€
  • Domain PF_INET, Type SOCK_STREAM, Protocol IPPROTO_SCTP β€” send queued data and tear down association. πŸ”₯
  • Domain PF_INET, Type SOCK_STREAM, Protocol IPPROTO_TCP β€” send queued data, wait for ACK, then send FIN. πŸ”₯
  • Domain PF_INET6, Type SOCK_DGRAM, Protocol IPPROTO_SCTP β€” failure, as socket is not connected. πŸ’€
  • Domain PF_INET6, Type SOCK_DGRAM, Protocol IPPROTO_UDP β€” failure, as socket is not connected. πŸ’€
  • Domain PF_INET6, Type SOCK_STREAM, Protocol IPPROTO_SCTP β€” send queued data and tear down association. πŸ”₯
  • Domain PF_INET6, Type SOCK_STREAM, Protocol IPPROTO_TCP β€” send queued data, wait for ACK, then send FIN. πŸ”₯

πŸ‘‘ RETURN VALUES πŸ‘‘

The shutdown() function returns the value 0 if successful; otherwise the value -1 is returned and the global variable errno is set to indicate the error.

so: 0 = slay, -1 = the group chat has bad news and errno is the receipts πŸ“±

😭 ERRORS 😭

The shutdown() system call fails if:

  • EBADF β€” the s argument is not a valid file descriptor. 🚩
  • EINVAL β€” the how argument is invalid. 🚩
  • ENOTCONN β€” the s argument specifies a socket which is not connected. 🚩
  • ENOTSOCK β€” the s argument does not refer to a socket. 🚩
bestie not every one of these is your fault but every one of these means you're not getting what you wanted πŸ™ˆ

🌈 SEE ALSO 🌈

connect(2), socket(2), inet(4), inet6(4)


⭐ STANDARDS ⭐

The shutdown() system call is expected to comply with IEEE Std 1003.1g-2000 (β€œPOSIX.1”), when finalized. pending finalization, we wait 🫢

πŸŽ€ HISTORY πŸŽ€

The shutdown() system call appeared in 4.2BSD. The SHUT_RD, SHUT_WR, and SHUT_RDWR constants appeared in IEEE Std 1003.1g-2000 (β€œPOSIX.1”). a legacy icon fr fr πŸ‘‘

πŸ’œ AUTHORS πŸ’œ

This manual page was updated by Bruce M. Simpson <bms@FreeBSD.org> to reflect how shutdown() behaves with PF_INET and PF_INET6 sockets. thank you for your service πŸ«‘πŸ’–

πŸ’€ BUGS πŸ’€

The ICMP β€œport unreachable” message should be generated in response to datagrams received on a local port to which s is bound after shutdown() is called.

ngl that one's just... not happening when it should 😭 noted, not fixed.

and that's the whole page bestie πŸ’… this one's from the Debian crew, dated July 27, 2015 β€” go forth and close your sockets responsibly ✨

πŸ“¦ where this page comes from