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

write() should not return the error from write_func() #138

Open
gopakumarce opened this issue Jun 23, 2021 · 3 comments
Open

write() should not return the error from write_func() #138

gopakumarce opened this issue Jun 23, 2021 · 3 comments

Comments

@gopakumarce
Copy link

First of all thanks a lot for this lib, helps a lot writing stuff for apple ecosystem.

As far as I understand from apple documentation, SSLWrite() will call SSLWriteFunc(), but if there is any kind of error returned by SSLWriteFunc(), SSLWrite() itself will return an error of its own, ie there is no responsibility the coder has to "save" the error returned by SSLWriteFunc() and then check that after calling SSLWrite() etc.. In fact, doing that might be erroneous - consider this example.

  1. We called SSLWrite(), SSLWriteFunc() might have returned errSslWouldBlock, but SSLWrite() itself succeeded because SSL lib is gonna buffer up the data we provide (and encrypt it and call SSLWriteFunc() on the encrypted data) - so the library has now "cached" an error errSslWouldBlock in conn.err
  2. Later again we call SSLWrite(), this time just as an example say there was some error and the API returned errSSLPeerCertExpired
  3. Now write() will go and check conn.err and will find errSslWouldBlock and that is what the caller to write() gets as an error, which is incorrect

So in summary, IMO there is no need to cache conn.err and return it - unless there was a reason for it, which ill be curious to know

@kornelski
Copy link
Owner

It would be helpful if you could write a test that demonstrates the problem.

@gopakumarce
Copy link
Author

Sure, I will attempt a test case. But does my line of reasoning sound logical ? Leaving aside all the Rust wrappers, the matter under discussion here is simply "should SSLWriteFunc() error be saved, should callers of SSLWrite() check for the saved error ?" and to me it sounds that the obvious answer is no, because SSLWrite() itself can/will check for the error return on SSLWriteFunc() and translate/return that appropriately as needed. What I was curious to know is whether there is a specific reason you have done so in the rust code or it was just something that was not necessarily for handling anything particular

@kornelski
Copy link
Owner

Yes, that makes sense. The docs say the result is passed on.

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

2 participants