On 3/17/2011 7:43 AM, ikuzar wrote:

I am confused.
When I used a simple c++ program which uses SSL functions for the first
time, I need not implement  a protocol. when I tell SSL_write( ) to send
5 bytes and tell SSL_read( ) to read 10 bytes, the last reads 5 bytes !
( doesn't it ? am I wrong ? I assume SSL reads expect \0 then it stop
reading).

No, that's not what it does. When you call SSL_read, it gives you however many bytes it has available at that time, up to a maximum of the number of bytes you asked for. If no data is available and the socket is blocking, it blocks until it has some data to give you and gives you that much.

It has no way to know when to stop reading. That's *your* job when you implement the protocol.

TCP and SSL are byte stream protocols that do not preserve message boundaries. If you call SSL_write and send 10 bytes, you should completely expect that you might call SSL_read 10 times and get 1 byte each time or you might get all 10 bytes in a one read. Or you might get 5 bytes and then 5 more bytes. It's a byte stream -- nothing 'glues' the bytes together.

If you want to end a 'message' with a \0 and read until you read a \0, then write code to do that. YOU MUST IMPLEMENT A PROTOCOL ON TOP OF SSL.

DS

______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    openssl-users@openssl.org
Automated List Manager                           majord...@openssl.org

Reply via email to