[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Problem with gnuplot backend + popen2 + non-blocking mode
From: |
John W. Eaton |
Subject: |
Re: Problem with gnuplot backend + popen2 + non-blocking mode |
Date: |
Thu, 24 Apr 2008 15:42:01 -0400 |
On 24-Apr-2008, Michael Goffioul wrote:
| On Thu, Apr 24, 2008 at 7:29 PM, John W. Eaton <address@hidden> wrote:
| > I would have expected the pipe that is open for writing to already be
| > in blocking-write mode. Here is what I see:
| >
| > octave:1> [to_gnuplot, from_gnuplot] = popen2 ("gnuplot")
| > in = 4
| > out = 5
| > octave:2> bitand (fcntl (to_gnuplot, F_GETFL, 0), O_NONBLOCK)
| > ans = 0
| > octave:3> bitand (fcntl (from_gnuplot, F_GETFL, 0), O_NONBLOCK)
| > ans = 2048
| >
| > Do you also see a non-zero result for the "to_gp" stream? If so, then
| > does the following patch fix the problem?
|
| I didn't check, but I'm pretty sure it won't change anything
| as fcntl does not work under Win32;
|
| > Instead of fixing the problem in gnuplot_drawnow, maybe the
| > octave_popen2 function for Windows should be fixed to open the writing
| > stream in blocking mode, same as the Unixy popen2 does?
|
| Indeed. I didn't realize that the sync_mode flag only controlled
| the read pipe, while the write pipe was always in blocking mode.
| The Windows version of popen2 does not do that, it puts both
| pipes in non-blocking mode.
|
| Do you want me to propose a patch? Or would you do it
| yourself? (it's a only one line to remove, in lo-sysdep.cc,
| around line 143; the SetNamedPipeHandleState call for
| parentWrite should be removed).
I checked in the following change. Is that OK?
Thanks,
jwe
# HG changeset patch
# User Michael Goffioul
# Date 1209066081 14400
# Node ID c0d3ecb30f4ba38749b9ccd2a322db0eb6832651
# Parent 2d2a969c731ca25a53191f3d428ebe1c2e818b4f
lo-sysdep.cc (octave_popen2): don't set PIPE_NOWAIT for parentWrite
diff --git a/liboctave/ChangeLog b/liboctave/ChangeLog
--- a/liboctave/ChangeLog
+++ b/liboctave/ChangeLog
@@ -1,3 +1,7 @@ 2008-04-21 John W. Eaton <address@hidden
+2008-04-24 Michael Goffioul <address@hidden>
+
+ * lo-sysdep.cc (octave_popen2): Don't set PIPE_NOWAIT for parentWrite.
+
2008-04-21 John W. Eaton <address@hidden>
* idx-vector.cc (IDX_VEC_REP::idx_vector_rep (const boolNDArray&)):
diff --git a/liboctave/lo-sysdep.cc b/liboctave/lo-sysdep.cc
--- a/liboctave/lo-sysdep.cc
+++ b/liboctave/lo-sysdep.cc
@@ -141,7 +141,6 @@ octave_popen2 (const std::string& cmd, c
{
pipeMode = PIPE_NOWAIT;
SetNamedPipeHandleState (parentRead, &pipeMode, 0, 0);
- SetNamedPipeHandleState (parentWrite, &pipeMode, 0, 0);
}
fildes[1] = _open_osfhandle (reinterpret_cast<long> (parentRead), _O_RDONLY
| _O_BINARY);
fildes[0] = _open_osfhandle (reinterpret_cast<long> (parentWrite), _O_WRONLY
| _O_BINARY);
diff --git a/scripts/plot/gnuplot_drawnow.m b/scripts/plot/gnuplot_drawnow.m
--- a/scripts/plot/gnuplot_drawnow.m
+++ b/scripts/plot/gnuplot_drawnow.m
@@ -78,6 +78,12 @@ function [plot_stream, enhanced] = open_
[plot_stream(1), plot_stream(2), pid] = popen2 (cmd);
if (pid < 0)
error ("drawnow: failed to open connection to gnuplot");
+ else
+ ## Ensure that the stream open from writing to gnuplot is in
+ ## blocking-write mode:
+ oflags = fcntl (plot_stream(1), F_GETFL, 0);
+ nflags = bitand (oflags, bitcmp (O_NONBLOCK));
+ fcntl (plot_stream(1), F_SETFL, nflags);
endif
else
plot_stream = popen (cmd, "w");