Title: SSL_connect(....) hangs

i am sorry for my mistake in SSL_read(...) in the foll. mail which i posted just now.
the call is num = SSL_read(m_pSSL,&response,1);
and takes 1 character at a time
sorry for the mistake but the problem remans the same
thanx
meenakshi

 -----Original Message-----
From:   Arora Meenakshi 
Sent:   Tuesday, June 06, 2000 3:59 PM
To:     Openssl-Users (E-mail)
Cc:     'WINSOCK-2 (E-mail)
Subject:        SSL_connect(....) hangs

i am trying to connect to a secured server using the foll. code...
The SSL_connect call hangs sometimes. Even if The SSL_connect works fine the SSL_read(...) hangs up. i am totally confused as the same piece of code works fine for my other application. if anyone has any suggestions pls. reply soon


        SSLeay_add_ssl_algorithms();
        RAND_screen();
        WORD versionRequested = MAKEWORD(2,2);
        WSADATA wsaData;
        int ret = 0;
        if((ret = WSAStartup(versionRequested,&wsaData)) != 0)
                ThrowCertInternetException();
        // create a SSL structure
        m_pMethod = SSLv2_client_method();
        if((m_pSSLContext = SSL_CTX_new(m_pMethod)) == 0x00)
                ThrowCertInternetException();

        // Create a socket and connect to server 
        if((m_socketDescriptor = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP)) == INVALID_SOCKET)
                ThrowCertInternetException();

        m_sockAddr.sin_family = AF_INET;
        m_sockAddr.sin_port = htons(443);
        m_sockAddr.sin_addr.s_addr = GetAddr((char*)a_pServer);
        // connect it to the server
        if((ret = connect(m_socketDescriptor,(struct sockaddr*)&m_sockAddr,sizeof(sockaddr))) == SOCKET_ERROR)
                ThrowCertInternetException();


        // Now we have TCP conncetion. Start SSL negotiation.
        if((m_pSSL = SSL_new(m_pSSLContext)) == 0x00)
                ThrowCertInternetException();
        //set the file descriptor
        SSL_set_fd (m_pSSL, m_socketDescriptor);
        if((ret = SSL_connect(m_pSSL)) == -1)
                ThrowCertInternetException();


..................
        int ret = SSL_write(m_pSSL,req,strlen(req));
        if(ret == SOCKET_ERROR)
                return 0x00;

        // get the response
        int num = 0;
        data = new char[MAX_DATA];
        int index = 0;
        char response;
        while(1)
        {
                num = SSL_read(m_pSSL,&response,1024);
                if(num == SOCKET_ERROR)
                        return 0x00;
                if(num == 0)
                        break;
                data[index++] = response;
        }

thanx
meenakshi

Reply via email to