> No. I don't like blocking sockets because it's very hard to get them > >right....
Experience, how EASY it could be done in nonblocking mode is what i'm currently correlating with your words. ... let's cut this this thread. I've droped idea of using third party components and now i'm writing code at lowest level. But it not takes to long to stuck at some point. Here is my problem: When connection is in non-blocking mode 'SSL_read' and 'SSL_write' can return 'SSL_ERROR_WANT_WRITE' or 'SSL_ERROR_WANT_READ'. This means that command should be repeated some time later. In unix environment you can use 'select' statement to block until desired condition is valid. On unix you can have 2 handles - one socket and one pipe(for communication from another thread), so 'select' blocks until one of the following events is met: 1.'Read' from the socket is signaled(data on the wire) 2.'Read' from the pipe is signaled(user wants to send something) 3.'Write' from to socket is signaled(socket is ready to send data, obtained first from user by pipe) and this example is covered for example in 's_client.c' file in openSSL source tree. (or in examples from ....) But unfortunataly it is not valid under windows. 'select' function under windows accepts only sockets from the same provider(TCP provider in my example), so you cannot mix pipes and sockets in the same 'select' statement. So if you want use 'select' you have to choices: 1. use 'select' with time intervals and poll the pipe (LAME) 2. open internal TCP connection from thread to another (VERY LAME) Windows has special API to deals with such kind of architecture. There are two main functions: WSAAsyncSelect and WSAEventSelect (and helper functions). I'm using secon one. It works like this: 1. WSAEventSelect associates network events from some socket with event object. When some those events occurs on the socket (for example: FD_READ,FD_WRITE...) windows signals event object. 2. User creates own event object and signals it when he wants to send some data 3. Communication thread invokes WaitForMultipleObjects function with socket event and user event as arguments. Function blocks until there is something to do (read data, send data, etc.) It works good (for unencrypted sockets of course) but unfortunately in another way then someone may think. 'select' statement returns immediately when desired condition is met - for example you are waiting for some data to arrive and this data arrives 'select' returns, if you will not read this data and you will invoke 'select' again it returns immediately because there is still data to read. The same is for write. 'select' returns if there is possibility to send data. For windows events it works like this: Thread is waiting for read condition to be met - for example it is waiting for some data to arrive. Data arrives, and thread weaks up. It signals that there is some data, but if you will not read this data and You will decide to wait again thread will not wake up !!! Windows supposes that you were noticed about some event and there is no need to notice you again. For write event it is much worst. Windows supposes that you can always write to socket and only when some special error occurs (WSAEWOULDBLOCK) it signals possibility to write when problem disappears. In practice it is more complicated, socket functions (send,recv) change internally some states. It is written in windows help files how it works (check MSDN for detailed explanation). It works good if you have control over issued commands. But if you are using third party components like openSSL which use some functions internally (recv,send) it is very complicated to predict behaviour of code. For example if return value from SSL_write is SSL_ERROR_WANT_WRITE what should I do? if SSL_write failed because send(used internally by openSSL) has returned WSAEWOULDBLOCK then I can wait for FD_WRITE condition to be met, but if it has failed from another reason waiting function will block.... I don't known which socket functions are issued by openSSL command, how many times and what are the error codes. It,s ill, really ill..... I have no force to write.... (I have some idea how it could be done (mix wit 'select') but first i try to ask someone) David, do you have any reference example how it should be done in windows environment??? Lucas ______________________________________________________________________ OpenSSL Project http://www.openssl.org User Support Mailing List openssl-users@openssl.org Automated List Manager [EMAIL PROTECTED]