ttworkhard
ttworkhard

Reputation: 301

why tcp connection is closed even if I didn't use close( ) function?

I used ctrl+c to terminate the socket program instead of close() function . TCP connection can be closed after a while . How dose the kernel deal with this situation? I thought only close() function could close the tcp connection.

Upvotes: 1

Views: 77

Answers (2)

usr
usr

Reputation: 171246

I thought only close() function could close the tcp connection.

Why would that be? TCP is a software-defined protocol. The OS can implement it however it likes. All sensible OS'es clean up all resources that a terminated process was using. Sockets will be closed as well. What good would a TCP connection be if no process was using it and no process ever could (because the last handle was destroyed)? Makes no sense to keep the connection around if no one could ever read or write it.

Upvotes: 0

user207421
user207421

Reputation: 311054

You can close the socket. The peer can close the connection.

Upvotes: 1

Related Questions