tags:

views:

69

answers:

2

Hi, read(2) and write(2) works both on socket descriptor as well as on file descriptor. In case of file descriptor, User file descriptor table->file table and finally to inode table where it checks for the file type(regular file/char/block), and reads accordingly. In case of char spl file, it gets the function pointers based on the major number of the file from the char device switch and calls the appropriate read/write routines registered for the device. Similarly appropriate read/write routine is called for block special file by getting the function pointers from the block device switch.

Could you please let me know what exatly happens when read/write called on socket descriptor. If read/write works on socket descriptor, we cant we use open instead of socket to get the descriptor?

A: 

Socket descriptors are associated with file structures too, but a set of file_operations functions for that structures differs from the usual. Initailization and use of those descriptors is therefore dirrerent. Read and write part of kernel-level interface just happened to be exactly equivalent.

Basilevs
I want to know what are the data structure allocated on calling socket(), what information is stored in inode table, how it eventually reaches to Network Interface Card driver routines on calling read/write
Ganesh Kundapur
A: 

read and write are valid for some types of sockets in some states; this all depends on the various structs which are passed around inside the kernel.

In principle, open() could create a socket descriptor, but the BSD sockets API was never defined that way.

There are some other (Somewhat linux-specific) types of file descriptor which are opened by system calls other than open(), for example epoll_create or timerfd_create. These work the same.

MarkR