From 771355dc2b3ac9d076482148a03591debb97f62e Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Sat, 6 Apr 2013 21:34:48 +0200 Subject: [PATCH] Make a useful constructor for Client. --- server.cpp | 17 +++++++++-------- server.h | 3 +++ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/server.cpp b/server.cpp index f5c117b..6dcddf0 100644 --- a/server.cpp +++ b/server.cpp @@ -21,6 +21,14 @@ 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; diff --git a/server.h b/server.h index 0f93b7f..6311c68 100644 --- 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; -- 2.39.2