"Fossies" - the Fresh Open Source Software Archive

Member "bayonne-1.2.16/server/protocols.cpp" (6 Jun 2003, 1860 Bytes) of package /linux/misc/old/bayonne-1.2.16.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "protocols.cpp" see the Fossies "Dox" file reference documentation.

    1 // Copyright (C) 2000-2001 Open Source Telecom Corporation.
    2 //  
    3 // This program is free software; you can redistribute it and/or modify
    4 // it under the terms of the GNU General Public License as published by
    5 // the Free Software Foundation; either version 2 of the License, or
    6 // (at your option) any later version.
    7 // 
    8 // This program is distributed in the hope that it will be useful,
    9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
   10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   11 // GNU General Public License for more details.
   12 // 
   13 // You should have received a copy of the GNU General Public License
   14 // along with this program; if not, write to the Free Software 
   15 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
   16 
   17 #include "server.h"
   18 
   19 #ifdef  CCXX_NAMESPACES
   20 namespace ost {
   21 using namespace std;
   22 #endif
   23 
   24 Protocol *Protocol::first = NULL;
   25 
   26 Protocol::Protocol(const char *keyid, tpport_t p) :
   27 Keydata(keyid), InetHostAddress(), ThreadLock()
   28 {
   29     const char *cp;
   30 
   31     static Keydata::Define keys[] = {
   32     {"address", "127.0.0.1"},
   33     {"sessions", "1"},
   34     {NULL, NULL}};
   35 
   36     load(keys);
   37     cp = getLast("port");
   38     if(cp)
   39         port = atoi(cp);
   40     else
   41         port = p;
   42 
   43     InetHostAddress addr(getLast("address"));
   44     *((InetHostAddress*)(this)) = addr;
   45     sessions = new Semaphore(atoi(getLast("sessions")));
   46     
   47     next = first;
   48     first = this;
   49 
   50     cp = getLast("resolver");
   51     if(cp)
   52         return;
   53 
   54     cp = getLast("address");
   55     if(*cp >= '0' && *cp <= '9')
   56         return;
   57 
   58     setValue("resolver", cp);
   59 }
   60 
   61 Protocol::~Protocol()
   62 {
   63     if(sessions)
   64         delete sessions;
   65 }
   66 
   67 InetHostAddress Protocol::getAddress(void)
   68 {
   69     InetHostAddress addr("127.0.0.1");
   70 
   71     readLock();
   72     addr = *this;
   73     unlock();
   74     return addr;
   75 }
   76 
   77 void Protocol::update(InetHostAddress addr)
   78 {
   79     writeLock();
   80     *((InetHostAddress*)(this)) = addr;
   81     unlock();
   82 }
   83 
   84 #ifdef  CCXX_NAMESPACES
   85 };
   86 #endif