8 |
|
|
9 |
|
string Daemon::crlf("\r\n"); |
10 |
|
|
11 |
< |
void Daemon::serve(bool fork, Daemon* self) |
11 |
> |
void Daemon::serve(Daemon* self) |
12 |
|
{ |
13 |
< |
api::TcpSocket server; |
13 |
> |
ext::StackReference<api::TcpSocket> server; |
14 |
|
|
15 |
|
server.SetAddress(api::InternetAddress(api::InternetAddress::Any, port)); |
16 |
– |
|
17 |
– |
if (fork) |
18 |
– |
{ |
19 |
– |
switch (pid_t pid = ::fork()) |
20 |
– |
{ |
21 |
– |
case -1: |
22 |
– |
cerr << program << ": fork()\n"; |
23 |
– |
|
24 |
– |
exit(1); |
25 |
– |
case 0: |
26 |
– |
break; |
27 |
– |
default: |
28 |
– |
cout << pid << '\n'; |
29 |
– |
return; |
30 |
– |
} |
31 |
– |
} |
32 |
– |
|
16 |
|
server.Listen(50); |
17 |
|
|
18 |
|
while (true) |
19 |
|
{ |
20 |
< |
Client* client (new Client(server)); |
20 |
> |
Client* client(new Client(server)); |
21 |
|
api::Thread thread(etl::BindAll(&Daemon::handle, self, client)); |
22 |
|
} |
23 |
|
} |
158 |
|
|
159 |
|
int Daemon::handle(Client* client) |
160 |
|
{ |
161 |
< |
ios::InputOutputStreamBufAdapter adapter(client->socket); |
179 |
< |
iostream sio(&adapter); |
161 |
> |
ios::ToIoStream sio(&client->socket, &client->socket); |
162 |
|
Environment env; |
163 |
|
stringstream post; |
164 |
|
ostringstream log; |
204 |
|
client->socket.ShutdownWrite(); |
205 |
|
|
206 |
|
delete client; |
207 |
+ |
|
208 |
+ |
return 0; |
209 |
|
} |
210 |
|
|
211 |
|
void Daemon::headers(istream& sin, Environment& env) |