mirror of
https://github.com/asterisk/asterisk.git
synced 2025-11-16 23:08:32 +00:00
utils: Wrap socket() and pipe() to reduce syscalls
Some platforms provide an implementation of socket() and pipe2() that allow the caller to specify that the resulting file descriptors should be non-blocking. Using these allows us to potentially elide 3 calls into 1 by avoiding extraneous calls to fcntl() to set the O_NONBLOCK flag afterwards. In passing, change ast_alertpipe_init() to use pipe2() directly instead of the wrapper if it is available. Change-Id: I3ebe654fb549587537161506c6c950f4ab298bb0
This commit is contained in:
@@ -51,6 +51,15 @@ int ast_alertpipe_init(int alert_pipe[2])
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_PIPE2
|
||||
|
||||
if (pipe2(alert_pipe, O_NONBLOCK)) {
|
||||
ast_log(LOG_WARNING, "Failed to create alert pipe: %s\n", strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
if (pipe(alert_pipe)) {
|
||||
ast_log(LOG_WARNING, "Failed to create alert pipe: %s\n", strerror(errno));
|
||||
return -1;
|
||||
@@ -62,6 +71,8 @@ int ast_alertpipe_init(int alert_pipe[2])
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user