3#define WIN32_LEAN_AND_MEAN
10extern "C" int DoSrv(
char * pIn );
11extern "C" int DoSrvMore(
char * pOut,
size_t nMax );
18 static const TCHAR pipeNameToSrv[] = _T(
"\\\\.\\pipe\\ToSrvPipe");
20 hPipeToSrv = CreateNamedPipe(
23 PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT | PIPE_REJECT_REMOTE_CLIENTS,
24 PIPE_UNLIMITED_INSTANCES,
29 if( hPipeToSrv == INVALID_HANDLE_VALUE)
32 static const TCHAR pipeNameFromSrv[] = __T(
"\\\\.\\pipe\\FromSrvPipe");
34 hPipeFromSrv = CreateNamedPipe(
37 PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT | PIPE_REJECT_REMOTE_CLIENTS,
38 PIPE_UNLIMITED_INSTANCES,
43 if( hPipeFromSrv == INVALID_HANDLE_VALUE)
50 CHAR chRequest[
nBuff ];
51 CHAR chResponse[
nBuff ];
58 printf(
"Obtaining pipe\n" );
59 bConnected = ConnectNamedPipe(hPipeToSrv, NULL) ?
60 TRUE : (GetLastError()==ERROR_PIPE_CONNECTED );
61 printf(
"Obtained to-srv %i\n", bConnected );
64 bConnected = ConnectNamedPipe(hPipeFromSrv, NULL) ?
65 TRUE : (GetLastError()==ERROR_PIPE_CONNECTED );
66 printf(
"Obtained from-srv %i\n", bConnected );
72 printf(
"About to read\n" );
73 bSuccess = ReadFile( hPipeToSrv, chRequest,
nBuff, &cbBytesRead, NULL);
75 chRequest[ cbBytesRead] =
'\0';
77 if( !bSuccess || cbBytesRead==0 )
80 printf(
"Rxd %s\n", chRequest );
89 WriteFile( hPipeFromSrv, chResponse, nWritten-1, &cbBytesWritten, NULL);
93 FlushFileBuffers( hPipeToSrv );
94 DisconnectNamedPipe( hPipeToSrv );
95 FlushFileBuffers( hPipeFromSrv );
96 DisconnectNamedPipe( hPipeFromSrv );
101 CloseHandle( hPipeToSrv );
102 CloseHandle( hPipeFromSrv );
105 CloseHandle( hPipeToSrv );
106 CloseHandle( hPipeFromSrv );
111#include <sys/types.h>
117const char fifotmpl[] =
"/tmp/audacity_script_pipe.%s.%d";
121extern "C" int DoSrv(
char * pIn );
122extern "C" int DoSrvMore(
char * pOut,
size_t nMax );
126 FILE *fromFifo = NULL;
130 char toFifoName[
nBuff];
131 char fromFifoName[
nBuff];
133 sprintf(toFifoName,
fifotmpl,
"to", getuid());
134 sprintf(fromFifoName,
fifotmpl,
"from", getuid());
137 unlink(fromFifoName);
141 rc = mkfifo(fromFifoName, S_IRWXU) & mkfifo(toFifoName, S_IRWXU);
144 perror(
"Unable to create fifos");
145 printf(
"Ignoring...");
150 toFifo = fopen(toFifoName,
"r");
153 perror(
"Unable to open fifo to server from script");
154 if (fromFifo != NULL)
160 fromFifo = fopen(fromFifoName,
"w");
161 if (fromFifo == NULL)
163 perror(
"Unable to open fifo from server to script");
167 while (fgets(buf,
sizeof(buf), toFifo) != NULL)
169 int len = strlen(buf);
177 printf(
"Server received %s\n", buf);
187 printf(
"Server sending %s",buf);
190 fwrite(buf, 1, len - 1, fromFifo);
195 printf(
"Read failed on fifo, quitting\n");
200 if (fromFifo != NULL)
204 unlink(fromFifoName);
int DoSrvMore(char *pOut, size_t nMax)