X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=lib%2Fsocket.c;h=503935c0a059e4dfd2da33eb356b3628f484b4e5;hb=b077fdeb65aca9d9bc15fcd311372816d87dc213;hp=e4de894c854e3e752271b1a3cb6833b400ec1a2c;hpb=48593f566ff9e0fee6544ba03478cb996380eaf7;p=deb_libnfs.git diff --git a/lib/socket.c b/lib/socket.c index e4de894..503935c 100644 --- a/lib/socket.c +++ b/lib/socket.c @@ -40,6 +40,8 @@ #include "libnfs-private.h" #include "slist.h" +static int rpc_disconnect_requeue(struct rpc_context *rpc); + static void set_nonblocking(int fd) { unsigned v; @@ -267,16 +269,16 @@ int rpc_service(struct rpc_context *rpc, int revents) return 0; } - if (revents & POLLOUT && rpc->outqueue != NULL) { - if (rpc_write_to_socket(rpc) != 0) { - rpc_set_error(rpc, "write to socket failed"); - return -1; + if (revents & POLLIN) { + if (rpc_read_from_socket(rpc) != 0) { + rpc_disconnect_requeue(rpc); + return 0; } } - if (revents & POLLIN) { - if (rpc_read_from_socket(rpc) != 0) { - rpc_disconnect(rpc, rpc_get_error(rpc)); + if (revents & POLLOUT && rpc->outqueue != NULL) { + if (rpc_write_to_socket(rpc) != 0) { + rpc_set_error(rpc, "write to socket failed"); return -1; } } @@ -350,6 +352,29 @@ int rpc_disconnect(struct rpc_context *rpc, char *error) return 0; } +/* disconnect but do not error all PDUs, just move pdus in-flight back to the outqueue */ +static int rpc_disconnect_requeue(struct rpc_context *rpc) +{ + struct rpc_pdu *pdu; + + if (rpc->fd != -1) { + close(rpc->fd); + } + rpc->fd = -1; + + rpc->is_connected = 0; + + /* socket is closed so we will not get any replies to any commands + * in flight. Move them all over from the waitpdu queue back to the out queue + */ + for (pdu=rpc->waitpdu; pdu; pdu=pdu->next) { + SLIST_REMOVE(&rpc->waitpdu, pdu); + SLIST_ADD(&rpc->outqueue, pdu); + } + + return 0; +} + int rpc_bind_udp(struct rpc_context *rpc, char *addr, int port) {