Asterisk - The Open Source Telephony Project GIT-master-7e7a603
Enumerations | Functions
alertpipe.h File Reference
#include "asterisk/utils.h"
Include dependency graph for alertpipe.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Enumerations

enum  ast_alert_status_t { AST_ALERT_READ_SUCCESS = 0 , AST_ALERT_NOT_READABLE , AST_ALERT_READ_FAIL , AST_ALERT_READ_FATAL }
 

Functions

void ast_alertpipe_clear (int alert_pipe[2])
 Sets the alert pipe file descriptors to default values. More...
 
void ast_alertpipe_close (int alert_pipe[2])
 Close an alert pipe. More...
 
ast_alert_status_t ast_alertpipe_flush (int alert_pipe[2])
 Consume all alerts written to the alert pipe. More...
 
int ast_alertpipe_init (int alert_pipe[2])
 Initialize an alert pipe. More...
 
ast_alert_status_t ast_alertpipe_read (int alert_pipe[2])
 Read an event from an alert pipe. More...
 
int ast_alertpipe_readable (int alert_pipe[2])
 Determine if the alert pipe is readable. More...
 
int ast_alertpipe_readfd (int alert_pipe[2])
 Get the alert pipe's read file descriptor. More...
 
void ast_alertpipe_swap (int alert_pipe_1[2], int alert_pipe_2[2])
 Swap the file descriptors from two alert pipes. More...
 
int ast_alertpipe_writable (int alert_pipe[2])
 Determine if the alert pipe is writable. More...
 
ssize_t ast_alertpipe_write (int alert_pipe[2])
 Write an event to an alert pipe. More...
 

Enumeration Type Documentation

◆ ast_alert_status_t

Enumerator
AST_ALERT_READ_SUCCESS 
AST_ALERT_NOT_READABLE 
AST_ALERT_READ_FAIL 
AST_ALERT_READ_FATAL 

Definition at line 24 of file alertpipe.h.

