-1

Just as the title saying,in a tcp connect example

  1. a server create a sockfd with socket(AF_INET, SOCK_STREAM, IPPROTO_TCP) function,
  2. then it bind the sockfd to a local sockaddr struct,
  3. the server accept the client's connection, and returns a clientfd
  4. server and client send or recv messages

here is the question,after step 4, is it necessary to close the clientfd by manual?

4

1 回答 1

1

返回clientfd的是一个全新的文件描述符。如果不这样做close,该文件描述符将泄漏。

所以,是的,您应该始终 closeaccept. 请注意,shutdown不会关闭文件描述符,它只是阻止它被用于进一步的通信。

于 2013-08-11T15:07:51.527 回答