The DejaVU Framework -- hush 3.0
[.] Papers Tutorials Examples Manuals Interfaces Sources Packages Resources ?

source: csclientimp.c hush-3.0b4/auxiliary/net/cs


[.] - [up] [top] - index README make include source scripts configure
  // csclientimp.cc
  
  include <net/cs/csaddress.h>
  include <net/cs/csclientimp.h>
  include <net/cs/dataconn.h>
  include <net/cs/samlib.h>
  
  include <stdio.h>
  
  //---------------------------- csclientimp implementation ---------------------
  
  csclientimp::csclientimp()
  {
      _address = NULL;
      _conn = NULL;
      _connected = 0;
  }
  
  csclientimp::~csclientimp()
  {
      if (_connected)
          disconnect_imp();
  }
  
  int csclientimp::connect_imp()
  {
      if (_address == NULL)
      {
          warn("csclientimp::connect_imp : no address\n");
          return -1;
      }
      if (_connected)
      {
          warn("csclientimp::connect_imp : alreay connected\n");
          return -1;
      }
  
      _conn = createdata(_address);
      if (_conn == NULL)
      {
          warn("csclientimp::connect_imp : couldn't create new dataconnection");
          return -1;
      }
  
      _connected = 1;
      return 0;
  }
  
  int csclientimp::connect_imp(const csaddress* addr)
  {
      _address = (csaddress*) addr;
  
      return connect_imp();
  }
  
  int csclientimp::connected_imp()
  {
      if (_conn == NULL)
          return 0;
      else if (!_conn -> connected())
      {
          delete _conn;
          _conn = NULL;
          _connected = 0;
          return 0;
      }
      else
          return 1;
  }
  
  void csclientimp::disconnect_imp()
  {
      if (!_connected)
      {
          warn("csclientimp::disconnect_imp : not connected");
          return;
      }
  
      if (_conn == NULL)
      {
          warn("csclientimp::disconnect_imp : _conn = NULL");
          return;
      }
  
      delete _conn;
      _conn = NULL;
      _connected = 0;
  }
  
  data_connection* csclientimp::connection_imp() const
  {
      return _conn;
  }
  
  csaddress* csclientimp::address_imp() const
  {
      if (!_connected)
          return 0;
      else
          return _address;
  }
  
  int csclientimp::read_imp(char* buffer, int maxbytes)
  {
      int retval;
  
      if (!_connected)
      {
          warn("csclientimp::read_imp : not connected");
          return -1;
      }
      if (_conn == NULL)
      {
          warn("csclientimp::read_imp : _conn = NULL");
          return -1;
      }
  
      retval = _conn -> read(buffer, maxbytes);
  
      if (retval <= 0)
      {
          delete _conn;
          _conn = NULL;
          _connected = 0;
      }
  
      return retval;
  }
  
  int csclientimp::readmsg_imp(char* buffer, int maxbytes)
  {
      int retval;
  
      if (!_connected)
      {
          warn("csclientimp::readmsg_imp : not connected");
          return -1;
      }
      if (_conn == NULL)
      {
          warn("csclientimp::readmsg_imp : _conn = NULL");
          return -1;
      }
  
      retval = _conn -> readmsg(buffer, maxbytes);
  
      if (retval <= 0)
      {
          delete _conn;
          _conn = NULL;
          _connected = 0;
      }
  
      return retval;
  }
  
  int csclientimp::write_imp(const char* buffer, int nrbytes)
  {
      int retval;
  
      if (!_connected)
      {
          warn("csclientimp::write_imp : not connected");
          return -1;
      }
      if (_conn == NULL)
      {
          warn("csclientimp::write_imp : _conn = NULL");
          return -1;
      }
  
      retval = _conn -> write(buffer, nrbytes);
  
      if (retval <= 0)
      {
          delete _conn;
          _conn = NULL;
          _connected = 0;
      }
  
      return retval;
  }
  
  int csclientimp::writemsg_imp(const char* buffer, int nrbytes)
  {
      int retval;
  
      if (!_connected)
      {
          warn("csclientimp::writemsg_imp : not connected");
          return -1;
      }
      if (_conn == NULL)
      {
          warn("csclientimp::writemsg_imp : _conn = NULL");
          return -1;
      }
  
      retval = _conn -> writemsg(buffer, nrbytes);
  
      if (retval <= 0)
      {
          delete _conn;
          _conn = NULL;
          _connected = 0;
      }
  
      return retval;
  }
  
  int csclientimp::ready_imp(timeval* timeout)
  {
      int retval;
  
      if (!_connected)
      {
          warn("csclientimp::ready_imp : not connected");
          return 0;
      }
      if (_conn == NULL)
      {
          warn("csclientimp::ready_imp : _conn = NULL");
          return 0;
      }
  
      retval = _conn -> ready(timeout);
      if (!_conn -> connected())
      {
          delete _conn;
          _conn = NULL;
          _connected = 0;
          return 0;
      }
      else
          return retval;
  }
  
  int csclientimp::fd_imp() const
  {
      if (!_connected)
      {
          warn("csclientimp::fd_imp : not connected");
          return -1;
      }
      if (_conn == NULL)
      {
          warn("csclientimp::fd_imp : _conn = NULL");
          return -1;
      }
  
      return _conn -> fd();
  }
  
  

[.] Papers Tutorials Examples Manuals Interfaces Sources Packages Resources ?
Hush Online Technology
hush@cs.vu.nl
09/09/98