1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
10 * This software is licensed as described in the file COPYING, which
11 * you should have received as part of this distribution. The terms
12 * are also available at https://curl.haxx.se/docs/copyright.html.
14 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 * copies of the Software, and permit persons to whom the Software is
16 * furnished to do so, under the terms of the COPYING file.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
21 ***************************************************************************/
23 #include "curl_setup.h"
26 * See comment in curl_memory.h for the explanation of this sanity check.
29 #ifdef CURLX_NO_MEMORY_CALLBACKS
30 #error "libcurl shall not ever be built with CURLX_NO_MEMORY_CALLBACKS defined"
33 #ifdef HAVE_NETINET_IN_H
34 #include <netinet/in.h>
39 #ifdef HAVE_ARPA_INET_H
40 #include <arpa/inet.h>
45 #ifdef HAVE_SYS_IOCTL_H
46 #include <sys/ioctl.h>
49 #ifdef HAVE_SYS_PARAM_H
50 #include <sys/param.h>
54 #include <curl/curl.h>
56 #include "vtls/vtls.h"
65 #include "sendf.h" /* for failf function prototype */
66 #include "connect.h" /* for Curl_getconnectinfo */
69 #include "non-ascii.h"
71 #include "conncache.h"
75 /* The last 3 #include files should be in this order */
76 #include "curl_printf.h"
77 #include "curl_memory.h"
80 void Curl_version_init(void);
82 /* win32_cleanup() is for win32 socket cleanup functionality, the opposite
84 static void win32_cleanup(void)
89 #ifdef USE_WINDOWS_SSPI
90 Curl_sspi_global_cleanup();
94 /* win32_init() performs win32 socket initialization to properly setup the
95 stack to allow networking */
96 static CURLcode win32_init(void)
99 WORD wVersionRequested;
103 #if defined(ENABLE_IPV6) && (USE_WINSOCK < 2)
104 Error IPV6_requires_winsock2
107 wVersionRequested = MAKEWORD(USE_WINSOCK, USE_WINSOCK);
109 res = WSAStartup(wVersionRequested, &wsaData);
112 /* Tell the user that we couldn't find a useable */
114 return CURLE_FAILED_INIT;
116 /* Confirm that the Windows Sockets DLL supports what we need.*/
117 /* Note that if the DLL supports versions greater */
118 /* than wVersionRequested, it will still return */
119 /* wVersionRequested in wVersion. wHighVersion contains the */
120 /* highest supported version. */
122 if(LOBYTE(wsaData.wVersion) != LOBYTE(wVersionRequested) ||
123 HIBYTE(wsaData.wVersion) != HIBYTE(wVersionRequested) ) {
124 /* Tell the user that we couldn't find a useable */
128 return CURLE_FAILED_INIT;
130 /* The Windows Sockets DLL is acceptable. Proceed. */
131 #elif defined(USE_LWIPSOCK)
135 #ifdef USE_WINDOWS_SSPI
137 CURLcode result = Curl_sspi_global_init();
146 /* true globals -- for curl_global_init() and curl_global_cleanup() */
147 static unsigned int initialized;
148 static long init_flags;
151 * strdup (and other memory functions) is redefined in complicated
152 * ways, but at this point it must be defined as the system-supplied strdup
153 * so the callback pointer is initialized correctly.
155 #if defined(_WIN32_WCE)
156 #define system_strdup _strdup
157 #elif !defined(HAVE_STRDUP)
158 #define system_strdup curlx_strdup
160 #define system_strdup strdup
163 #if defined(_MSC_VER) && defined(_DLL) && !defined(__POCC__)
164 # pragma warning(disable:4232) /* MSVC extension, dllimport identity */
167 #ifndef __SYMBIAN32__
169 * If a memory-using function (like curl_getenv) is used before
170 * curl_global_init() is called, we need to have these pointers set already.
172 curl_malloc_callback Curl_cmalloc = (curl_malloc_callback)malloc;
173 curl_free_callback Curl_cfree = (curl_free_callback)free;
174 curl_realloc_callback Curl_crealloc = (curl_realloc_callback)realloc;
175 curl_strdup_callback Curl_cstrdup = (curl_strdup_callback)system_strdup;
176 curl_calloc_callback Curl_ccalloc = (curl_calloc_callback)calloc;
177 #if defined(WIN32) && defined(UNICODE)
178 curl_wcsdup_callback Curl_cwcsdup = (curl_wcsdup_callback)_wcsdup;
182 * Symbian OS doesn't support initialization to code in writeable static data.
183 * Initialization will occur in the curl_global_init() call.
185 curl_malloc_callback Curl_cmalloc;
186 curl_free_callback Curl_cfree;
187 curl_realloc_callback Curl_crealloc;
188 curl_strdup_callback Curl_cstrdup;
189 curl_calloc_callback Curl_ccalloc;
192 #if defined(_MSC_VER) && defined(_DLL) && !defined(__POCC__)
193 # pragma warning(default:4232) /* MSVC extension, dllimport identity */
197 * curl_global_init() globally initializes curl given a bitwise set of the
198 * different features of what to initialize.
200 static CURLcode global_init(long flags, bool memoryfuncs)
206 /* Setup the default memory functions here (again) */
207 Curl_cmalloc = (curl_malloc_callback)malloc;
208 Curl_cfree = (curl_free_callback)free;
209 Curl_crealloc = (curl_realloc_callback)realloc;
210 Curl_cstrdup = (curl_strdup_callback)system_strdup;
211 Curl_ccalloc = (curl_calloc_callback)calloc;
212 #if defined(WIN32) && defined(UNICODE)
213 Curl_cwcsdup = (curl_wcsdup_callback)_wcsdup;
217 if(flags & CURL_GLOBAL_SSL)
218 if(!Curl_ssl_init()) {
219 DEBUGF(fprintf(stderr, "Error: Curl_ssl_init failed\n"));
220 return CURLE_FAILED_INIT;
223 if(flags & CURL_GLOBAL_WIN32)
225 DEBUGF(fprintf(stderr, "Error: win32_init failed\n"));
226 return CURLE_FAILED_INIT;
230 if(!Curl_amiga_init()) {
231 DEBUGF(fprintf(stderr, "Error: Curl_amiga_init failed\n"));
232 return CURLE_FAILED_INIT;
238 DEBUGF(fprintf(stderr, "Warning: LONG namespace not available\n"));
242 if(Curl_resolver_global_init()) {
243 DEBUGF(fprintf(stderr, "Error: resolver_global_init failed\n"));
244 return CURLE_FAILED_INIT;
247 (void)Curl_ipv6works();
249 #if defined(USE_LIBSSH2) && defined(HAVE_LIBSSH2_INIT)
250 if(libssh2_init(0)) {
251 DEBUGF(fprintf(stderr, "Error: libssh2_init failed\n"));
252 return CURLE_FAILED_INIT;
256 if(flags & CURL_GLOBAL_ACK_EINTR)
268 * curl_global_init() globally initializes curl given a bitwise set of the
269 * different features of what to initialize.
271 CURLcode curl_global_init(long flags)
273 return global_init(flags, TRUE);
277 * curl_global_init_mem() globally initializes curl and also registers the
278 * user provided callback routines.
280 CURLcode curl_global_init_mem(long flags, curl_malloc_callback m,
281 curl_free_callback f, curl_realloc_callback r,
282 curl_strdup_callback s, curl_calloc_callback c)
284 /* Invalid input, return immediately */
285 if(!m || !f || !r || !s || !c)
286 return CURLE_FAILED_INIT;
289 /* Already initialized, don't do it again, but bump the variable anyway to
290 work like curl_global_init() and require the same amount of cleanup
296 /* set memory functions before global_init() in case it wants memory
304 /* Call the actual init function, but without setting */
305 return global_init(flags, FALSE);
309 * curl_global_cleanup() globally cleanups curl, uses the value of
310 * "init_flags" to determine what needs to be cleaned up and what doesn't.
312 void curl_global_cleanup(void)
320 Curl_global_host_cache_dtor();
322 if(init_flags & CURL_GLOBAL_SSL)
325 Curl_resolver_global_cleanup();
327 if(init_flags & CURL_GLOBAL_WIN32)
330 Curl_amiga_cleanup();
332 #if defined(USE_LIBSSH2) && defined(HAVE_LIBSSH2_EXIT)
333 (void)libssh2_exit();
340 * curl_easy_init() is the external interface to alloc, setup and init an
341 * easy handle that is returned. If anything goes wrong, NULL is returned.
343 struct Curl_easy *curl_easy_init(void)
346 struct Curl_easy *data;
348 /* Make sure we inited the global SSL stuff */
350 result = curl_global_init(CURL_GLOBAL_DEFAULT);
352 /* something in the global init failed, return nothing */
353 DEBUGF(fprintf(stderr, "Error: curl_global_init failed\n"));
358 /* We use curl_open() with undefined URL so far */
359 result = Curl_open(&data);
361 DEBUGF(fprintf(stderr, "Error: Curl_open failed\n"));
369 * curl_easy_setopt() is the external interface for setting options on an
373 #undef curl_easy_setopt
374 CURLcode curl_easy_setopt(struct Curl_easy *data, CURLoption tag, ...)
380 return CURLE_BAD_FUNCTION_ARGUMENT;
384 result = Curl_setopt(data, tag, arg);
392 struct socketmonitor {
393 struct socketmonitor *next; /* the next node in the list or NULL */
394 struct pollfd socket; /* socket info of what to monitor */
398 long ms; /* timeout, run the timeout function when reached */
399 bool msbump; /* set TRUE when timeout is set by callback */
400 int num_sockets; /* number of nodes in the monitor list */
401 struct socketmonitor *list; /* list of sockets to monitor */
402 int running_handles; /* store the returned number */
407 * Callback that gets called with a new value when the timeout should be
411 static int events_timer(struct Curl_multi *multi, /* multi handle */
412 long timeout_ms, /* see above */
413 void *userp) /* private callback pointer */
415 struct events *ev = userp;
418 /* timeout removed */
420 else if(timeout_ms == 0)
421 /* timeout is already reached! */
422 timeout_ms = 1; /* trigger asap */
432 * convert from poll() bit definitions to libcurl's CURL_CSELECT_* ones
434 static int poll2cselect(int pollmask)
437 if(pollmask & POLLIN)
438 omask |= CURL_CSELECT_IN;
439 if(pollmask & POLLOUT)
440 omask |= CURL_CSELECT_OUT;
441 if(pollmask & POLLERR)
442 omask |= CURL_CSELECT_ERR;
449 * convert from libcurl' CURL_POLL_* bit definitions to poll()'s
451 static short socketcb2poll(int pollmask)
454 if(pollmask & CURL_POLL_IN)
456 if(pollmask & CURL_POLL_OUT)
463 * Callback that gets called with information about socket activity to
466 static int events_socket(struct Curl_easy *easy, /* easy handle */
467 curl_socket_t s, /* socket */
468 int what, /* see above */
469 void *userp, /* private callback
471 void *socketp) /* private socket
474 struct events *ev = userp;
475 struct socketmonitor *m;
476 struct socketmonitor *prev=NULL;
478 #if defined(CURL_DISABLE_VERBOSE_STRINGS)
485 if(m->socket.fd == s) {
487 if(what == CURL_POLL_REMOVE) {
488 struct socketmonitor *nxt = m->next;
489 /* remove this node from the list of monitored sockets */
496 infof(easy, "socket cb: socket %d REMOVED\n", s);
499 /* The socket 's' is already being monitored, update the activity
500 mask. Convert from libcurl bitmask to the poll one. */
501 m->socket.events = socketcb2poll(what);
502 infof(easy, "socket cb: socket %d UPDATED as %s%s\n", s,
503 what&CURL_POLL_IN?"IN":"",
504 what&CURL_POLL_OUT?"OUT":"");
509 m = m->next; /* move to next node */
512 if(what == CURL_POLL_REMOVE) {
513 /* this happens a bit too often, libcurl fix perhaps? */
515 "%s: socket %d asked to be REMOVED but not present!\n",
519 m = malloc(sizeof(struct socketmonitor));
523 m->socket.events = socketcb2poll(what);
524 m->socket.revents = 0;
526 infof(easy, "socket cb: socket %d ADDED as %s%s\n", s,
527 what&CURL_POLL_IN?"IN":"",
528 what&CURL_POLL_OUT?"OUT":"");
531 return CURLE_OUT_OF_MEMORY;
542 * Do the multi handle setups that only event-based transfers need.
544 static void events_setup(struct Curl_multi *multi, struct events *ev)
547 curl_multi_setopt(multi, CURLMOPT_TIMERFUNCTION, events_timer);
548 curl_multi_setopt(multi, CURLMOPT_TIMERDATA, ev);
550 /* socket callback */
551 curl_multi_setopt(multi, CURLMOPT_SOCKETFUNCTION, events_socket);
552 curl_multi_setopt(multi, CURLMOPT_SOCKETDATA, ev);
558 * waits for activity on any of the given sockets, or the timeout to trigger.
561 static CURLcode wait_or_timeout(struct Curl_multi *multi, struct events *ev)
565 CURLcode result = CURLE_OK;
569 struct socketmonitor *m;
571 struct pollfd fds[4];
575 struct timeval before;
576 struct timeval after;
578 /* populate the fds[] array */
579 for(m = ev->list, f=&fds[0]; m; m = m->next) {
580 f->fd = m->socket.fd;
581 f->events = m->socket.events;
583 /* fprintf(stderr, "poll() %d check socket %d\n", numfds, f->fd); */
588 /* get the time stamp to use to figure out how long poll takes */
589 before = curlx_tvnow();
591 /* wait for activity or timeout */
592 pollrc = Curl_poll(fds, numfds, (int)ev->ms);
594 after = curlx_tvnow();
596 ev->msbump = FALSE; /* reset here */
601 /* fprintf(stderr, "call curl_multi_socket_action(TIMEOUT)\n"); */
602 mcode = curl_multi_socket_action(multi, CURL_SOCKET_TIMEOUT, 0,
603 &ev->running_handles);
605 else if(pollrc > 0) {
606 /* loop over the monitored sockets to see which ones had activity */
607 for(i = 0; i< numfds; i++) {
609 /* socket activity, tell libcurl */
610 int act = poll2cselect(fds[i].revents); /* convert */
611 infof(multi->easyp, "call curl_multi_socket_action(socket %d)\n",
613 mcode = curl_multi_socket_action(multi, fds[i].fd, act,
614 &ev->running_handles);
619 /* If nothing updated the timeout, we decrease it by the spent time.
620 * If it was updated, it has the new timeout time stored already.
622 ev->ms += curlx_tvdiff(after, before);
626 return CURLE_RECV_ERROR;
629 return CURLE_URL_MALFORMAT; /* TODO: return a proper error! */
631 /* we don't really care about the "msgs_in_queue" value returned in the
633 msg = curl_multi_info_read(multi, &pollrc);
635 result = msg->data.result;
646 * Runs a transfer in a blocking manner using the events-based API
648 static CURLcode easy_events(struct Curl_multi *multi)
650 struct events evs= {2, FALSE, 0, NULL, 0};
652 /* if running event-based, do some further multi inits */
653 events_setup(multi, &evs);
655 return wait_or_timeout(multi, &evs);
657 #else /* CURLDEBUG */
658 /* when not built with debug, this function doesn't exist */
659 #define easy_events(x) CURLE_NOT_BUILT_IN
662 static CURLcode easy_transfer(struct Curl_multi *multi)
665 CURLMcode mcode = CURLM_OK;
666 CURLcode result = CURLE_OK;
667 struct timeval before;
668 int without_fds = 0; /* count number of consecutive returns from
669 curl_multi_wait() without any filedescriptors */
671 while(!done && !mcode) {
672 int still_running = 0;
675 before = curlx_tvnow();
676 mcode = curl_multi_wait(multi, NULL, 0, 1000, &rc);
680 struct timeval after = curlx_tvnow();
682 /* If it returns without any filedescriptor instantly, we need to
683 avoid busy-looping during periods where it has nothing particular
685 if(curlx_tvdiff(after, before) <= 10) {
687 if(without_fds > 2) {
688 int sleep_ms = without_fds < 10 ? (1 << (without_fds - 1)) : 1000;
689 Curl_wait_ms(sleep_ms);
693 /* it wasn't "instant", restart counter */
697 /* got file descriptor, restart counter */
700 mcode = curl_multi_perform(multi, &still_running);
703 /* only read 'still_running' if curl_multi_perform() return OK */
704 if(!mcode && !still_running) {
705 CURLMsg *msg = curl_multi_info_read(multi, &rc);
707 result = msg->data.result;
713 /* Make sure to return some kind of error if there was a multi problem */
715 result = (mcode == CURLM_OUT_OF_MEMORY) ? CURLE_OUT_OF_MEMORY :
716 /* The other multi errors should never happen, so return
717 something suitably generic */
718 CURLE_BAD_FUNCTION_ARGUMENT;
726 * easy_perform() is the external interface that performs a blocking
727 * transfer as previously setup.
729 * CONCEPT: This function creates a multi handle, adds the easy handle to it,
730 * runs curl_multi_perform() until the transfer is done, then detaches the
731 * easy handle, destroys the multi handle and returns the easy handle's return
734 * REALITY: it can't just create and destroy the multi handle that easily. It
735 * needs to keep it around since if this easy handle is used again by this
736 * function, the same multi handle must be re-used so that the same pools and
737 * caches can be used.
739 * DEBUG: if 'events' is set TRUE, this function will use a replacement engine
740 * instead of curl_multi_perform() and use curl_multi_socket_action().
742 static CURLcode easy_perform(struct Curl_easy *data, bool events)
744 struct Curl_multi *multi;
746 CURLcode result = CURLE_OK;
747 SIGPIPE_VARIABLE(pipe_st);
750 return CURLE_BAD_FUNCTION_ARGUMENT;
753 failf(data, "easy handle already used in multi handle");
754 return CURLE_FAILED_INIT;
758 multi = data->multi_easy;
760 /* this multi handle will only ever have a single easy handled attached
761 to it, so make it use minimal hashes */
762 multi = Curl_multi_handle(1, 3);
764 return CURLE_OUT_OF_MEMORY;
765 data->multi_easy = multi;
768 /* Copy the MAXCONNECTS option to the multi handle */
769 curl_multi_setopt(multi, CURLMOPT_MAXCONNECTS, data->set.maxconnects);
771 mcode = curl_multi_add_handle(multi, data);
773 curl_multi_cleanup(multi);
774 if(mcode == CURLM_OUT_OF_MEMORY)
775 return CURLE_OUT_OF_MEMORY;
777 return CURLE_FAILED_INIT;
780 sigpipe_ignore(data, &pipe_st);
782 /* assign this after curl_multi_add_handle() since that function checks for
783 it and rejects this handle otherwise */
786 /* run the transfer */
787 result = events ? easy_events(multi) : easy_transfer(multi);
789 /* ignoring the return code isn't nice, but atm we can't really handle
790 a failure here, room for future improvement! */
791 (void)curl_multi_remove_handle(multi, data);
793 sigpipe_restore(&pipe_st);
795 /* The multi handle is kept alive, owned by the easy handle */
801 * curl_easy_perform() is the external interface that performs a blocking
802 * transfer as previously setup.
804 CURLcode curl_easy_perform(struct Curl_easy *data)
806 return easy_perform(data, FALSE);
811 * curl_easy_perform_ev() is the external interface that performs a blocking
812 * transfer using the event-based API internally.
814 CURLcode curl_easy_perform_ev(struct Curl_easy *data)
816 return easy_perform(data, TRUE);
822 * curl_easy_cleanup() is the external interface to cleaning/freeing the given
825 void curl_easy_cleanup(struct Curl_easy *data)
827 SIGPIPE_VARIABLE(pipe_st);
832 sigpipe_ignore(data, &pipe_st);
834 sigpipe_restore(&pipe_st);
838 * curl_easy_getinfo() is an external interface that allows an app to retrieve
839 * information from a performed transfer and similar.
841 #undef curl_easy_getinfo
842 CURLcode curl_easy_getinfo(struct Curl_easy *data, CURLINFO info, ...)
849 paramp = va_arg(arg, void *);
851 result = Curl_getinfo(data, info, paramp);
858 * curl_easy_duphandle() is an external interface to allow duplication of a
859 * given input easy handle. The returned handle will be a new working handle
860 * with all options set exactly as the input source handle.
862 struct Curl_easy *curl_easy_duphandle(struct Curl_easy *data)
864 struct Curl_easy *outcurl = calloc(1, sizeof(struct Curl_easy));
869 * We setup a few buffers we need. We should probably make them
870 * get setup on-demand in the code, as that would probably decrease
871 * the likeliness of us forgetting to init a buffer here in the future.
873 outcurl->set.buffer_size = data->set.buffer_size;
874 outcurl->state.buffer = malloc(CURL_BUFSIZE(outcurl->set.buffer_size) + 1);
875 if(!outcurl->state.buffer)
878 outcurl->state.headerbuff = malloc(HEADERSIZE);
879 if(!outcurl->state.headerbuff)
881 outcurl->state.headersize = HEADERSIZE;
883 /* copy all userdefined values */
884 if(Curl_dupset(outcurl, data))
887 /* the connection cache is setup on demand */
888 outcurl->state.conn_cache = NULL;
890 outcurl->state.lastconnect = NULL;
892 outcurl->progress.flags = data->progress.flags;
893 outcurl->progress.callback = data->progress.callback;
896 /* If cookies are enabled in the parent handle, we enable them
897 in the clone as well! */
898 outcurl->cookies = Curl_cookie_init(data,
899 data->cookies->filename,
901 data->set.cookiesession);
902 if(!outcurl->cookies)
906 /* duplicate all values in 'change' */
907 if(data->change.cookielist) {
908 outcurl->change.cookielist =
909 Curl_slist_duplicate(data->change.cookielist);
910 if(!outcurl->change.cookielist)
914 if(data->change.url) {
915 outcurl->change.url = strdup(data->change.url);
916 if(!outcurl->change.url)
918 outcurl->change.url_alloc = TRUE;
921 if(data->change.referer) {
922 outcurl->change.referer = strdup(data->change.referer);
923 if(!outcurl->change.referer)
925 outcurl->change.referer_alloc = TRUE;
928 /* Clone the resolver handle, if present, for the new handle */
929 if(Curl_resolver_duphandle(&outcurl->state.resolver,
930 data->state.resolver))
933 Curl_convert_setup(outcurl);
935 Curl_initinfo(outcurl);
937 outcurl->magic = CURLEASY_MAGIC_NUMBER;
939 /* we reach this point and thus we are OK */
946 curl_slist_free_all(outcurl->change.cookielist);
947 outcurl->change.cookielist = NULL;
948 Curl_safefree(outcurl->state.buffer);
949 Curl_safefree(outcurl->state.headerbuff);
950 Curl_safefree(outcurl->change.url);
951 Curl_safefree(outcurl->change.referer);
952 Curl_freeset(outcurl);
960 * curl_easy_reset() is an external interface that allows an app to re-
961 * initialize a session handle to the default values.
963 void curl_easy_reset(struct Curl_easy *data)
965 Curl_safefree(data->state.pathbuffer);
967 data->state.path = NULL;
969 Curl_free_request_state(data);
971 /* zero out UserDefined data: */
973 memset(&data->set, 0, sizeof(struct UserDefined));
974 (void)Curl_init_userdefined(&data->set);
976 /* zero out Progress data: */
977 memset(&data->progress, 0, sizeof(struct Progress));
979 /* zero out PureInfo data: */
982 data->progress.flags |= PGRS_HIDE;
983 data->state.current_speed = -1; /* init to negative == impossible */
987 * curl_easy_pause() allows an application to pause or unpause a specific
988 * transfer and direction. This function sets the full new state for the
989 * current connection this easy handle operates on.
991 * NOTE: if you have the receiving paused and you call this function to remove
992 * the pausing, you may get your write callback called at this point.
994 * Action is a bitmask consisting of CURLPAUSE_* bits in curl/curl.h
996 CURLcode curl_easy_pause(struct Curl_easy *data, int action)
998 struct SingleRequest *k = &data->req;
999 CURLcode result = CURLE_OK;
1001 /* first switch off both pause bits */
1002 int newstate = k->keepon &~ (KEEP_RECV_PAUSE| KEEP_SEND_PAUSE);
1004 /* set the new desired pause bits */
1005 newstate |= ((action & CURLPAUSE_RECV)?KEEP_RECV_PAUSE:0) |
1006 ((action & CURLPAUSE_SEND)?KEEP_SEND_PAUSE:0);
1008 /* put it back in the keepon */
1009 k->keepon = newstate;
1011 if(!(newstate & KEEP_RECV_PAUSE) && data->state.tempwrite) {
1012 /* we have a buffer for sending that we now seem to be able to deliver
1013 since the receive pausing is lifted! */
1015 /* get the pointer in local copy since the function may return PAUSE
1016 again and then we'll get a new copy allocted and stored in
1017 the tempwrite variables */
1018 char *tempwrite = data->state.tempwrite;
1020 data->state.tempwrite = NULL;
1021 result = Curl_client_chop_write(data->easy_conn, data->state.tempwritetype,
1022 tempwrite, data->state.tempwritesize);
1026 /* if there's no error and we're not pausing both directions, we want
1027 to have this handle checked soon */
1029 ((newstate&(KEEP_RECV_PAUSE|KEEP_SEND_PAUSE)) !=
1030 (KEEP_RECV_PAUSE|KEEP_SEND_PAUSE)) )
1031 Curl_expire(data, 0); /* get this handle going again */
1037 static CURLcode easy_connection(struct Curl_easy *data,
1039 struct connectdata **connp)
1042 return CURLE_BAD_FUNCTION_ARGUMENT;
1044 /* only allow these to be called on handles with CURLOPT_CONNECT_ONLY */
1045 if(!data->set.connect_only) {
1046 failf(data, "CONNECT_ONLY is required!");
1047 return CURLE_UNSUPPORTED_PROTOCOL;
1050 *sfd = Curl_getconnectinfo(data, connp);
1052 if(*sfd == CURL_SOCKET_BAD) {
1053 failf(data, "Failed to get recent socket");
1054 return CURLE_UNSUPPORTED_PROTOCOL;
1061 * Receives data from the connected socket. Use after successful
1062 * curl_easy_perform() with CURLOPT_CONNECT_ONLY option.
1063 * Returns CURLE_OK on success, error code on error.
1065 CURLcode curl_easy_recv(struct Curl_easy *data, void *buffer, size_t buflen,
1071 struct connectdata *c;
1073 result = easy_connection(data, &sfd, &c);
1078 result = Curl_read(c, sfd, buffer, buflen, &n1);
1089 * Sends data over the connected socket. Use after successful
1090 * curl_easy_perform() with CURLOPT_CONNECT_ONLY option.
1092 CURLcode curl_easy_send(struct Curl_easy *data, const void *buffer,
1093 size_t buflen, size_t *n)
1098 struct connectdata *c = NULL;
1100 result = easy_connection(data, &sfd, &c);
1105 result = Curl_write(c, sfd, buffer, buflen, &n1);
1108 return CURLE_SEND_ERROR;