fpagliughi / sockpp

Modern C++ socket library.
BSD 3-Clause "New" or "Revised" License
782 stars 126 forks source link

socket::close() preserves last_error() #28

Closed snej closed 4 years ago

snej commented 4 years ago

As a result of fixing #23 in ddf71320, socket::close() now clears the last_error property to 0. This means when connector::connect() or acceptor::open() close themselves after encountering an error, the error code is lost. Fixed this by changing socket::close to preserve a pre-existing non- zero last_error.

Fixes #27

fpagliughi commented 4 years ago

This is a much smaller fix than I had initially imagined. I was thinking of having a close_with_no_side_effect() type of call that was used internally by the library, in the specific areas where it was warranted. Pretty much your close(h), as implemented here.

Part of the problem from #23 was that close() was not behaving like the other system calls. With this, it again isn't behaving exactly like the other calls.

But maybe that's OK.

snej commented 4 years ago

A just_close method would be good too ... I jsut went the way I did because it required fewer changes. I'll let you decide :)

fpagliughi commented 4 years ago

OK, went with this close(h) then added a close_on_err() Up in develop branch