When the flag SO_LINGER is set on a socket, then a call to close() is blocked until all buffered data is sent or some timeout expires. Otherwise close() returns immediately. Use abortOnClose() to set this socket option.
close()
abortOnClose()