2012年3月30日 星期五

struct socket & struct sock 分析

User space application 透過下列函式的調用取得 socket descriptor

int socket(int domain, int type, int protocol); 

在system call中,這個sockfd就會被映射成一個表示socket的struct
下面是其完整定義

struct socket {
    socket_state state;
    unsigned long flags;
    const struct proto_ops *ops;
    struct fasync_struct *fasync_list;
    struct file *file;
    struct sock *sk;
    wait_queue_head_t wait;
    short type;
}; 


state用於表示socket所處的狀態,不過此成員只對TCP socket有用
因為TCP是connection-oriented的protocol,需要維護socket狀態



[Reference] http://miox.cc/2009/05/struct-socket.html

沒有留言:

張貼留言