diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2011-04-16 17:08:38 +0000 |
---|---|---|
committer | Giampaolo Rodola <g.rodola@gmail.com> | 2011-04-16 17:08:38 +0000 |
commit | 2db7aca209c988517b1c3f499320945c24dd2a2d (patch) | |
tree | d7c1436324f6976e148374f356507daec91098bb /sendfilemodule.c | |
parent | 2591f69646a1f8defaf8d132e635b133c69adf46 (diff) | |
download | pysendfile-2db7aca209c988517b1c3f499320945c24dd2a2d.tar.gz |
- Linux: add error handling for getsockopt() and setsockopt()
- test for non socket fd
- test suite now automatically remotes test files on interpreter exit
Diffstat (limited to 'sendfilemodule.c')
-rw-r--r-- | sendfilemodule.c | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/sendfilemodule.c b/sendfilemodule.c index 24941c0..6054dca 100644 --- a/sendfilemodule.c +++ b/sendfilemodule.c @@ -251,38 +251,36 @@ method_sendfile(PyObject *self, PyObject *args, PyObject *kwdict) if (head || tail) { int cork = 1; // first, fetch the original setting - getsockopt(in_fd, SOL_TCP, TCP_CORK, (void*)&orig_cork, &orig_cork_len); - setsockopt(in_fd, SOL_TCP, TCP_CORK, (void*)&cork, sizeof(cork)); + ret = getsockopt(out_fd, SOL_TCP, TCP_CORK, + (void*)&orig_cork, &orig_cork_len); + if (ret == -1) + return PyErr_SetFromErrno(PyExc_OSError); + ret = setsockopt(out_fd, SOL_TCP, TCP_CORK, (void*)&cork, sizeof(cork)); + if (ret == -1) + return PyErr_SetFromErrno(PyExc_OSError); } // send header if (head) { sent_h = send(out_fd, head, head_len, 0); - if (sent_h < 0) { - PyErr_SetFromErrno(PyExc_OSError); - return NULL; - } - else if (sent_h < head_len) { + if (sent_h < 0) + return PyErr_SetFromErrno(PyExc_OSError); + else if (sent_h < head_len) goto done; - } } // send file Py_BEGIN_ALLOW_THREADS; sent_f = sendfile(out_fd, in_fd, &offset, count); Py_END_ALLOW_THREADS; - if (sent_f == -1) { - PyErr_SetFromErrno(PyExc_OSError); - return NULL; - } + if (sent_f == -1) + return PyErr_SetFromErrno(PyExc_OSError); // send trailer if (tail) { sent_t = send(out_fd, tail, tail_len, 0); - if (sent_t < 0) { - PyErr_SetFromErrno(PyExc_OSError); - return NULL; - } + if (sent_t < 0) + return PyErr_SetFromErrno(PyExc_OSError); } goto done; |