> 
> If OpenSSL is unable to perform an operation, that means it tried it and 
> couldn't do it. If that operation was a write, then when it becomes possible, 
> you will get a write event. If that operation wasn't a write, then who cares 
> when a write becomes possible?
> 


Maybe I show it using simple pseudocode (arguments to functions are not exactly 
as in real implementation and some function are simplifed versions of real one, 
some functions are omitted):

<--- PSEUDO CODE -------->

bool WaitOnWrite = false;
int res;

// it associates FD_WRITE event with SockEvent object

  WSAEventSelect(sock,SockEvent,FD_WRITE);

for (;;)
{

  if (WaitOnWrite) 
    WaitForMultipleObjects(SockEvent)
  else          
    WaitForMultipleObjects(UserEvent);


  res = SSL_write(sock,userBuf,len);
  res = SSL_get_error(sock,res);

  switch(res)
  { 
    case SSL_ERROR_NONE:
      WaitOnWrite = false;
      break;

    case SSL_ERROR_WANT_WRITE:
      WaitOnWrite = false;
      break;
  }
}

<--- PSEUDO CODE END -------->

The code above works like this: When it starts it waits for data from user
(user signals when he wants to send some data by setting UserEvent), then 
SSL_write sends data from userBuf, if SS_write will success then procedure is 
repeated if not program will wait for FD_WRITE event to occur. But 
unfortunately it can deadlock. Why? Because there is clearly specified in 
windows help that FD_WRITE event only will be send if previous invoke of 'send' 
function will fail with WSAEWOULDBLOCK error. (if you don't issue 'send' or 
'send' will fail from other reason, FD_WRITE will not be send!). So I have to 
know, what reason 'SSL_write' failed or I can deadlock. If i use nonencrypted 
connection(Winsock API) it's not a problem. After 'send' command I can check 
error by using 'GetLastError'command. But if I use OpenSSL ('SSL_write' 
replaces 'send') the only message I will get is SSL_ERROR_WANT_WRITE. SSL_write 
can internaly issue 'send' a couple of times, it can clear or modify windows 
last error code, SSL_ERROR_WANT_WRITE can be generated from other reason then 
underlaying winsock failur (internal OpenSSL logic), finally 'send' may fail 
from other reason then WSAEWOULDBLOCK. Now, I hope, it's clear for you.

Conclusion:
OpenSSL is designed to work with 'select' statement. In windows environment 
'select' can not be used, and native windows API for waiting on multiple 
objects seems to be incompatibile with openSSL (i should rather say OpenSSL is 
incompatibile with windows). Writing applications that perform asynchronous IO 
operations (interleaving input and outputs) seems to questionable. That's my 
opinion - nobody shows me working code so far.(timeouts and polling are rather 
for testing then for serious code)

> 
> I don't get it. Why are you back on how to tell when a socket event occured? 
> I thought you had solved that problem by using events.
> 

No,no. All the time i've tried to show you that I haven't. I have said that I 
have an idea, but this is only my idea, it's not simple using of windows events 
but rather special mixing windows events with 'select' statements, it has 
rather complex logic, it has several drawbacks (in normal usage it generates 
sometimes some unnecessary function invokations and when something goes wrong i 
have to kill the thread or close connection from other (but i have to do it in 
reason of serious  failure, not normal usage)) and this is connected with logic 
of my application (for other purpouses this method is not suitable - especially 
for server code). If I have no choice i will use it, but it's always worth to 
try something better...

Lucas
______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    openssl-users@openssl.org
Automated List Manager                           [EMAIL PROTECTED]

Reply via email to