Ok. Thank everybody for your help.
Now it works.

2011/3/17 Ryan Pfeifle <r...@vpi-corp.com>

> Yes, if SSL_write() sends 5 bytes, SSL_read() will return 5 bytes even
> though the passed buffer is 10 bytes (SSL does NOT expect \0 to stop
> reading).  But like David said, you are ignoring the return value of
> SSL_read(), which tells you how many bytes were actually received.  Your
> code is expecting MY_recv() to update its len parameter with the new byte
> count, but it is not doing that, and you are not null terminating the buffer
> you print.  That is why you end up printing garbage.
>
>
>
> You need to change MYrecv() to something more like this:
>
>
>
> MY_recv(MY_cn sd, char* buf,  size_t *len, unsigned int flags, unsigned int
> timeout) {
>
>                 ret = SSL_read(socki->ssl, buf, *len);
>
>                 *len = ret;
>
> }
>
>
>
> int MYApi::MYrecv(MY_cn sd)
>
> {
>
> strresult *r = new strresult;
>
> const size_t L=8*1024;
>
> size_t  len = L;
>
> char buf[L];
>
>
>
> r->first = MY_recv(sd, buf, &len, flags, timeout);
>
> if (r->first > 0)
>
> r->second.assign(buf, len);
>
> return r;
>
> }
>
>
>
> data = api.MYrecv(cn)
>
>
>
>
>
>
>
>
>  Ryan Pfeifle
> Sr. Programmer
> Voice Print International, Inc.
> <http://www.VPI-corp.com/>
> *Immediate Results. Unmatched Value.* <http://www.VPI-corp.com/Value>TM
>
> *Tel: *1.805.389.5200 x5297
>  *Fax: *N/A
> *Email: *r...@vpi-corp.com
> *Web:* www.VPI-corp.com
>
>
>
> Experience the* **VPI Value Advantage<http://www.vpi-corp.com/ValueAdvantage>
> *TM
>
>
> The information transmitted in this message is intended only for the
> addressee and may contain confidential and/or privileged material. Any
> review, retransmission, dissemination or other use of, or taking of any
> action in reliance upon, this information by persons or entities other than
> the intended recipient is prohibited. If you received this in error, please
> contact the sender and delete this material from any computer.
>
>
> *From:* owner-openssl-us...@openssl.org [mailto:
> owner-openssl-us...@openssl.org] *On Behalf Of *ikuzar
> *Sent:* Thursday, March 17, 2011 7:44 AM
> *To:* openssl-users@openssl.org
> *Subject:* Re: data size issue with SSL_read( ) / SSL_write
>
>
>
> 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). Anyway, when SSL_write( ) sends "TEST", SSL_read( ) reads "TEST"
> and not "TEST��y 0�y ..."
>
> Now, in my python program, the difference between my simple c++ program is
> that, I retrieve a string ( a_string.data( ), a_string.size( ) ) and tell
> SLL_write through my API to send this string.
>
>
> 2011/3/17 David Schwartz <dav...@webmaster.com>
>
> On 3/17/2011 6:40 AM, ikuzar wrote:
>
> Why do we expect \r\n ? why not \0 ?
>
>
>
> That's why you need to implement a protocol.
>
> DS
>
>
>
> ______________________________________________________________________
> OpenSSL Project                                 http://www.openssl.org
> User Support Mailing List                    openssl-users@openssl.org
> Automated List Manager                           majord...@openssl.org
>
>
>

<<vpi_logo.jpg>>

Reply via email to