Make a useful constructor for Client.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 6 Apr 2013 19:34:48 +0000 (21:34 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 6 Apr 2013 19:34:48 +0000 (21:34 +0200)
server.cpp
server.h

index f5c117b..6dcddf0 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;
index 0f93b7f..6311c68 100644 (file)
--- a/server.h
+++ b/server.h
@@ -13,6 +13,9 @@
 #define MAX_CLIENT_REQUEST 16384
 
 struct Client {
+       Client() {}
+       Client(int sock);
+
        // The file descriptor associated with this socket.
        int sock;