Is there a difference between
shutdown($socket, 0) if $socket;
shutdown($socket, 2) if $socket;
close($socket) if $socket;
and
shutdown($socket, 2) if $socket;
close($socket) if $socket;
Also is there a difference between
shutdown($socket, 1) if $socket;
shutdown($socket, 2) if $socket;
close($socket) if $socket;
and
shutdown($socket, 2) if $socket;
close($socket) if $socket;
And finally is the close needed at all?
shutdowncauses one side of the TCP connection to stop reading (0), or writing (1), or both (2). So the first two snippets have the same effect, as do the next two.shutdowndoes not release the file descriptor, socloseis still needed.The difference between single
closeand one preceded byshutdown( fd, 2 )is that in the second case TCP will not try to deliver outstanding data to the remote side (seeSO_LINGER).