pzz

SO_LINGER & Linux

Sep 08, 2009 23:25

Я всегда думал, что если на сокете в неблокирующемся режиме (O_NONBLOCK) поставить SO_LINGER, то close() будет возвращаться немедленно, а linger time будет определять, сколько времени соединение будет болтаться в полузакрытом состоянии ( Read more... )

Хозяйке на заметку

Leave a comment

Comments 4

_slw September 9 2009, 08:36:20 UTC
а во FreeBSD как?

Reply


calcin September 9 2009, 08:57:35 UTC
Выдержка из мануала setsockopt() во FreeBSD:

SO_LINGER controls the action taken when unsent messages are queued on
socket and a close(2) is performed. If the socket promises reliable
delivery of data and SO_LINGER is set, the system will block the process
on the close(2) attempt until it is able to transmit the data or until it
decides it is unable to deliver the information (a timeout period, termed
the linger interval, is specified in seconds in the setsockopt() system
call when SO_LINGER is requested). If SO_LINGER is disabled and a
close(2) is issued, the system will process the close in a manner that
allows the process to continue as quickly as possible.

Так что похоже, во FreeBSD то же самое, и вообще это POSIX.
С помощью SO_LINGER от TIME_WAIT не отделаться.

http://www.developerweb.net/forum/archive/index.php/t-2982.html

Reply

isysoev September 12 2009, 13:04:39 UTC
Если стоит задача именно убрать TIME_WAIT, то она решается так: таймаут контролируется на user-level, по истечении этого таймаута ставим SO_LINGER с нулевым таймаутом и делаем close(). Ядро сразу же закрывает сокет и все связанные с ним структуры.

Reply

pzz September 22 2009, 21:14:48 UTC
Это безумно утомительно, честно говоря. Кроме того, получится не совсем то, что хотелось бы. А именно, хотелось бы, чтобы линух про соединение просто забыл несколько раньше, чем по дефолту. А так еще и лишний RST пошлют...

Reply


Leave a comment

Up