24 {
ast_alert_status_t
Definition: alertpipe.h:24
@ AST_ALERT_READ_FATAL
Definition: alertpipe.h:28
@ AST_ALERT_READ_FAIL
Definition: alertpipe.h:27
@ AST_ALERT_READ_SUCCESS
Definition: alertpipe.h:25
@ AST_ALERT_NOT_READABLE
Definition: alertpipe.h:26

Function Documentation

◆ ast_alertpipe_clear()

void ast_alertpipe_clear ( int  alert_pipe[2])
inline

Sets the alert pipe file descriptors to default values.

Since
13.16.0
Parameters
alert_pipea two-element array containing the alert pipe's file descriptors

Definition at line 98 of file alertpipe.h.

111{

References alert_pipe.

Referenced by ast_alertpipe_close(), ast_alertpipe_init(), and ast_channel_internal_alertpipe_clear().

◆ ast_alertpipe_close()

void ast_alertpipe_close ( int  alert_pipe[2])

Close an alert pipe.

Since
13.16.0
Parameters
alert_pipea two-element containing the alert pipe's file descriptors

Definition at line 79 of file alertpipe.c.

80{
81#ifdef HAVE_EVENTFD
82
83 if (alert_pipe[0] == alert_pipe[1]) {
84 if (alert_pipe[0] > -1) {
85 close(alert_pipe[0]);
87 }
88 return;
89 }
90
91#endif
92
93 if (alert_pipe[0] > -1) {
94 close(alert_pipe[0]);
95 }
96 if (alert_pipe[1] > -1) {
97 close(alert_pipe[1]);
98 }
100}
void ast_alertpipe_clear(int alert_pipe[2])
Sets the alert pipe file descriptors to default values.
Definition: alertpipe.h:98
int alert_pipe[2]
Definition: res_corosync.c:276

References alert_pipe, and ast_alertpipe_clear().

Referenced by ast_alertpipe_init(), ast_channel_internal_alertpipe_close(), bridge_channel_destroy(), dealloc_signal(), and really_quit().

◆ ast_alertpipe_flush()

ast_alert_status_t ast_alertpipe_flush ( int  alert_pipe[2])

Consume all alerts written to the alert pipe.

Since
13.16.0
Parameters
alert_pipea two-element array containing the alert pipe's file descriptors
Return values
AST_ALERT_READ_SUCCESSon success
AST_ALERT_NOT_READABLEif the alert pipe is not readable
AST_ALERT_READ_FATALif the alert pipe's file descriptors are in blocking mode, or a read error occurs.

Definition at line 134 of file alertpipe.c.

135{
136 int bytes_read;
137 uint64_t tmp[16];
138
141 }
142
143 /* Read the alertpipe until it is exhausted. */
144 for (;;) {
145 bytes_read = read(alert_pipe[0], tmp, sizeof(tmp));
146 if (bytes_read < 0) {
147 if (errno == EINTR) {
148 continue;
149 }
150 if (errno == EAGAIN || errno == EWOULDBLOCK) {
151 /*
152 * Would block so nothing left to read.
153 * This is the normal loop exit.
154 */
155 break;
156 }
157 ast_log(LOG_WARNING, "read() failed flushing alertpipe: %s\n",
158 strerror(errno));
159 return AST_ALERT_READ_FAIL;
160 }
161 if (!bytes_read) {
162 /* Read nothing so we are done */
163 break;
164 }
165 }
166
168}
int ast_alertpipe_readable(int alert_pipe[2])
Determine if the alert pipe is readable.
Definition: alertpipe.h:114
#define ast_log
Definition: astobj2.c:42
static int tmp()
Definition: bt_open.c:389
#define LOG_WARNING
int errno

References alert_pipe, AST_ALERT_NOT_READABLE, AST_ALERT_READ_FAIL, AST_ALERT_READ_SUCCESS, ast_alertpipe_readable(), ast_log, errno, LOG_WARNING, and tmp().

Referenced by ast_channel_internal_alert_flush().

◆ ast_alertpipe_init()

int ast_alertpipe_init ( int  alert_pipe[2])

Initialize an alert pipe.

Since
13.16.0
Parameters
alert_pipea two-element array to hold the alert pipe's file descriptors
Return values
non-zeroif a failure occurred.
zerootherwise.

Definition at line 38 of file alertpipe.c.

39{
40#ifdef HAVE_EVENTFD
41
42 int fd = eventfd(0, EFD_NONBLOCK | EFD_SEMAPHORE);
43 if (fd > -1) {
44 alert_pipe[0] = alert_pipe[1] = fd;
45 return 0;
46 }
47
48 ast_log(LOG_WARNING, "Failed to create alert pipe with eventfd(), falling back to pipe(): %s\n",
49 strerror(errno));
51
52#endif
53
54#ifdef HAVE_PIPE2
55
56 if (pipe2(alert_pipe, O_NONBLOCK)) {
57 ast_log(LOG_WARNING, "Failed to create alert pipe: %s\n", strerror(errno));
58 return -1;
59 }
60
61#else
62
63 if (pipe(alert_pipe)) {
64 ast_log(LOG_WARNING, "Failed to create alert pipe: %s\n", strerror(errno));
65 return -1;
66 } else {
67 if (ast_fd_set_flags(alert_pipe[0], O_NONBLOCK)
68 || ast_fd_set_flags(alert_pipe[1], O_NONBLOCK)) {
70 return -1;
71 }
72 }
73
74#endif
75
76 return 0;
77}
void ast_alertpipe_close(int alert_pipe[2])
Close an alert pipe.
Definition: alertpipe.c:79
#define ast_fd_set_flags(fd, flags)
Set flags on the given file descriptor.
Definition: utils.h:1039

References alert_pipe, ast_alertpipe_clear(), ast_alertpipe_close(), ast_fd_set_flags, ast_log, errno, and LOG_WARNING.

Referenced by alloc_signal(), ast_channel_internal_alertpipe_init(), asterisk_daemon(), and bridge_channel_internal_alloc().

◆ ast_alertpipe_read()

ast_alert_status_t ast_alertpipe_read ( int  alert_pipe[2])

Read an event from an alert pipe.

Since
13.16.0
Parameters
alert_pipea two-element array containing the alert pipe's file descriptors
Return values
AST_ALERT_READ_SUCCESSon success
AST_ALERT_NOT_READABLEif the alert pipe is not readable
AST_ALERT_READ_FATALif the alert pipe's file descriptors are in blocking mode, or a read error occurs.

Definition at line 102 of file alertpipe.c.

103{
104 uint64_t tmp;
105
108 }
109
110 if (read(alert_pipe[0], &tmp, sizeof(tmp)) < 0) {
111 if (errno != EINTR && errno != EAGAIN) {
112 ast_log(LOG_WARNING, "read() failed: %s\n", strerror(errno));
113 return AST_ALERT_READ_FAIL;
114 }
115 }
116
118}

