OpenSSL: Sending and receiving data using SSL_write and SSL_read functions. What's the problem?

Hello!
Write a simple mail client for POP3s c++ using the openssl libraries.
When writing are faced with the following problem: after creating ssl connection to the server (for example, pop.mail.ru or pop.google.com with 995 port) and receiving confirmation, it is impossible to send the following command(e.g., user ) and make the response from the server. After sending data to SSL_write function, the program exits with code 0 in a minute. What could be the problem?

communicateWithPOP void(const int sock, const argValues* values){

 int bytes;
 string reply ;
 char buf[2048];

 SSL_CTX *ctx;
 SSL* ssl;
SSL_library_init();
 ctx = InitCTX();
 ssl = SSL_new(ctx);
 SSL_set_fd(ssl, sock);
SSL_CTX_set_default_verify_paths(ctx);


 if(SSL_connect(ssl) == -1)
ERR_print_errors_fp(stderr);

else{

 string nameReq = "user usr";
 bytes = SSL_read(ssl,buf,sizeof(buf));
 buf[bytes] = 0;
 cout << "[CONNECTION] : "<< buf << endl;
 memset(buf,0, sizeof(buf));

 int sslwRet = SSL_write(ssl, nameReq.c_str(), strlen(nameReq.c_str()));
 cout << "SSL_write ret :" << sslwRet << endl;

 bytes = SSL_read(ssl, buf, sizeof(buf));
 cout << "SSL_read ret :" << bytes << endl;

SSL_free(ssl);

}

close(sock);
SSL_CTX_free(ctx);
}

59db91d8df3ba542611459.jpeg
June 14th 19 at 18:23
0 answer

Find more questions by tags CC++OpenSSL