Skip to content

Instantly share code, notes, and snippets.

@nileshgr
Last active August 28, 2015 16:32
Show Gist options
  • Save nileshgr/10f4bcb7b8b370966dc1 to your computer and use it in GitHub Desktop.
Save nileshgr/10f4bcb7b8b370966dc1 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <fcgio.h>
#include <asio.hpp>
#include <thread>
#include <unistd.h>
#include <string>
#define FCGI_SOCKET "/tmp/fcgi_socket"
void hello(asio::local::stream_protocol::socket& sock) {
std::string msg = "Hello World\n";
asio::write(sock, asio::buffer(msg));
sleep(10);
}
int main() {
::unlink(FCGI_SOCKET);
using namespace asio::local;
asio::io_service fcgi_ioservice;
stream_protocol::endpoint fcgi_endpoint(FCGI_SOCKET);
stream_protocol::socket fcgi_socket(fcgi_ioservice);
stream_protocol::acceptor fcgi_acceptor (fcgi_ioservice, fcgi_endpoint);
while(true) {
fcgi_acceptor.accept(fcgi_socket);
std::thread t1 (hello, std::ref(fcgi_socket));
t1.join();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment