All who have answered: Thanks a lot. Yes, I understood that the poll() should read to a buffer last night, in the shower. You know how that works ;). But I also understood that I had misunderstood the way the "poll" and "read" methods were being used, and "read" will be called no matter what "poll" returns, until all the data has been received, or an error is returned, so it's fine,
Now, I've finished the core coding of the thing up to the point where I can actually test things.. and it doesn't work. SSL_Connect doesn't succeed, and my read and write functions are never called. Here's some sample code, if anyone cares for checking what might I be missing... I'm sure it's a quite stupid mistake, but I just can't figure it out, never having coded OSSL apps before. There's quite a lot of non-standard methods, but their working is pretty straight forward. All I'm doing is creating an SSL_Client instance and trying to a nssl listening in localhost:8888, the socket gets connected, but the prints in BIO_larvita_write and _read are never done, and I'm guessing those are used for the handshake. SSL_Connect returns with -2 and the printf("%s\n",ERR_error_string(err,NULL)); spits this: error:00000001:lib(0):func(0):reason(1). static BIO_METHOD larvita_method = { BIO_TYPE_LARVITA, "larvita socket", larvita_write, larvita_read, NULL, NULL, NULL, larvita_new, larvita_free, NULL, }; static int larvita_write(BIO* bio, const char* buf, int len) { printf("larvita_write(%s)\n",buf); int ret; //clear_sys_error(); ret = ((TCP_Client*)bio->ptr)->send_data((Uint8*)buf,len); BIO_clear_retry_flags(bio); if(ret == 0) { BIO_set_retry_write(bio); } return ret; } static int larvita_read(BIO* b, char* out, int len) { printf("larvita_read()\n"); int ret = 0; BIO_clear_retry_flags(b); ret = ((TCP_Client*)b->ptr)->read((Uint8*)out,len); if(ret == 0) { BIO_set_retry_read(b); } return ret; } static int larvita_new(BIO* bio) { bio->init = 0; bio->num = 0; bio->ptr = NULL; bio->flags = 0; return 1; } static int larvita_free(BIO* bio) { if(bio == NULL) return 0; if(bio->shutdown) { if(bio->init) { if(bio->ptr) { memdelete((TCP_Client*)bio->ptr); bio->ptr = NULL; } } bio->init = 0; bio->flags = 0; } return 1; } BIO_METHOD *BIO_s_larvita_client(){ return (&larvita_method); } BIO *BIO_new_larvita_client(TCP_Client* client){ BIO* ret = NULL; if((ret = BIO_new(BIO_s_larvita_client()))) { ret->ptr = client; } return ret; } Error SSL_Client::connect_to_host(String p_host,int p_port) { printf("ssl connecting to host %s:%d\n",p_host.ascii().get_data(),p_port); Error ret = this->client->connect_to_host(p_host,p_port); printf("connected? err: %d\n",ret); if(ret == OK) { int err; while((err = SSL_connect(this->ssl)) < 0) { printf("err = %d\n",err); switch((err = SSL_get_error(this->ssl,err))) { case SSL_ERROR_WANT_READ: break; case SSL_ERROR_WANT_WRITE: break; default: printf("%s\n",ERR_error_string(err,NULL)); break; } } printf("ssl opened? err: %d\n",err); } return ret; } SSL_CTX* SSL_Client::ctx = NULL; void SSL_Client::initialize_ctx() { SSL_library_init(); SSL_load_error_strings(); ERR_load_crypto_strings(); SSL_Client::ctx = SSL_CTX_new(SSLv23_method()); SSL_CTX_set_cipher_list(SSL_Client::ctx,CIPHERS_LIST); } SSL_Client::SSL_Client() { if(!SSL_Client::ctx) SSL_Client::initialize_ctx(); this->client = TCP_Client::create(); this->ssl = SSL_new(this->ctx); this->bio = BIO_new_larvita_client(this->client); SSL_set_bio(this->ssl,this->bio,this->bio); SSL_set_connect_state(this->ssl); } -- |_|0|_| |_|_|0| |0|0|0| (\__/) (='.'=)This is Bunny. Copy and paste bunny (")_(") to help him gain world domination. ______________________________________________________________________ OpenSSL Project http://www.openssl.org User Support Mailing List openssl-users@openssl.org Automated List Manager [EMAIL PROTECTED]