diff options
author | Luke Leighton <lkcl@samba.org> | 2000-04-11 05:25:07 +0000 |
---|---|---|
committer | Luke Leighton <lkcl@samba.org> | 2000-04-11 05:25:07 +0000 |
commit | 696d2d7a6854ebdf9a2720a5173460f7646af961 (patch) | |
tree | 4a71c5cb8fa20116b1c36d84844e5d180b7c9bdd | |
parent | 543753d42bb2dced8adcf615c1bce7afccf277f1 (diff) | |
download | samba-696d2d7a6854ebdf9a2720a5173460f7646af961.tar.gz samba-696d2d7a6854ebdf9a2720a5173460f7646af961.tar.xz samba-696d2d7a6854ebdf9a2720a5173460f7646af961.zip |
simplifying write_pipe and read_pipe code -- also it looks like there
is a minimum pipe read parameter which i make sure is passed in
to read_pipe, which gets passed in as the minimum value to
read_data_with_timeout()
created two functions read_data_outstanding() and write_data_outstanding()
which do a select with a timeout (0 = instantaneous) to tell if there is
read or write data left.
-rw-r--r-- | source/lib/util_sock.c | 60 | ||||
-rw-r--r-- | source/msrpc/msrpcd_process.c | 47 | ||||
-rw-r--r-- | source/rpc_server/srv_pipe.c | 31 | ||||
-rw-r--r-- | source/smbd/pipes.c | 2 |
4 files changed, 68 insertions, 72 deletions
diff --git a/source/lib/util_sock.c b/source/lib/util_sock.c index f4e3438ed07..459ab16501d 100644 --- a/source/lib/util_sock.c +++ b/source/lib/util_sock.c @@ -235,6 +235,54 @@ ssize_t write_socket(int fd, char *buf, size_t len) return (ret); } +/******************************************************************* + checks if write data is outstanding. + ********************************************************************/ +int write_data_outstanding(int fd, unsigned int time_out) +{ + int selrtn; + fd_set fds; + struct timeval timeout; + + FD_ZERO(&fds); + FD_SET(fd, &fds); + + timeout.tv_sec = (time_t) (time_out / 1000); + timeout.tv_usec = (long)(1000 * (time_out % 1000)); + + selrtn = sys_select(fd + 1, NULL, &fds, &timeout); + + if (selrtn <= 0) + { + return selrtn; + } + return FD_ISSET(fd, &fds) ? 1 : 0; +} + +/******************************************************************* + checks if read data is outstanding. + ********************************************************************/ +int read_data_outstanding(int fd, unsigned int time_out) +{ + int selrtn; + fd_set fds; + struct timeval timeout; + + FD_ZERO(&fds); + FD_SET(fd, &fds); + + timeout.tv_sec = (time_t) (time_out / 1000); + timeout.tv_usec = (long)(1000 * (time_out % 1000)); + + selrtn = sys_select(fd + 1, &fds, NULL, &timeout); + + if (selrtn <= 0) + { + return selrtn; + } + return FD_ISSET(fd, &fds) ? 1 : 0; +} + /**************************************************************************** read from a socket ****************************************************************************/ @@ -275,11 +323,8 @@ time_out = timeout in milliseconds ssize_t read_with_timeout(int fd, char *buf, size_t mincnt, size_t maxcnt, unsigned int time_out) { - fd_set fds; - int selrtn; ssize_t readret; size_t nread = 0; - struct timeval timeout; /* just checking .... */ if (maxcnt <= 0) @@ -333,16 +378,9 @@ ssize_t read_with_timeout(int fd, char *buf, size_t mincnt, size_t maxcnt, system performance will suffer severely as select always returns true on disk files */ - /* Set initial timeout */ - timeout.tv_sec = (time_t) (time_out / 1000); - timeout.tv_usec = (long)(1000 * (time_out % 1000)); - for (nread = 0; nread < mincnt;) { - FD_ZERO(&fds); - FD_SET(fd, &fds); - - selrtn = sys_select(fd + 1, &fds, NULL, &timeout); + int selrtn = read_data_outstanding(fd, time_out); /* Check if error */ if (selrtn == -1) diff --git a/source/msrpc/msrpcd_process.c b/source/msrpc/msrpcd_process.c index 8cd099a6a01..870ce2621a4 100644 --- a/source/msrpc/msrpcd_process.c +++ b/source/msrpc/msrpcd_process.c @@ -51,13 +51,9 @@ extern int max_send; static BOOL receive_message_or_msrpc(int c, prs_struct * ps, int timeout, BOOL *got_msrpc) { - fd_set fds; int selrtn; - struct timeval to; - int maxfd; - DEBUG(10, - ("receive_message_or_msrpc: timeout %d fd %d\n", timeout, c)); + DEBUG(10, ("receive_message_or_msrpc: timeout %d fd %d\n", timeout, c)); smb_read_error = 0; @@ -68,19 +64,7 @@ static BOOL receive_message_or_msrpc(int c, prs_struct * ps, * If so - copy and return it. */ - /* - * Setup the select read fd set. - */ - - FD_ZERO(&fds); - FD_SET(c, &fds); - maxfd = 0; - - to.tv_sec = timeout / 1000; - to.tv_usec = (timeout % 1000) * 1000; - - selrtn = sys_select(MAX(maxfd, c) + 1, &fds, NULL, - timeout > 0 ? &to : NULL); + selrtn = read_data_outstanding(c, timeout); /* Check if error */ if (selrtn == -1) @@ -99,12 +83,8 @@ static BOOL receive_message_or_msrpc(int c, prs_struct * ps, return False; } - if (FD_ISSET(c, &fds)) - { - *got_msrpc = True; - return receive_msrpc(c, ps, 0); - } - return False; + *got_msrpc = True; + return receive_msrpc(c, ps, 0); } @@ -158,23 +138,12 @@ static void process_msrpc(rpcsrv_struct * l, const char *name, while (rpc_local(l, NULL, 0, name)) { - fd_set fds; int selrtn; - struct timeval to; - int maxfd; int timeout = SMBD_SELECT_TIMEOUT * 1000; smb_read_error = 0; - FD_ZERO(&fds); - FD_SET(l->c, &fds); - maxfd = 0; - - to.tv_sec = timeout / 1000; - to.tv_usec = (timeout % 1000) * 1000; - - selrtn = sys_select(MAX(maxfd, l->c) + 1, NULL, &fds, - timeout > 0 ? &to : NULL); + selrtn = write_data_outstanding(l->c, timeout); /* Check if error */ if (selrtn == -1) @@ -190,11 +159,9 @@ static void process_msrpc(rpcsrv_struct * l, const char *name, return; } - if (FD_ISSET(l->c, &fds)) + if (!msrpc_send(l->c, &l->rsmb_pdu)) { - if (!msrpc_send(l->c, &l->rsmb_pdu)) - prs_free_data(&l->rsmb_pdu); - break; + DEBUG(1,("msrpc_send: failed\n")); } prs_free_data(&l->rsmb_pdu); } diff --git a/source/rpc_server/srv_pipe.c b/source/rpc_server/srv_pipe.c index 9eb6b22c017..14368e3fc78 100644 --- a/source/rpc_server/srv_pipe.c +++ b/source/rpc_server/srv_pipe.c @@ -35,13 +35,11 @@ extern int DEBUGLEVEL; BOOL readwrite_pipe(pipes_struct * p, char *data, int len, char **rdata, int *rlen, BOOL *pipe_outstanding) { - fd_set fds; int selrtn; - struct timeval timeout; DEBUG(10, ("rpc_to_smb_readwrite: len %d\n", len)); - if (write_socket(p->m->fd, data, len) != len) + if (write_pipe(p, data, len) != len) { return False; } @@ -57,9 +55,10 @@ BOOL readwrite_pipe(pipes_struct * p, char *data, int len, return False; } - /* compromise. MUST read a minimum of an rpc header. - * timeout waiting for the rest for 10 seconds */ - (*rlen) = read_with_timeout(p->m->fd, (*rdata), 16, (*rlen), 10000); + /* + * timeout waiting for the rest for 10 seconds + */ + (*rlen) = read_pipe(p, (*rdata), 1, (*rlen)); if ((*rlen) < 0) { return False; @@ -77,23 +76,16 @@ BOOL readwrite_pipe(pipes_struct * p, char *data, int len, * response. *dur*! what's msrpc got to do with smb, ANYWAY!! */ - FD_ZERO(&fds); - FD_SET(p->m->fd, &fds); - - /* Set initial timeout to zero */ - timeout.tv_sec = 0; - timeout.tv_usec = 0; - - selrtn = sys_select(p->m->fd + 1, &fds, NULL, &timeout); + selrtn = read_data_outstanding(p->m->fd, 0); /* Check if error */ if (selrtn == -1) { /* something is wrong. Maybe the socket is dead? */ - return -1; + return False; } - *pipe_outstanding = FD_ISSET(p->m->fd, &fds); + *pipe_outstanding = (selrtn > 0); return True; } @@ -120,9 +112,9 @@ ssize_t write_pipe(pipes_struct * p, char *data, size_t n) read by an SMBtrans (file_offset != 0). ****************************************************************************/ -int read_pipe(pipes_struct * p, char *data, int n) +int read_pipe(pipes_struct * p, char *data, int min_len, int max_len) { - DEBUG(6, ("read_pipe: %x name: %s len: %d", p->pnum, p->name, n)); + DEBUG(6, ("read_pipe: %x name: %s len: %d", p->pnum, p->name, max_len)); if (!p) { @@ -130,6 +122,5 @@ int read_pipe(pipes_struct * p, char *data, int n) return -1; } - /* read a minimum of 1 byte! :-) */ - return read_with_timeout(p->m->fd, data, 1, n, 10000); + return read_with_timeout(p->m->fd, data, min_len, max_len, 10000); } diff --git a/source/smbd/pipes.c b/source/smbd/pipes.c index 71376b8a0a9..bb412712344 100644 --- a/source/smbd/pipes.c +++ b/source/smbd/pipes.c @@ -239,7 +239,7 @@ int reply_pipe_read_and_X(char *inbuf, char *outbuf, int length, int bufsize) set_message(outbuf, 12, 0, True); data = smb_buf(outbuf); - nread = read_pipe(p, data, smb_maxcnt); + nread = read_pipe(p, data, smb_mincnt, smb_maxcnt); if (nread < 0) return (UNIXERROR(ERRDOS, ERRnoaccess)); |