开发者

Where are socket FDs are stored?

开发者 https://www.devze.com 2023-01-11 15:21 出处:网络
I faced few issues while writing server application using TCP on linux system. I have few queries开发者_C百科.

I faced few issues while writing server application using TCP on linux system. I have few queries开发者_C百科.

  1. Where are socket FDs are stored and what are the attributes associated with socket FDs.
  2. How the kernel differentiates between FDs like socket FDs, file Fds, Message Queue FDs

Socket FDs are received as

int sockFD = socket(..., ..., ...);

what is the difference between

a) close(sockFD);

and

b) int sockCopy = sockFD; //copy the socketfd

    close(sockCopy);

Case b will not close socket why?


  1. Socket file descriptors are stored in integer variables in your application, just like other file descriptors.

  2. The kernel internally differentiates between different file descriptor types through the different function pointers within the associated struct file.

  3. There is no difference; int sockCopy = sockFD; close(sockCopy); will close the socket. The kernel does not care what you call the variable that you store the file descriptor in - all it cares about is the numerical value.

0

精彩评论

暂无评论...
验证码 换一张
取 消