References alert_pipe, AST_ALERT_NOT_READABLE, AST_ALERT_READ_FAIL, AST_ALERT_READ_SUCCESS, ast_alertpipe_readable(), ast_log, errno, LOG_WARNING, and tmp().

Referenced by ast_channel_internal_alert_read(), bridge_channel_handle_write(), monitor_sig_flags(), and wait_for_signal_or_hangup().

◆ ast_alertpipe_readable()

int ast_alertpipe_readable ( int  alert_pipe[2])
inline

Determine if the alert pipe is readable.

Since
13.16.0
Parameters
alert_pipea two-element array containing the alert pipe's file descriptors
Return values
non-zeroif the alert pipe is readable.
zerootherwise.

Definition at line 114 of file alertpipe.h.

127{

References alert_pipe.

Referenced by ast_alertpipe_flush(), ast_alertpipe_read(), and ast_channel_internal_alert_readable().

◆ ast_alertpipe_readfd()

int ast_alertpipe_readfd ( int  alert_pipe[2])
inline

Get the alert pipe's read file descriptor.

Since
13.16.0
Parameters
alert_pipea two-element array containing the alert pipe's file descriptors
Return values
-1if the file descriptor is not initialized.
non-negativeotherwise.

Definition at line 146 of file alertpipe.h.

157{

References SWAP.

Referenced by ast_channel_internal_alert_readfd().

◆ ast_alertpipe_swap()

void ast_alertpipe_swap ( int  alert_pipe_1[2],
int  alert_pipe_2[2] 
)
inline

Swap the file descriptors from two alert pipes.

Since
13.16.0
Parameters
alert_pipe_1a two-element array containing an alert pipe's file descriptors
alert_pipe_2a two-element array containing an alert pipe's file descriptors

Definition at line 161 of file alertpipe.h.

Referenced by ast_channel_internal_alertpipe_swap().

◆ ast_alertpipe_writable()

int ast_alertpipe_writable ( int  alert_pipe[2])
inline

Determine if the alert pipe is writable.

Since
13.16.0
Parameters
alert_pipea two-element array containing the alert pipe's file descriptors
Return values
non-zeroif the alert pipe is writable.
zerootherwise.

Definition at line 130 of file alertpipe.h.

143{

References alert_pipe.

Referenced by ast_alertpipe_write(), and ast_channel_alert_writable().

◆ ast_alertpipe_write()

ssize_t ast_alertpipe_write ( int  alert_pipe[2])

Write an event to an alert pipe.

Since
13.16.0
Parameters
alert_pipea two-element array containing the alert pipe's file descriptors
Return values
0Success
1Failure

Definition at line 120 of file alertpipe.c.

121{
122 uint64_t tmp = 1;
123
125 errno = EBADF;
126 return 0;
127 }
128
129 /* preset errno in case returned size does not match */
130 errno = EPIPE;
131 return write(alert_pipe[1], &tmp, sizeof(tmp)) != sizeof(tmp);
132}
int ast_alertpipe_writable(int alert_pipe[2])
Determine if the alert pipe is writable.
Definition: alertpipe.h:130

References alert_pipe, ast_alertpipe_writable(), errno, and tmp().

Referenced by __quit_handler(), _hup_handler(), ast_bridge_channel_queue_frame(), ast_channel_alert_write(), send_signal(), and wait_for_signal_or_hangup().