octave-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-bug-tracker] [bug #33330] fgets hangs octave when reading newlin


From: Rik
Subject: [Octave-bug-tracker] [bug #33330] fgets hangs octave when reading newline
Date: Wed, 18 May 2011 04:04:21 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:2.0.1) Gecko/20100101 Firefox/4.0.1

Follow-up Comment #5, bug #33330 (project octave):

The 'hang' is not really a hang.  When you do a read on a socket and there is
nothing available the operating system has two choices.  The default is
blocking I/O which means the process stops and waits for input.  For example,
when you call zenity from a bash command line it stops and waits for you to do
something with the graphical object.  It doesn't just return to the prompt and
allow you to continue typing.  Octave is operating the same way.  If you must,
you can tell the operating system that you want non-blocking I/O in which case
any call to read something from the socket will return immediately if there is
nothing there.  However, you shouldn't build this into a tight polling loop. 
Don't try something like the loop below.


while (isempty (fscanf (fid, '%s', 'C')))
  sleep (1);
endwhile


If you do need to change to non-blocking mode you can use the fcntl() function
like so


fcntl (fid, F_SETFL, O_NONBLOCK);


in which case a read on an empty socket will return [] immediately.


    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?33330>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]