source: azure_iot_hub/trunk/curl-7.57.0/lib/sigpipe.h@ 389

Last change on this file since 389 was 389, checked in by coas-nagasima, 5 years ago

ビルドが通るよう更新

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-chdr;charset=UTF-8
File size: 2.6 KB
Line 
1#ifndef HEADER_CURL_SIGPIPE_H
2#define HEADER_CURL_SIGPIPE_H
3/***************************************************************************
4 * _ _ ____ _
5 * Project ___| | | | _ \| |
6 * / __| | | | |_) | |
7 * | (__| |_| | _ <| |___
8 * \___|\___/|_| \_\_____|
9 *
10 * Copyright (C) 1998 - 2013, Daniel Stenberg, <daniel@haxx.se>, et al.
11 *
12 * This software is licensed as described in the file COPYING, which
13 * you should have received as part of this distribution. The terms
14 * are also available at https://curl.haxx.se/docs/copyright.html.
15 *
16 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
17 * copies of the Software, and permit persons to whom the Software is
18 * furnished to do so, under the terms of the COPYING file.
19 *
20 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21 * KIND, either express or implied.
22 *
23 ***************************************************************************/
24#include "curl_setup.h"
25
26#if defined(HAVE_SIGNAL_H) && defined(HAVE_SIGACTION) && defined(USE_OPENSSL)
27#include <signal.h>
28
29struct sigpipe_ignore {
30 struct sigaction old_pipe_act;
31 bool no_signal;
32};
33
34#define SIGPIPE_VARIABLE(x) struct sigpipe_ignore x
35
36/*
37 * sigpipe_ignore() makes sure we ignore SIGPIPE while running libcurl
38 * internals, and then sigpipe_restore() will restore the situation when we
39 * return from libcurl again.
40 */
41static void sigpipe_ignore(struct Curl_easy *data,
42 struct sigpipe_ignore *ig)
43{
44 /* get a local copy of no_signal because the Curl_easy might not be
45 around when we restore */
46 ig->no_signal = data->set.no_signal;
47 if(!data->set.no_signal) {
48 struct sigaction action;
49 /* first, extract the existing situation */
50 memset(&ig->old_pipe_act, 0, sizeof(struct sigaction));
51 sigaction(SIGPIPE, NULL, &ig->old_pipe_act);
52 action = ig->old_pipe_act;
53 /* ignore this signal */
54 action.sa_handler = SIG_IGN;
55 sigaction(SIGPIPE, &action, NULL);
56 }
57}
58
59/*
60 * sigpipe_restore() puts back the outside world's opinion of signal handler
61 * and SIGPIPE handling. It MUST only be called after a corresponding
62 * sigpipe_ignore() was used.
63 */
64static void sigpipe_restore(struct sigpipe_ignore *ig)
65{
66 if(!ig->no_signal)
67 /* restore the outside state */
68 sigaction(SIGPIPE, &ig->old_pipe_act, NULL);
69}
70
71#else
72/* for systems without sigaction */
73#define sigpipe_ignore(x,y) Curl_nop_stmt
74#define sigpipe_restore(x) Curl_nop_stmt
75#define SIGPIPE_VARIABLE(x)
76#endif
77
78#endif /* HEADER_CURL_SIGPIPE_H */
Note: See TracBrowser for help on using the repository browser.