Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example should read all pending data... #35

Closed
rphillips opened this issue Jan 23, 2015 · 11 comments
Closed

Example should read all pending data... #35

rphillips opened this issue Jan 23, 2015 · 11 comments

Comments

@rphillips
Copy link

It should be a while loop here to read all pending data...

https://github.com/zhaozg/lua-openssl/blob/master/lib/luv/ssl.lua#L130

Thanks for the great library!

@imzyxwvu
Copy link
Contributor

I argee. And when ssl:read() returns want_read, the loop should end.

@zhaozg
Copy link
Owner

zhaozg commented Jan 24, 2015

according to https://github.com/zhaozg/lua-openssl/blob/master/src/ssl.c#L1417-L1418,
ssl:read([number bytes=ssl:pending()]), will always try to read all pending data if not given bytes to read,
so I think your options are done already.

@imzyxwvu
Copy link
Contributor

I called ssl:read() in my program (without any argument), it didn't read all pending data in the memory bio. Then if I call ssl:read() again, more data will be readed, without any new data pushed to the memory bio.

@zhaozg
Copy link
Owner

zhaozg commented Jan 25, 2015

OK, I'll check it, maybe bugs.

@zhaozg
Copy link
Owner

zhaozg commented Jan 26, 2015

@imzyxwvu 可能是在读完之后新产生的数据吧,即使实在ssl:read()中加上读取的参数也会出现这种现象

@imzyxwvu
Copy link
Contributor

@zhaozg 不,我自己写的uv绑定,参考那个lib重新实现。我向input mem bio里面写了数据之后有的时候只从ssl对象上read一次只读出了一部分数据,不够,但是接收数据回调没被再次调用。但是如果我在没有往mem bio写入新数据的情况下再调用一次read就能读出剩下的数据。我再翻翻openssl文档。我晚上试试写个程序重现下。

translation: I wrote a libuv binding myself (not luv), so I referenced that lua lib to implement one for my own binding. When I wrote some data to the input mem bio, ssl:read() succeeded but didn't return all data expected, but the on-data callback wasn't trigged any more. So I tried to call ssl:read() again and it returned the left data. I will try to write a program to show you the problem tonight.

@zhaozg
Copy link
Owner

zhaozg commented Jan 26, 2015

我最近太忙了,可能没有办法及时解决这个问题,我尽快处理这个问题吧。

I'm busy now, can't solve this problem in a timely, please wait some days to deal with this issue. thanks.

@imzyxwvu
Copy link
Contributor

@zhaozg 我看了下 openssl document,你的C代码没错。ssl底层数据流是由许多records组成的,SSL_pending返回当前正在处理的那一个record中还未读取的字节数,如果一次性写入input bio多个ssl record,那么openssl会依次处理,SSL_pending每次只返回当前正处理的record中剩余的字节数,只有你用SSL_read把当前record读完了,openssl才处理下一个record(如果bio中下一个record还不完整,SSL_pending返回0),这也就是要循环read的原因。

translation: in a word, there is nothing wrong in the C code.

@zhaozg zhaozg closed this as completed in 650cfd4 Feb 3, 2015
@imzyxwvu
Copy link
Contributor

imzyxwvu commented Feb 3, 2015

remember openssl document said that SSL_read may also yields WANT_WRITE.

@zhaozg
Copy link
Owner

zhaozg commented Feb 3, 2015

@imzyxwvu thanks

@zhaozg zhaozg reopened this Feb 3, 2015
@zhaozg
Copy link
Owner

zhaozg commented Mar 15, 2015

@zhaozg zhaozg closed this as completed Mar 15, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants