cURL / Mailing Lists / curl-library / Single Mail

curl-library

Getting the error Failed to get recent socket, Unsupported protocol while establishing HTTPS connection

From: ankit Tripathi <erankit0903_at_gmail.com>
Date: Mon, 5 Mar 2012 17:23:43 +0530

Hi ,
I am trying to establish HTTPS connection with some url by using libcurl.
For sending and receiving message i am using curl_easy_send and curl_easy
_recv .i am to able to send the msg . after waiting on the wait_on_socket
function for receiving the response from PEER it is throwing the error 1)
" Failed to get recent socket "
2)"Unsupported protocol " .while waiting on socket for the receiving first
it wait around 15 to 20 sec and then it trows the error.i am providing here
the test application in which i am making https connection with google.com.
after waiting on socket for 15-20 sec it throws the error 1)" Failed to
get recent socket "
2)"Unsupported protocol " .i tried to googling but i didn't found much
.please help me out as soon as possible.i am also providing the test
application below.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 3 #include <stdio.h>
  4 #include <string.h>
  5 #include <curl/curl.h>
  6
  7
  8 /* Auxiliary function that waits on the socket. */
  9 static int wait_on_socket(curl_socket_t sockfd, int for_recv, long
timeout_ms)
 10 {
 11 struct timeval tv;
 12 fd_set infd, outfd, errfd;
 13 int res;
 14
 15 tv.tv_sec = timeout_ms / 1000;
 16 tv.tv_usec= (timeout_ms % 1000) * 1000;
 17
 18 FD_ZERO(&infd);
 19 FD_ZERO(&outfd);
 20 FD_ZERO(&errfd);
 21
 22 FD_SET(sockfd, &errfd); /* always check for error */
 23
 24 if(for_recv)
 25 {
 26 FD_SET(sockfd, &infd);
 27 res = select(sockfd + 1, &infd, &outfd, &errfd, NULL); /*Setting
NULL for waiting upto infinite time*/
 28 }
 29 else
 30 {
 31 FD_SET(sockfd, &outfd);
 32 res = select(sockfd + 1, &infd, &outfd, &errfd, &tv);
 33 }
 34
       36 return res;
 37 }
 38
 39 int main(void)
 40 {
 41 CURL *curl;
 42 CURLcode res;
 43 curl_socket_t sockfd; /* socket */
 44 long sockextr;
 45 size_t iolen;
 46
 47 curl = curl_easy_init();
 48 if(curl) {
 49 curl_easy_setopt(curl, CURLOPT_URL, "https://google.com:443");
 50 /* Do not do the transfer - only connect to host */
 51 curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 1L);
 52 curl_easy_setopt(curl,CURLOPT_SSL_VERIFYPEER,1L);
 53 curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 2L);
 54 curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
 55 res = curl_easy_perform(curl);
 56
 57 if(CURLE_OK != res)
 58 {
 59 printf("Error: %s\n", curl_easy_strerror(res));
 60 return 1;
 61 }
 62
                      /* Extract the socket from the curl handle */
 65
 66 res = curl_easy_getinfo(curl, CURLINFO_LASTSOCKET, &sockextr);
 67
 68 if(CURLE_OK != res)
 69 {
 70 printf("Error: %s\n", curl_easy_strerror(res));
 71 return 1;
 72 }
 73 sockfd = sockextr;
 74
 75
 76 while(1)
 77 {
 78 char buf[1024];
 79 printf("\nwaiting for recv msg\n");
 80 int s=wait_on_socket(sockfd, 1, 60000L);
 81 printf("\nno of socket %d return to read\n",s);
 82 res = curl_easy_recv(curl, buf, 1024, &iolen);
 83
 84 if(CURLE_OK != res)
 85 {
 86 printf("Error in recv: %s\n", curl_easy_strerror(res));
 87 break;
 88 }
 89 printf("Received %d bytes.data %s\n", iolen,buf);
 90 }
 91
 92 curl_easy_cleanup(curl);
 93 }
 94 return 0;
 95 }

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
i am also providing the o/p which i am getting on the console
..............
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
* About to connect() to google.com port 443 (#0)
* Trying 74.125.236.73...
* connected
* Connected to google.com (74.125.236.73) port 443 (#0)
* successfully set certificate verify locations:
* CAfile: /etc/pki/tls/certs/ca-bundle.crt
  CApath: none
* SSL connection using RC4-SHA
* Server certificate:
* subject: C=US; ST=California; L=Mountain View; O=Google Inc; CN=*.
google.com
* start date: 2012-02-16 10:38:09 GMT
* expire date: 2013-02-16 10:48:09 GMT
* subjectAltName: google.com matched
* issuer: C=US; O=Google Inc; CN=Google Internet Authority
* SSL certificate verify ok.
* Connection #0 to host google.com left intact

waiting for recv msg

no of socket 1 return to read
* Failed to get recent socket
Error in recv: Unsupported protocol
* Closing connection #0
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

My application is like that where it has to wait for message from PEER
without any time limit.....

Thanks
ANKIT TRIPATHI

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2012-03-05