ngxin之main函数的解读(二)

上次说到ngx_connecntion_t,   现在看看ngx_connection_t的定义

         struct ngx_connection_s {
             void               *data;//用于关联其他的ngx_connection_t结构体
             ngx_event_t        *read;//设置该链接的读事件
             ngx_event_t        *write;//设置该链接的写事件  
             ngx_socket_t        fd; //该数据类型是int的重定义也就是链接描述符
             /*ngx_recv_pt是一个函数指针 typedef ssize_t(*ngx_recv_pt)(ngx_connection_t*c,u_char*buf,size_t size);
             也就是说,这是一个接受线程,只处理对方发送来的数据
             */
             ngx_recv_pt         recv;
             /*ngx_send_pt是一个函数指针typedef ssize_t(*ngx_send_pt)(ngx_connection_t*t,u_char*buf,size_t size);
              也就是说,这是一个发送线程,只处理发送数据
             */
             ngx_send_pt         send;
             /*ngx_recv_chain_pt也是一个函数指针 typedef ssize_t(*ngx_recv_chain_pt)(ngx_connection_t*c,ngx_chain_t*in);
               该函数指针与众不同的就是她处理的就是ngx_chain_t的数据结构
              */             
             ngx_recv_chain_pt   recv_chain;
             /*
               这个我就不说了,跟前面是一样的
              */
             ngx_send_chain_pt   send_chain;
              /*
               ngx_listeining_t用于设置网络连接的socket监听,它对应一个ngx_listening_t结构体,而该ngx_listening_t结构体中的*connection成员
               又指向该ngx_connection_s结构体
              */
             ngx_listening_t    *listening;
             /*
               off_t默认类型是32bit的long int
             */
             off_t               sent;
 
             ngx_log_t          *log;
 
             ngx_pool_t         *pool;
 
            struct sockaddr    *sockaddr;
            socklen_t           socklen;
            ngx_str_t           addr_text;
 
            ngx_str_t           proxy_protocol_addr;
 
            #if (NGX_SSL)
              ngx_ssl_connection_t  *ssl;
            #endif
 
            struct sockaddr    *local_sockaddr;
            socklen_t           local_socklen;
 
           ngx_buf_t          *buffer;
 
           ngx_queue_t         queue;
 
           ngx_atomic_uint_t   number;
 
           ngx_uint_t          requests;
 
           unsigned            buffered:8;
 
           unsigned            log_error:3;     /* ngx_connection_log_error_e */
 
           unsigned            unexpected_eof:1;
           unsigned            timedout:1;
           unsigned            error:1;
           unsigned            destroyed:1;
 
           unsigned            idle:1;
           unsigned            reusable:1;
           unsigned            close:1;
   
           unsigned            sendfile:1;
           unsigned            sndlowat:1;
           unsigned            tcp_nodelay:2;   /* ngx_connection_tcp_nodelay_e */
           unsigned            tcp_nopush:2;    /* ngx_connection_tcp_nopush_e */
 
           unsigned            need_last_buf:1;
 
           #if (NGX_HAVE_IOCP)
               unsigned            accept_context_updated:1;
          #endif
 
         #if (NGX_HAVE_AIO_SENDFILE)
            unsigned            aio_sendfile:1;
            unsigned            busy_count:2;
            ngx_buf_t          *busy_sendfile;
        #endif
 
       #if (NGX_THREADS)
          ngx_atomic_t        lock;
       #endif
 };
 

现在说下ngx_event_t的定义

 struct ngx_event_s {
     void            *data;
 
     unsigned         write:1;
 
     unsigned         accept:1;
 
     /* used to detect the stale events in kqueue, rtsig, and epoll */
     unsigned         instance:1;
 
     /*
      * the event was passed or would be passed to a kernel;
      * in aio mode - operation was posted.
      */
     unsigned         active:1;
 
     unsigned         disabled:1;
 
     /* the ready event; in aio mode 0 means that no operation can be posted */
     unsigned         ready:1;
 
     unsigned         oneshot:1;
 
     /* aio operation is complete */
     unsigned         complete:1;
 
     unsigned         eof:1;
     unsigned         error:1;
 
     unsigned         timedout:1;
     unsigned         timer_set:1;
 
     unsigned         delayed:1;
 
     unsigned         deferred_accept:1;
 
     /* the pending eof reported by kqueue, epoll or in aio chain operation */
     unsigned         pending_eof:1;
 
 #if !(NGX_THREADS)
     unsigned         posted_ready:1;
 #endif
 
 #if (NGX_WIN32)
     /* setsockopt(SO_UPDATE_ACCEPT_CONTEXT) was successful */
     unsigned         accept_context_updated:1;
 #endif
 
 #if (NGX_HAVE_KQUEUE)
     unsigned         kq_vnode:1;
 
     /* the pending errno reported by kqueue */
     int              kq_errno;
 #endif
 
     /*
      * kqueue only:
      *   accept:     number of sockets that wait to be accepted
      *   read:       bytes to read when event is ready
      *               or lowat when event is set with NGX_LOWAT_EVENT flag
      *   write:      available space in buffer when event is ready
      *               or lowat when event is set with NGX_LOWAT_EVENT flag
      *
      * iocp: TODO
      *
      * otherwise:
      *   accept:     1 if accept many, 0 otherwise
      */
 
 #if (NGX_HAVE_KQUEUE) || (NGX_HAVE_IOCP)
     int              available;
 #else
     unsigned         available:1;
 #endif
 
     ngx_event_handler_pt  handler;
 
 
 #if (NGX_HAVE_AIO)
 
 #if (NGX_HAVE_IOCP)
     ngx_event_ovlp_t ovlp;
 #else
     struct aiocb     aiocb;
 #endif
 
 #endif
 
     ngx_uint_t       index;
 
     ngx_log_t       *log;
 
     ngx_rbtree_node_t   timer;
 
     unsigned         closed:1;
 
     /* to test on worker exit */
     unsigned         channel:1;
     unsigned         resolver:1;
 
 #if (NGX_THREADS)
 
     unsigned         locked:1;
 
     unsigned         posted_ready:1;
     unsigned         posted_timedout:1;
     unsigned         posted_eof:1;
 
 #if (NGX_HAVE_KQUEUE)
     /* the pending errno reported by kqueue */
     int              posted_errno;
 #endif
 
 #if (NGX_HAVE_KQUEUE) || (NGX_HAVE_IOCP)
     int              posted_available;
 #else
     unsigned         posted_available:1;
 #endif
 
     ngx_atomic_t    *lock;
     ngx_atomic_t    *own_lock;
 
 #endif
 
     /* the links of the posted queue */
     ngx_event_t     *next;
     ngx_event_t    **prev;
 
 
 #if 0
 
     /* the threads support */
 
     /*
      * the event thread context, we store it here
      * if $(CC) does not understand __thread declaration
      * and pthread_getspecific() is too costly
      */
 
     void            *thr_ctx;
 
 #if (NGX_EVENT_T_PADDING)
 
     /* event should not cross cache line in SMP */
 
     uint32_t         padding[NGX_EVENT_T_PADDING];
 #endif
 #endif
 };
 

这样,我们就暂时将main函数中的几种数据结构写完了,现在看看其他的


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

世纪殇

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值