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"
79 #ifdef USE_TIZEN_FEATURE_DLP
80 #include "extensions/curl_extensions.h"
83 void Curl_version_init(void);
85 /* win32_cleanup() is for win32 socket cleanup functionality, the opposite
87 static void win32_cleanup(void)
92 #ifdef USE_WINDOWS_SSPI
93 Curl_sspi_global_cleanup();
97 /* win32_init() performs win32 socket initialization to properly setup the
98 stack to allow networking */
99 static CURLcode win32_init(void)
102 WORD wVersionRequested;
106 #if defined(ENABLE_IPV6) && (USE_WINSOCK < 2)
107 Error IPV6_requires_winsock2
110 wVersionRequested = MAKEWORD(USE_WINSOCK, USE_WINSOCK);
112 res = WSAStartup(wVersionRequested, &wsaData);
115 /* Tell the user that we couldn't find a useable */
117 return CURLE_FAILED_INIT;
119 /* Confirm that the Windows Sockets DLL supports what we need.*/
120 /* Note that if the DLL supports versions greater */
121 /* than wVersionRequested, it will still return */
122 /* wVersionRequested in wVersion. wHighVersion contains the */
123 /* highest supported version. */
125 if(LOBYTE(wsaData.wVersion) != LOBYTE(wVersionRequested) ||
126 HIBYTE(wsaData.wVersion) != HIBYTE(wVersionRequested) ) {
127 /* Tell the user that we couldn't find a useable */
131 return CURLE_FAILED_INIT;
133 /* The Windows Sockets DLL is acceptable. Proceed. */
134 #elif defined(USE_LWIPSOCK)
138 #ifdef USE_WINDOWS_SSPI
140 CURLcode result = Curl_sspi_global_init();
149 /* true globals -- for curl_global_init() and curl_global_cleanup() */
150 static unsigned int initialized;
151 static long init_flags;
154 * strdup (and other memory functions) is redefined in complicated
155 * ways, but at this point it must be defined as the system-supplied strdup
156 * so the callback pointer is initialized correctly.
158 #if defined(_WIN32_WCE)
159 #define system_strdup _strdup
160 #elif !defined(HAVE_STRDUP)
161 #define system_strdup curlx_strdup
163 #define system_strdup strdup
166 #if defined(_MSC_VER) && defined(_DLL) && !defined(__POCC__)
167 # pragma warning(disable:4232) /* MSVC extension, dllimport identity */
170 #ifndef __SYMBIAN32__
172 * If a memory-using function (like curl_getenv) is used before
173 * curl_global_init() is called, we need to have these pointers set already.
175 curl_malloc_callback Curl_cmalloc = (curl_malloc_callback)malloc;
176 curl_free_callback Curl_cfree = (curl_free_callback)free;
177 curl_realloc_callback Curl_crealloc = (curl_realloc_callback)realloc;
178 curl_strdup_callback Curl_cstrdup = (curl_strdup_callback)system_strdup;
179 curl_calloc_callback Curl_ccalloc = (curl_calloc_callback)calloc;
180 #if defined(WIN32) && defined(UNICODE)
181 curl_wcsdup_callback Curl_cwcsdup = (curl_wcsdup_callback)_wcsdup;
185 * Symbian OS doesn't support initialization to code in writeable static data.
186 * Initialization will occur in the curl_global_init() call.
188 curl_malloc_callback Curl_cmalloc;
189 curl_free_callback Curl_cfree;
190 curl_realloc_callback Curl_crealloc;
191 curl_strdup_callback Curl_cstrdup;
192 curl_calloc_callback Curl_ccalloc;
195 #if defined(_MSC_VER) && defined(_DLL) && !defined(__POCC__)
196 # pragma warning(default:4232) /* MSVC extension, dllimport identity */
200 * curl_global_init() globally initializes curl given a bitwise set of the
201 * different features of what to initialize.
203 static CURLcode global_init(long flags, bool memoryfuncs)
208 #ifdef USE_TIZEN_FEATURE_DLP
210 * Initialize Tizen DLP
212 curl_extensions_tizen_dlp_init();
216 /* Setup the default memory functions here (again) */
217 Curl_cmalloc = (curl_malloc_callback)malloc;
218 Curl_cfree = (curl_free_callback)free;
219 Curl_crealloc = (curl_realloc_callback)realloc;
220 Curl_cstrdup = (curl_strdup_callback)system_strdup;
221 Curl_ccalloc = (curl_calloc_callback)calloc;
222 #if defined(WIN32) && defined(UNICODE)
223 Curl_cwcsdup = (curl_wcsdup_callback)_wcsdup;
227 if(flags & CURL_GLOBAL_SSL)
228 if(!Curl_ssl_init()) {
229 DEBUGF(fprintf(stderr, "Error: Curl_ssl_init failed\n"));
230 return CURLE_FAILED_INIT;
233 if(flags & CURL_GLOBAL_WIN32)
235 DEBUGF(fprintf(stderr, "Error: win32_init failed\n"));
236 return CURLE_FAILED_INIT;
240 if(!Curl_amiga_init()) {
241 DEBUGF(fprintf(stderr, "Error: Curl_amiga_init failed\n"));
242 return CURLE_FAILED_INIT;
248 DEBUGF(fprintf(stderr, "Warning: LONG namespace not available\n"));
252 if(Curl_resolver_global_init()) {
253 DEBUGF(fprintf(stderr, "Error: resolver_global_init failed\n"));
254 return CURLE_FAILED_INIT;
257 (void)Curl_ipv6works();
259 #if defined(USE_LIBSSH2) && defined(HAVE_LIBSSH2_INIT)
260 if(libssh2_init(0)) {
261 DEBUGF(fprintf(stderr, "Error: libssh2_init failed\n"));
262 return CURLE_FAILED_INIT;
266 if(flags & CURL_GLOBAL_ACK_EINTR)
278 * curl_global_init() globally initializes curl given a bitwise set of the
279 * different features of what to initialize.
281 CURLcode curl_global_init(long flags)
283 return global_init(flags, TRUE);
287 * curl_global_init_mem() globally initializes curl and also registers the
288 * user provided callback routines.
290 CURLcode curl_global_init_mem(long flags, curl_malloc_callback m,
291 curl_free_callback f, curl_realloc_callback r,
292 curl_strdup_callback s, curl_calloc_callback c)
294 /* Invalid input, return immediately */
295 if(!m || !f || !r || !s || !c)
296 return CURLE_FAILED_INIT;
299 /* Already initialized, don't do it again, but bump the variable anyway to
300 work like curl_global_init() and require the same amount of cleanup
306 /* set memory functions before global_init() in case it wants memory
314 /* Call the actual init function, but without setting */
315 return global_init(flags, FALSE);
319 * curl_global_cleanup() globally cleanups curl, uses the value of
320 * "init_flags" to determine what needs to be cleaned up and what doesn't.
322 void curl_global_cleanup(void)
330 Curl_global_host_cache_dtor();
332 if(init_flags & CURL_GLOBAL_SSL)
335 Curl_resolver_global_cleanup();
337 if(init_flags & CURL_GLOBAL_WIN32)
340 Curl_amiga_cleanup();
342 #if defined(USE_LIBSSH2) && defined(HAVE_LIBSSH2_EXIT)
343 (void)libssh2_exit();
350 * curl_easy_init() is the external interface to alloc, setup and init an
351 * easy handle that is returned. If anything goes wrong, NULL is returned.
353 struct Curl_easy *curl_easy_init(void)
356 struct Curl_easy *data;
358 /* Make sure we inited the global SSL stuff */
360 result = curl_global_init(CURL_GLOBAL_DEFAULT);
362 /* something in the global init failed, return nothing */
363 DEBUGF(fprintf(stderr, "Error: curl_global_init failed\n"));
368 /* We use curl_open() with undefined URL so far */
369 result = Curl_open(&data);
371 DEBUGF(fprintf(stderr, "Error: Curl_open failed\n"));
379 * curl_easy_setopt() is the external interface for setting options on an
383 #undef curl_easy_setopt
384 CURLcode curl_easy_setopt(struct Curl_easy *data, CURLoption tag, ...)
390 return CURLE_BAD_FUNCTION_ARGUMENT;
394 result = Curl_setopt(data, tag, arg);
402 struct socketmonitor {
403 struct socketmonitor *next; /* the next node in the list or NULL */
404 struct pollfd socket; /* socket info of what to monitor */
408 long ms; /* timeout, run the timeout function when reached */
409 bool msbump; /* set TRUE when timeout is set by callback */
410 int num_sockets; /* number of nodes in the monitor list */
411 struct socketmonitor *list; /* list of sockets to monitor */
412 int running_handles; /* store the returned number */
417 * Callback that gets called with a new value when the timeout should be
421 static int events_timer(struct Curl_multi *multi, /* multi handle */
422 long timeout_ms, /* see above */
423 void *userp) /* private callback pointer */
425 struct events *ev = userp;
428 /* timeout removed */
430 else if(timeout_ms == 0)
431 /* timeout is already reached! */
432 timeout_ms = 1; /* trigger asap */
442 * convert from poll() bit definitions to libcurl's CURL_CSELECT_* ones
444 static int poll2cselect(int pollmask)
447 if(pollmask & POLLIN)
448 omask |= CURL_CSELECT_IN;
449 if(pollmask & POLLOUT)
450 omask |= CURL_CSELECT_OUT;
451 if(pollmask & POLLERR)
452 omask |= CURL_CSELECT_ERR;
459 * convert from libcurl' CURL_POLL_* bit definitions to poll()'s
461 static short socketcb2poll(int pollmask)
464 if(pollmask & CURL_POLL_IN)
466 if(pollmask & CURL_POLL_OUT)
473 * Callback that gets called with information about socket activity to
476 static int events_socket(struct Curl_easy *easy, /* easy handle */
477 curl_socket_t s, /* socket */
478 int what, /* see above */
479 void *userp, /* private callback
481 void *socketp) /* private socket
484 struct events *ev = userp;
485 struct socketmonitor *m;
486 struct socketmonitor *prev=NULL;
488 #if defined(CURL_DISABLE_VERBOSE_STRINGS)
495 if(m->socket.fd == s) {
497 if(what == CURL_POLL_REMOVE) {
498 struct socketmonitor *nxt = m->next;
499 /* remove this node from the list of monitored sockets */
506 infof(easy, "socket cb: socket %d REMOVED\n", s);
509 /* The socket 's' is already being monitored, update the activity
510 mask. Convert from libcurl bitmask to the poll one. */
511 m->socket.events = socketcb2poll(what);
512 infof(easy, "socket cb: socket %d UPDATED as %s%s\n", s,
513 what&CURL_POLL_IN?"IN":"",
514 what&CURL_POLL_OUT?"OUT":"");
519 m = m->next; /* move to next node */
522 if(what == CURL_POLL_REMOVE) {
523 /* this happens a bit too often, libcurl fix perhaps? */
525 "%s: socket %d asked to be REMOVED but not present!\n",
529 m = malloc(sizeof(struct socketmonitor));
533 m->socket.events = socketcb2poll(what);
534 m->socket.revents = 0;
536 infof(easy, "socket cb: socket %d ADDED as %s%s\n", s,
537 what&CURL_POLL_IN?"IN":"",
538 what&CURL_POLL_OUT?"OUT":"");
541 return CURLE_OUT_OF_MEMORY;
552 * Do the multi handle setups that only event-based transfers need.
554 static void events_setup(struct Curl_multi *multi, struct events *ev)
557 curl_multi_setopt(multi, CURLMOPT_TIMERFUNCTION, events_timer);
558 curl_multi_setopt(multi, CURLMOPT_TIMERDATA, ev);
560 /* socket callback */
561 curl_multi_setopt(multi, CURLMOPT_SOCKETFUNCTION, events_socket);
562 curl_multi_setopt(multi, CURLMOPT_SOCKETDATA, ev);
568 * waits for activity on any of the given sockets, or the timeout to trigger.
571 static CURLcode wait_or_timeout(struct Curl_multi *multi, struct events *ev)
575 CURLcode result = CURLE_OK;
579 struct socketmonitor *m;
581 struct pollfd fds[4];
585 struct timeval before;
586 struct timeval after;
588 /* populate the fds[] array */
589 for(m = ev->list, f=&fds[0]; m; m = m->next) {
590 f->fd = m->socket.fd;
591 f->events = m->socket.events;
593 /* fprintf(stderr, "poll() %d check socket %d\n", numfds, f->fd); */
598 /* get the time stamp to use to figure out how long poll takes */
599 before = curlx_tvnow();
601 /* wait for activity or timeout */
602 pollrc = Curl_poll(fds, numfds, (int)ev->ms);
604 after = curlx_tvnow();
606 ev->msbump = FALSE; /* reset here */
611 /* fprintf(stderr, "call curl_multi_socket_action(TIMEOUT)\n"); */
612 mcode = curl_multi_socket_action(multi, CURL_SOCKET_TIMEOUT, 0,
613 &ev->running_handles);
615 else if(pollrc > 0) {
616 /* loop over the monitored sockets to see which ones had activity */
617 for(i = 0; i< numfds; i++) {
619 /* socket activity, tell libcurl */
620 int act = poll2cselect(fds[i].revents); /* convert */
621 infof(multi->easyp, "call curl_multi_socket_action(socket %d)\n",
623 mcode = curl_multi_socket_action(multi, fds[i].fd, act,
624 &ev->running_handles);
629 /* If nothing updated the timeout, we decrease it by the spent time.
630 * If it was updated, it has the new timeout time stored already.
632 ev->ms += curlx_tvdiff(after, before);
636 return CURLE_RECV_ERROR;
639 return CURLE_URL_MALFORMAT; /* TODO: return a proper error! */
641 /* we don't really care about the "msgs_in_queue" value returned in the
643 msg = curl_multi_info_read(multi, &pollrc);
645 result = msg->data.result;
656 * Runs a transfer in a blocking manner using the events-based API
658 static CURLcode easy_events(struct Curl_multi *multi)
660 struct events evs= {2, FALSE, 0, NULL, 0};
662 /* if running event-based, do some further multi inits */
663 events_setup(multi, &evs);
665 return wait_or_timeout(multi, &evs);
667 #else /* CURLDEBUG */
668 /* when not built with debug, this function doesn't exist */
669 #define easy_events(x) CURLE_NOT_BUILT_IN
672 static CURLcode easy_transfer(struct Curl_multi *multi)
675 CURLMcode mcode = CURLM_OK;
676 CURLcode result = CURLE_OK;
677 struct timeval before;
678 int without_fds = 0; /* count number of consecutive returns from
679 curl_multi_wait() without any filedescriptors */
681 while(!done && !mcode) {
682 int still_running = 0;
685 before = curlx_tvnow();
686 mcode = curl_multi_wait(multi, NULL, 0, 1000, &rc);
690 struct timeval after = curlx_tvnow();
692 /* If it returns without any filedescriptor instantly, we need to
693 avoid busy-looping during periods where it has nothing particular
695 if(curlx_tvdiff(after, before) <= 10) {
697 if(without_fds > 2) {
698 int sleep_ms = without_fds < 10 ? (1 << (without_fds - 1)) : 1000;
699 Curl_wait_ms(sleep_ms);
703 /* it wasn't "instant", restart counter */
707 /* got file descriptor, restart counter */
710 mcode = curl_multi_perform(multi, &still_running);
713 /* only read 'still_running' if curl_multi_perform() return OK */
714 if(!mcode && !still_running) {
715 CURLMsg *msg = curl_multi_info_read(multi, &rc);
717 result = msg->data.result;
723 /* Make sure to return some kind of error if there was a multi problem */
725 result = (mcode == CURLM_OUT_OF_MEMORY) ? CURLE_OUT_OF_MEMORY :
726 /* The other multi errors should never happen, so return
727 something suitably generic */
728 CURLE_BAD_FUNCTION_ARGUMENT;
736 * easy_perform() is the external interface that performs a blocking
737 * transfer as previously setup.
739 * CONCEPT: This function creates a multi handle, adds the easy handle to it,
740 * runs curl_multi_perform() until the transfer is done, then detaches the
741 * easy handle, destroys the multi handle and returns the easy handle's return
744 * REALITY: it can't just create and destroy the multi handle that easily. It
745 * needs to keep it around since if this easy handle is used again by this
746 * function, the same multi handle must be re-used so that the same pools and
747 * caches can be used.
749 * DEBUG: if 'events' is set TRUE, this function will use a replacement engine
750 * instead of curl_multi_perform() and use curl_multi_socket_action().
752 static CURLcode easy_perform(struct Curl_easy *data, bool events)
754 struct Curl_multi *multi;
756 CURLcode result = CURLE_OK;
757 SIGPIPE_VARIABLE(pipe_st);
760 return CURLE_BAD_FUNCTION_ARGUMENT;
763 failf(data, "easy handle already used in multi handle");
764 return CURLE_FAILED_INIT;
768 multi = data->multi_easy;
770 /* this multi handle will only ever have a single easy handled attached
771 to it, so make it use minimal hashes */
772 multi = Curl_multi_handle(1, 3);
774 return CURLE_OUT_OF_MEMORY;
775 data->multi_easy = multi;
778 /* Copy the MAXCONNECTS option to the multi handle */
779 curl_multi_setopt(multi, CURLMOPT_MAXCONNECTS, data->set.maxconnects);
781 mcode = curl_multi_add_handle(multi, data);
783 curl_multi_cleanup(multi);
784 if(mcode == CURLM_OUT_OF_MEMORY)
785 return CURLE_OUT_OF_MEMORY;
787 return CURLE_FAILED_INIT;
790 sigpipe_ignore(data, &pipe_st);
792 /* assign this after curl_multi_add_handle() since that function checks for
793 it and rejects this handle otherwise */
796 /* run the transfer */
797 result = events ? easy_events(multi) : easy_transfer(multi);
799 /* ignoring the return code isn't nice, but atm we can't really handle
800 a failure here, room for future improvement! */
801 (void)curl_multi_remove_handle(multi, data);
803 sigpipe_restore(&pipe_st);
805 /* The multi handle is kept alive, owned by the easy handle */
811 * curl_easy_perform() is the external interface that performs a blocking
812 * transfer as previously setup.
814 CURLcode curl_easy_perform(struct Curl_easy *data)
816 return easy_perform(data, FALSE);
821 * curl_easy_perform_ev() is the external interface that performs a blocking
822 * transfer using the event-based API internally.
824 CURLcode curl_easy_perform_ev(struct Curl_easy *data)
826 return easy_perform(data, TRUE);
832 * curl_easy_cleanup() is the external interface to cleaning/freeing the given
835 void curl_easy_cleanup(struct Curl_easy *data)
837 SIGPIPE_VARIABLE(pipe_st);
842 sigpipe_ignore(data, &pipe_st);
844 sigpipe_restore(&pipe_st);
848 * curl_easy_getinfo() is an external interface that allows an app to retrieve
849 * information from a performed transfer and similar.
851 #undef curl_easy_getinfo
852 CURLcode curl_easy_getinfo(struct Curl_easy *data, CURLINFO info, ...)
859 paramp = va_arg(arg, void *);
861 result = Curl_getinfo(data, info, paramp);
868 * curl_easy_duphandle() is an external interface to allow duplication of a
869 * given input easy handle. The returned handle will be a new working handle
870 * with all options set exactly as the input source handle.
872 struct Curl_easy *curl_easy_duphandle(struct Curl_easy *data)
874 struct Curl_easy *outcurl = calloc(1, sizeof(struct Curl_easy));
879 * We setup a few buffers we need. We should probably make them
880 * get setup on-demand in the code, as that would probably decrease
881 * the likeliness of us forgetting to init a buffer here in the future.
883 outcurl->set.buffer_size = data->set.buffer_size;
884 outcurl->state.buffer = malloc(CURL_BUFSIZE(outcurl->set.buffer_size) + 1);
885 if(!outcurl->state.buffer)
888 outcurl->state.headerbuff = malloc(HEADERSIZE);
889 if(!outcurl->state.headerbuff)
891 outcurl->state.headersize = HEADERSIZE;
893 /* copy all userdefined values */
894 if(Curl_dupset(outcurl, data))
897 /* the connection cache is setup on demand */
898 outcurl->state.conn_cache = NULL;
900 outcurl->state.lastconnect = NULL;
902 outcurl->progress.flags = data->progress.flags;
903 outcurl->progress.callback = data->progress.callback;
906 /* If cookies are enabled in the parent handle, we enable them
907 in the clone as well! */
908 outcurl->cookies = Curl_cookie_init(data,
909 data->cookies->filename,
911 data->set.cookiesession);
912 if(!outcurl->cookies)
916 /* duplicate all values in 'change' */
917 if(data->change.cookielist) {
918 outcurl->change.cookielist =
919 Curl_slist_duplicate(data->change.cookielist);
920 if(!outcurl->change.cookielist)
924 if(data->change.url) {
925 outcurl->change.url = strdup(data->change.url);
926 if(!outcurl->change.url)
928 outcurl->change.url_alloc = TRUE;
931 if(data->change.referer) {
932 outcurl->change.referer = strdup(data->change.referer);
933 if(!outcurl->change.referer)
935 outcurl->change.referer_alloc = TRUE;
938 /* Clone the resolver handle, if present, for the new handle */
939 if(Curl_resolver_duphandle(&outcurl->state.resolver,
940 data->state.resolver))
943 Curl_convert_setup(outcurl);
945 Curl_initinfo(outcurl);
947 outcurl->magic = CURLEASY_MAGIC_NUMBER;
949 /* we reach this point and thus we are OK */
956 curl_slist_free_all(outcurl->change.cookielist);
957 outcurl->change.cookielist = NULL;
958 Curl_safefree(outcurl->state.buffer);
959 Curl_safefree(outcurl->state.headerbuff);
960 Curl_safefree(outcurl->change.url);
961 Curl_safefree(outcurl->change.referer);
962 Curl_freeset(outcurl);
970 * curl_easy_reset() is an external interface that allows an app to re-
971 * initialize a session handle to the default values.
973 void curl_easy_reset(struct Curl_easy *data)
975 Curl_safefree(data->state.pathbuffer);
977 data->state.path = NULL;
979 Curl_free_request_state(data);
981 /* zero out UserDefined data: */
983 memset(&data->set, 0, sizeof(struct UserDefined));
984 (void)Curl_init_userdefined(&data->set);
986 /* zero out Progress data: */
987 memset(&data->progress, 0, sizeof(struct Progress));
989 /* zero out PureInfo data: */
992 data->progress.flags |= PGRS_HIDE;
993 data->state.current_speed = -1; /* init to negative == impossible */
997 * curl_easy_pause() allows an application to pause or unpause a specific
998 * transfer and direction. This function sets the full new state for the
999 * current connection this easy handle operates on.
1001 * NOTE: if you have the receiving paused and you call this function to remove
1002 * the pausing, you may get your write callback called at this point.
1004 * Action is a bitmask consisting of CURLPAUSE_* bits in curl/curl.h
1006 CURLcode curl_easy_pause(struct Curl_easy *data, int action)
1008 struct SingleRequest *k = &data->req;
1009 CURLcode result = CURLE_OK;
1011 /* first switch off both pause bits */
1012 int newstate = k->keepon &~ (KEEP_RECV_PAUSE| KEEP_SEND_PAUSE);
1014 /* set the new desired pause bits */
1015 newstate |= ((action & CURLPAUSE_RECV)?KEEP_RECV_PAUSE:0) |
1016 ((action & CURLPAUSE_SEND)?KEEP_SEND_PAUSE:0);
1018 /* put it back in the keepon */
1019 k->keepon = newstate;
1021 if(!(newstate & KEEP_RECV_PAUSE) && data->state.tempwrite) {
1022 /* we have a buffer for sending that we now seem to be able to deliver
1023 since the receive pausing is lifted! */
1025 /* get the pointer in local copy since the function may return PAUSE
1026 again and then we'll get a new copy allocted and stored in
1027 the tempwrite variables */
1028 char *tempwrite = data->state.tempwrite;
1030 data->state.tempwrite = NULL;
1031 result = Curl_client_chop_write(data->easy_conn, data->state.tempwritetype,
1032 tempwrite, data->state.tempwritesize);
1036 /* if there's no error and we're not pausing both directions, we want
1037 to have this handle checked soon */
1039 ((newstate&(KEEP_RECV_PAUSE|KEEP_SEND_PAUSE)) !=
1040 (KEEP_RECV_PAUSE|KEEP_SEND_PAUSE)) )
1041 Curl_expire(data, 0); /* get this handle going again */
1047 static CURLcode easy_connection(struct Curl_easy *data,
1049 struct connectdata **connp)
1052 return CURLE_BAD_FUNCTION_ARGUMENT;
1054 /* only allow these to be called on handles with CURLOPT_CONNECT_ONLY */
1055 if(!data->set.connect_only) {
1056 failf(data, "CONNECT_ONLY is required!");
1057 return CURLE_UNSUPPORTED_PROTOCOL;
1060 *sfd = Curl_getconnectinfo(data, connp);
1062 if(*sfd == CURL_SOCKET_BAD) {
1063 failf(data, "Failed to get recent socket");
1064 return CURLE_UNSUPPORTED_PROTOCOL;
1071 * Receives data from the connected socket. Use after successful
1072 * curl_easy_perform() with CURLOPT_CONNECT_ONLY option.
1073 * Returns CURLE_OK on success, error code on error.
1075 CURLcode curl_easy_recv(struct Curl_easy *data, void *buffer, size_t buflen,
1081 struct connectdata *c;
1083 result = easy_connection(data, &sfd, &c);
1088 result = Curl_read(c, sfd, buffer, buflen, &n1);
1099 * Sends data over the connected socket. Use after successful
1100 * curl_easy_perform() with CURLOPT_CONNECT_ONLY option.
1102 CURLcode curl_easy_send(struct Curl_easy *data, const void *buffer,
1103 size_t buflen, size_t *n)
1108 struct connectdata *c = NULL;
1110 result = easy_connection(data, &sfd, &c);
1115 result = Curl_write(c, sfd, buffer, buflen, &n1);
1118 return CURLE_SEND_ERROR;