- ssize_t ret;
- bool finished;
-
- switch (conn->state) {
- case WRITE:
- ret = write(conn->fd.fd, conn->u.write.buf, conn->u.write.len);
- if (ret < 0)
- return io_close(conn, NULL);
- conn->u.write.buf += ret;
- conn->u.write.len -= ret;
- finished = (conn->u.write.len == 0);
- break;
- case WRITEPART:
- ret = write(conn->fd.fd, conn->u.writepart.buf,
- *conn->u.writepart.lenp);
- if (ret < 0)
- return io_close(conn, NULL);
- *conn->u.writepart.lenp = ret;
- finished = true;
- break;
- case READ:
- ret = read(conn->fd.fd, conn->u.read.buf, conn->u.read.len);
- if (ret <= 0)
- return io_close(conn, NULL);
- conn->u.read.buf += ret;
- conn->u.read.len -= ret;
- finished = (conn->u.read.len == 0);
- break;
- case READPART:
- ret = read(conn->fd.fd, conn->u.readpart.buf,
- *conn->u.readpart.lenp);
- if (ret <= 0)
- return io_close(conn, NULL);
- *conn->u.readpart.lenp = ret;
- finished = true;
- break;
- default:
- /* Shouldn't happen. */
- abort();
+ if (conn->plan.io(conn->fd.fd, &conn->plan)) {
+ set_current(conn);
+ if (timeout_active(conn))
+ backend_del_timeout(conn);
+ conn->plan = conn->plan.next(conn, conn->plan.next_arg);
+ backend_plan_changed(conn);
+ set_current(NULL);