* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2013, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2014, 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
#include <sys/param.h>
#endif
-#if defined(HAVE_SIGNAL_H) && defined(HAVE_SIGACTION) && defined(USE_OPENSSL)
-#define SIGPIPE_IGNORE 1
-#include <signal.h>
-#endif
-
#include "strequal.h"
#include "urldata.h"
#include <curl/curl.h>
#include "transfer.h"
-#include "sslgen.h"
+#include "vtls/vtls.h"
#include "url.h"
#include "getinfo.h"
#include "hostip.h"
#include "warnless.h"
#include "conncache.h"
#include "multiif.h"
+#include "sigpipe.h"
#define _MPRINTF_REPLACE /* use our functions only */
#include <curl/mprintf.h>
/* The last #include file should be: */
#include "memdebug.h"
-#ifdef SIGPIPE_IGNORE
-struct sigpipe_ignore {
- struct sigaction old_pipe_act;
- bool no_signal;
-};
-
-#define SIGPIPE_VARIABLE(x) struct sigpipe_ignore x
-
-/*
- * 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 SessionHandle *data,
- struct sigpipe_ignore *ig)
-{
- /* get a local copy of no_signal because the SessionHandle 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 */
- memset(&ig->old_pipe_act, 0, sizeof(struct sigaction));
- 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);
-}
-
-#else
-/* for systems without sigaction */
-#define sigpipe_ignore(x,y) Curl_nop_stmt
-#define sigpipe_restore(x) Curl_nop_stmt
-#define SIGPIPE_VARIABLE(x)
-#endif
-
/* win32_cleanup() is for win32 socket cleanup functionality, the opposite
of win32_init() */
static void win32_cleanup(void)
if(!m || !f || !r || !s || !c)
return CURLE_FAILED_INIT;
- /* Already initialized, don't do it again */
- if(initialized)
+ if(initialized) {
+ /* Already initialized, don't do it again, but bump the variable anyway to
+ work like curl_global_init() and require the same amount of cleanup
+ calls. */
+ initialized++;
return CURLE_OK;
+ }
/* Call the actual init function first */
code = curl_global_init(flags);
#ifdef CURLDEBUG
-struct monitor {
- struct monitor *next; /* the next node in the list or NULL */
+struct socketmonitor {
+ struct socketmonitor *next; /* the next node in the list or NULL */
struct pollfd socket; /* socket info of what to monitor */
};
long ms; /* timeout, run the timeout function when reached */
bool msbump; /* set TRUE when timeout is set by callback */
int num_sockets; /* number of nodes in the monitor list */
- struct monitor *list; /* list of sockets to monitor */
+ struct socketmonitor *list; /* list of sockets to monitor */
int running_handles; /* store the returned number */
};
pointer */
{
struct events *ev = userp;
- struct monitor *m;
- struct monitor *prev=NULL;
+ struct socketmonitor *m;
+ struct socketmonitor *prev=NULL;
(void)socketp;
m = ev->list;
if(m->socket.fd == s) {
if(what == CURL_POLL_REMOVE) {
- struct monitor *nxt = m->next;
+ struct socketmonitor *nxt = m->next;
/* remove this node from the list of monitored sockets */
if(prev)
prev->next = nxt;
__func__, s); */
}
else {
- m = malloc(sizeof(struct monitor));
+ m = malloc(sizeof(struct socketmonitor));
m->next = ev->list;
m->socket.fd = s;
m->socket.events = socketcb2poll(what);
while(!done) {
CURLMsg *msg;
- struct monitor *m;
+ struct socketmonitor *m;
struct pollfd *f;
struct pollfd fds[4];
int numfds=0;
{
bool done = FALSE;
CURLMcode mcode = CURLM_OK;
- CURLcode code;
+ CURLcode code = CURLE_OK;
struct timeval before;
int without_fds = 0; /* count number of consecutive returns from
curl_multi_wait() without any filedescriptors */
while(!done && !mcode) {
- int still_running;
+ int still_running = 0;
int ret;
before = curlx_tvnow();
}
}
}
+
+ /* Make sure to return some kind of error if there was a multi problem */
+ if(mcode) {
+ return (mcode == CURLM_OUT_OF_MEMORY) ? CURLE_OUT_OF_MEMORY :
+ /* The other multi errors should never happen, so return
+ something suitably generic */
+ CURLE_BAD_FUNCTION_ARGUMENT;
+ }
+
return code;
}
return CURLE_BAD_FUNCTION_ARGUMENT;
if(data->multi) {
- failf(data, "easy handled already used in multi handle");
+ failf(data, "easy handle already used in multi handle");
return CURLE_FAILED_INIT;
}