summaryrefslogtreecommitdiff
path: root/source3/lib/util_sock.c
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2002-01-20 02:40:05 +0000
committerAndrew Bartlett <abartlet@samba.org>2002-01-20 02:40:05 +0000
commitbb6af711b8f9a525b74198abbe7f1c37014ca6f7 (patch)
treebd27852105178310652be36d293282b0abd1de7d /source3/lib/util_sock.c
parent93a8358910d2b8788ffea33c04244ffd5ffecabf (diff)
downloadsamba-bb6af711b8f9a525b74198abbe7f1c37014ca6f7.tar.gz
samba-bb6af711b8f9a525b74198abbe7f1c37014ca6f7.tar.bz2
samba-bb6af711b8f9a525b74198abbe7f1c37014ca6f7.zip
This is the current patch from Luke Leighton <lckl@samba-tng.org> to add a
degree of seperation betwen reading/writing the raw NamedPipe SMB packets and the matching operations inside smbd's RPC components. This patch is designed for no change in behaviour, and my tests hold that to be true. This patch does however allow for the future loadable modules interface to specify function pointers in replacement of the fixed state. The pipes_struct has been split into two peices, with smb_np_struct taking the information that should be generic to where the data ends up. Some other minor changes are made: we get another small helper function in util_sock.c and some of the original code has better failure debugs and variable use. (As per on-list comments). Andrew Bartlett (This used to be commit 8ef13cabdddf58b741886782297fb64b2fb7e489)
Diffstat (limited to 'source3/lib/util_sock.c')
-rw-r--r--source3/lib/util_sock.c39
1 files changed, 27 insertions, 12 deletions
diff --git a/source3/lib/util_sock.c b/source3/lib/util_sock.c
index ba3c6f71b4..10ed2aaa0b 100644
--- a/source3/lib/util_sock.c
+++ b/source3/lib/util_sock.c
@@ -194,6 +194,30 @@ ssize_t read_udp_socket(int fd,char *buf,size_t len)
return(ret);
}
+/*******************************************************************
+ 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_intr(fd + 1, &fds, &timeout);
+
+ if (selrtn <= 0)
+ {
+ return selrtn;
+ }
+ return FD_ISSET(fd, &fds) ? 1 : 0;
+}
+
/****************************************************************************
Read data from a socket with a timout in msec.
mincount = if timeout, minimum to read before returning
@@ -315,13 +339,11 @@ static ssize_t read_socket_with_timeout(int fd,char *buf,size_t mincnt,size_t ma
time_out = timeout in milliseconds
****************************************************************************/
-ssize_t read_with_timeout(int fd,char *buf,size_t mincnt,size_t maxcnt,unsigned int time_out)
+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)
@@ -356,15 +378,8 @@ ssize_t read_with_timeout(int fd,char *buf,size_t mincnt,size_t maxcnt,unsigned
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_intr(fd+1,&fds,&timeout);
+ int selrtn = read_data_outstanding(fd, time_out);
if(selrtn <= 0)
return selrtn;