/*
* This file is part of rasdaman community.
*
* Rasdaman community is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Rasdaman community is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with rasdaman community. If not, see .
*
* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann /
rasdaman GmbH.
*
* For more information please see
* or contact Peter Baumann via .
/
/**
* SOURCE: akgnet_server.cc
*
* MODULE: akg network
* CLASS: GenericServer, BlockingServer
*
* COMMENTS:
*
*/
#include "debug.hh"
#include
//#include
akg::GenericServer::GenericServer() throw()
{
listenPort = 0;
exitRequest = false;
}
akg::GenericServer::~GenericServer() throw()
{
}
void akg::GenericServer::setListenPort(int x) throw()
{
listenPort = x;
}
int akg::GenericServer::getListenPort() throw()
{
return listenPort;
}
void akg::GenericServer::setTimeout(int sec,int milisec) throw()
{ selector.setTimeout(sec,milisec);
}
void akg::GenericServer::disableTimeout() throw()
{ selector.disableTimeout();
}
void akg::GenericServer::shouldExit() throw()
{
exitRequest = true;
}
bool akg::GenericServer::initListenSocket(int port, bool nonblocking) throw()
{
if(listenSocket.open(port) == false) return false;
if(nonblocking) listenSocket.setNonBlocking(true);
selector.setRead(listenSocket());
DBTALK("Listen socket="<0)
{
if(serverSocket.isOpen())
{
TALK( "socket is open." );
if(selector.isRead(serverSocket()))
{
TALK( "socket is readable, executing request." );
executeRequest(serverSocket);
TALK( "closing socket." );
closeSocket(serverSocket);
TALK( "socket closed." );
}
}
else if(selector.isRead(listenSocket()))
{
TALK( "socket not open, but readable (???). connecting new client." );
connectNewClient(serverSocket);
TALK( "after client connect." );
// we don't care why it could fail
}
else
{
TALK( "no read socket - should never have reached this point." );
}
}
if(rasp == 0)
{
TALK( "exec timeout" );
executeTimeout();
}
if(rasp<0)
{
TALK( "Internal connect error: bad selector." );
}
}
LEAVE( "akg::BlockingServer::runServer, result=true" );
return true;
}