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.
你能不能让我知道在套接字描述符上调用read/write时会发生什么.如果读取/写入对套接字描述符起作用,我们不能使用open而不是socket来获取描述符?
Hou*_*eng 11
正如我在内存中所知,文件描述符将包含标识以标识此fd的文件系统类型.内核将根据文件系统类型调用相应的处理函数.你可以在linux内核中看到源read_write.c.
简而言之,内核做了:
希望这清楚,谢谢,厚城
套接字描述符也与文件结构相关联,但该结构的一组 file_operations 函数与通常的不同。因此,这些描述符的初始化和使用是不同的。内核级接口的读写部分恰好是完全等效的。
归档时间: |
|
查看次数: |
23553 次 |
最近记录: |