开发者

Where are socket FDs are stored?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