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>
55 #include <curl/curl.h>
57 #include "vtls/vtls.h"
66 #include "sendf.h" /* for failf function prototype */
67 #include "connect.h" /* for Curl_getconnectinfo */
70 #include "non-ascii.h"
72 #include "conncache.h"
76 /* The last 3 #include files should be in this order */
77 #include "curl_printf.h"
78 #include "curl_memory.h"
81 void Curl_version_init(void);
83 /* win32_cleanup() is for win32 socket cleanup functionality, the opposite
85 static void win32_cleanup(void)
90 #ifdef USE_WINDOWS_SSPI
91 Curl_sspi_global_cleanup();
95 /* win32_init() performs win32 socket initialization to properly setup the
96 stack to allow networking */
97 static CURLcode win32_init(void)
100 WORD wVersionRequested;
104 #if defined(ENABLE_IPV6) && (USE_WINSOCK < 2)
105 Error IPV6_requires_winsock2
108 wVersionRequested = MAKEWORD(USE_WINSOCK, USE_WINSOCK);
110 res = WSAStartup(wVersionRequested, &wsaData);
113 /* Tell the user that we couldn't find a useable */
115 return CURLE_FAILED_INIT;
117 /* Confirm that the Windows Sockets DLL supports what we need.*/
118 /* Note that if the DLL supports versions greater */
119 /* than wVersionRequested, it will still return */
120 /* wVersionRequested in wVersion. wHighVersion contains the */
121 /* highest supported version. */
123 if(LOBYTE(wsaData.wVersion) != LOBYTE(wVersionRequested) ||
124 HIBYTE(wsaData.wVersion) != HIBYTE(wVersionRequested) ) {
125 /* Tell the user that we couldn't find a useable */
129 return CURLE_FAILED_INIT;
131 /* The Windows Sockets DLL is acceptable. Proceed. */
132 #elif defined(USE_LWIPSOCK)
136 #ifdef USE_WINDOWS_SSPI
138 CURLcode result = Curl_sspi_global_init();
149 * Initialise use of IDNA library.
150 * It falls back to ASCII if $CHARSET isn't defined. This doesn't work for
151 * idna_to_ascii_lz().
153 static void idna_init (void)
159 if(!getenv("CHARSET") && cp > 0) {
160 snprintf(buf, sizeof(buf), "CHARSET=cp%u", cp);
167 #endif /* USE_LIBIDN */
169 /* true globals -- for curl_global_init() and curl_global_cleanup() */
170 static unsigned int initialized;
171 static long init_flags;
174 * strdup (and other memory functions) is redefined in complicated
175 * ways, but at this point it must be defined as the system-supplied strdup
176 * so the callback pointer is initialized correctly.
178 #if defined(_WIN32_WCE)
179 #define system_strdup _strdup
180 #elif !defined(HAVE_STRDUP)
181 #define system_strdup curlx_strdup
183 #define system_strdup strdup
186 #if defined(_MSC_VER) && defined(_DLL) && !defined(__POCC__)
187 # pragma warning(disable:4232) /* MSVC extension, dllimport identity */
190 #ifndef __SYMBIAN32__
192 * If a memory-using function (like curl_getenv) is used before
193 * curl_global_init() is called, we need to have these pointers set already.
195 curl_malloc_callback Curl_cmalloc = (curl_malloc_callback)malloc;
196 curl_free_callback Curl_cfree = (curl_free_callback)free;
197 curl_realloc_callback Curl_crealloc = (curl_realloc_callback)realloc;
198 curl_strdup_callback Curl_cstrdup = (curl_strdup_callback)system_strdup;
199 curl_calloc_callback Curl_ccalloc = (curl_calloc_callback)calloc;
200 #if defined(WIN32) && defined(UNICODE)
201 curl_wcsdup_callback Curl_cwcsdup = (curl_wcsdup_callback)_wcsdup;
205 * Symbian OS doesn't support initialization to code in writeable static data.
206 * Initialization will occur in the curl_global_init() call.
208 curl_malloc_callback Curl_cmalloc;
209 curl_free_callback Curl_cfree;
210 curl_realloc_callback Curl_crealloc;
211 curl_strdup_callback Curl_cstrdup;
212 curl_calloc_callback Curl_ccalloc;
215 #if defined(_MSC_VER) && defined(_DLL) && !defined(__POCC__)
216 # pragma warning(default:4232) /* MSVC extension, dllimport identity */
220 * curl_global_init() globally initializes cURL given a bitwise set of the
221 * different features of what to initialize.
223 static CURLcode global_init(long flags, bool memoryfuncs)
229 /* Setup the default memory functions here (again) */
230 Curl_cmalloc = (curl_malloc_callback)malloc;
231 Curl_cfree = (curl_free_callback)free;
232 Curl_crealloc = (curl_realloc_callback)realloc;
233 Curl_cstrdup = (curl_strdup_callback)system_strdup;
234 Curl_ccalloc = (curl_calloc_callback)calloc;
235 #if defined(WIN32) && defined(UNICODE)
236 Curl_cwcsdup = (curl_wcsdup_callback)_wcsdup;
240 if(flags & CURL_GLOBAL_SSL)
241 if(!Curl_ssl_init()) {
242 DEBUGF(fprintf(stderr, "Error: Curl_ssl_init failed\n"));
243 return CURLE_FAILED_INIT;
246 if(flags & CURL_GLOBAL_WIN32)
248 DEBUGF(fprintf(stderr, "Error: win32_init failed\n"));
249 return CURLE_FAILED_INIT;
253 if(!Curl_amiga_init()) {
254 DEBUGF(fprintf(stderr, "Error: Curl_amiga_init failed\n"));
255 return CURLE_FAILED_INIT;
261 DEBUGF(fprintf(stderr, "Warning: LONG namespace not available\n"));
269 if(Curl_resolver_global_init()) {
270 DEBUGF(fprintf(stderr, "Error: resolver_global_init failed\n"));
271 return CURLE_FAILED_INIT;
274 (void)Curl_ipv6works();
276 #if defined(USE_LIBSSH2) && defined(HAVE_LIBSSH2_INIT)
277 if(libssh2_init(0)) {
278 DEBUGF(fprintf(stderr, "Error: libssh2_init failed\n"));
279 return CURLE_FAILED_INIT;
283 if(flags & CURL_GLOBAL_ACK_EINTR)
295 * curl_global_init() globally initializes cURL given a bitwise set of the
296 * different features of what to initialize.
298 CURLcode curl_global_init(long flags)
300 return global_init(flags, TRUE);
304 * curl_global_init_mem() globally initializes cURL and also registers the
305 * user provided callback routines.
307 CURLcode curl_global_init_mem(long flags, curl_malloc_callback m,
308 curl_free_callback f, curl_realloc_callback r,
309 curl_strdup_callback s, curl_calloc_callback c)
311 /* Invalid input, return immediately */
312 if(!m || !f || !r || !s || !c)
313 return CURLE_FAILED_INIT;
316 /* Already initialized, don't do it again, but bump the variable anyway to
317 work like curl_global_init() and require the same amount of cleanup
323 /* set memory functions before global_init() in case it wants memory
331 /* Call the actual init function, but without setting */
332 return global_init(flags, FALSE);
336 * curl_global_cleanup() globally cleanups cURL, uses the value of
337 * "init_flags" to determine what needs to be cleaned up and what doesn't.
339 void curl_global_cleanup(void)
347 Curl_global_host_cache_dtor();
349 if(init_flags & CURL_GLOBAL_SSL)
352 Curl_resolver_global_cleanup();
354 if(init_flags & CURL_GLOBAL_WIN32)
357 Curl_amiga_cleanup();
359 #if defined(USE_LIBSSH2) && defined(HAVE_LIBSSH2_EXIT)
360 (void)libssh2_exit();
367 * curl_easy_init() is the external interface to alloc, setup and init an
368 * easy handle that is returned. If anything goes wrong, NULL is returned.
370 struct Curl_easy *curl_easy_init(void)
373 struct Curl_easy *data;
375 /* Make sure we inited the global SSL stuff */
377 result = curl_global_init(CURL_GLOBAL_DEFAULT);
379 /* something in the global init failed, return nothing */
380 DEBUGF(fprintf(stderr, "Error: curl_global_init failed\n"));
385 /* We use curl_open() with undefined URL so far */
386 result = Curl_open(&data);
388 DEBUGF(fprintf(stderr, "Error: Curl_open failed\n"));
396 * curl_easy_setopt() is the external interface for setting options on an
400 #undef curl_easy_setopt
401 CURLcode curl_easy_setopt(struct Curl_easy *data, CURLoption tag, ...)
407 return CURLE_BAD_FUNCTION_ARGUMENT;
411 result = Curl_setopt(data, tag, arg);
419 struct socketmonitor {
420 struct socketmonitor *next; /* the next node in the list or NULL */
421 struct pollfd socket; /* socket info of what to monitor */
425 long ms; /* timeout, run the timeout function when reached */
426 bool msbump; /* set TRUE when timeout is set by callback */
427 int num_sockets; /* number of nodes in the monitor list */
428 struct socketmonitor *list; /* list of sockets to monitor */
429 int running_handles; /* store the returned number */
434 * Callback that gets called with a new value when the timeout should be
438 static int events_timer(struct Curl_multi *multi, /* multi handle */
439 long timeout_ms, /* see above */
440 void *userp) /* private callback pointer */
442 struct events *ev = userp;
445 /* timeout removed */
447 else if(timeout_ms == 0)
448 /* timeout is already reached! */
449 timeout_ms = 1; /* trigger asap */
459 * convert from poll() bit definitions to libcurl's CURL_CSELECT_* ones
461 static int poll2cselect(int pollmask)
464 if(pollmask & POLLIN)
465 omask |= CURL_CSELECT_IN;
466 if(pollmask & POLLOUT)
467 omask |= CURL_CSELECT_OUT;
468 if(pollmask & POLLERR)
469 omask |= CURL_CSELECT_ERR;
476 * convert from libcurl' CURL_POLL_* bit definitions to poll()'s
478 static short socketcb2poll(int pollmask)
481 if(pollmask & CURL_POLL_IN)
483 if(pollmask & CURL_POLL_OUT)
490 * Callback that gets called with information about socket activity to
493 static int events_socket(struct Curl_easy *easy, /* easy handle */
494 curl_socket_t s, /* socket */
495 int what, /* see above */
496 void *userp, /* private callback
498 void *socketp) /* private socket
501 struct events *ev = userp;
502 struct socketmonitor *m;
503 struct socketmonitor *prev=NULL;
505 #if defined(CURL_DISABLE_VERBOSE_STRINGS)
512 if(m->socket.fd == s) {
514 if(what == CURL_POLL_REMOVE) {
515 struct socketmonitor *nxt = m->next;
516 /* remove this node from the list of monitored sockets */
523 infof(easy, "socket cb: socket %d REMOVED\n", s);
526 /* The socket 's' is already being monitored, update the activity
527 mask. Convert from libcurl bitmask to the poll one. */
528 m->socket.events = socketcb2poll(what);
529 infof(easy, "socket cb: socket %d UPDATED as %s%s\n", s,
530 what&CURL_POLL_IN?"IN":"",
531 what&CURL_POLL_OUT?"OUT":"");
536 m = m->next; /* move to next node */
539 if(what == CURL_POLL_REMOVE) {
540 /* this happens a bit too often, libcurl fix perhaps? */
542 "%s: socket %d asked to be REMOVED but not present!\n",
546 m = malloc(sizeof(struct socketmonitor));
550 m->socket.events = socketcb2poll(what);
551 m->socket.revents = 0;
553 infof(easy, "socket cb: socket %d ADDED as %s%s\n", s,
554 what&CURL_POLL_IN?"IN":"",
555 what&CURL_POLL_OUT?"OUT":"");
558 return CURLE_OUT_OF_MEMORY;
569 * Do the multi handle setups that only event-based transfers need.
571 static void events_setup(struct Curl_multi *multi, struct events *ev)
574 curl_multi_setopt(multi, CURLMOPT_TIMERFUNCTION, events_timer);
575 curl_multi_setopt(multi, CURLMOPT_TIMERDATA, ev);
577 /* socket callback */
578 curl_multi_setopt(multi, CURLMOPT_SOCKETFUNCTION, events_socket);
579 curl_multi_setopt(multi, CURLMOPT_SOCKETDATA, ev);
585 * waits for activity on any of the given sockets, or the timeout to trigger.
588 static CURLcode wait_or_timeout(struct Curl_multi *multi, struct events *ev)
592 CURLcode result = CURLE_OK;
596 struct socketmonitor *m;
598 struct pollfd fds[4];
602 struct timeval before;
603 struct timeval after;
605 /* populate the fds[] array */
606 for(m = ev->list, f=&fds[0]; m; m = m->next) {
607 f->fd = m->socket.fd;
608 f->events = m->socket.events;
610 /* fprintf(stderr, "poll() %d check socket %d\n", numfds, f->fd); */
615 /* get the time stamp to use to figure out how long poll takes */
616 before = curlx_tvnow();
618 /* wait for activity or timeout */
619 pollrc = Curl_poll(fds, numfds, (int)ev->ms);
621 after = curlx_tvnow();
623 ev->msbump = FALSE; /* reset here */
628 /* fprintf(stderr, "call curl_multi_socket_action(TIMEOUT)\n"); */
629 mcode = curl_multi_socket_action(multi, CURL_SOCKET_TIMEOUT, 0,
630 &ev->running_handles);
632 else if(pollrc > 0) {
633 /* loop over the monitored sockets to see which ones had activity */
634 for(i = 0; i< numfds; i++) {
636 /* socket activity, tell libcurl */
637 int act = poll2cselect(fds[i].revents); /* convert */
638 infof(multi->easyp, "call curl_multi_socket_action(socket %d)\n",
640 mcode = curl_multi_socket_action(multi, fds[i].fd, act,
641 &ev->running_handles);
646 /* If nothing updated the timeout, we decrease it by the spent time.
647 * If it was updated, it has the new timeout time stored already.
649 ev->ms += curlx_tvdiff(after, before);
653 return CURLE_RECV_ERROR;
656 return CURLE_URL_MALFORMAT; /* TODO: return a proper error! */
658 /* we don't really care about the "msgs_in_queue" value returned in the
660 msg = curl_multi_info_read(multi, &pollrc);
662 result = msg->data.result;
673 * Runs a transfer in a blocking manner using the events-based API
675 static CURLcode easy_events(struct Curl_multi *multi)
677 struct events evs= {2, FALSE, 0, NULL, 0};
679 /* if running event-based, do some further multi inits */
680 events_setup(multi, &evs);
682 return wait_or_timeout(multi, &evs);
684 #else /* CURLDEBUG */
685 /* when not built with debug, this function doesn't exist */
686 #define easy_events(x) CURLE_NOT_BUILT_IN
689 static CURLcode easy_transfer(struct Curl_multi *multi)
692 CURLMcode mcode = CURLM_OK;
693 CURLcode result = CURLE_OK;
694 struct timeval before;
695 int without_fds = 0; /* count number of consecutive returns from
696 curl_multi_wait() without any filedescriptors */
698 while(!done && !mcode) {
699 int still_running = 0;
702 before = curlx_tvnow();
703 mcode = curl_multi_wait(multi, NULL, 0, 1000, &rc);
707 struct timeval after = curlx_tvnow();
709 /* If it returns without any filedescriptor instantly, we need to
710 avoid busy-looping during periods where it has nothing particular
712 if(curlx_tvdiff(after, before) <= 10) {
714 if(without_fds > 2) {
715 int sleep_ms = without_fds < 10 ? (1 << (without_fds - 1)) : 1000;
716 Curl_wait_ms(sleep_ms);
720 /* it wasn't "instant", restart counter */
724 /* got file descriptor, restart counter */
727 mcode = curl_multi_perform(multi, &still_running);
730 /* only read 'still_running' if curl_multi_perform() return OK */
731 if(!mcode && !still_running) {
732 CURLMsg *msg = curl_multi_info_read(multi, &rc);
734 result = msg->data.result;
740 /* Make sure to return some kind of error if there was a multi problem */
742 result = (mcode == CURLM_OUT_OF_MEMORY) ? CURLE_OUT_OF_MEMORY :
743 /* The other multi errors should never happen, so return
744 something suitably generic */
745 CURLE_BAD_FUNCTION_ARGUMENT;
753 * easy_perform() is the external interface that performs a blocking
754 * transfer as previously setup.
756 * CONCEPT: This function creates a multi handle, adds the easy handle to it,
757 * runs curl_multi_perform() until the transfer is done, then detaches the
758 * easy handle, destroys the multi handle and returns the easy handle's return
761 * REALITY: it can't just create and destroy the multi handle that easily. It
762 * needs to keep it around since if this easy handle is used again by this
763 * function, the same multi handle must be re-used so that the same pools and
764 * caches can be used.
766 * DEBUG: if 'events' is set TRUE, this function will use a replacement engine
767 * instead of curl_multi_perform() and use curl_multi_socket_action().
769 static CURLcode easy_perform(struct Curl_easy *data, bool events)
771 struct Curl_multi *multi;
773 CURLcode result = CURLE_OK;
774 SIGPIPE_VARIABLE(pipe_st);
777 return CURLE_BAD_FUNCTION_ARGUMENT;
780 failf(data, "easy handle already used in multi handle");
781 return CURLE_FAILED_INIT;
785 multi = data->multi_easy;
787 /* this multi handle will only ever have a single easy handled attached
788 to it, so make it use minimal hashes */
789 multi = Curl_multi_handle(1, 3);
791 return CURLE_OUT_OF_MEMORY;
792 data->multi_easy = multi;
795 /* Copy the MAXCONNECTS option to the multi handle */
796 curl_multi_setopt(multi, CURLMOPT_MAXCONNECTS, data->set.maxconnects);
798 mcode = curl_multi_add_handle(multi, data);
800 curl_multi_cleanup(multi);
801 if(mcode == CURLM_OUT_OF_MEMORY)
802 return CURLE_OUT_OF_MEMORY;
804 return CURLE_FAILED_INIT;
807 sigpipe_ignore(data, &pipe_st);
809 /* assign this after curl_multi_add_handle() since that function checks for
810 it and rejects this handle otherwise */
813 /* run the transfer */
814 result = events ? easy_events(multi) : easy_transfer(multi);
816 /* ignoring the return code isn't nice, but atm we can't really handle
817 a failure here, room for future improvement! */
818 (void)curl_multi_remove_handle(multi, data);
820 sigpipe_restore(&pipe_st);
822 /* The multi handle is kept alive, owned by the easy handle */
828 * curl_easy_perform() is the external interface that performs a blocking
829 * transfer as previously setup.
831 CURLcode curl_easy_perform(struct Curl_easy *data)
833 return easy_perform(data, FALSE);
838 * curl_easy_perform_ev() is the external interface that performs a blocking
839 * transfer using the event-based API internally.
841 CURLcode curl_easy_perform_ev(struct Curl_easy *data)
843 return easy_perform(data, TRUE);
849 * curl_easy_cleanup() is the external interface to cleaning/freeing the given
852 void curl_easy_cleanup(struct Curl_easy *data)
854 SIGPIPE_VARIABLE(pipe_st);
859 sigpipe_ignore(data, &pipe_st);
861 sigpipe_restore(&pipe_st);
865 * curl_easy_getinfo() is an external interface that allows an app to retrieve
866 * information from a performed transfer and similar.
868 #undef curl_easy_getinfo
869 CURLcode curl_easy_getinfo(struct Curl_easy *data, CURLINFO info, ...)
876 paramp = va_arg(arg, void *);
878 result = Curl_getinfo(data, info, paramp);
885 * curl_easy_duphandle() is an external interface to allow duplication of a
886 * given input easy handle. The returned handle will be a new working handle
887 * with all options set exactly as the input source handle.
889 struct Curl_easy *curl_easy_duphandle(struct Curl_easy *data)
891 struct Curl_easy *outcurl = calloc(1, sizeof(struct Curl_easy));
896 * We setup a few buffers we need. We should probably make them
897 * get setup on-demand in the code, as that would probably decrease
898 * the likeliness of us forgetting to init a buffer here in the future.
900 outcurl->state.headerbuff = malloc(HEADERSIZE);
901 if(!outcurl->state.headerbuff)
903 outcurl->state.headersize = HEADERSIZE;
905 /* copy all userdefined values */
906 if(Curl_dupset(outcurl, data))
909 /* the connection cache is setup on demand */
910 outcurl->state.conn_cache = NULL;
912 outcurl->state.lastconnect = NULL;
914 outcurl->progress.flags = data->progress.flags;
915 outcurl->progress.callback = data->progress.callback;
918 /* If cookies are enabled in the parent handle, we enable them
919 in the clone as well! */
920 outcurl->cookies = Curl_cookie_init(data,
921 data->cookies->filename,
923 data->set.cookiesession);
924 if(!outcurl->cookies)
928 /* duplicate all values in 'change' */
929 if(data->change.cookielist) {
930 outcurl->change.cookielist =
931 Curl_slist_duplicate(data->change.cookielist);
932 if(!outcurl->change.cookielist)
936 if(data->change.url) {
937 outcurl->change.url = strdup(data->change.url);
938 if(!outcurl->change.url)
940 outcurl->change.url_alloc = TRUE;
943 if(data->change.referer) {
944 outcurl->change.referer = strdup(data->change.referer);
945 if(!outcurl->change.referer)
947 outcurl->change.referer_alloc = TRUE;
950 /* Clone the resolver handle, if present, for the new handle */
951 if(Curl_resolver_duphandle(&outcurl->state.resolver,
952 data->state.resolver))
955 Curl_convert_setup(outcurl);
957 outcurl->magic = CURLEASY_MAGIC_NUMBER;
959 /* we reach this point and thus we are OK */
966 curl_slist_free_all(outcurl->change.cookielist);
967 outcurl->change.cookielist = NULL;
968 Curl_safefree(outcurl->state.headerbuff);
969 Curl_safefree(outcurl->change.url);
970 Curl_safefree(outcurl->change.referer);
971 Curl_freeset(outcurl);
979 * curl_easy_reset() is an external interface that allows an app to re-
980 * initialize a session handle to the default values.
982 void curl_easy_reset(struct Curl_easy *data)
984 Curl_safefree(data->state.pathbuffer);
986 data->state.path = NULL;
988 Curl_free_request_state(data);
990 /* zero out UserDefined data: */
992 memset(&data->set, 0, sizeof(struct UserDefined));
993 (void)Curl_init_userdefined(&data->set);
995 /* zero out Progress data: */
996 memset(&data->progress, 0, sizeof(struct Progress));
998 data->progress.flags |= PGRS_HIDE;
999 data->state.current_speed = -1; /* init to negative == impossible */
1003 * curl_easy_pause() allows an application to pause or unpause a specific
1004 * transfer and direction. This function sets the full new state for the
1005 * current connection this easy handle operates on.
1007 * NOTE: if you have the receiving paused and you call this function to remove
1008 * the pausing, you may get your write callback called at this point.
1010 * Action is a bitmask consisting of CURLPAUSE_* bits in curl/curl.h
1012 CURLcode curl_easy_pause(struct Curl_easy *data, int action)
1014 struct SingleRequest *k = &data->req;
1015 CURLcode result = CURLE_OK;
1017 /* first switch off both pause bits */
1018 int newstate = k->keepon &~ (KEEP_RECV_PAUSE| KEEP_SEND_PAUSE);
1020 /* set the new desired pause bits */
1021 newstate |= ((action & CURLPAUSE_RECV)?KEEP_RECV_PAUSE:0) |
1022 ((action & CURLPAUSE_SEND)?KEEP_SEND_PAUSE:0);
1024 /* put it back in the keepon */
1025 k->keepon = newstate;
1027 if(!(newstate & KEEP_RECV_PAUSE) && data->state.tempwrite) {
1028 /* we have a buffer for sending that we now seem to be able to deliver
1029 since the receive pausing is lifted! */
1031 /* get the pointer in local copy since the function may return PAUSE
1032 again and then we'll get a new copy allocted and stored in
1033 the tempwrite variables */
1034 char *tempwrite = data->state.tempwrite;
1036 data->state.tempwrite = NULL;
1037 result = Curl_client_chop_write(data->easy_conn, data->state.tempwritetype,
1038 tempwrite, data->state.tempwritesize);
1042 /* if there's no error and we're not pausing both directions, we want
1043 to have this handle checked soon */
1045 ((newstate&(KEEP_RECV_PAUSE|KEEP_SEND_PAUSE)) !=
1046 (KEEP_RECV_PAUSE|KEEP_SEND_PAUSE)) )
1047 Curl_expire(data, 0); /* get this handle going again */
1053 static CURLcode easy_connection(struct Curl_easy *data,
1055 struct connectdata **connp)
1058 return CURLE_BAD_FUNCTION_ARGUMENT;
1060 /* only allow these to be called on handles with CURLOPT_CONNECT_ONLY */
1061 if(!data->set.connect_only) {
1062 failf(data, "CONNECT_ONLY is required!");
1063 return CURLE_UNSUPPORTED_PROTOCOL;
1066 *sfd = Curl_getconnectinfo(data, connp);
1068 if(*sfd == CURL_SOCKET_BAD) {
1069 failf(data, "Failed to get recent socket");
1070 return CURLE_UNSUPPORTED_PROTOCOL;
1077 * Receives data from the connected socket. Use after successful
1078 * curl_easy_perform() with CURLOPT_CONNECT_ONLY option.
1079 * Returns CURLE_OK on success, error code on error.
1081 CURLcode curl_easy_recv(struct Curl_easy *data, void *buffer, size_t buflen,
1087 struct connectdata *c;
1089 result = easy_connection(data, &sfd, &c);
1094 result = Curl_read(c, sfd, buffer, buflen, &n1);
1105 * Sends data over the connected socket. Use after successful
1106 * curl_easy_perform() with CURLOPT_CONNECT_ONLY option.
1108 CURLcode curl_easy_send(struct Curl_easy *data, const void *buffer,
1109 size_t buflen, size_t *n)
1114 struct connectdata *c = NULL;
1116 result = easy_connection(data, &sfd, &c);
1121 result = Curl_write(c, sfd, buffer, buflen, &n1);
1124 return CURLE_SEND_ERROR;