I start to write a daemon (linux), which listen for requests via mod_proxy_fcgi or nginx proxy_pass. A similar application is php-fpm. My daemon is something like c-fpm, talking with specific other daemons (local unix sockets) to do the work with database handling and producing html output.
I search for examples how to handle the fcgi input from webserver. With google I cannot found, what I look for.
The code snippet after getting the input:
clientHdl = sockserver->accept(sockserver, CPSOCK_KEEPALIVE, nullptr, 0);
if( clientHdl > -1 )
{
PTStream stream = nullptr;
ssize_t rdBytes = -1;
stream = CPStreamCreate(pool);
rdBytes = sockserver->readToStream(sockserver, clientHdl, stream);
if(rdBytes > 0 )
{
char* ptr = stream->getPointer(stream);
size_t s = stream->getSize(stream);
LOGINFO(("%s: [%s]", prefix, ptr ));
}
stream->free(stream);
shutdown(clientHdl, SHUT_RDWR);
close( clientHdl );
}
The question is: what to do with ptr? For my start it is very hard to read and understand the source of php-fpm. I would love it, to find a simpler example.
Thank you in advance
Edit: the folowing code opened my eyes:
if(rdBytes > 0 )
{
char* ptr = stream->getPointer(stream);
size_t s = stream->getSize(stream);
char z;
char pbuf[200];
size_t pi = 0;
for( size_t i = 0; i < s; i++ )
{
z = ptr[i];
if( z < 32 )
{
static const char h[]="0123456789ABCDEF";
pbuf[ pi++ ] = '[';
pbuf[ pi++ ] = h[ (z >> 4) & 0xF ];
pbuf[ pi++ ] = h[ z & 0xF ];
pbuf[ pi++ ] = ']';
}
else
{
pbuf[ pi++ ] = z;
}
if((pi + 5) > sizeof(pbuf))
{
pbuf[pi] = '\0';
LOGINFO(("%s: %s", prefix, pbuf));
pi = 0;
}
}
pbuf[pi] = '\0';
LOGINFO(("%s: %s", prefix, pbuf));
}
So, now I do not know, if I should delete my question or wait for some interesting information from you.