diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2011-04-16 17:25:53 +0000 |
---|---|---|
committer | Giampaolo Rodola <g.rodola@gmail.com> | 2011-04-16 17:25:53 +0000 |
commit | 60789c86854bb60444a8db07e3b7afe3f53a1064 (patch) | |
tree | fdd7d860db87c7d49214d76ef87d2872e73ffcec | |
parent | 2db7aca209c988517b1c3f499320945c24dd2a2d (diff) | |
download | pysendfile-60789c86854bb60444a8db07e3b7afe3f53a1064.tar.gz |
Linux: when sending header/trailer and send() return 0 raise EAGAIN
-rw-r--r-- | sendfilemodule.c | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/sendfilemodule.c b/sendfilemodule.c index 6054dca..1148b5d 100644 --- a/sendfilemodule.c +++ b/sendfilemodule.c @@ -248,7 +248,7 @@ method_sendfile(PyObject *self, PyObject *args, PyObject *kwdict) &tail, &tail_len, &flags)) return NULL; - if (head || tail) { + if (head_len != 0 || tail_len != 0) { int cork = 1; // first, fetch the original setting ret = getsockopt(out_fd, SOL_TCP, TCP_CORK, @@ -261,10 +261,16 @@ method_sendfile(PyObject *self, PyObject *args, PyObject *kwdict) } // send header - if (head) { + if (head_len != 0) { sent_h = send(out_fd, head, head_len, 0); if (sent_h < 0) return PyErr_SetFromErrno(PyExc_OSError); + else if (sent_h == 0) { + // A return value of 0 is supposed to be interpreted as EOF + // being reached. We do not want that and raise EAGAIN instead. + errno = EAGAIN; + return PyErr_SetFromErrno(PyExc_OSError); + } else if (sent_h < head_len) goto done; } @@ -277,10 +283,16 @@ method_sendfile(PyObject *self, PyObject *args, PyObject *kwdict) return PyErr_SetFromErrno(PyExc_OSError); // send trailer - if (tail) { + if (tail_len != 0) { sent_t = send(out_fd, tail, tail_len, 0); if (sent_t < 0) return PyErr_SetFromErrno(PyExc_OSError); + else if (sent_t == 0) { + // A return value of 0 is supposed to be interpreted as EOF + // being reached. We do not want that and raise EAGAIN instead. + errno = EAGAIN; + return PyErr_SetFromErrno(PyExc_OSError); + } } goto done; |