X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;ds=sidebyside;f=lib%2Fsocket.c;h=055109a73c9f7b4be1f69d73f0552feb5c2d51ff;hb=2449d3f787d5a95e7cd19a0a9c95fd24ade60e3d;hp=152dfb4a44df57528ccc7106348bcf32afb14764;hpb=d43a8953f531478fa8bfd9eb60a0de257cd06814;p=deb_libnfs.git diff --git a/lib/socket.c b/lib/socket.c index 152dfb4..055109a 100644 --- a/lib/socket.c +++ b/lib/socket.c @@ -210,6 +210,7 @@ static int rpc_read_from_socket(struct rpc_context *rpc) if (count < 0) { rpc_set_error(rpc, "Failed recvfrom: %s", strerror(errno)); free(buf); + return -1; } if (rpc_process_pdu(rpc, buf, count) != 0) { rpc_set_error(rpc, "Invalid/garbage pdu received from server. Ignoring PDU"); @@ -251,7 +252,7 @@ static int rpc_read_from_socket(struct rpc_context *rpc) pdu_size = rpc_get_pdu_size(rpc->inbuf); if (rpc->insize < pdu_size) { unsigned char *buf; - + buf = malloc(pdu_size); if (buf == NULL) { rpc_set_error(rpc, "Failed to allocate buffer of %d bytes for pdu, errno:%d. Closing socket.", pdu_size, errno); @@ -485,10 +486,10 @@ static int rpc_connect_sockaddr_async(struct rpc_context *rpc, struct sockaddr_s if (connect(rpc->fd, (struct sockaddr *)s, socksize) != 0 && errno != EINPROGRESS) { rpc_set_error(rpc, "connect() to server failed. %s(%d)", strerror(errno), errno); return -1; - } + } return 0; -} +} int rpc_connect_async(struct rpc_context *rpc, const char *server, int port, rpc_cb cb, void *private_data) { @@ -532,7 +533,7 @@ int rpc_connect_async(struct rpc_context *rpc, const char *server, int port, rpc } return 0; -} +} int rpc_disconnect(struct rpc_context *rpc, char *error) { @@ -617,7 +618,7 @@ int rpc_bind_udp(struct rpc_context *rpc, char *addr, int port) sprintf(service, "%d", port); if (getaddrinfo(addr, service, NULL, &ai) != 0) { rpc_set_error(rpc, "Invalid address:%s. " - "Can not resolv into IPv4/v6 structure."); + "Can not resolv into IPv4/v6 structure.", addr); return -1; } @@ -625,13 +626,13 @@ int rpc_bind_udp(struct rpc_context *rpc, char *addr, int port) case AF_INET: rpc->fd = socket(ai->ai_family, SOCK_DGRAM, 0); if (rpc->fd == -1) { - rpc_set_error(rpc, "Failed to create UDP socket: %s", strerror(errno)); + rpc_set_error(rpc, "Failed to create UDP socket: %s", strerror(errno)); freeaddrinfo(ai); return -1; } if (bind(rpc->fd, (struct sockaddr *)ai->ai_addr, sizeof(struct sockaddr_in)) != 0) { - rpc_set_error(rpc, "Failed to bind to UDP socket: %s",strerror(errno)); + rpc_set_error(rpc, "Failed to bind to UDP socket: %s",strerror(errno)); freeaddrinfo(ai); return -1; } @@ -662,7 +663,7 @@ int rpc_set_udp_destination(struct rpc_context *rpc, char *addr, int port, int i sprintf(service, "%d", port); if (getaddrinfo(addr, service, NULL, &ai) != 0) { rpc_set_error(rpc, "Invalid address:%s. " - "Can not resolv into IPv4/v6 structure."); + "Can not resolv into IPv4/v6 structure.", addr); return -1; } @@ -707,3 +708,10 @@ int rpc_queue_length(struct rpc_context *rpc) } return i; } + +void rpc_set_fd(struct rpc_context *rpc, int fd) +{ + assert(rpc->magic == RPC_CONTEXT_MAGIC); + + rpc->fd = fd; +}