Hi,
I am developing an SSL application on NT 4.0 and
I wish to use overlapped IO (asynchronous IO) to handle
clients. My application sits between the server and client.
I would like to know if it is safe to use a given SSL structure
from different threads if I guarantee that not more than
one thread accesses a given SSL structure simultaneously.
I am sending some pseudo-code below. I would like to
know if this is feasible and if yes, then its apparent drawbacks
if any, compared to plain thread-per client non-blocking model.
What I'm aiming to do here is have threads service
not a particular client, but just IO completion packets.
This should therotically result in more efficient processing.
I have an array of global information structures that looks like
struct info : public OVERLAPPED
{
SSL *pSSL;
Socket acceptedSocket;
Socket serverSocket;
char *serverbuf;
char *clientbuf;
int serverBytesRead;
int clientBytesRead;
int nextOperation;
//Constructor
info()
{...}
}
PostQueuedCompletionStatus does an explicit posting on IO Completion
Port queue. WSARecv and WSASend do so implicitly.
Each thread is an IO completion handler and looks like this
CompletionHandlerThread()
{
...
GetQueuedCompletionStatus(&info);
switch(info.nextOperation)
{
case ACCEPT:
Put info.acceptedSocket on IO Completion port
Connect to server
info.serverSocket = serverSocket;
//Read ahead on server
WSARecv(info.serverSocket,info.serverbuf,&info);
if(info.clientBytesRead = SSLRead(info->pSSL,info.clientbuf)) {
info.nextOperation = WRITE_SERVER;
PostQueuedCompletionStatus(&info);
}
else //Repost same message as operation couldnot complete
PostQueuedCompletionStatus(&info);
break;
case READ_CLIENT:
info.nextOperation = READ_CLIENT;
WSA_send(serverSocket,info.serverbuf,clientBytesRead,&info);
break;
case READ_SERVER:
if(SSL_Write(info->SSL,info.serverbuf)) {
info.nextOperation = READ_SERVER;
PostQueuedCompletionStatus(&info);
}
else //repost same message
PostQueuedCompletionStatus(&info);
break;
case WRITE_CLIENT:
info.nextOperation = WRITE_CLIENT;
WSARecv(info.serverSocket,info.serverBuf,&info);
case WRITE_SERVER:
if(info.clientbytesRead = SSLRead(info.pSSL,info.clientbuf)) {
info.nextOperation = WRITE_SERVER;
PostQueuedCompletionStatus(&info);
}
else //repost same message
PostQueuedCompletionStatus(&info);
break;
}
....
}
The pseudo-code might have some minor mistakes, but I hope
the point I'm trying to make is not lost.
Thanks for any help,
Amit.
______________________________________________________________________
OpenSSL Project http://www.openssl.org
User Support Mailing List [EMAIL PROTECTED]
Automated List Manager [EMAIL PROTECTED]