Main Page   Packages   Class Hierarchy   Alphabetical List   Data Structures   File List   Namespace Members   Data Fields   Globals  

Server.cpp

Go to the documentation of this file.
00001 /*
00002  * $Id: Server.cpp,v 1.4 2002/08/09 09:32:36 virtualcasino Exp $
00003  */
00004 #include<Server.h>
00005 #include<Bingo.h>
00006 #include<unistd.h>
00007 
00008 extern SharedVar<int> counter;
00009 
00010 SharedVar<int> Server::stayUp(true);
00011 
00012 void Server::takeDown(){
00013         stayUp.setValue(false);
00014         Socket *a;
00015         a = new Socket("localhost", 12345);
00016 }
00017 
00018 Server::Server(int pp):ServerSocket(pp){;}
00019 
00020 bool Server::init(){
00021         //At this point we must run a few check to see if all
00022         //subsystems are working properly
00023         genCards();
00024         return true;
00025 }
00026 
00027 int Server::start(int argc, char *argv[]){
00028         Client *c;
00029         Socket *s;
00030 //      stayUp = true;
00031         while(stayUp.getValue()){
00032                 s = accept();
00033                 if(!stayUp.getValue())
00034                         break;
00035                 if(s != 0){
00036                         c = new Client(s);
00037                         delete s;
00038                         counter++;
00039                         cout << "Clients: " << counter.getValue() << endl;
00040                         c->start();
00041                 }
00042         }
00043         return 0;
00044 }
00045 
00046 bool Server::cleanup(){
00047         while(counter.getValue() > 0){
00048                         cout << "Clients pending: " << counter.getValue() << endl;
00049                         usleep(50000);
00050         }
00051         //Here goes any cleanup handlers
00052         return true;
00053 }

Powered by:

SourceForge Logo