From 8f2b453f74e65f48aaa7780f0b5cc64934b6b5b9 Mon Sep 17 00:00:00 2001 From: Erik Zandvliet Date: Tue, 15 Jun 2010 17:20:12 +0200 Subject: [PATCH] PLS multiclient build --- Server/main.cpp | 13 ++++++------- Server/user.cpp | 19 ++++--------------- 2 files changed, 10 insertions(+), 22 deletions(-) diff --git a/Server/main.cpp b/Server/main.cpp index ad002592..610d4f90 100644 --- a/Server/main.cpp +++ b/Server/main.cpp @@ -26,7 +26,6 @@ int main( int argc, char * argv[] ) { for (int i = 0; i < buffers; i ++ ) { ringbuf[i] = new buffer; ringbuf[i]->data = (char*) malloc(size_per_buffer); - ringbuf[i]->data[0] = i+'a'; } for (int i = 0; i < buffers; i ++ ) { std::cout << "Buffer[" << i << "][0]: " << ringbuf[i]->data[0] << "\n"; } int connections = atoi(argv[3]); @@ -53,14 +52,14 @@ int main( int argc, char * argv[] ) { while(true) { loopcount ++; - std::cout << "#" << loopcount << "\n"; inp_amount = fread(&input,1,11,stdin); if (input[0] == 9) { - std::cout << "9!!\n"; open_connection = get_empty(connectionList,connections); if (open_connection != -1) { connectionList[open_connection]->connect( (SWUnixSocket *)listener.accept(&BError) ); if (connectionList[open_connection]->is_connected()) { + std::cout << "#" << loopcount << ": "; + std::cout << "!!Client " << open_connection << " connected.!!\n"; connectionList[open_connection]->send_msg(&header[0],13,NULL); } } @@ -78,14 +77,14 @@ int main( int argc, char * argv[] ) { position_current ++; } ringbuf[current_buffer]->size = position_current; - std::cout << "Total message read!\n"; +// std::cout << "Total message read!\n"; for (int i = 0; i < connections; i++) { - std::cout << "Checking connection " << i << "\n"; if (connectionList[i]->is_connected()) { - std::cout << "Connected...\n"; +// std::cout << "Client " << i << " connected, sending..\n"; if ( connectionList[i]->myConnection->send(&ringbuf[current_buffer]->data[0], ringbuf[current_buffer]->size, &BError) == -1) { - std::cout << " -1 :(\n"; connectionList[i]->disconnect(); + std::cout << "#" << loopcount << ": "; + std::cout << "!!Client " << i << " disconnected.!!\n"; } } } diff --git a/Server/user.cpp b/Server/user.cpp index 88337fe1..20e3f2f0 100644 --- a/Server/user.cpp +++ b/Server/user.cpp @@ -15,9 +15,7 @@ void user::set_buffer(buffer * newBuffer) { sent = 0; } -int user::get_number() { - return myBuffer->number; -} +int user::get_number() { return myBuffer->number; } bool user::complete_send() { if (sent == myBuffer->size) { return true; } @@ -31,17 +29,8 @@ void user::disconnect() { } } -void user::connect(SWUnixSocket * newConnection) { - myConnection = newConnection; -} +void user::connect(SWUnixSocket * newConnection) { myConnection = newConnection; } -bool user::is_connected( ) { -std::cout << " - Checking...:"; - if (myConnection) { std::cout << " true\n"; return true; } - std::cout << " false\n"; - return false; -} +bool user::is_connected( ) { return myConnection; } -int user::send_msg(char * message, int length, SWBaseSocket::SWBaseError * BError) { - return myConnection->send(message,length,BError); -} +int user::send_msg(char * message, int length, SWBaseSocket::SWBaseError * BError) { return myConnection->send(message,length,BError); }