I'm learning about network programming in Unix and currently trying to understand the concept of socket and file descriptors. From what I have understood a file descriptor is simply a position in an array of pointers (File descriptor table?) and these pointers point to a file somewhere in memory.
Do socket descriptors share this array with file descriptors, but the pointer instead refers to a socket. Or is there something else that's only used for sockets?
Is this array unique to every application/process?
Yes, sockets are also indices into the same table as files. At least for UNIX systems (like Linux and OSX), Windows is different, which is why you can't use e.g. read
and write
to receive and send data.
Each process has its own "file" descriptor table.