bpo-32622: Normalize ENOTCONN to ConnectionError on macOS (GH-5369) · python/cpython@2a2247c (original) (raw)

`@@ -362,6 +362,17 @@ def _sock_sendfile_native_impl(self, fut, registered_fd, sock, fileno,

`

362

362

`fd, sock, fileno,

`

363

363

`offset, count, blocksize, total_sent)

`

364

364

`except OSError as exc:

`

``

365

`+

if (registered_fd is not None and

`

``

366

`+

exc.errno == errno.ENOTCONN and

`

``

367

`+

type(exc) is not ConnectionError):

`

``

368

`+

If we have an ENOTCONN and this isn't a first call to

`

``

369

`+

sendfile(), i.e. the connection was closed in the middle

`

``

370

`+

of the operation, normalize the error to ConnectionError

`

``

371

`+

to make it consistent across all Posix systems.

`

``

372

`+

new_exc = ConnectionError(

`

``

373

`+

"socket is not connected", errno.ENOTCONN)

`

``

374

`+

new_exc.cause = exc

`

``

375

`+

exc = new_exc

`

365

376

`if total_sent == 0:

`

366

377

`# We can get here for different reasons, the main

`

367

378

`# one being 'file' is not a regular mmap(2)-like

`