Yes by default close()
will be non-blocking on an SCTP socket, it will just initiate the shutdown procedure, not wait for it to complete.
You can change this by setting the SO_LINGER socket option:
struct linger lin;
unsigned int len =sizeof(lin);
lin.l_onoff=1;
lin.l_linger=10;
setsockopt(socketfd,SOL_SOCKET, SO_LINGER,&lin, len);
Whith this setting, close()
will block up to 10 seconds From the SCTP Socket API RFC:
8.1.4. SO_LINGER
An application can use this option to perform the SCTP ABORT
primitive. This option affects all associations related to the
socket.
The linger option structure is
struct linger {
int l_onoff; /* option on/off /
int l_linger; / linger time */ };
To enable the option, set l_onoff to 1. If the l_linger value is
set to 0, calling close() is the same as the ABORT primitive. If
the value is set to a negative value, the setsockopt() call will
return an error. If the value is set to a positive value
linger_time, the close() can be blocked for at most linger_time.
Please note that the time unit is in seconds, according to POSIX,
but might be different on specific platforms. If the graceful
shutdown phase does not finish during this period, close() will
return, but the graceful shutdown phase will continue in the
system.
Note that this is a socket-level option, not an SCTP-level option.
When using this option, an application must specify a level of
SOL_SOCKET in the call.
If you're using Linux, there's also these notes in the source code.