mirror of
https://github.com/curl/curl.git
synced 2024-12-21 06:50:10 +08:00
a58b50fca6
- Renames Curl_readwrite() to Curl_sendrecv() to reflect that it is mainly about talking to the server, not reads or writes to the client. Add a `nowp` parameter since the single caller already has this. - Curl_sendrecv() now runs all possible operations whenever it is called and either it had been polling sockets or the 'select_bits' are set. POLL_IN/POLL_OUT are not always directly related to send/recv operations. Filters like HTTP/2, QUIC or TLS may monitor reverse directions. If a transfer does not want to send (KEEP_SEND), it will not do so, as before. Same for receives. - Curl_update_timer() now checks the absolute timestamp of an expiry and the last/new timeout to determine if the application needs to stop/start/restart its timer. This fixes edge cases where updates did not happen as they should have. - improved --test-event curl_easy_perform() simulation to handle situations where no sockets are registered but a timeout is in place. - fixed bug in events_socket() that complained about removing a socket that was unknown, when indeed it had removed the socket just before, only it was the last in the list - fixed conncache's internal handle to carry the multi instance (where the cache has one) so that operations on the closure handle trigger event callbacks correctly. - fixed conncache to not POLL_REMOVE a socket twice when a conneciton was closed. Closes #14561
100 lines
3.1 KiB
C
100 lines
3.1 KiB
C
#ifndef HEADER_CURL_SIGPIPE_H
|
|
#define HEADER_CURL_SIGPIPE_H
|
|
/***************************************************************************
|
|
* _ _ ____ _
|
|
* Project ___| | | | _ \| |
|
|
* / __| | | | |_) | |
|
|
* | (__| |_| | _ <| |___
|
|
* \___|\___/|_| \_\_____|
|
|
*
|
|
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
|
|
*
|
|
* This software is licensed as described in the file COPYING, which
|
|
* you should have received as part of this distribution. The terms
|
|
* are also available at https://curl.se/docs/copyright.html.
|
|
*
|
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
|
* copies of the Software, and permit persons to whom the Software is
|
|
* furnished to do so, under the terms of the COPYING file.
|
|
*
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
* KIND, either express or implied.
|
|
*
|
|
* SPDX-License-Identifier: curl
|
|
*
|
|
***************************************************************************/
|
|
#include "curl_setup.h"
|
|
|
|
#if defined(HAVE_SIGACTION) && \
|
|
(defined(USE_OPENSSL) || defined(USE_MBEDTLS) || defined(USE_WOLFSSL))
|
|
#include <signal.h>
|
|
|
|
struct sigpipe_ignore {
|
|
struct sigaction old_pipe_act;
|
|
bool no_signal;
|
|
};
|
|
|
|
#define SIGPIPE_VARIABLE(x) struct sigpipe_ignore x
|
|
#define SIGPIPE_MEMBER(x) struct sigpipe_ignore x
|
|
|
|
static void sigpipe_init(struct sigpipe_ignore *ig)
|
|
{
|
|
memset(ig, 0, sizeof(*ig));
|
|
ig->no_signal = TRUE;
|
|
}
|
|
|
|
/*
|
|
* sigpipe_ignore() makes sure we ignore SIGPIPE while running libcurl
|
|
* internals, and then sigpipe_restore() will restore the situation when we
|
|
* return from libcurl again.
|
|
*/
|
|
static void sigpipe_ignore(struct Curl_easy *data,
|
|
struct sigpipe_ignore *ig)
|
|
{
|
|
/* get a local copy of no_signal because the Curl_easy might not be
|
|
around when we restore */
|
|
ig->no_signal = data->set.no_signal;
|
|
if(!data->set.no_signal) {
|
|
struct sigaction action;
|
|
/* first, extract the existing situation */
|
|
sigaction(SIGPIPE, NULL, &ig->old_pipe_act);
|
|
action = ig->old_pipe_act;
|
|
/* ignore this signal */
|
|
action.sa_handler = SIG_IGN;
|
|
sigaction(SIGPIPE, &action, NULL);
|
|
}
|
|
}
|
|
|
|
/*
|
|
* sigpipe_restore() puts back the outside world's opinion of signal handler
|
|
* and SIGPIPE handling. It MUST only be called after a corresponding
|
|
* sigpipe_ignore() was used.
|
|
*/
|
|
static void sigpipe_restore(struct sigpipe_ignore *ig)
|
|
{
|
|
if(!ig->no_signal)
|
|
/* restore the outside state */
|
|
sigaction(SIGPIPE, &ig->old_pipe_act, NULL);
|
|
}
|
|
|
|
static void sigpipe_apply(struct Curl_easy *data,
|
|
struct sigpipe_ignore *ig)
|
|
{
|
|
if(data->set.no_signal != ig->no_signal) {
|
|
sigpipe_restore(ig);
|
|
sigpipe_ignore(data, ig);
|
|
}
|
|
}
|
|
|
|
#else
|
|
/* for systems without sigaction */
|
|
#define sigpipe_ignore(x,y) Curl_nop_stmt
|
|
#define sigpipe_apply(x,y) Curl_nop_stmt
|
|
#define sigpipe_init(x) Curl_nop_stmt
|
|
#define sigpipe_restore(x) Curl_nop_stmt
|
|
#define SIGPIPE_VARIABLE(x)
|
|
#define SIGPIPE_MEMBER(x) bool x
|
|
#endif
|
|
|
|
#endif /* HEADER_CURL_SIGPIPE_H */
|