Line | Count | Source |
1 | | /* |
2 | | * Copyright (C) 2017 OpenSIPS Project |
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 | | |
22 | | #ifndef _CORE_IPC_H |
23 | | #define _CORE_IPC_H |
24 | | |
25 | | |
26 | | typedef short ipc_handler_type; |
27 | | extern int ipc_shared_fd_read; |
28 | | #define IPC_TYPE_NONE (-1) |
29 | 0 | #define ipc_bad_handler_type(htype) ((htype) < 0) |
30 | | |
31 | 0 | #define IPC_FD_READ(_proc_no) pt[_proc_no].ipc_pipe[0] |
32 | 0 | #define IPC_FD_WRITE(_proc_no) pt[_proc_no].ipc_pipe[1] |
33 | 0 | #define IPC_FD_READ_SELF IPC_FD_READ(process_no) |
34 | | #define IPC_FD_READ_SHARED ipc_shared_fd_read |
35 | 0 | #define IPC_FD_SYNC_READ(_proc_no) pt[_proc_no].ipc_sync_pipe[0] |
36 | 0 | #define IPC_FD_SYNC_WRITE(_proc_no) pt[_proc_no].ipc_sync_pipe[1] |
37 | 0 | #define IPC_FD_SYNC_READ_SELF IPC_FD_SYNC_READ(process_no) |
38 | | |
39 | | /* prototype of IPC handler - function called by the IPC engine |
40 | | * when the a job with the correspoding type was received */ |
41 | | typedef void (ipc_handler_f)(int sender, void *payload); |
42 | | |
43 | | /* prototype of a Remotely Executed Function (RPC) via IPC - function |
44 | | * to be passed via an IPC job in order to be executed in a different process*/ |
45 | | typedef void (ipc_rpc_f)(int sender, void *param); |
46 | | |
47 | | |
48 | | /* |
49 | | * Register a new IPC handler type, associated with "name" and "hdl". |
50 | | * Must be called in the pre-fork phase. |
51 | | * |
52 | | * Returned value: validate with BAD_HANDLER_TYPE() |
53 | | */ |
54 | | ipc_handler_type ipc_register_handler(ipc_handler_f *hdl, char *name); |
55 | | |
56 | | |
57 | | /* |
58 | | * Push a job for "dst_proc" and quickly return |
59 | | * |
60 | | * Return: 0 on success, -1 on failure |
61 | | */ |
62 | | int ipc_send_job(int dst_proc, ipc_handler_type type, void *payload); |
63 | | |
64 | | |
65 | | /* |
66 | | * Push the execution of a function, remotely, on the "dst_proc" process |
67 | | * and quickly return |
68 | | * |
69 | | * Return: 0 on success, -1 on failure |
70 | | */ |
71 | | int ipc_send_rpc(int dst_proc, ipc_rpc_f *rpc, void *param); |
72 | | |
73 | | /* |
74 | | * Push the execution of a function, remotely, on all the processes |
75 | | * that have IPC |
76 | | * |
77 | | * Return: number of processes the function was sent to |
78 | | */ |
79 | | int ipc_send_rpc_all(ipc_rpc_f *rpc, void *param); |
80 | | |
81 | | |
82 | | /* |
83 | | * Send a synchronous message to a specific "dst_proc" process |
84 | | * Use this command when you are sure that the "dst_proc" is waiting only for |
85 | | * this specific "response", and cannot overlap with a different task |
86 | | * |
87 | | * Return: 0 on success, -1 on failure |
88 | | */ |
89 | | int ipc_send_sync_reply(int dst_proc, void *param); |
90 | | |
91 | | |
92 | | /* |
93 | | * Wait for a message sent by a different process synchronously using the |
94 | | * ipc_send_sync_reply() function. |
95 | | * |
96 | | * Return: 0 on success, -1 on failure |
97 | | */ |
98 | | int ipc_recv_sync_reply(void **param); |
99 | | |
100 | | |
101 | | /* |
102 | | * Push a job for the next available OpenSIPS worker and quickly return |
103 | | * |
104 | | * Return: 0 on success, -1 on failure |
105 | | */ |
106 | | int ipc_dispatch_job(ipc_handler_type type, void *payload); |
107 | | |
108 | | |
109 | | /* |
110 | | * Push the execution of a function, remotely, to next available OpenSIPS |
111 | | * worker process and quickly return |
112 | | * |
113 | | * Return: 0 on success, -1 on failure |
114 | | */ |
115 | | int ipc_dispatch_rpc( ipc_rpc_f *rpc, void *param); |
116 | | |
117 | | |
118 | | /* |
119 | | * default handler for F_IPC reactor jobs. Copy-paste its code and improve |
120 | | * if this is not enough for you |
121 | | */ |
122 | | void ipc_handle_job(int fd); |
123 | | |
124 | | |
125 | | /* |
126 | | * reads and execute all the jobs available on the pipe, without blocking |
127 | | */ |
128 | | void ipc_handle_all_pending_jobs(int fd); |
129 | | |
130 | | |
131 | | /* |
132 | | * A way of checking whether a process is already running within a |
133 | | * ipc_dispatch_rpc() context, in order to avoid double async dispatching, |
134 | | * which is effectively a waste of resources. |
135 | | */ |
136 | | extern int ipc_running_rpc_job; |
137 | 0 | static inline int ipc_is_async_dispatch(void) { return ipc_running_rpc_job; }Unexecuted instantiation: dprint.c:ipc_is_async_dispatch Unexecuted instantiation: pt.c:ipc_is_async_dispatch Unexecuted instantiation: statistics.c:ipc_is_async_dispatch Unexecuted instantiation: ipc.c:ipc_is_async_dispatch Unexecuted instantiation: core_stats.c:ipc_is_async_dispatch Unexecuted instantiation: pt_load.c:ipc_is_async_dispatch Unexecuted instantiation: sr_module.c:ipc_is_async_dispatch Unexecuted instantiation: db_insertq.c:ipc_is_async_dispatch Unexecuted instantiation: proto_tcp.c:ipc_is_async_dispatch Unexecuted instantiation: proto_udp.c:ipc_is_async_dispatch Unexecuted instantiation: net_tcp_proc.c:ipc_is_async_dispatch Unexecuted instantiation: net_tcp.c:ipc_is_async_dispatch Unexecuted instantiation: tcp_common.c:ipc_is_async_dispatch Unexecuted instantiation: net_udp.c:ipc_is_async_dispatch Unexecuted instantiation: net_tcp_report.c:ipc_is_async_dispatch Unexecuted instantiation: event_interface.c:ipc_is_async_dispatch Unexecuted instantiation: async.c:ipc_is_async_dispatch Unexecuted instantiation: daemonize.c:ipc_is_async_dispatch Unexecuted instantiation: timer.c:ipc_is_async_dispatch Unexecuted instantiation: reactor.c:ipc_is_async_dispatch Unexecuted instantiation: io_wait.c:ipc_is_async_dispatch Unexecuted instantiation: sr_module_deps.c:ipc_is_async_dispatch Unexecuted instantiation: cfg_reload.c:ipc_is_async_dispatch Unexecuted instantiation: socket_info.c:ipc_is_async_dispatch Unexecuted instantiation: pt_scaling.c:ipc_is_async_dispatch Unexecuted instantiation: signals.c:ipc_is_async_dispatch Unexecuted instantiation: msg_translator.c:ipc_is_async_dispatch Unexecuted instantiation: cfg.tab.c:ipc_is_async_dispatch Unexecuted instantiation: shutdown.c:ipc_is_async_dispatch |
138 | | |
139 | | |
140 | | /* internal functions */ |
141 | | int init_ipc(void); |
142 | | |
143 | | |
144 | | int create_ipc_pipes(int proc_no); |
145 | | |
146 | | |
147 | | /* required by the IPC PIPE macros */ |
148 | | #include "pt.h" |
149 | | |
150 | | #endif |