ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/Smersh/Daemon.hpp
(Generate patch)

Comparing Smersh/Daemon.hpp (file contents):
Revision 179 by Douglas Thrift, 2004-07-02T21:16:12-07:00 vs.
Revision 184 by Douglas Thrift, 2004-07-13T21:43:09-07:00

# Line 7 | Line 7
7   #ifndef _Daemon_hpp_
8   #define _Daemon_hpp_
9  
10 + #include <arpa/inet.h>
11 + #include <sys/utsname.h>
12   #include <menes-api/socket.hpp>
13   #include <menes-api/threads.hpp>
14   #include <menes-etl/fnbind.hpp>
# Line 18 | Line 20
20   class Daemon
21   {
22   protected:
23 <        struct Client { api::TcpSocket socket; api::InternetAddress ip; Client() :
24 <                ip(api::InternetAddress::Any) {} };
25 < private:
26 <        virtual int handle(Client* client);
27 <        void headers(istream& sin, Environment& env);
28 < protected:
23 >        struct Client
24 >        {
25 >                api::InternetAddress ip;
26 >                api::Socket socket;
27 >                Client(api::TcpSocket& server) : socket(server, &ip) {}
28 >        };
29          enum Status { ok = 200, found = 302, seeOther, bad = 400, notFound = 404,
30                  lengthRequired = 411, mediaType = 415, serverError = 500,
31                  notImplemented, version = 505 };
32   private:
33 +        int port;
34 +        virtual int handle(Client* client);
35 +        void headers(istream& sin, Environment& env);
36          Status message(istream& sin, Environment& env, ostream& post);
32        string reason(Status status);
37   protected:
38          static string crlf;
39          string log;
40 <        Daemon(const string& log) : log(log) {}
41 <        void serve(int port, bool fork, Daemon* self);
40 >        Daemon(int port, const string& log) : port(port), log(log) {}
41 >        void serve(bool fork, Daemon* self);
42          istream& getline(istream& sin, string& line) { std::getline(sin, line,
43                  '\r'); sin.get(); return sin; }
44          Status request(istream& sin, Environment& env, ostream& post, ostream& log);
45          void response(ostream& sout, Status status);
46 +        string reason(Status status);
47          string server();
48 <        streamsize error(ostream& sout, Status status);
48 >        string server(const Environment& env);
49 >        streamsize error(ostream& sout, Status status, const Environment& env);
50          string date(bool log = false);
51   public:
52 <        Daemon(int port, bool fork, const string& log) : log(log) {
53 <                Person::configure(); serve(port, fork, this); }
52 >        Daemon(int port, bool fork, const string& log) : port(port), log(log) {
53 >                Person::configure(); serve(fork, this); }
54          virtual ~Daemon() {}
55   };
56  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines