i am hoping win32 developers can lend out a hand. i cannot determine 
how to handle SSL_read and SSL_write using WSAAsyncSelect.


for example:

if i create a socket, and register it with WSAAsyncSelect for
FD_READ and FD_WRITE, i can generate a windows' message map
like the following:

[in this not so real world example, lets say when i want to send
something, szSendBuf is "magically" filled, and szRecvBuf will 
be "magically" filled.]

=============================================
LRESULT CALLBACK SockWndProc(HWND hwnd, UINT uiMsg, WPARAM wParam, LPARAM 
lParam)
{
  SOCKET hSock;
  WORD wWSAEvent, wWSAErr;

  static char szRecvBuf[1024];
  static char szSendBuf[5][1024];  // queue of 5 items.

  switch (uiMsg)
  {
  case WM_WSANOTIFY:
    hSock = static_cast<SOCKET>(wParam);
    wWSAEvent = WSAGETSELECTEVENT(lParam);
    wWSAErr = WSAGETSELECTERROR(lParam);

    switch (wWSAEvent)
    {
      case FD_READ:
      ...  do something with SSL_read here such as 
                if (SSL_pending())
                        SSL_read(m_ssl, szRecvBuf, 1024)
      break;

    case FD_WRITE:
      if (sendqueue.getLength() > 0)
      ...  do something with SSL_write here
                SSL_write(m_ssl, szSendBuf, 1024)
      break;
    }
    break;

  ...
  }
  return DefWindowProc(hwnd, uiMsg, wParam, lParam);
}
=============================================

here is where i get stumped.

1)  should i first check wWSAErr for WSAEWOULDBLOCK, or
not do this after a call to SSL_read?  or do it at all?

2)  if i call SSL_read, and it generates an error, that SSL_get_error
later reports as 
        - SSL_ERROR_WANT_WRITE
                do i just break out of the FD_READ case
                or should i loop here and keep calling SSL_read?
                if i break the case statement, will it be guaranteed 
                that FD_READ will be triggered again or should i explicitly 
                loop here to keep calling call SSL_read over again?

        - SSL_ERROR_WANT_READ...same as above?

2.5)  the same questions go for SSL_write and FD_WRITE.  if i first 
call SSL_write(m_ssl, buf, sizeof(buf)) and it returns WANT_READ/WRITE, 
should i explicitly call SSL_write again, or wait for FD_WRITE to 
be triggered again?

3)  if SSL_read can cause write operations, how do i know that the
FD_WRITE which would be triggered is fired because i wanted asked to 
send something, not a side effect from SSL_read?  or does it even matter
that i was receiving something with SSL_read, it caused a write op, 
firing FD_WRITE, and i have something queued up to send that it
starts sending the item in the queue

4)  does anyone have any samples or urls for samples they would like to 
share
for non-blocking win32 sockets with SSL?

TIA

jeff
[EMAIL PROTECTED]


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

Reply via email to