I try to connect my application in C with IIS via NamedPipe but I cannot get a pipe handle. CreateFile function always return ERROR_PIPE_BUSY value. What is correct way to get this handle? This is my source code:
#include <Windows.h>
#include <stdio.h>
#pragma warning(disable : 4996)
static void Log(const char * log, int logLen)
{
FILE * file;
file = fopen("C:\\Programy\\fastCGI\\Debug\\log.log", "ab");
fwrite(log, 1, logLen, file);
fwrite("\n", 1, 1, file);
fclose(file);
}
static void LogTxt(const char * log)
{
Log(log, strlen(log));
}
static void LogErrCode(const char * log, int logLen, int err)
{
char buf[1024];
itoa(err, buf, 10);
strcat(buf, log);
LogTxt(buf);
}
int main(int argc, char * argv[])
{
HANDLE pipe;
BOOL fSuccess = FALSE;
wchar_t pipeName[1024];
LogTxt(getenv("_FCGI_X_PIPE_"));
while (1)
{
pipe = CreateFileA(getenv("_FCGI_X_PIPE_"), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
// Break if the pipe handle is valid.
if (pipe != INVALID_HANDLE_VALUE)
break;
// Exit if an error other than ERROR_PIPE_BUSY occurs.
if (GetLastError() != ERROR_PIPE_BUSY)
{
LogErrCode(" Could not open pipe.", 21, GetLastError());
return -1;
}
// All pipe instances are busy, so wait for 2 seconds.
if (!WaitNamedPipeA(getenv("_FCGI_X_PIPE_"), 2000))
{
LogErrCode(" Could not open pipe: 2 second wait timed out.", 45, GetLastError());
return -1;
}
}
return 0;
}
When I read from stdin I get the request, but how to send a response?
2 Posts
How to get FastCGI NamedPipe handle in C
Dec 19, 2016 11:09 AM|Ankar1|LINK
Hi
I try to connect my application in C with IIS via NamedPipe but I cannot get a pipe handle. CreateFile function always return ERROR_PIPE_BUSY value. What is correct way to get this handle? This is my source code:
When I read from stdin I get the request, but how to send a response?
This is my source code to read from stdin:
Thanks for any advice
3750 Posts
Microsoft
Re: How to get FastCGI NamedPipe handle in C
Dec 20, 2016 03:00 AM|Yuk Ding|LINK
Hi Ankar1,
This link provide the correct steps to create named pipe for client and server side:
https://www.codeproject.com/questions/232056/named-pipes-windows-error-pipe-busy
Besides, this link also provide the instruction to create named pipe client:
https://msdn.microsoft.com/en-us/library/aa365592(v=vs.85).aspx
I think maybe c# could be the better language to handle IIS.
Best Regards,
Yuk Ding
MSDN Community Support
Please remember to "Mark as Answer" the responses that resolved your issue.
2 Posts
Re: How to get FastCGI NamedPipe handle in C
Dec 20, 2016 12:03 PM|Ankar1|LINK
Thank you for your reply but I've already was on this sites.
Today I found something else:
https://blogs.iis.net/yaminij/getting-started-with-writing-a-fastcgi-client-application-fastcgi-test-client
I checked only the exe file with IIS 7.5 but it works. Now I have to read the source code and figure out how it works.
3750 Posts
Microsoft
Re: How to get FastCGI NamedPipe handle in C
Dec 21, 2016 10:00 AM|Yuk Ding|LINK
Hi Ankar1,
Thanks for sharing your experience.
Best Regards,
Yuk Ding
MSDN Community Support
Please remember to "Mark as Answer" the responses that resolved your issue.
1 Post
Re: How to get FastCGI NamedPipe handle in C
Feb 07, 2017 05:04 AM|arriscig55|LINK
Merci pour le lien. C'est vrai que des fois nous avons du mal avec l'informatique.