The need for a special SMB receive system call

Andrew Bartlett abartlet at
Tue Sep 24 22:31:00 GMT 2002

Richard Sharpe wrote:
> Hi,
> In the course of hacking Samba to use the recv variant of sendfile I have
> had to modify the low level routines that read in an SMB off of a socket.
> Currently, Samba makes two system calls to reveive an SMB, one to receive
> the length and the other to receive the rest of the SMB[1].
> Because I wanted to leave write data on the socket for Write&X calls, and
> have this data transferred directly to the open file in the case where it
> can be safely done (Ie, we have an oplock on the file etc), I had to split
> that into a minumum of three reads: One to read the length, another to
> read to the end of the fixed header of the SMB so we can check the command
> type, and that last one to read out the rest of the data if it is not a
> Write&X request.

I was wondering about a much less elegent solution:

Why can't we do a non-blocking read on the socket, into a (large)

We would then process the commands one-by one, until we reached one that
had a length beyond the end of the buffer.  Then we memmove it to the
start, read to it's end, process and start the game again.

What am I missing here... (I'm sure there must be somthing).

Andrew Bartlett

Andrew Bartlett                                 abartlet at
Manager, Authentication Subsystems, Samba Team  abartlet at
Student Network Administrator, Hawker College   abartlet at

More information about the samba-technical mailing list