Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

perl shutdown a socket

Tags:

sockets

perl

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?

like image 215
bliof Avatar asked Sep 05 '12 13:09

bliof


1 Answers

shutdown causes 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.

shutdown does not release the file descriptor, so close is still needed.

The difference between single close and one preceded by shutdown( fd, 2 ) is that in the second case TCP will not try to deliver outstanding data to the remote side (see SO_LINGER).

like image 111
Nikolai Fetissov Avatar answered Oct 24 '22 03:10

Nikolai Fetissov