關於Socket option --SO_LINGER option
by 艾鍗學院, 2011-08-09 22:33, 人氣(2688)
static struct linger linger = {0, 0};
int lsize = sizeof(struct linger);
setsockopt(sock, SOL_SOCKET, SO_LINGER, (void *)&linger, lsize);
int lsize = sizeof(struct linger);
setsockopt(sock, SOL_SOCKET, SO_LINGER, (void *)&linger, lsize);
---------------------
SO_LINGER (see following NOTE) controls the action taken when unsent
messages are queued on socket and a close(S) is performed. If the socket
promises reliable delivery of data and SO_LINGER is set, the system will
block the process on the close 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 the setsockopt call
when SO_LINGER is requested. If SO_LINGER is disabled and a close is
issued, the system will process the close in a manner that allows the
process to continue as quickly as possible.
NOTE: Due to artifacts of the current implementation, the linger option no
longer has an effect. It is still recognized by the system for backward
compatibility. Currently, close operations complete as expeditiously as
possible. If unsent data remains, the protocols will ensure its delivery.
messages are queued on socket and a close(S) is performed. If the socket
promises reliable delivery of data and SO_LINGER is set, the system will
block the process on the close 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 the setsockopt call
when SO_LINGER is requested. If SO_LINGER is disabled and a close is
issued, the system will process the close in a manner that allows the
process to continue as quickly as possible.
NOTE: Due to artifacts of the current implementation, the linger option no
longer has an effect. It is still recognized by the system for backward
compatibility. Currently, close operations complete as expeditiously as
possible. If unsent data remains, the protocols will ensure its delivery.