aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/process.cpp17
-rw-r--r--src/process.h7
-rw-r--r--src/tests/procs.cpp2
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()
94 94
95size_t Bu::Process::read( void *pBuf, size_t nBytes ) 95size_t Bu::Process::read( void *pBuf, size_t nBytes )
96{ 96{
97 return TEMP_FAILURE_RETRY( ::read( iStdOut, pBuf, nBytes ) ); 97 size_t nRead = TEMP_FAILURE_RETRY( ::read( iStdOut, pBuf, nBytes ) );
98 if( nRead == 0 )
99 {
100 close();
101 return 0;
102 }
103 return nRead;
98 /* 104 /*
99 size_t iTotal = 0; 105 size_t iTotal = 0;
100 for(;;) 106 for(;;)
@@ -162,12 +168,12 @@ void Bu::Process::setPosEnd( long )
162 168
163bool Bu::Process::isEos() 169bool Bu::Process::isEos()
164{ 170{
165 return false; 171 return (iPid == 0);
166} 172}
167 173
168bool Bu::Process::isOpen() 174bool Bu::Process::isOpen()
169{ 175{
170 return true; 176 return (iPid != 0);
171} 177}
172 178
173void Bu::Process::flush() 179void Bu::Process::flush()
@@ -212,3 +218,8 @@ void Bu::Process::setBlocking( bool bBlocking )
212 fcntl( iStdOut, F_SETFL, fcntl( iStdOut, F_GETFL, 0 )|O_NONBLOCK ); 218 fcntl( iStdOut, F_SETFL, fcntl( iStdOut, F_GETFL, 0 )|O_NONBLOCK );
213} 219}
214 220
221pid_t Bu::Process::getPid()
222{
223 return iPid;
224}
225
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
53 virtual bool isBlocking(); 53 virtual bool isBlocking();
54 virtual void setBlocking( bool bBlocking=true ); 54 virtual void setBlocking( bool bBlocking=true );
55 55
56 /**
57 * Returns the pid of the child process, or zero if there is no
58 * currently running child. Note that a read operation must be
59 * performed in order to discover that the child has ended.
60 */
61 pid_t getPid();
62
56 private: 63 private:
57 int iStdIn; 64 int iStdIn;
58 int iStdOut; 65 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()
13{ 13{
14 //Bu::Process p( argv[1], argv+1 ); 14 //Bu::Process p( argv[1], argv+1 );
15 Bu::Process p("mplayer", "mplayer", "dvd://", "-framedrop", 15 Bu::Process p("mplayer", "mplayer", "dvd://", "-framedrop",
16 "-ao", "null", "-nosound", "-vf", "framestep=I,cropdetect" "-sstep", 16 "-ao", "null", "-nosound", "-vf", "framestep=I,cropdetect", "-sstep",
17 "197", NULL ); 17 "197", NULL );
18 18
19 char buf[1000]; 19 char buf[1000];