diff --git a/lib-src/mod-script-pipe/PipeServer.cpp b/lib-src/mod-script-pipe/PipeServer.cpp index 4d4212277..583f43acd 100644 --- a/lib-src/mod-script-pipe/PipeServer.cpp +++ b/lib-src/mod-script-pipe/PipeServer.cpp @@ -54,13 +54,17 @@ void PipeServer() for(;;) { + // open to (incoming) pipe first. printf( "Obtaining pipe\n" ); bConnected = ConnectNamedPipe(hPipeToSrv, NULL) ? TRUE : (GetLastError()==ERROR_PIPE_CONNECTED ); printf( "Obtained to-srv %i\n", bConnected ); + + // open from (outgoing) pipe second. This could block if there is no reader. bConnected = ConnectNamedPipe(hPipeFromSrv, NULL) ? TRUE : (GetLastError()==ERROR_PIPE_CONNECTED ); printf( "Obtained from-srv %i\n", bConnected ); + if( bConnected ) { for(;;) @@ -142,13 +146,7 @@ void PipeServer() // return; } - fromFifo = fopen(fromFifoName, "w"); - if (fromFifo == NULL) - { - perror("Unable to open fifo from server to script"); - return; - } - + // open to (incoming) pipe first. toFifo = fopen(toFifoName, "r"); if (toFifo == NULL) { @@ -158,6 +156,14 @@ void PipeServer() return; } + // open from (outgoing) pipe second. This could block if there is no reader. + fromFifo = fopen(fromFifoName, "w"); + if (fromFifo == NULL) + { + perror("Unable to open fifo from server to script"); + return; + } + while (fgets(buf, sizeof(buf), toFifo) != NULL) { int len = strlen(buf);