Make a useful constructor for Client.
[cubemap] / server.cpp
index f5c117b6dcbad54ac13ac30e89e861f8c5943130..6dcddf0b4431e983909e012cb863636f6ccab635 100644 (file)
 
 using namespace std;
 
+Client::Client(int sock)
+       : state(Client::READING_REQUEST),
+         header_bytes_sent(0),
+         bytes_sent(0)
+{
+       request.reserve(1024);
+}
+
 Server::Server()
 {
        pthread_mutex_init(&mutex, NULL);
@@ -96,14 +104,7 @@ void Server::do_work()
 void Server::add_client(int sock)
 {
        MutexLock lock(&mutex);
-       Client new_client;
-       new_client.sock = sock;
-       new_client.request.reserve(1024);
-       new_client.state = Client::READING_REQUEST;
-       new_client.header_bytes_sent = 0;
-       new_client.bytes_sent = 0;
-
-       clients.insert(make_pair(sock, new_client));
+       clients.insert(make_pair(sock, Client(sock)));
 
        // Start listening on data from this socket.
        epoll_event ev;