/*
* 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 .
*/
/*************************************************************
*
*
* PURPOSE:
*
*
* COMMENTS:
* - why sometimes exit() and sometimes return on error?
* should be return or exception, always.
*
************************************************************/
#include "srvrasmgrcomm.hh"
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "raslib/rminit.hh"
#include "debug.hh"
// exit code of the server when communication is impossible
// PB: Why 10 ? Anyway, should not use exit in a server, how often did I tell you, Walter Schatz!!!
const unsigned int EXIT_CODE = 10;
// max number of retries to connect to rasmgr in informRasMgr()
const unsigned int SRV_MAX_RETRY = 10000000;
// how many retries are attempted before a message is issued informRasMgr()
const unsigned int SRV_TALK_INTERVAL = 100000;
SrvRasmgrComm rasmgrComm;
SrvRasmgrComm::SrvRasmgrComm()
{
timeout = 0;
serverName = 0;
rasmgrHost = 0;
rasmgrPort = -1;
}
// note: should make use of timeout as defined in cmd line,
// but that's a major undertaking -- PB 2005-sep-02
void SrvRasmgrComm::init(unsigned int timeOut, const char* instanceName, const char* nRasmgrHost, int nRasmgrPort)
{
timeout = timeOut;
serverName = instanceName;
rasmgrHost = nRasmgrHost;
rasmgrPort = nRasmgrPort;
}
unsigned int SrvRasmgrComm::getTimeout()
{
return timeout;
}
void SrvRasmgrComm::informRasmgrServerAvailable()
{
informRasMGR(SERVER_AVAILABLE);
}
void SrvRasmgrComm::informRasmgrServerDown()
{
informRasMGR(SERVER_DOWN);
}
void SrvRasmgrComm::informRasmgrServerStillAvailable()
{
// too verbose, blows up log file
// RMInit::logOut << "informing rasmgr: server still available." << endl;
informRasMGR(SERVER_REGULARSIG);
}
void SrvRasmgrComm::informRasMGR(int what)
{ //what: 0 - going down
// 1 - available
// 2 - regular signal
// cout<<"servername ="<h_addr;
int sock;
bool ok=false;
long talkInterval=SRV_TALK_INTERVAL;
long maxRetry=SRV_MAX_RETRY;
long retry =0;
// creating socket
for(retry=0;retryp_proto);
//std::cout<<"Socket="<p_proto<