From: Ronnie Sahlberg Date: Sun, 2 Feb 2014 16:45:21 +0000 (-0800) Subject: Add a rpc_set_fd() fucntion which can be used to swap the underlying socket file... X-Git-Tag: upstream/1.9.6^2~121 X-Git-Url: https://git.piment-noir.org/?p=deb_libnfs.git;a=commitdiff_plain;h=6ec481d3fae973cf077d70c9cf870b425fee7112 Add a rpc_set_fd() fucntion which can be used to swap the underlying socket file descriptor This is mainly needed when having to track and control the file descriptors that are used by libnfs, for example when trying to emulate dup2() ontop of libnfs. --- diff --git a/include/nfsc/libnfs-raw.h b/include/nfsc/libnfs-raw.h index b62ea70..a680f5c 100644 --- a/include/nfsc/libnfs-raw.h +++ b/include/nfsc/libnfs-raw.h @@ -59,6 +59,20 @@ struct nfs_fh3 *nfs_get_fh(struct nfsfh *nfsfh); */ void rpc_set_next_xid(struct rpc_context *rpc, uint32_t xid); +/* This function can be used to set the file descriptor used for + * the RPC context. It is primarily useful when emulating dup2() + * and similar or where you want full control of the filedescriptor numbers + * used by the rpc socket. + * + * ... + * oldfd = rpc_get_fd(rpc); + * dup2(oldfd, newfd); + * rpc_set_fd(rpc, newfd); + * close(oldfd); + * ... + */ +void rpc_set_fd(struct rpc_context *rpc, int fd); + #define RPC_STATUS_SUCCESS 0 #define RPC_STATUS_ERROR 1 #define RPC_STATUS_CANCEL 2 diff --git a/lib/libnfs-win32.def b/lib/libnfs-win32.def index b1018ec..6461d5d 100644 --- a/lib/libnfs-win32.def +++ b/lib/libnfs-win32.def @@ -196,4 +196,5 @@ rpc_rquota1_null_async rpc_rquota1_getquota_async rpc_rquota1_getactivequota_async rpc_service +rpc_set_fd rpc_which_events diff --git a/lib/socket.c b/lib/socket.c index 152dfb4..b750d6f 100644 --- a/lib/socket.c +++ b/lib/socket.c @@ -707,3 +707,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; +}