* sure want to abort the hard way.
*/
if (conn_ctrl_ready(conn) && !(conn->flags & CO_FL_SOCK_RD_SH)) {
- if (!(conn->flags & CO_FL_WAIT_RD) && conn->ctrl->drain && conn->ctrl->drain(conn->t.sock.fd))
+ if (!(conn->flags & CO_FL_WAIT_RD) && conn->ctrl->drain && conn->ctrl->drain(conn->t.sock.fd) > 0)
fdtab[conn->t.sock.fd].linger_risk = 0;
}
conn_force_close(conn);
* server state to be suddenly changed.
*/
if (conn_ctrl_ready(conn) && !(conn->flags & CO_FL_SOCK_RD_SH)) {
- if (!(conn->flags & CO_FL_WAIT_RD) && conn->ctrl->drain && conn->ctrl->drain(conn->t.sock.fd))
+ if (!(conn->flags & CO_FL_WAIT_RD) && conn->ctrl->drain && conn->ctrl->drain(conn->t.sock.fd) > 0)
fdtab[conn->t.sock.fd].linger_risk = 0;
}
conn_force_close(conn);
}
/* Tries to drain any pending incoming data from the socket to reach the
- * receive shutdown. Returns non-zero if the shutdown was found, otherwise
- * zero. This is useful to decide whether we can close a connection cleanly
- * are we must kill it hard.
+ * receive shutdown. Returns positive if the shutdown was found, negative
+ * if EAGAIN was hit, otherwise zero. This is useful to decide whether we
+ * can close a connection cleanly are we must kill it hard.
*/
int tcp_drain(int fd)
{
if (len < 0) {
if (errno == EAGAIN) /* connection not closed yet */
- return 0;
+ return -1;
if (errno == EINTR) /* oops, try again */
continue;
/* other errors indicate a dead connection, fine. */
return;
if ((fdtab[conn->t.sock.fd].ev & (FD_POLL_ERR|FD_POLL_HUP)) ||
- (conn->ctrl->drain && conn->ctrl->drain(conn->t.sock.fd)))
+ (conn->ctrl->drain && conn->ctrl->drain(conn->t.sock.fd) > 0))
conn->flags |= CO_FL_SOCK_RD_SH;
/* disable draining if we were called and have no drain function */