File tree Expand file tree Collapse file tree 1 file changed +19
-22
lines changed
Expand file tree Collapse file tree 1 file changed +19
-22
lines changed Original file line number Diff line number Diff line change @@ -378,31 +378,28 @@ void AConnection::onNoPollEvent(struct pollfd &) {
378378 Poll::setTimeout (timeout);
379379}
380380
381- static bool initPipes ( int a[ 2 ], int b[ 2 ]) {
382- static int const fdsize = 4 ;
383- int fd[fdsize];
384- int flags[fdsize];
385-
386- if (pipe (&(fd[ 0 ]) ) == -1 ) return false ;
387- if (pipe (&(fd[ 2 ]) ) == -1 ) {
388- close (fd [0 ]);
389- close (fd [1 ]);
381+ /* *
382+ * @param pipeIn pipe to receive output of cgi
383+ * @param pipOut pipe to send data from server to cgi
384+ */
385+ static bool initPipes ( int pipeIn[ 2 ], int pipeOut[ 2 ]) {
386+ if (pipe (pipeIn ) == -1 ) return false ;
387+ if (pipe (pipeOut ) == -1 ) {
388+ close (pipeIn [0 ]);
389+ close (pipeIn [1 ]);
390390 return false ;
391391 }
392- for (int i = 0 ; i < fdsize; ++i) {
393- flags[i] = fcntl (fd[i], F_GETFL, 0 );
394- if (flags[i] == -1 || fcntl (fd[i], F_SETFL, flags[i] | O_NONBLOCK) == -1 ) {
395- close (fd[0 ]);
396- close (fd[1 ]);
397- close (fd[2 ]);
398- close (fd[3 ]);
399- return false ;
400- }
392+ int flagsIn = fcntl (pipeIn[0 ], F_GETFL, 0 );
393+ int flagsOut = fcntl (pipeOut[1 ], F_GETFL, 0 );
394+ if (flagsIn == -1 || fcntl (pipeIn[0 ], F_SETFL, flagsIn | O_NONBLOCK) == -1 ||
395+ flagsOut == -1 ||
396+ fcntl (pipeOut[1 ], F_SETFL, flagsOut | O_NONBLOCK) == -1 ) {
397+ close (pipeIn[0 ]);
398+ close (pipeIn[1 ]);
399+ close (pipeOut[0 ]);
400+ close (pipeOut[1 ]);
401+ return false ;
401402 }
402- a[0 ] = fd[0 ];
403- a[1 ] = fd[1 ];
404- b[0 ] = fd[2 ];
405- b[1 ] = fd[3 ];
406403 return true ;
407404}
408405
You can’t perform that action at this time.
0 commit comments