"Fossies" - the Fresh Open Source Software Archive

Member "opensips-3.0.1/reactor_defs.h" (16 Apr 2019, 3411 Bytes) of package /linux/misc/opensips-3.0.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "reactor_defs.h" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 2.4.5_vs_3.0.0.

    1 /*
    2  * Copyright (C) 2014 OpenSIPS Solutions
    3  *
    4  * This file is part of opensips, a free SIP server.
    5  *
    6  * opensips is free software; you can redistribute it and/or modify
    7  * it under the terms of the GNU General Public License as published by
    8  * the Free Software Foundation; either version 2 of the License, or
    9  * (at your option) any later version.
   10  *
   11  * opensips is distributed in the hope that it will be useful,
   12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   14  * GNU General Public License for more details.
   15  *
   16  * You should have received a copy of the GNU General Public License
   17  * along with this program; if not, write to the Free Software
   18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
   19  *
   20  *
   21  * history:
   22  * ---------
   23  *  2014-08-25  created (bogdan)
   24  */
   25 
   26 
   27 #ifndef _REACTOR_DEFS_H_
   28 #define _REACTOR_DEFS_H_
   29 
   30 /*  This should be included by files where the reactor is used (in terms of 
   31  *  submitting fd's to it).
   32  *  The header file provides both the reactor definitions, the fd manipulation
   33  *  functions, but NO looping and triggering functions.
   34  *  IF you need to implement a reactor core (looping, triggering), use
   35  *  the reactor.h file directly !!!
   36  */
   37 
   38 
   39 #include "ip_addr.h"
   40 #include "io_wait.h"
   41 #include "globals.h"
   42 
   43 struct worker_io_data {
   44     /* source info buffer */
   45     union sockaddr_union* from_sa;
   46     /* received info */
   47     struct receive_info ri;
   48     /* SIP interface */
   49     struct socket_info *si;
   50 };
   51 
   52 enum reactor_prios {
   53     RCT_PRIO_NET=0,
   54     RCT_PRIO_ASYNC,
   55     RCT_PRIO_PROC,
   56     RCT_PRIO_TIMER,
   57     RCT_PRIO_MAX };
   58 
   59 enum fd_types { F_NONE=0,
   60         /* generic fd types, to be handled by all SIP worker processes */
   61         F_TIMER_JOB,  F_FD_ASYNC, F_LAUNCH_ASYNC, F_IPC, F_SCRIPT_ASYNC=16,
   62         /* fd type specifc to UDP oriented processes (SIP workers) */
   63         F_UDP_READ,
   64         /* fd types specific to TCP oriented processes (SIP workers) */
   65         F_TCPMAIN, F_TCPCONN,
   66         /* fd types for TCP management process (TCP main process) */
   67         F_TCP_LISTENER, F_TCP_TCPWORKER, F_TCP_WORKER,
   68         /* fd type specific to FreeSWITCH ESL traffic (FS worker process) */
   69         F_FS_CONN,
   70         };
   71 
   72 extern io_wait_h _worker_io;
   73 extern unsigned int reactor_size;
   74 
   75 int init_reactor_size(void);
   76 
   77 #define init_worker_reactor( _name, _prio_max) \
   78     init_io_wait(&_worker_io, _name, reactor_size, io_poll_method, _prio_max)
   79 
   80 #define reactor_add_reader( _fd, _type, _prio, _data) \
   81     io_watch_add(&_worker_io, _fd, _type, _data, _prio, IO_WATCH_READ)
   82 
   83 #define reactor_add_writer( _fd, _type, _prio, _data) \
   84     io_watch_add(&_worker_io, _fd, _type, _data, _prio, IO_WATCH_WRITE)
   85 
   86 #define reactor_del_reader( _fd, _idx, _io_flags) \
   87     io_watch_del(&_worker_io, _fd, _idx, _io_flags, IO_WATCH_READ)
   88 
   89 #define reactor_del_writer( _fd, _idx, _io_flags) \
   90     io_watch_del(&_worker_io, _fd, _idx, _io_flags, IO_WATCH_WRITE)
   91 
   92 #define reactor_del_all( _fd, _idx, _io_flags) \
   93     io_watch_del(&_worker_io, _fd, _idx, _io_flags, IO_WATCH_READ|IO_WATCH_WRITE)
   94 
   95 #define destroy_worker_reactor() \
   96     destroy_io_wait(&_worker_io)
   97 
   98 #define reactor_has_async() \
   99     (io_poll_method==POLL_POLL || io_poll_method==POLL_EPOLL)
  100 
  101 #define reactor_is_empty() \
  102     (_worker_io.fd_no==0)
  103 
  104 #define reactor_set_app_flag( _type, _app_flag) \
  105     io_set_app_flag( &_worker_io , _type, _app_flag)
  106 
  107 #define reactor_check_app_flag(_app_flag) \
  108     io_check_app_flag( &_worker_io , _app_flag)
  109 
  110 #endif
  111