Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4729052
  • 博文数量: 930
  • 博客积分: 12070
  • 博客等级: 上将
  • 技术积分: 11448
  • 用 户 组: 普通用户
  • 注册时间: 2008-08-15 16:57
文章分类

全部博文(930)

文章存档

2011年(60)

2010年(220)

2009年(371)

2008年(279)

分类: LINUX

2010-03-24 11:37:40

结构体sock是套接口在网络层的表示,在代码/usr/src/linux-2.6.19/include/net/sock.h定义:

struct sock {
    struct
sock_common    __sk_common;
#define sk_family         __sk_common.skc_family
#define sk_state          __sk_common.skc_state
#define sk_reuse          __sk_common.skc_reuse
#define sk_bound_dev_if   __sk_common.skc_bound_dev_if
#define sk_node           __sk_common.skc_node
#define sk_bind_node      __sk_common.skc_bind_node
#define sk_refcnt         __sk_common.skc_refcnt
#define sk_hash           __sk_common.skc_hash
#define sk_prot           __sk_common.skc_prot
    unsigned char         sk_shutdown : 2,
                          sk_no_check : 2,
                          sk_userlocks : 4;
    unsigned char         sk_protocol;
    unsigned short        sk_type;
    int                   sk_rcvbuf;
    socket_lock_t         sk_lock;
    wait_queue_head_t     *sk_sleep;
    struct dst_entry      *sk_dst_cache;
    struct xfrm_policy    *sk_policy[2];
    rwlock_t              sk_dst_lock;
    atomic_t              sk_rmem_alloc;
    atomic_t              sk_wmem_alloc;
    atomic_t              sk_omem_alloc;
    struct sk_buff_head   sk_receive_queue;
    struct sk_buff_head   sk_write_queue;
    struct sk_buff_head   sk_async_wait_queue;
    int                   sk_wmem_queued;
    int                   sk_forward_alloc;
    gfp_t                 sk_allocation;
    int                   sk_sndbuf;
    int                   sk_route_caps;
    int                   sk_gso_type;
    int                   sk_rcvlowat;
    unsigned long         sk_flags;
    unsigned long         sk_lingertime;
    struct {
        struct sk_buff *head;
        struct sk_buff *tail;
    } sk_backlog;
    struct sk_buff_head   sk_error_queue;
    struct proto          *sk_prot_creator;
    rwlock_t              sk_callback_lock;
    int                   sk_err,
                          sk_err_soft;
    unsigned short        sk_ack_backlog;
    unsigned short        sk_max_ack_backlog;
    __u32                 sk_priority;
    struct ucred          sk_peercred;
    long                  sk_rcvtimeo;
    long                  sk_sndtimeo;
    struct sk_filter      *sk_filter;
    void                  *sk_protinfo;
    struct timer_list     sk_timer;
    struct timeval        sk_stamp;
    struct socket         *sk_socket;
    void                  *sk_user_data;
    struct page           *sk_sndmsg_page;
    struct sk_buff        *sk_send_head;
    __u32                 sk_sndmsg_off;
    int                   sk_write_pending;
    void                  *sk_security;
    sk_state_change();
    sk_data_ready();
    sk_write_space();
    sk_error_report();
    sk_backlog_rcv();
    sk_destruct();
};



sock->sk_shutdown            是一组标志位SEND_SHUTDOWN and/or RCV_SHUTDOWN
sock->sk_userlocks           SO_SNDBUF and SO_RCVBUF
sock->sk_rcvbuf              表示接收缓冲区的字节长度
sock->sk_rmem_alloc          表示接收队列已提交的字节数
sock->sk_receive_queue       表示接收的数据包的队列
sock->sk_wmem_alloc          表示发送队列已提交的字节数
sock->sk_write_queue         表示发送数据包的队列
sock->sk_sndbuf              表示发送缓冲区的字节长度
sock->sk_flags               SO_LINGER (l_onoff),SO_BROADCAST,SO_KEEPALIVE,SO_OOBINLINE
sock->sk_prot                是指定的域内部的协议处理函数集,它是套接口层和传输层之间的一个接口,提供诸如bind(), accept(), close()等操作
sock->sk_ack_backlog         表示当前的侦听队列
sock->sk_max_ack_backlog     表示最大的侦听队列
sock->sk_type                表示套接字的类型,如SOCK_STREAM
sock->sk_protocol            表示在当前域中套接字所属的协议
   
    几个函数指针均属回调函数,分别在套接口状态变化,有数据到达需要处理,有发送空间可用,有错误等时候被回调最后一个函数sk_destruct在套接口释放时被回调
阅读(2782) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~