summaryrefslogtreecommitdiff
path: root/source3/lib
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>1997-12-20 14:36:11 +0000
committerJeremy Allison <jra@samba.org>1997-12-20 14:36:11 +0000
commitbe71d43585cf4b42efff7995dbf061fddd6077f5 (patch)
tree53aa1a15f742d51dbfa51bcee50c7e310f7e3ad1 /source3/lib
parentd57c055478a34b9c4a0fc7ba90d20f510d0df797 (diff)
downloadsamba-be71d43585cf4b42efff7995dbf061fddd6077f5.tar.gz
samba-be71d43585cf4b42efff7995dbf061fddd6077f5.tar.bz2
samba-be71d43585cf4b42efff7995dbf061fddd6077f5.zip
client.c:
clientgen.c: clientutil.c: clitar.c: Changed usage of receive_smb to new function client_receive_smb except for one use of receive_smb in client.c. This is the receive_smb used to discard packets received whilst in a keyboard wait state. util.c: Created new function client_receive_smb that ignores session keepalives just as the old receive_smb used to do. Created internal function read_smb_length_return_keepalive that is used internally by the changed receive_smb call. Changed read_smb_len to not use an internal buffer - it is never called with a null buffer so such code is redundant. Jeremy. (This used to be commit 1084fb46821cb96702da35439da4a8df9d255698)
Diffstat (limited to 'source3/lib')
-rw-r--r--source3/lib/util.c79
1 files changed, 64 insertions, 15 deletions
diff --git a/source3/lib/util.c b/source3/lib/util.c
index 41ea593ae5..409fe7135c 100644
--- a/source3/lib/util.c
+++ b/source3/lib/util.c
@@ -2240,32 +2240,27 @@ int transfer_file(int infd,int outfd,int n,char *header,int headlen,int align)
/****************************************************************************
read 4 bytes of a smb packet and return the smb length of the packet
-possibly store the result in the buffer
+store the result in the buffer
+This version of the function will return a length of zero on receiving
+a keepalive packet.
****************************************************************************/
-int read_smb_length(int fd,char *inbuf,int timeout)
+static int read_smb_length_return_keepalive(int fd,char *inbuf,int timeout)
{
- char *buffer;
- char buf[4];
int len=0, msg_type;
BOOL ok=False;
- if (inbuf)
- buffer = inbuf;
- else
- buffer = buf;
-
while (!ok)
{
if (timeout > 0)
- ok = (read_with_timeout(fd,buffer,4,4,timeout) == 4);
+ ok = (read_with_timeout(fd,inbuf,4,4,timeout) == 4);
else
- ok = (read_data(fd,buffer,4) == 4);
+ ok = (read_data(fd,inbuf,4) == 4);
if (!ok)
return(-1);
- len = smb_len(buffer);
- msg_type = CVAL(buffer,0);
+ len = smb_len(inbuf);
+ msg_type = CVAL(inbuf,0);
if (msg_type == 0x85)
DEBUG(5,("Got keepalive packet\n"));
@@ -2276,12 +2271,37 @@ int read_smb_length(int fd,char *inbuf,int timeout)
return(len);
}
+/****************************************************************************
+read 4 bytes of a smb packet and return the smb length of the packet
+store the result in the buffer. This version of the function will
+never return a session keepalive (length of zero).
+****************************************************************************/
+int read_smb_length(int fd,char *inbuf,int timeout)
+{
+ int len;
+
+ for(;;)
+ {
+ len = read_smb_length(fd, inbuf, timeout);
+
+ if(len < 0)
+ return len;
+ /* Ignore session keepalives. */
+ if(CVAL(inbuf,0) != 0x85)
+ break;
+ }
+
+ return len;
+}
/****************************************************************************
read an smb from a fd. Note that the buffer *MUST* be of size
BUFFER_SIZE+SAFETY_MARGIN.
-The timeout is in milli seconds
+ The timeout is in milli seconds.
+
+ This function will return on a
+ receipt of a session keepalive packet.
****************************************************************************/
BOOL receive_smb(int fd,char *buffer, int timeout)
{
@@ -2291,7 +2311,7 @@ BOOL receive_smb(int fd,char *buffer, int timeout)
bzero(buffer,smb_size + 100);
- len = read_smb_length(fd,buffer,timeout);
+ len = read_smb_length_return_keepalive(fd,buffer,timeout);
if (len < 0)
return(False);
@@ -2312,6 +2332,35 @@ BOOL receive_smb(int fd,char *buffer, int timeout)
}
/****************************************************************************
+ read an smb from a fd ignoring all keepalive packets. Note that the buffer
+ *MUST* be of size BUFFER_SIZE+SAFETY_MARGIN.
+ The timeout is in milli seconds
+
+ This is exactly the same as receive_smb except that it never returns
+ a session keepalive packet (just as receive_smb used to do).
+ receive_smb was changed to return keepalives as the oplock processing means this call
+ should never go into a blocking read.
+****************************************************************************/
+
+BOOL client_receive_smb(int fd,char *buffer, int timeout)
+{
+ BOOL ret;
+
+ for(;;)
+ {
+ ret = receive_smb(fd, buffer, timeout);
+
+ if(ret == False)
+ return ret;
+
+ /* Ignore session keepalive packets. */
+ if(CVAL(buffer,0) != 0x85)
+ break;
+ }
+ return ret;
+}
+
+/****************************************************************************
read a message from a udp fd.
The timeout is in milli seconds
****************************************************************************/