{
Client &cl = get_client_by_response(resp);
if(cl.async)
- {
- cl.sock->write(resp.str());
- cl.stale = true;
- }
+ send_response(cl, *cl.response);
}
void Server::data_available()
cl.in_buf.erase(0, len);
}
- bool keepalive = false;
if(cl.request && cl.request->is_complete() && !response)
{
+ cl.keepalive = false;
if(cl.request->has_header("Connection"))
- keepalive = (cl.request->get_header("Connection")=="keep-alive");
+ cl.keepalive = (cl.request->get_header("Connection")=="keep-alive");
response = new Response(NONE);
try
}
if(response)
+ send_response(cl, *response);
+}
+
+void Server::send_response(Client &cl, Response &resp)
+{
+ cl.sock->write(resp.str());
+ cl.async = false;
+ if(cl.keepalive)
{
- cl.sock->write(response->str());
- if(keepalive)
- {
- delete cl.request;
- cl.request = 0;
- delete cl.response;
- cl.response = 0;
- }
- else
- {
- cl.sock->shutdown(IO::M_WRITE);
- cl.stale = true;
- }
+ delete cl.request;
+ cl.request = 0;
+ delete cl.response;
+ cl.response = 0;
+ }
+ else
+ {
+ cl.sock->shutdown(IO::M_WRITE);
+ cl.stale = true;
}
}
sock(s),
request(0),
response(0),
+ keepalive(false),
async(false),
stale(false)
{ }
std::string in_buf;
Request *request;
Response *response;
+ bool keepalive;
bool async;
bool stale;
private:
void data_available();
void client_data_available(Client &);
+ void send_response(Client &, Response &);
void client_end_of_file(Client &);
Client &get_client_by_response(Response &);
};