Do you have a question? Post it now! No Registration Necessary. Now with pictures!
December 30, 2004, 1:25 pm
rate this thread
Re: scp sink function
The sink function reads the stream from the input, decapsulates the
files and directories contained therein and writes them to disk.
Remember that in scp, the same binary runs on both client and server.
The sender (which may be either client or server) calls source(), which
generates the stream which is sent over the connection to another scp,
which calls the sink() function to write the contents of the stream
On Unix (and probably any POSIX platform), the read() and write() syscalls
can partially complete. atomicio ensures that the entire buffer is
written (or read) in, multiple calls if necessary.
Consider the following code:
if (write(fd, buf, 100) < 0)
The write() will return -1 if there is an error, however under some
circumstances the call might write, eg, half the buffer, and return a
value of "50". If that happens, the remainder of the buffer would not
be written and will be discarded, but the program will continue. Those
50 bytes may have been important...
atomicio() is basically a while loop that repeatedly calls read() or
write() while advancng a pointer through the buffer, until either the
entire buffer is written or a hard error is encountered. You can do the
same thing with a while loop inline, but it's much harder to read...
Darren Tucker (dtucker at zip.com.au)
GPG key 8FF4FA69 / D9A3 86E9 7EEE AF4B B2D4 37C9 C982 80C7 8FF4 FA69
Good judgement comes with experience. Unfortunately, the experience
usually comes from bad judgement.
- » ssh on command line: force using a group size (prime size) of 1024 (and no...
- — Newest thread in » Secure Shell Forum