Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Closing a socket before terminating

When a process writes to a socket the kernel stores this data in an internal buffer first before pushing it though. Now if the process terminates (before closing the socket) with data still in the buffer, the kernel doesn't bother to flush them out.

So my question is:

When a process closes a socket and then dies immediately, are we in a situation where we might loose the data in the buffer? Does the kernel flush the buffer immediately when close socket is called?

like image 447
Kam Avatar asked Jun 11 '26 07:06

Kam


1 Answers

From the manpage for close:

If fildes refers to a socket, close() shall cause the socket to be destroyed. If the socket is in connection-mode, and the SO_LINGER option is set for the socket with non-zero linger time, and the socket has untransmitted data, then close() shall block for up to the current linger interval until all data is transmitted.

like image 156
Tony Delroy Avatar answered Jun 14 '26 02:06

Tony Delroy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!