Hello, Here is my test code. I am downloading a file with https connection. This is compiled as $g++ -lssl -lcrypto sslShow.cpp. on OS X 10.5.8 Using default OS X libs (libcrypto 0.9.7 and libssl 0.9.7)
When it has downloaded some 2MB data, I closed my laptop lid (OSX induced sleep) After 5 minutes when i open my laptop, the process hangs at the same place as before. I have reproduced the same with latest 0.9.8k version also. Please suggest. 1. What i should include in this code to correct this hang? 2. How to set read/write timeouts? Thanks a lot guys. (the Test Code & Call Trace is as follows ) ============CALL TRACE======= Call graph: 811 Thread_2507 811 start 811 main 811 BIO_read 811 ssl_read 811 ssl3_read_internal 811 ssl3_read_bytes 811 ssl3_read_n 811 BIO_read 811 read$UNIX2003 811 read$UNIX2003 ============================MY TEST CODE ===================== #include <openssl/ssl.h> #include <openssl/err.h> #include <openssl/bio.h> #include <iostream> #define MAX_PACKET_SIZE 10000 int main() { BIO * bio; SSL * ssl; SSL_CTX * ctx; /* Initializing OpenSSL */ SSL_load_error_strings(); ERR_load_BIO_strings(); OpenSSL_add_all_algorithms(); SSL_library_init(); //mandatory and missing from some examples ctx = SSL_CTX_new(SSLv23_client_method()); if (ctx == NULL) { std::cout << "Ctx is null" << std::endl; ERR_print_errors_fp(stderr); } //using a store from examples if(! SSL_CTX_load_verify_locations(ctx, "/Users/pd/workspace/openssl/TrustStore.pem", NULL)) { /* Handle failed load here */ std::cout << "Faild load verify locations" << std::endl; } bio = BIO_new_ssl_connect(ctx); BIO_get_ssl(bio, & ssl); SSL_set_mode(ssl, SSL_MODE_AUTO_RETRY); //replace with your own test server BIO_set_conn_hostname(bio, "www.myDomain.com:https"); if(BIO_do_connect(bio) <= 0) { std::cout<<"Failed connection" << std::endl; } else { std::cout<<"Connected" << std::endl; } if(SSL_get_verify_result(ssl) != X509_V_OK) { /* Handle the failed verification */ std::cout << "Failed get verify result " << std::endl; fprintf(stderr, "Certificate verification error: %i\n", SSL_get_verify_result(ssl)); //do not exit here (but some more verification would not hurt) because if you are using a self-signed certificate you will receive 18 //18 X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT which is not an error } char *write_buf = "GET /downloads/goodApp.exe / HTTP/1.0\n\n"; if(BIO_write(bio, write_buf, strlen(write_buf)) <= 0){ if(! BIO_should_retry(bio)){ /* Handle failed write here */ } /* Do something to handle the retry */ std::cout << "Failed write" << std::endl; } char buf[MAX_PACKET_SIZE]; int p; char r[1024]; FILE *fp; fp = fopen("something.abc", "a+"); for(;;){ p = BIO_read(bio, r, 1023); if(p <= 0) break; r[p] = 0; fprintf(fp, "%s", r); } fclose(fp); std::cout << "Done reading" << std::endl; /* To free it from memory, use this line */ ERR_print_errors_fp(stderr); BIO_free_all(bio); } return 0; } On Thu, Oct 29, 2009 at 4:57 PM, David Schwartz <dav...@webmaster.com>wrote: > > Parimal Das wrote: > > > Its the second case Darry, > > Here the 'sleep' is Operating System Sleep mode induced by closing the > lid > of laptop. > > After opening the laptop, when the system wakes up, > > My application is always hanging at the same place. > > Bug is in your code. It is doing what you asked it do -- waiting up to > forever for data from the other side. The other side will never send > anything because it has long forgotten about the connection. Your > application will never send anything because it is blocked in a read > function. TCP and UDP will do the same thing if you call 'read' or 'recv' > and block for data that will never arrive. > > DS > > > > ______________________________________________________________________ > OpenSSL Project http://www.openssl.org > User Support Mailing List openssl-users@openssl.org > Automated List Manager majord...@openssl.org > -- -- Warm Regards, Parimal Das