Commit 514592b8 authored by Daniel Stenberg's avatar Daniel Stenberg
Browse files

- Introducing curl_easy_send() and curl_easy_recv(). They can be used to send

  and receive data over a connection previously setup with curl_easy_perform()
  and its CURLOPT_CONNECT_ONLY option. The sendrecv.c example was added to
  show how they can be used.
parent d72efff8
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -7,6 +7,12 @@
                                  Changelog


Daniel Stenberg (9 May 2008)
- Introducing curl_easy_send() and curl_easy_recv(). They can be used to send
  and receive data over a connection previously setup with curl_easy_perform()
  and its CURLOPT_CONNECT_ONLY option. The sendrecv.c example was added to
  show how they can be used.

Yang Tse (9 May 2008)
- Internal time differences now use monotonic time source if available.
  This also implies the removal of the winmm.lib dependency for WIN32.
+3 −2
Original line number Diff line number Diff line
@@ -3,8 +3,8 @@ Curl and libcurl 7.18.2
 Public curl releases:         105
 Command line options:         126
 curl_easy_setopt() options:   150
 Public functions in libcurl:  56
 Public web site mirrors:      39
 Public functions in libcurl:  58
 Public web site mirrors:      37
 Known libcurl bindings:       36
 Contributors:                 636

@@ -14,6 +14,7 @@ This release includes the following changes:
 o CURLOPT_NOBODY is now supported over SFTP
 o curl can now run on Symbian OS
 o curl -w redirect_url and CURLINFO_REDIRECT_URL
 o added curl_easy_send() and curl_easy_recv()

This release includes the following bugfixes:

+2 −1
Original line number Diff line number Diff line
@@ -4,7 +4,8 @@ check_PROGRAMS = 10-at-a-time anyauthput cookie_interface \
  getinfo getinmemory http-post httpput \
  https multi-app multi-debugcallback multi-double \
  multi-post multi-single persistant post-callback \
  postit2 sepheaders simple simplepost simplessl
  postit2 sepheaders simple simplepost simplessl \
  sendrecv

# These examples require external dependencies that may not be commonly
# available on POSIX systems, so don't bother attempting to compile them here.
+117 −0
Original line number Diff line number Diff line
/*****************************************************************************
 *                                  _   _ ____  _
 *  Project                     ___| | | |  _ \| |
 *                             / __| | | | |_) | |
 *                            | (__| |_| |  _ <| |___
 *                             \___|\___/|_| \_\_____|
 *
 * An example of curl_easy_send() and curl_easy_recv() usage.
 *
 * $Id$
 */

#include <stdio.h>
#include <string.h>
#include <curl/curl.h>

/* Auxiliary function that waits on the socket. */
static int wait_on_socket(int sockfd, int for_recv, long timeout_ms)
{
  struct timeval tv;
  long seconds, usecs;
  fd_set infd, outfd, errfd;
  int res;

  tv.tv_sec = timeout_ms / 1000;
  tv.tv_usec= (timeout_ms % 1000) * 1000;

  FD_ZERO(&infd);
  FD_ZERO(&outfd);
  FD_ZERO(&errfd);

  FD_SET(sockfd, &errfd); /* always check for error */

  if(for_recv)
  {
    FD_SET(sockfd, &infd);
  }
  else
  {
    FD_SET(sockfd, &outfd);
  }

  /* select() returns the number of signalled sockets or -1 */
  res = select(sockfd + 1, &infd, &outfd, &errfd, &tv);
  return res;
}

int main(void)
{
  CURL *curl;
  CURLcode res;
  /* Minimalistic http request */
  const char *request = "GET / HTTP/1.0\r\nHost: curl.haxx.se\r\n\r\n";
  int sockfd; /* socket */
  size_t iolen;

  curl = curl_easy_init();
  if(curl) {
    curl_easy_setopt(curl, CURLOPT_URL, "curl.haxx.se");
    /* Do not do the transfer - only connect to host */
    curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 1L);
    res = curl_easy_perform(curl);

    if(CURLE_OK != res)
    {
      printf("Error: %s\n", strerror(res));
      return 1;
    }

    /* Extract the socket from the curl handle - we'll need it
     * for waiting */
    res = curl_easy_getinfo(curl, CURLINFO_LASTSOCKET, &sockfd);

    if(CURLE_OK != res)
    {
      printf("Error: %s\n", strerror(res));
      return 1;
    }

    /* wait for the socket to become ready for sending */
    if(!wait_on_socket(sockfd, 0, 60000L))
    {
      printf("Error: timeout.\n");
      return 1;
    }

    puts("Sending request.");
    /* Send the request. Real applications should check the iolen
     * to see if all the request has been sent */
    res = curl_easy_send(curl, request, strlen(request), &iolen);

    if(CURLE_OK != res)
    {
      printf("Error: %s\n", strerror(res));
      return 1;
    }
    puts("Reading response.");

    /* read the response */
    for(;;)
    {
      char buf[1024];

      wait_on_socket(sockfd, 1, 60000L);
      res = curl_easy_recv(curl, buf, 1024, &iolen);

      if(CURLE_OK != res)
        break;

      printf("Received %u bytes.\n", iolen);
    }

    /* always cleanup */
    curl_easy_cleanup(curl);
  }
  return 0;
}
+5 −3
Original line number Diff line number Diff line
@@ -19,7 +19,7 @@ man_MANS = curl_easy_cleanup.3 curl_easy_getinfo.3 curl_easy_init.3 \
 libcurl-tutorial.3 curl_easy_reset.3 curl_easy_escape.3		 \
 curl_easy_unescape.3 curl_multi_setopt.3 curl_multi_socket.3		 \
 curl_multi_timeout.3 curl_formget.3 curl_multi_assign.3		 \
 curl_easy_pause.3
 curl_easy_pause.3 curl_easy_recv.3 curl_easy_send.3

HTMLPAGES = curl_easy_cleanup.html curl_easy_getinfo.html		  \
 curl_easy_init.html curl_easy_perform.html curl_easy_setopt.html	  \
@@ -37,7 +37,8 @@ HTMLPAGES = curl_easy_cleanup.html curl_easy_getinfo.html \
 curl_share_strerror.html curl_global_init_mem.html libcurl-tutorial.html \
 curl_easy_reset.html curl_easy_escape.html curl_easy_unescape.html	  \
 curl_multi_setopt.html curl_multi_socket.html curl_multi_timeout.html	  \
 curl_formget.html curl_multi_assign.html curl_easy_pause.html
 curl_formget.html curl_multi_assign.html curl_easy_pause.html \
 curl_easy_recv.html curl_easy_send.html

PDFPAGES = curl_easy_cleanup.pdf curl_easy_getinfo.pdf curl_easy_init.pdf \
 curl_easy_perform.pdf curl_easy_setopt.pdf curl_easy_duphandle.pdf	  \
@@ -54,7 +55,8 @@ PDFPAGES = curl_easy_cleanup.pdf curl_easy_getinfo.pdf curl_easy_init.pdf \
 curl_share_strerror.pdf curl_global_init_mem.pdf libcurl-tutorial.pdf	  \
 curl_easy_reset.pdf curl_easy_escape.pdf curl_easy_unescape.pdf	  \
 curl_multi_setopt.pdf curl_multi_socket.pdf curl_multi_timeout.pdf	  \
 curl_formget.pdf curl_multi_assign.pdf curl_easy_pause.pdf
 curl_formget.pdf curl_multi_assign.pdf curl_easy_pause.pdf \
 curl_easy_recv.pdf curl_easy_send.pdf

CLEANFILES = $(HTMLPAGES) $(PDFPAGES)

Loading