type 정리

dandb3·2024년 1월 2일
0

webserv

목록 보기
5/6

자료형

  • ngx_socket_t
    typedef int  ngx_socket_t;
  • ngx_fd_t
    typedef int                      ngx_fd_t;
  • ngx_int_t
    typedef intptr_t        ngx_int_t;
  • ngx_uint_t
    typedef uintptr_t       ngx_uint_t;

구조체

  • ngx_array_t
    typedef struct {
        void        *elts;
        ngx_uint_t   nelts;
        size_t       size;
        ngx_uint_t   nalloc;
        ngx_pool_t  *pool;
    } ngx_array_t;
    
  • ngx_buf_t
    struct ngx_buf_s {
        u_char          *pos;
        u_char          *last;
        off_t            file_pos;
        off_t            file_last;
    
        u_char          *start;         /* start of buffer */
        u_char          *end;           /* end of buffer */
        ngx_buf_tag_t    tag;
        ngx_file_t      *file;
        ngx_buf_t       *shadow;
    
        /* the buf's content could be changed */
        unsigned         temporary:1;
    
        /*
         * the buf's content is in a memory cache or in a read only memory
         * and must not be changed
         */
        unsigned         memory:1;
    
        /* the buf's content is mmap()ed and must not be changed */
        unsigned         mmap:1;
    
        unsigned         recycled:1;
        unsigned         in_file:1;
        unsigned         flush:1;
        unsigned         sync:1;
        unsigned         last_buf:1;
        unsigned         last_in_chain:1;
    
        unsigned         last_shadow:1;
        unsigned         temp_file:1;
    
        /* STUB */ int   num;
    };
  • ngx_file_t
    struct ngx_file_s {
        ngx_fd_t                   fd;
        ngx_str_t                  name;
        ngx_file_info_t            info;
    
        off_t                      offset;
        off_t                      sys_offset;
    
        ngx_log_t                 *log;
    
    #if (NGX_THREADS || NGX_COMPAT)
        ngx_int_t                (*thread_handler)(ngx_thread_task_t *task,
                                                   ngx_file_t *file);
        void                      *thread_ctx;
        ngx_thread_task_t         *thread_task;
    #endif
    
    #if (NGX_HAVE_FILE_AIO || NGX_COMPAT)
        ngx_event_aio_t           *aio;
    #endif
    
        unsigned                   valid_info:1;
        unsigned                   directio:1;
    };
  • ngx_conf_t
    struct ngx_conf_s {
        char                 *name;
        ngx_array_t          *args;
    
        ngx_cycle_t          *cycle;
        ngx_pool_t           *pool;
        ngx_pool_t           *temp_pool;
        ngx_conf_file_t      *conf_file;
        ngx_log_t            *log;
    
        void                 *ctx;
        ngx_uint_t            module_type;
        ngx_uint_t            cmd_type;
    
        ngx_conf_handler_pt   handler;
        void                 *handler_conf;
    };
  • ngx_conf_file_t
    typedef struct {
        ngx_file_t            file;
        ngx_buf_t            *buffer;
        ngx_buf_t            *dump;
        ngx_uint_t            line;
    } ngx_conf_file_t;
  • ngx_cycle_t
    struct ngx_cycle_s {
        void                  ****conf_ctx;
        ngx_pool_t               *pool;
    
        ngx_log_t                *log;
        ngx_log_t                 new_log;
    
        ngx_uint_t                log_use_stderr;  /* unsigned  log_use_stderr:1; */
    
        ngx_connection_t        **files;
        ngx_connection_t         *free_connections;
        ngx_uint_t                free_connection_n;
    
        ngx_module_t            **modules;
        ngx_uint_t                modules_n;
        ngx_uint_t                modules_used;    /* unsigned  modules_used:1; */
    
        ngx_queue_t               reusable_connections_queue;
        ngx_uint_t                reusable_connections_n;
        time_t                    connections_reuse_time;
    
        ngx_array_t               listening;
        ngx_array_t               paths;
    
        ngx_array_t               config_dump;
        ngx_rbtree_t              config_dump_rbtree;
        ngx_rbtree_node_t         config_dump_sentinel;
    
        ngx_list_t                open_files;
        ngx_list_t                shared_memory;
    
        ngx_uint_t                connection_n;
        ngx_uint_t                files_n;
    
        ngx_connection_t         *connections;
        ngx_event_t              *read_events;
        ngx_event_t              *write_events;
    
        ngx_cycle_t              *old_cycle;
    
        ngx_str_t                 conf_file;
        ngx_str_t                 conf_param;
        ngx_str_t                 conf_prefix;
        ngx_str_t                 prefix;
        ngx_str_t                 error_log;
        ngx_str_t                 lock_file;
        ngx_str_t                 hostname;
    };
  • ngx_module_t
    struct ngx_module_s {
        ngx_uint_t            ctx_index;
        ngx_uint_t            index;
    
        char                 *name;
    
        ngx_uint_t            spare0;
        ngx_uint_t            spare1;
    
        ngx_uint_t            version;
        const char           *signature;
    
        void                 *ctx;
        ngx_command_t        *commands; // ngx_command_t들의 배열 인듯?
        ngx_uint_t            type;
    
        ngx_int_t           (*init_master)(ngx_log_t *log);
    
        ngx_int_t           (*init_module)(ngx_cycle_t *cycle);
    
        ngx_int_t           (*init_process)(ngx_cycle_t *cycle);
        ngx_int_t           (*init_thread)(ngx_cycle_t *cycle);
        void                (*exit_thread)(ngx_cycle_t *cycle);
        void                (*exit_process)(ngx_cycle_t *cycle);
    
        void                (*exit_master)(ngx_cycle_t *cycle);
    
        uintptr_t             spare_hook0;
        uintptr_t             spare_hook1;
        uintptr_t             spare_hook2;
        uintptr_t             spare_hook3;
        uintptr_t             spare_hook4;
        uintptr_t             spare_hook5;
        uintptr_t             spare_hook6;
        uintptr_t             spare_hook7;
    };
    
  • ngx_command_t
    struct ngx_command_s {
        ngx_str_t             name;
        ngx_uint_t            type;
        char               *(*set)(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
        ngx_uint_t            conf;
        ngx_uint_t            offset;
        void                 *post;
    };
    
  • ngx_listening_t
    struct ngx_listening_s {
        ngx_socket_t        fd;
    
        struct sockaddr    *sockaddr;
        socklen_t           socklen;    /* size of sockaddr */
        size_t              addr_text_max_len;
        ngx_str_t           addr_text;
    
        int                 type;
    
        int                 backlog;
        int                 rcvbuf;
        int                 sndbuf;
    #if (NGX_HAVE_KEEPALIVE_TUNABLE)
        int                 keepidle;
        int                 keepintvl;
        int                 keepcnt;
    #endif
    
        /* handler of accepted connection */
        ngx_connection_handler_pt   handler;
    
        void               *servers;  /* array of ngx_http_in_addr_t, for example */
    
        ngx_log_t           log;
        ngx_log_t          *logp;
    
        size_t              pool_size;
        /* should be here because of the AcceptEx() preread */
        size_t              post_accept_buffer_size;
    
        ngx_listening_t    *previous;
        ngx_connection_t   *connection;
    
        ngx_rbtree_t        rbtree;
        ngx_rbtree_node_t   sentinel;
    
        ngx_uint_t          worker;
    
        unsigned            open:1;
        unsigned            remain:1;
        unsigned            ignore:1;
    
        unsigned            bound:1;       /* already bound */
        unsigned            inherited:1;   /* inherited from previous process */
        unsigned            nonblocking_accept:1;
        unsigned            listen:1;
        unsigned            nonblocking:1;
        unsigned            shared:1;    /* shared between threads or processes */
        unsigned            addr_ntop:1;
        unsigned            wildcard:1;
    
    #if (NGX_HAVE_INET6)
        unsigned            ipv6only:1;
    #endif
        unsigned            reuseport:1;
        unsigned            add_reuseport:1;
        unsigned            keepalive:2;
        unsigned            quic:1;
    
        unsigned            deferred_accept:1;
        unsigned            delete_deferred:1;
        unsigned            add_deferred:1;
    #if (NGX_HAVE_DEFERRED_ACCEPT && defined SO_ACCEPTFILTER)
        char               *accept_filter;
    #endif
    #if (NGX_HAVE_SETFIB)
        int                 setfib;
    #endif
    
    #if (NGX_HAVE_TCP_FASTOPEN)
        int                 fastopen;
    #endif
    
    };
    • 소켓마다 하나씩 만들어진다.
    • servers 멤버 변수를 보면, void * 형태로 ngx_http_in_addr_t의 array 형태가 올 수 있다고 했는데, 아래의 경우 array형태로 온다고 생각했다.
      server {
      		listen 80;
      		listen 1.1.1.1:80;
      		listen 2.2.2.2:80;
      }
  • ngx_connection_t
    struct ngx_connection_s {
        void               *data;
        ngx_event_t        *read;
        ngx_event_t        *write;
    
        ngx_socket_t        fd;
    
        ngx_recv_pt         recv;
        ngx_send_pt         send;
        ngx_recv_chain_pt   recv_chain;
        ngx_send_chain_pt   send_chain;
    
        ngx_listening_t    *listening;
    
        off_t               sent;
    
        ngx_log_t          *log;
    
        ngx_pool_t         *pool;
    
        int                 type;
    
        struct sockaddr    *sockaddr;
        socklen_t           socklen;
        ngx_str_t           addr_text;
    
        ngx_proxy_protocol_t  *proxy_protocol;
    
    #if (NGX_QUIC || NGX_COMPAT)
        ngx_quic_stream_t     *quic;
    #endif
    
    #if (NGX_SSL || NGX_COMPAT)
        ngx_ssl_connection_t  *ssl;
    #endif
    
        ngx_udp_connection_t  *udp;
    
        struct sockaddr    *local_sockaddr;
        socklen_t           local_socklen;
    
        ngx_buf_t          *buffer;
    
        ngx_queue_t         queue;
    
        ngx_atomic_uint_t   number;
    
        ngx_msec_t          start_time;
        ngx_uint_t          requests;
    
        unsigned            buffered:8;
    
        unsigned            log_error:3;     /* ngx_connection_log_error_e */
    
        unsigned            timedout:1;
        unsigned            error:1;
        unsigned            destroyed:1;
        unsigned            pipeline:1;
    
        unsigned            idle:1;
        unsigned            reusable:1;
        unsigned            close:1;
        unsigned            shared: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;
        unsigned            need_flush_buf:1;
    
    #if (NGX_HAVE_SENDFILE_NODISKIO || NGX_COMPAT)
        unsigned            busy_count:2;
    #endif
    
    #if (NGX_THREADS || NGX_COMPAT)
        ngx_thread_task_t  *sendfile_task;
    #endif
    };
  • ngx_event_t
    struct ngx_event_s {
        void            *data;
    
        unsigned         write:1;
    
        unsigned         accept:1;
    
        /* used to detect the stale events in kqueue 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;
    
        unsigned         posted:1;
    
        unsigned         closed:1;
    
        /* to test on worker exit */
        unsigned         channel:1;
        unsigned         resolver:1;
    
        unsigned         cancelable:1;
    
    #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
         *   read:       bytes to read when event is ready, -1 if not known
         */
    
        int              available;
    
        ngx_event_handler_pt  handler;
    
    #if (NGX_HAVE_IOCP)
        ngx_event_ovlp_t ovlp;
    #endif
    
        ngx_uint_t       index;
    
        ngx_log_t       *log;
    
        ngx_rbtree_node_t   timer;
    
        /* the posted queue */
        ngx_queue_t      queue;
    
    #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
    };
  • ngx_http_connection_t
    typedef struct {
        ngx_http_addr_conf_t             *addr_conf;
        ngx_http_conf_ctx_t              *conf_ctx;
    
    #if (NGX_HTTP_SSL || NGX_COMPAT)
        ngx_str_t                        *ssl_servername;
    #if (NGX_PCRE)
        ngx_http_regex_t                 *ssl_servername_regex;
    #endif
    #endif
    
        ngx_chain_t                      *busy;
        ngx_int_t                         nbusy;
    
        ngx_chain_t                      *free;
    
        unsigned                          ssl:1;
        unsigned                          proxy_protocol:1;
    } ngx_http_connection_t;
  • ngx_http_core_srv_conf_t
    typedef struct {
        /* array of the ngx_http_server_name_t, "server_name" directive */
        ngx_array_t                 server_names;
    
        /* server ctx */
        ngx_http_conf_ctx_t        *ctx;
    
        u_char                     *file_name;
        ngx_uint_t                  line;
    
        ngx_str_t                   server_name;
    
        size_t                      connection_pool_size;
        size_t                      request_pool_size;
        size_t                      client_header_buffer_size;
    
        ngx_bufs_t                  large_client_header_buffers;
    
        ngx_msec_t                  client_header_timeout;
    
        ngx_flag_t                  ignore_invalid_headers;
        ngx_flag_t                  merge_slashes;
        ngx_flag_t                  underscores_in_headers;
    
        unsigned                    listen:1;
    #if (NGX_PCRE)
        unsigned                    captures:1;
    #endif
    
        ngx_http_core_loc_conf_t  **named_locations;
    } ngx_http_core_srv_conf_t;
    • 얘가 configuration file에서의 server block에 해당하는 구조체인 것 같다.
  • ngx_http_conf_ctx_t
    typedef struct {
        void        **main_conf;
        void        **srv_conf;
        void        **loc_conf;
    } ngx_http_conf_ctx_t;
  • ngx_http_addr_conf_t
    struct ngx_http_addr_conf_s {
        /* the default server configuration for this address:port */
        ngx_http_core_srv_conf_t  *default_server;
    
        ngx_http_virtual_names_t  *virtual_names;
    
        unsigned                   ssl:1;
        unsigned                   http2:1;
        unsigned                   quic:1;
        unsigned                   proxy_protocol:1;
    };
  • ngx_http_in_addr_t
    typedef struct {
        in_addr_t                  addr;
        ngx_http_addr_conf_t       conf;
    } ngx_http_in_addr_t;
  • ngx_http_port_t
    typedef struct {
        /* ngx_http_in_addr_t or ngx_http_in6_addr_t */
        void                      *addrs;
        ngx_uint_t                 naddrs;
    } ngx_http_port_t;
  • ngx_http_server_name_t
    typedef struct {
    #if (NGX_PCRE)
        ngx_http_regex_t          *regex;
    #endif
        ngx_http_core_srv_conf_t  *server;   /* virtual name server conf */
        ngx_str_t                  name;
    } ngx_http_server_name_t;
  • ngx_http_virtual_names_t
    typedef struct {
        ngx_hash_combined_t        names;
    
        ngx_uint_t                 nregex;
        ngx_http_server_name_t    *regex;
    } ngx_http_virtual_names_t;

함수 포인터

  • ngx_recv_pt
    typedef ssize_t (*ngx_recv_pt)(ngx_connection_t *c, u_char *buf, size_t size);
  • ngx_send_pt
    typedef ssize_t (*ngx_send_pt)(ngx_connection_t *c, u_char *buf, size_t size);
  • ngx_recv_chain_pt
    typedef ssize_t (*ngx_recv_chain_pt)(ngx_connection_t *c, ngx_chain_t *in,
        off_t limit);
  • ngx_send_chain_pt
    typedef ngx_chain_t *(*ngx_send_chain_pt)(ngx_connection_t *c, ngx_chain_t *in,
        off_t limit);
  • ngx_event_handler_pt
    typedef void (*ngx_event_handler_pt)(ngx_event_t *ev);
  • ngx_conf_handler_pt
    typedef char *(*ngx_conf_handler_pt)(ngx_conf_t *cf, ngx_command_t *dummy, void *conf);
profile
공부 내용 저장소

0개의 댓글