Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

apr_file_pipe_create() - save more syscalls with pipe2() #56

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 12 additions & 16 deletions file_io/unix/pipe.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,10 @@ static apr_status_t file_pipe_create(apr_file_t **in,
apr_interval_time_t fd_timeout;

#ifdef HAVE_PIPE2
if (blocking == APR_FULL_NONBLOCK) {
/* If pipe2() is available, use O_NONBLOCK by default unless
* APR_FULL_BLOCK is requested, then set the individual pipe state
* as desired later - changing the state uses two syscalls. */
if (blocking != APR_FULL_BLOCK) {
if (pipe2(filedes, O_NONBLOCK) == -1) {
return errno;
}
Expand Down Expand Up @@ -239,21 +242,14 @@ static apr_status_t file_pipe_create(apr_file_t **in,
apr_pool_cleanup_register((*out)->pool, (void *)(*out), apr_unix_file_cleanup,
apr_pool_cleanup_null);

switch (blocking) {
case APR_FULL_BLOCK:
break;
case APR_READ_BLOCK:
apr_file_pipe_timeout_set(*out, 0);
break;
case APR_WRITE_BLOCK:
apr_file_pipe_timeout_set(*in, 0);
break;
default:
/* These are noops for the pipe2() case */
apr_file_pipe_timeout_set(*out, 0);
apr_file_pipe_timeout_set(*in, 0);
break;
}
/* Set each pipe to the desired O_NONBLOCK state, which may be a
* noop depending on whether the pipe2() or pipe() case was
* used. (timeout of -1 == blocking) */
apr_file_pipe_timeout_set(*in, (blocking == APR_FULL_BLOCK
|| blocking == APR_READ_BLOCK) ? -1 : 0);
apr_file_pipe_timeout_set(*out, (blocking == APR_FULL_BLOCK
|| blocking == APR_WRITE_BLOCK) ? -1 : 0);

return APR_SUCCESS;
}

Expand Down
Loading