forked from OpenSIPS/opensips
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ipc.h
133 lines (101 loc) · 3.67 KB
/
ipc.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/*
* Copyright (C) 2017 OpenSIPS Project
*
* This file is part of opensips, a free SIP server.
*
* opensips is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version
*
* opensips is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _CORE_IPC_H
#define _CORE_IPC_H
typedef short ipc_handler_type;
extern int ipc_shared_fd_read;
#define IPC_TYPE_NONE (-1)
#define ipc_bad_handler_type(htype) ((htype) < 0)
#define IPC_FD_READ(_proc_no) pt[_proc_no].ipc_pipe[0]
#define IPC_FD_WRITE(_proc_no) pt[_proc_no].ipc_pipe[1]
#define IPC_FD_READ_SELF IPC_FD_READ(process_no)
#define IPC_FD_READ_SHARED ipc_shared_fd_read
#define IPC_FD_SYNC_READ(_proc_no) pt[_proc_no].ipc_sync_pipe[0]
#define IPC_FD_SYNC_WRITE(_proc_no) pt[_proc_no].ipc_sync_pipe[1]
#define IPC_FD_SYNC_READ_SELF IPC_FD_SYNC_READ(process_no)
/* prototype of IPC handler - function called by the IPC engine
* when the a job with the correspoding type was received */
typedef void (ipc_handler_f)(int sender, void *payload);
/* prototype of a Remotely Executed Function (RPC) via IPC - function
* to be passed via an IPC job in order to be executed in a different process*/
typedef void (ipc_rpc_f)(int sender, void *param);
/*
* Register a new IPC handler type, associated with "name" and "hdl".
* Must be called in the pre-fork phase.
*
* Returned value: validate with BAD_HANDLER_TYPE()
*/
ipc_handler_type ipc_register_handler(ipc_handler_f *hdl, char *name);
/*
* Push a job for "dst_proc" and quickly return
*
* Return: 0 on success, -1 on failure
*/
int ipc_send_job(int dst_proc, ipc_handler_type type, void *payload);
/*
* Push the execution of a function, remotely, on the "dst_proc" process
* and quickly return
*
* Return: 0 on success, -1 on failure
*/
int ipc_send_rpc(int dst_proc, ipc_rpc_f *rpc, void *param);
/*
* Send a synchronous message to a specific "dst_proc" process
* Use this command when you are sure that the "dst_proc" is waiting only for
* this specific "response", and cannot overlap with a different task
*
* Return: 0 on success, -1 on failure
*/
int ipc_send_sync_reply(int dst_proc, void *param);
/*
* Wait for a message sent by a different process synchronously using the
* ipc_send_sync_reply() function.
*
* Return: 0 on success, -1 on failure
*/
int ipc_recv_sync_reply(void **param);
/*
* Push a job for the next available OpenSIPS worker and quickly return
*
* Return: 0 on success, -1 on failure
*/
int ipc_dispatch_job(ipc_handler_type type, void *payload);
/*
* Push the execution of a function, remotely, to next available OpenSIPS
* worker process and quickly return
*
* Return: 0 on success, -1 on failure
*/
int ipc_dispatch_rpc( ipc_rpc_f *rpc, void *param);
/*
* default handler for F_IPC reactor jobs. Copy-paste its code and improve
* if this is not enough for you
*/
void ipc_handle_job(int fd);
/*
* reads and execute all the jobs available on the pipe, without blocking
*/
void ipc_handle_all_pending_jobs(int fd);
/* internal functions */
int init_ipc(void);
int create_ipc_pipes(int proc_no);
/* required by the IPC PIPE macros */
#include "pt.h"
#endif