From e35e62a080ac636f5820b2f88f75a1383f14d713 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Thu, 10 Dec 2009 22:35:51 +0000 Subject: Process is working much better, it actually follows the guidelines for most of it's functions now, such as isEos and whotnot, although it won't work in non- blocking mode yet, and I'm still trying to figure out a good way to have it deal with both stdout and stderr. --- src/process.cpp | 17 ++++++++++++++--- src/process.h | 7 +++++++ src/tests/procs.cpp | 2 +- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/process.cpp b/src/process.cpp index bea5932..9340647 100644 --- a/src/process.cpp +++ b/src/process.cpp @@ -94,7 +94,13 @@ void Bu::Process::close() size_t Bu::Process::read( void *pBuf, size_t nBytes ) { - return TEMP_FAILURE_RETRY( ::read( iStdOut, pBuf, nBytes ) ); + size_t nRead = TEMP_FAILURE_RETRY( ::read( iStdOut, pBuf, nBytes ) ); + if( nRead == 0 ) + { + close(); + return 0; + } + return nRead; /* size_t iTotal = 0; for(;;) @@ -162,12 +168,12 @@ void Bu::Process::setPosEnd( long ) bool Bu::Process::isEos() { - return false; + return (iPid == 0); } bool Bu::Process::isOpen() { - return true; + return (iPid != 0); } void Bu::Process::flush() @@ -212,3 +218,8 @@ void Bu::Process::setBlocking( bool bBlocking ) fcntl( iStdOut, F_SETFL, fcntl( iStdOut, F_GETFL, 0 )|O_NONBLOCK ); } +pid_t Bu::Process::getPid() +{ + return iPid; +} + diff --git a/src/process.h b/src/process.h index 121b2dc..e04bb59 100644 --- a/src/process.h +++ b/src/process.h @@ -53,6 +53,13 @@ namespace Bu virtual bool isBlocking(); virtual void setBlocking( bool bBlocking=true ); + /** + * Returns the pid of the child process, or zero if there is no + * currently running child. Note that a read operation must be + * performed in order to discover that the child has ended. + */ + pid_t getPid(); + private: int iStdIn; int iStdOut; diff --git a/src/tests/procs.cpp b/src/tests/procs.cpp index c456823..4f177c9 100644 --- a/src/tests/procs.cpp +++ b/src/tests/procs.cpp @@ -13,7 +13,7 @@ int main() { //Bu::Process p( argv[1], argv+1 ); Bu::Process p("mplayer", "mplayer", "dvd://", "-framedrop", - "-ao", "null", "-nosound", "-vf", "framestep=I,cropdetect" "-sstep", + "-ao", "null", "-nosound", "-vf", "framestep=I,cropdetect", "-sstep", "197", NULL ); char buf[1000]; -- cgit v1.2.3