Fix posix_file::close handling of EINTR:

fix #1445

These changes optimize for Linux at the possible
expense of non-conforming platforms like HP-UX.
This commit is contained in:
Vinnie Falco
2019-02-09 11:32:33 -08:00
parent 68ee0df2ce
commit 0ce8ebbefd
2 changed files with 26 additions and 9 deletions

View File

@ -1,3 +1,9 @@
Version 213:
* Fix posix_file::close handling of EINTR
--------------------------------------------------------------------------------
Version 212:
* dynamic_buffer_ref tests and tidy

View File

@ -40,19 +40,30 @@ int
file_posix::
native_close(native_handle_type& fd)
{
/* https://github.com/boostorg/beast/issues/1445
This function is tuned for Linux / Mac OS:
* only calls close() once
* returns the error directly to the caller
* does not loop on EINTR
If this is incorrect for the platform, then the
caller will need to implement their own type
meeting the File requirements and use the correct
behavior.
See:
http://man7.org/linux/man-pages/man2/close.2.html
*/
int ev = 0;
if(fd != -1)
{
for(;;)
{
if(::close(fd) == 0)
break;
int const ev = errno;
if(errno != EINTR)
return ev;
}
if(::close(fd) != 0)
ev = errno;
fd = -1;
}
return 0;
return ev;
}
file_posix::