void httpreq_on_connect(uv_connect_t* con, int status) { if(status == -1) { printf("ERROR: httpreq_on_connect, cannot connect. @todo clean memory\n"); return; } HTTPRequest* req = static_cast<HTTPRequest*>(con->data); int result = uv_read_start((uv_stream_t*)&req->tcp_req, httpreq_alloc, httpreq_on_read); if(result == -1) { printf("ERROR: uv_read_start() error: %s\n", uv_err_name(uv_last_error(req->loop))); return; } if(!req->is_secure) { req->sendData(&req->out_buffer[0], req->out_buffer.size()); } else { req->ssl = SSL_new(req->ssl_ctx); req->ssl_buffer.addApplicationData(&req->out_buffer[0],req->out_buffer.size()); SSL_set_connect_state(req->ssl); SSL_do_handshake(req->ssl); req->ssl_buffer.init(req->ssl, ssl_write_to_socket, req, ssl_read_decrypted, req); req->ssl_buffer.update(); } }
// ----------------------------------------------- // UV AND SSL CALLBACKS // ----------------------------------------------- void ssl_write_to_socket(const char* data, size_t len, void* user) { HTTPRequest* req = static_cast<HTTPRequest*>(user); req->sendData(data, len); }