20 |
|
|
21 |
|
if (fork) |
22 |
|
{ |
23 |
< |
switch (::fork()) |
23 |
> |
switch (pid_t pid = ::fork()) |
24 |
|
{ |
25 |
|
case -1: |
26 |
|
cerr << program << ": fork()\n"; |
29 |
|
case 0: |
30 |
|
break; |
31 |
|
default: |
32 |
+ |
cout << pid << '\n'; |
33 |
|
return; |
34 |
|
} |
35 |
|
} |
38 |
|
|
39 |
|
while (true) |
40 |
|
{ |
41 |
< |
api::TcpSocket* client(new api::TcpSocket()); |
41 |
> |
Client* client (new Client); |
42 |
|
|
43 |
< |
server.Accept(*client); |
43 |
> |
server.Accept(client->socket, &client->ip); |
44 |
|
|
45 |
|
api::Thread thread(etl::BindAll(&Daemon::handle, self, client)); |
46 |
|
} |
126 |
|
return when; |
127 |
|
} |
128 |
|
|
129 |
< |
string Daemon::ip(const api::TcpSocket& socket) |
129 |
> |
int Daemon::handle(Client* client) |
130 |
|
{ |
131 |
< |
api::InternetAddress address(socket.GetAddress()); |
131 |
< |
|
132 |
< |
return inet_ntoa(address->sin_addr); |
133 |
< |
} |
134 |
< |
|
135 |
< |
int Daemon::handle(api::TcpSocket* client) |
136 |
< |
{ |
137 |
< |
ios::InputOutputStreamBufAdapter adapter(*client); |
131 |
> |
ios::InputOutputStreamBufAdapter adapter(client->socket); |
132 |
|
iostream sio(&adapter); |
133 |
|
Environment env; |
134 |
|
stringstream post; |
162 |
|
|
163 |
|
ofstream fout(this->log.c_str(), ios_base::app); |
164 |
|
|
165 |
< |
fout << ip(*client) << " - - " << date(true) << ' ' << log.str() << '\n'; |
165 |
> |
fout << inet_ntoa(client->ip->sin_addr) << " - - " << date(true) << ' ' |
166 |
> |
<< log.str() << '\n'; |
167 |
|
sio << flush; |
168 |
|
|
169 |
< |
client->ShutdownWrite(); |
169 |
> |
client->socket.ShutdownWrite(); |
170 |
|
|
171 |
|
delete client; |
172 |
|
} |