* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2016, 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
- * are also available at http://curl.haxx.se/docs/copyright.html.
+ * are also available at https://curl.haxx.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* KIND, either express or implied.
*
***************************************************************************/
-/* An example of curl_easy_send() and curl_easy_recv() usage. */
+/* <DESC>
+ * An example of curl_easy_send() and curl_easy_recv() usage.
+ * </DESC>
+ */
#include <stdio.h>
#include <string.h>
FD_SET(sockfd, &errfd); /* always check for error */
- if(for_recv)
- {
+ if(for_recv) {
FD_SET(sockfd, &infd);
}
- else
- {
+ else {
FD_SET(sockfd, &outfd);
}
size_t iolen;
curl_off_t nread;
+ /* A general note of caution here: if you're using curl_easy_recv() or
+ curl_easy_send() to implement HTTP or _any_ other protocol libcurl
+ supports "natively", you're doing it wrong and you should stop.
+
+ This example uses HTTP only to show how to use this API, it does not
+ suggest that writing an application doing this is sensible.
+ */
+
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "http://example.com");
curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 1L);
res = curl_easy_perform(curl);
- if(CURLE_OK != res)
- {
+ if(CURLE_OK != res) {
printf("Error: %s\n", strerror(res));
return 1;
}
*/
res = curl_easy_getinfo(curl, CURLINFO_LASTSOCKET, &sockextr);
- if(CURLE_OK != res)
- {
+ if(CURLE_OK != res) {
printf("Error: %s\n", curl_easy_strerror(res));
return 1;
}
- sockfd = sockextr;
+ sockfd = (curl_socket_t)sockextr;
/* wait for the socket to become ready for sending */
- if(!wait_on_socket(sockfd, 0, 60000L))
- {
+ if(!wait_on_socket(sockfd, 0, 60000L)) {
printf("Error: timeout.\n");
return 1;
}
* to see if all the request has been sent */
res = curl_easy_send(curl, request, strlen(request), &iolen);
- if(CURLE_OK != res)
- {
+ if(CURLE_OK != res) {
printf("Error: %s\n", curl_easy_strerror(res));
return 1;
}
puts("Reading response.");
/* read the response */
- for(;;)
- {
+ for(;;) {
char buf[1024];
wait_on_socket(sockfd, 1, 60000L);