Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

correctly check for hangup during reserve

Revert a9d4367.

Instead of closing the connection immediately when the client
hangs up, merely cancel any pending reserve command. We still
process any other commands that are available so that a client
can read responses if the connection is only half closed.

fixes #144
  • Loading branch information...
commit c2ee0f36f070b5fa1fbf31f81617a384d167c742 1 parent bf4dd7a
@kr authored
View
3  darwin.c
@@ -106,6 +106,9 @@ socknext(Socket **s, int64 timeout)
if (r > 0) {
*s = ev.udata;
+ if (ev.flags & EV_EOF) {
+ return 'h';
+ }
switch (ev.filter) {
case EVFILT_READ:
return 'r';
View
1  dat.h
@@ -271,6 +271,7 @@ struct Conn {
job soonest_job; // memoization of the soonest job
int rw; // currently want: 'r', 'w', or 'h'
int pending_timeout;
+ char halfclosed;
char cmd[LINE_BUF_SIZE]; // this string is NOT NUL-terminated
int cmd_len;
View
2  doc/protocol.md
@@ -168,7 +168,7 @@ A timeout value of `0` will cause the server to immediately return either a resp
###### Non-succesful responses
* `DEADLINE_SOON\r\n` During the TTR of a reserved job, the last second is kept by the server as a safety margin, during which the client will not be made to wait for another job. If the client issues a reserve command during the safety margin, or if the safety margin arrives while the client is waiting on a reserve command.
-* `TIMED_OUT\r\n` If a non-negative timeout was specified and the timeout exceeded before a job became available, the server will respond with TIMED_OUT.
+* `TIMED_OUT\r\n` If a non-negative timeout was specified and the timeout exceeded before a job became available, or if the client's connection is half-closed, the server will respond with TIMED_OUT.
Otherwise, the only other response to this command is a successful reservation
in the form of a text line followed by the job body:
View
3  doc/protocol.txt
@@ -225,7 +225,8 @@ the server automatically releases it.
TIMED_OUT\r\n
If a non-negative timeout was specified and the timeout exceeded before a job
-became available, the server will respond with TIMED_OUT.
+became available, or if the client's connection is half-closed, the server
+will respond with TIMED_OUT.
Otherwise, the only other response to this command is a successful reservation
in the form of a text line followed by the job body:
View
4 linux.c
@@ -81,7 +81,9 @@ socknext(Socket **s, int64 timeout)
if (r) {
*s = ev.data.ptr;
- if (ev.events & (EPOLLIN|EPOLLHUP|EPOLLRDHUP)) {
+ if (ev.events & (EPOLLHUP|EPOLLRDHUP)) {
+ return 'h';
+ } else if (ev.events & EPOLLIN) {
return 'r';
} else if (ev.events & EPOLLOUT) {
return 'w';
View
9 prot.c
@@ -1764,7 +1764,10 @@ conn_data(Conn *c)
/* otherwise we sent incomplete data, so just keep waiting */
break;
case STATE_WAIT:
- // nothing
+ if (c->halfclosed) {
+ c->pending_timeout = -1;
+ return reply_msg(remove_waiting_conn(c), MSG_TIMED_OUT);
+ }
break;
}
}
@@ -1801,6 +1804,10 @@ h_conn(const int fd, const short which, Conn *c)
return;
}
+ if (which == 'h') {
+ c->halfclosed = 1;
+ }
+
conn_data(c);
while (cmd_data_ready(c) && (c->cmd_len = cmd_len(c))) do_cmd(c);
update_conns();
Please sign in to comment.
Something went wrong with that request. Please try again.