Write calls which do partial writes
neeraj sangal
neeraj at matrix.UUCP
Wed May 3 04:47:18 AEST 1989
These are questions related to the call:
n = write(fd, buf, len);
As documented in write(2), n is the number of bytes written if the call
is successful; n is -1 otherwise. I had all along assumed that when write
completes successfully, n would equal len. However, at least in Sun OS 4.0
this assumption is not true if fd is a descriptor for a TCP/IP socket and the
socket has been set to do non-blocking I/O.
This raises a number of questions:
1. Can n be less than len if fd is NOT set to non-blocking?
2. Is it true that stream based "sockets" behave similarily?
3. If this is true then won't a number of existing programs break
(especially when they are piped together)?
This approach regarding writes to network file descriptors is quite
logical, especially when used in conjunction with select(2). Select can be
used to detect when write can be done without blocking; however, there is no
way to determine the amount that can be written out without blocking.
The question I have is related to the implementation of select(2) (and
poll). When does select return an indication that a file descriptor
can be written to? Will the underlying protocol complete select the
moment a single byte can be transferred or will it wait before completing
select in the hope that a larger buffer space will free up?
There is a need for a signal to indicate when write to a file
descriptor can be done (similar to SIGIO which is used to indicate when a
read may be done). Is there any reason why this has not been implemented?
Is it being planned or considered for a future version?
On a related matter, how does one do an asynchronous connect on
a BSD socket? The documentation does mention an errno called
EINPROGRESS to indicate that asynchronous connect is in progress. But
then how does one find out whether connect completed and whether it
succeeded or failed?
Neeraj Sangal
Matrix Computer Systems, Inc. 7 1/2 Harris Rd, Nashua, NH 03062
uunet!matrix!neeraj (603) 888-7790
More information about the Comp.unix.wizards
mailing list