summaryrefslogtreecommitdiffabout
path: root/include/kingate/fastcgi.h
blob: fd293b9fae7369d85f0bbe02fa441a69baed67bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#ifndef __KINGATE_FASTCGI_H
#define __KINGATE_FASTCGI_H

#include "kingate/cgi_interface.h"
#include <fcgio.h>

/**
 * @file
 * @brief the fastcgi-specific implementation.
 */

namespace kingate {

    /**
     * The fcgi listening socket.
     */
    class fcgi_socket {
	    static bool _initialized;
	public:
	    /**
	     * socket file descriptor.
	     */
	    int sock;

	    /**
	     * @param s the socket name. (if the socket starts with a colon,
	     * then it is interpreted as a tcp port number.
	     * @param bl backlog listen queue depth.
	     */
	    fcgi_socket(const char* s,int bl);
	    /**
	     * @param s the file descriptor of preopened socket.
	     */
	    fcgi_socket(int s);
	    ~fcgi_socket();
    };

    /**
     * The implementation of the interface to the FastCGI.
     */
    class fcgi_interface : public cgi_interface {
	public:
	    /**
	     * stdin fcgi streambuf.
	     */
	    fcgi_streambuf sbin;
	    /**
	     * stdout fcgi streambuf.
	     */
	    fcgi_streambuf sbout;
	    /**
	     * stderr fcgi streambuf.
	     */
	    fcgi_streambuf sberr;
	    /**
	     * stdin istream.
	     */
	    istream sin;
	    /**
	     * stdout ostream.
	     */
	    ostream sout;
	    /**
	     * stderr ostream.
	     */
	    ostream serr;
	    /**
	     * The FCGI request.
	     */
	    FCGX_Request request;

	    /**
	     * @param s the socked used for interfacing with the server.
	     * @param f the request flags (e.g. FCGI_FAIL_ON_INTR).
	     */
	    fcgi_interface(fcgi_socket& s,int f=0);
	    virtual ~fcgi_interface();

	    /**
	     * @overload cgi_interface::in()
	     */
	    istream& in() { return sin; }
	    /**
	     * @overload cgi_interface::out()
	     */
	    ostream& out() { return sout; }
	    /**
	     * @overload cgi_interface::out()
	     */
	    ostream& err() { return serr; }
    };

}

#endif /* __KINGATE_FASTCGI_H */
/*
 * vim:set ft=cpp:
 */