1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-15 15:49:36 +02:00

Fix order in which pipes are opened on linux.

This commit is contained in:
James Crook 2018-01-14 11:50:58 +00:00
parent f9dab3679c
commit 549fa48a24

View File

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