From: Gary Wright Date: 2007-12-30T07:05:15+09:00 Subject: Re: IO#write_nonblock and Errno::EAGAIN On Dec 29, 2007, at 1:47 PM, Tony Arcieri wrote: > How do you figure out how many bytes were actually written in the > event of a partial write? > > Looking at the description: > > "write_nonblock just calls write(2). It causes all errors write(2) > causes: EAGAIN, EINTR, etc. The result may also be smaller than > string.length (partial write). The caller should care such errors > and partial write." > > In the case of a partial write, write(2) returns the number of > bytes written (which will differ from the number of bytes > requested) and set errno to EAGAIN. > > Is there any way to silently swallow that exception and get the > return value from write(2)? I'm implementing a buffered writer and > need to know how many bytes to remove from the internal buffer > because they were successfully written. I believe you won't get a partial write *and* an exception. You'll get one or the other. Sometimes you'll get a partial write and then an exception on the *next* attempt to write to the file descriptor. This can happen, for example, when a network connection is shutdown in the middle of a write. Gary Wright