Hello,
I'm re-writing an application with OpenSSL.
Originally, the application uses only plain TCP socket as a TCP client, it
has two threads, receives and submits message asynchronously. Namely, the
timing of sending/receiving messages are independent on each other, and
there is no logical sequence.
How does it possible to do asynchronous read/write with multithread?
The outline of the original code is below;
------ snip ------
sock = socket( ... ) ;
connect( sock ... ) ;
pthread_create( thread_receive ) ;
pthread_create( thread_send ) ;
void *thread_receive( .. ) {
while ( ! end_of_transaction ) {
input_from_aux_device() ;
write( sock ... ) ;
}
}
void *thread_send( .. ) {
while ( ! end_of_transaction ) {
read( sock ... ) ;
output_to_aux_device() ;
}
}
------ snip ------
I found an FAQ about multithreading;
> an SSL connection may not concurrently be used by multiple threads
So, at first, I made two simple wrapper functions to replace plain
read/write functions.
------ snip ------
int read_ssl( .. ) {
pthread_mutex_lock( &rw_lock ) ;
SSL_read( ... ) ;
pthread_mutex_unlock( &rw_lock ) ;
}
int write_ssl( .. ) {
pthread_mutex_lock( rw_lock ) ;
SSL_write( ... ) ;
pthread_mutex_unlock( rw_lock ) ;
}
------ snip ------
Of course, it did not work. The mutex was locked during waiting messages at
SSL_read, could not send any messages.
Can you please help me?
Thank you in advance!
--
YAMANEKO / Mao
http://yamamaya.com/
http://wiki.livedoor.jp/yamamaya_com/
______________________________________________________________________
OpenSSL Project http://www.openssl.org
User Support Mailing List [email protected]
Automated List Manager [EMAIL PROTECTED]