[erlang-questions] Using select in a Port
Per Hedeland
per@REDACTED
Fri Oct 19 15:18:47 CEST 2007
Michael Schreckenbauer <grimlog@REDACTED> wrote:
>
>This proceeds, if at least one(!) of the fds you gave won't block, when you do
>a read on it. That could be stdin or any other.
>
>> if FD_ISSET(0, &readfds) {
>> memset(buf, 0, BUFFER_SIZE);
>> read_cmd(buf, &size);
>
>Here you check the right fd, but read_cmd always uses stdin.
>The nonblocking fd is 3, your file, as you can see in the debug output. So
>read_cmd must fail. It needs an additional parameter holding the fd you want
>to use.
No, this is code is correct per se - if fd 0 is ready, he calls a
function that reads only from fd 0, which is clearly OK. The other fd's
are handled in note_read(), which isn't included in the mail but is
where the debug output is produced. Regardless of that, select says that
fd 0 *is* "ready" - the error is in assuming that this means that there
is (some specific amount of) data to read.
--Per Hedeland
More information about the erlang-questions
mailing list