Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between calling setSoLinger with a 0 value and not enabling soLinger at all?

Tags:

java

sockets

In Java, is there a difference between setting a socket with Socket.setSoLinger(true, 0) and not calling setSoLinger at all? Is there a difference in how the socket is closed?

I have looked through the Java sources, and I don't see anything special around socket closes with regards to soLinger. This leads me to believe this is an OS specific behavior. In my case I am working on Linux.

like image 850
mmorrisson Avatar asked Oct 08 '22 10:10

mmorrisson


1 Answers

When a timeout is specified via setSoLinger(), close() blocks until the closing hand-shake is completed, or until the specified amount of time passes.

However, close() provides no indication that the closing handshake failed to complete, even if the time limit set by setSoLinger() expires before the closing sequence completes.

In other words, setSoLinger() does not provide any additional assurance to the application in current implementations.

Here's the source of info.

like image 59
Zaki Avatar answered Oct 12 '22 10:10

Zaki