in reply to Re^7: Forks, Pipes and Exec (file descriptors)
in thread Forks, Pipes and Exec
The last problem I seem to be fighting is that when I run the code to set a pipe as nonblocking, it isn't really nonblocking. I seem to get a chunk of data every 15 seconds or so on Win2k3 using this code:
That problem has nothing to do with blocking. You are simply Suffering from buffering. The addition of $|++; to the top of yes.pl and you will get your output once per second.
However, if the connected process is not a perl script, but some executable that doesn't disable buffering, then there may be nothing that you can do about this unless you can modify and re-build that executable. If you were using the underlying OS api calls to create the pipe, then you can disable buffering from either end, but Perl doesn't expose that functionality.
If there isn't anything on the pipe that doesn't matter, I just continue and service the next request that may/may not be waiting. Select is never used so I didn't see this as an issue.
Hm. Unless I am misunderstanding you, it does matter. If you try to read from a pipe and there is nothing available, then the read will block until there is. Even if the pipe is non-blocking. Which means you won't be able to "continue and service the next request" once you enter a readstate on one pipe until something becomes available on that pipe.
Setting the pipe non-blocking allows you to use select to discover when the is something to be read and only enter the read when you know it will be satisfied immediately. But, I said above, there is no way to set an anonymous pipe non-blocking on win32.
With respect to an alternative way to code yout application so that it will work on Win32. I'm afraid I still find your descriiption insuffucuently clear to suggest anything. There are several bit of this latest post that leave me confused. For example,
- when you say
"I'm using the non-blocking because I have a thread that executes..."
Do you mean you are already using threads--explicitly? Or are you using (pseudo-)processes via fork?
- And
" is to provide an instance of the module that can start another process/thread/etc."
Again, which is it? Processes? Threads? Both? And what is "etc."
Please don't take that as pendantry. Too often people will use these terms interchangably, but it is important to distinguish between them.
The two processes will communicate with each other in a command/result xml format (all commands come from the instantiated module and are sent to the child process). The child process is the responsible for servicing those requests which includes starting up additional cli programs and buffering their output. The buffer will be regularly checked for errors and when the parent process requests the errors, they are passed back up.
That implies you are talking about bi-directional communications via pipes--Expect style. I don't think anyone has got that to work from Perl on Win32.
I hope that explains things.
Sorry, but no it doesn't. At this point, the overall architecture of your application is about as clear as mud to me. It involves child processes, and pipes, and sending commands to the children, and getting replies back, and running multiple of these concurrently, but I have no overview.
And quite how you are achieving this on linux without using select is beyond me?
If you have code that works on Linux and don't mind letting me see it--either here or via email--that would certainly be the quickest way for me to understand what you are doing and perhaps be able to suggest how to make it work on Win32.
From what I've understood of what you've said POE certainly sounds like an option, though as you imply it would probably mean re-writing everything you have and involve a pretty steep learning curve. I'm also not sure how portable POE code is to Win32.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^9: Forks, Pipes and Exec (file descriptors)
by diabelek (Beadle) on Nov 08, 2008 at 04:12 UTC | |
by BrowserUk (Patriarch) on Nov 08, 2008 at 15:12 UTC | |
by diabelek (Beadle) on Nov 12, 2008 at 04:05 UTC | |
by BrowserUk (Patriarch) on Nov 12, 2008 at 05:45 UTC | |
by diabelek (Beadle) on Nov 12, 2008 at 15:46 UTC | |
|