Reputation: 6853
I was wondering what is a file descriptor of the network socket and how to get it? I believe it is a number?
Upvotes: 3
Views: 2530
Reputation: 284
What is 'the' network socket? If it's a socket you created, it will be the return value from socket() or accept(). If you're writing a daemon, the socket will be determined by whatever did the accept() on your behalf -- for example, /etc/xinetd will set it to 0, 1, and 2.
Upvotes: 2
Reputation: 29794
It is indeed a number and you get it by issuing the socket(2)
system call. It is stored in the process's task_struct
and you need it to send or receive data.
More exactly, the kernel uses the file descriptor to locate File Objects
stored in the files_struct
struct inside the task_struct
. It behaves like a bitmap where the number of the file descriptor represents the position the File Object
occupies inside that structure.
Upvotes: 5