Where are socket FDs are stored?
I faced few issues while writing server application using TCP on linux system. I have few queries开发者_C百科.
- Where are socket FDs are stored and what are the attributes associated with socket FDs.
- 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?
Socket file descriptors are stored in integer variables in your application, just like other file descriptors.
The kernel internally differentiates between different file descriptor types through the different function pointers within the associated
struct file
.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.
精彩评论