]> git.sesse.net Git - cubemap/commitdiff
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 f5c117b6dcbad54ac13ac30e89e861f8c5943130..6dcddf0b4431e983909e012cb863636f6ccab635 100644 (file)
 
 using namespace std;
 
 
 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);
 Server::Server()
 {
        pthread_mutex_init(&mutex, NULL);
@@ -96,14 +104,7 @@ void Server::do_work()
 void Server::add_client(int sock)
 {
        MutexLock lock(&mutex);
 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;
 
        // Start listening on data from this socket.
        epoll_event ev;
index 0f93b7f0b034caa1eb88a276f3b2aa40fa78fc83..6311c68095c6ef9558bbb7518fb5e8d9a2caae02 100644 (file)
--- a/server.h
+++ b/server.h
@@ -13,6 +13,9 @@
 #define MAX_CLIENT_REQUEST 16384
 
 struct Client {
 #define MAX_CLIENT_REQUEST 16384
 
 struct Client {
+       Client() {}
+       Client(int sock);
+
        // The file descriptor associated with this socket.
        int sock;
 
        // The file descriptor associated with this socket.
        int sock;