Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

TLI.cpp

Go to the documentation of this file.
00001 #include "ace_pch.h"
00002 // $Id: TLI.cpp,v 1.1.1.3.40.1 2003/03/13 19:44:22 chad Exp $
00003 
00004 // Defines the member functions for the base class of the ACE_TLI
00005 // abstraction.
00006 
00007 #include "ace/TLI.h"
00008 #include "ace/Log_Msg.h"
00009 
00010 ACE_RCSID(ace, TLI, "$Id: TLI.cpp,v 1.1.1.3.40.1 2003/03/13 19:44:22 chad Exp $")
00011 
00012 #if defined (ACE_HAS_TLI)
00013 
00014 #if !defined (__ACE_INLINE__)
00015 #include "ace/TLI.i"
00016 #endif /* __ACE_INLINE__ */
00017 
00018 ACE_ALLOC_HOOK_DEFINE(ACE_TLI)
00019 
00020 void
00021 ACE_TLI::dump (void) const
00022 {
00023   ACE_TRACE ("ACE_TLI::dump");
00024 }
00025 
00026 ACE_TLI::ACE_TLI (void)
00027 {
00028   ACE_TRACE ("ACE_TLI::ACE_TLI");
00029 #if defined (ACE_HAS_SVR4_TLI)
00030 // Solaris 2.4 ACE_TLI option handling is broken.  Thus, we must do
00031 // the memory allocation ourselves...  Thanks to John P. Hearn
00032 // (jph@ccrl.nj.nec.com) for the help.
00033 
00034   this->so_opt_req.opt.maxlen = sizeof (opthdr) + sizeof (long);
00035   ACE_NEW (this->so_opt_req.opt.buf,
00036            char[this->so_opt_req.opt.maxlen]);
00037 
00038   this->so_opt_ret.opt.maxlen = sizeof (opthdr) + sizeof (long);
00039   ACE_NEW (this->so_opt_ret.opt.buf,
00040            char[this->so_opt_ret.opt.maxlen]);
00041 
00042   if (this->so_opt_ret.opt.buf == 0)
00043     {
00044       delete [] this->so_opt_req.opt.buf;
00045       this->so_opt_req.opt.buf = 0;
00046       return;
00047     }
00048 #endif /* ACE_HAS_SVR4_TLI */
00049 }
00050 
00051 ACE_HANDLE
00052 ACE_TLI::open (const char device[], int oflag, struct t_info *info)
00053 {
00054   ACE_TRACE ("ACE_TLI::open");
00055   if (oflag == 0)
00056     oflag = O_RDWR;
00057   this->set_handle (ACE_OS::t_open ((char *) device, oflag, info));
00058 
00059   return this->get_handle ();
00060 }
00061 
00062 ACE_TLI::~ACE_TLI (void)
00063 {
00064   ACE_TRACE ("ACE_TLI::~ACE_TLI");
00065 #if defined (ACE_HAS_SVR4_TLI)
00066   if (this->so_opt_req.opt.buf)
00067     {
00068       delete [] this->so_opt_req.opt.buf;
00069       delete [] this->so_opt_ret.opt.buf;
00070       this->so_opt_req.opt.buf = 0;
00071       this->so_opt_ret.opt.buf = 0;
00072     }
00073 #endif /* ACE_HAS_SVR4_TLI */
00074 }
00075 
00076 ACE_TLI::ACE_TLI (const char device[], int oflag, struct t_info *info)
00077 {
00078   ACE_TRACE ("ACE_TLI::ACE_TLI");
00079   if (this->open (device, oflag, info) == ACE_INVALID_HANDLE)
00080     ACE_ERROR ((LM_ERROR,  ACE_LIB_TEXT ("%p\n"),  ACE_LIB_TEXT ("ACE_TLI::ACE_TLI")));
00081 }
00082 
00083 int
00084 ACE_TLI::get_local_addr (ACE_Addr &sa) const
00085 {
00086   ACE_TRACE ("ACE_TLI::get_local_addr");
00087 #if defined (ACE_HAS_SVR4_TLI)
00088   struct netbuf name;
00089 
00090   name.maxlen = sa.get_size ();
00091   name.buf    = (char *) sa.get_addr ();
00092 
00093   if (ACE_OS::ioctl (this->get_handle (), TI_GETMYNAME, &name) == -1)
00094 /*  if (ACE_OS::t_getname (this->get_handle (), &name, LOCALNAME) == -1) */
00095     return -1;
00096   else
00097     return 0;
00098 #else /* SunOS4 */
00099   ACE_UNUSED_ARG (sa);
00100   ACE_NOTSUP_RETURN (-1);
00101 #endif /* ACE_HAS_SVR4_TLI */
00102 }
00103 
00104 int
00105 ACE_TLI::close (void)
00106 {
00107   ACE_TRACE ("ACE_TLI::close");
00108   int result = 0; // Geisler: result must be int
00109 
00110   if (this->get_handle () != ACE_INVALID_HANDLE)
00111     {
00112       result = ACE_OS::t_close (this->get_handle ());
00113       this->set_handle (ACE_INVALID_HANDLE);
00114     }
00115   return result;
00116 }
00117 
00118 int
00119 ACE_TLI::set_option (int level, int option, void *optval, int optlen)
00120 {
00121   ACE_TRACE ("ACE_TLI::set_option");
00122 #if defined (ACE_HAS_SVR4_TLI)
00123   /* Set up options for ACE_TLI */
00124 
00125   struct opthdr *opthdr = 0; /* See <sys/socket.h> for details on this format */
00126 
00127   this->so_opt_req.flags = T_NEGOTIATE;
00128   this->so_opt_req.opt.len = sizeof *opthdr + OPTLEN (optlen);
00129 
00130   if (this->so_opt_req.opt.len > this->so_opt_req.opt.maxlen)
00131     {
00132 #if !defined (ACE_HAS_SET_T_ERRNO)
00133       t_errno = TBUFOVFLW;
00134 #else
00135       set_t_errno (TBUFOVFLW);
00136 #endif /* ACE_HAS_SET_T_ERRNO */
00137       return -1;
00138     }
00139 
00140   opthdr        = (struct opthdr *) this->so_opt_req.opt.buf;
00141   opthdr->level = level;
00142   opthdr->name  = option;
00143   opthdr->len   = OPTLEN (optlen);
00144   ACE_OS::memcpy (OPTVAL (opthdr), optval, optlen);
00145 
00146   return ACE_OS::t_optmgmt (this->get_handle (), &this->so_opt_req, &this->so_opt_ret);
00147 #else
00148   ACE_UNUSED_ARG (level);
00149   ACE_UNUSED_ARG (option);
00150   ACE_UNUSED_ARG (optval);
00151   ACE_UNUSED_ARG (optlen);
00152   return -1;
00153 #endif /* ACE_HAS_SVR4_TLI */
00154 }
00155 
00156 int
00157 ACE_TLI::get_option (int level, int option, void *optval, int &optlen)
00158 {
00159   ACE_TRACE ("ACE_TLI::get_option");
00160 #if defined (ACE_HAS_SVR4_TLI)
00161   struct opthdr *opthdr = 0; /* See <sys/socket.h> for details on this format */
00162 
00163   this->so_opt_req.flags = T_CHECK;
00164   this->so_opt_ret.opt.len = sizeof *opthdr + OPTLEN (optlen);
00165 
00166   if (this->so_opt_ret.opt.len > this->so_opt_ret.opt.maxlen)
00167     {
00168 #if !defined (ACE_HAS_SET_T_ERRNO)
00169       t_errno = TBUFOVFLW;
00170 #else
00171       set_t_errno (TBUFOVFLW);
00172 #endif /* ACE_HAS_SET_T_ERRNO */
00173       return -1;
00174     }
00175 
00176   opthdr        = (struct opthdr *) this->so_opt_req.opt.buf;
00177   opthdr->level = level;
00178   opthdr->name  = option;
00179   opthdr->len   = OPTLEN (optlen);
00180   if (ACE_OS::t_optmgmt (this->get_handle (), &this->so_opt_req, &this->so_opt_ret) == -1)
00181     return -1;
00182   else
00183     {
00184       ACE_OS::memcpy (optval, OPTVAL (opthdr), optlen);
00185       return 0;
00186     }
00187 #else
00188   ACE_UNUSED_ARG (level);
00189   ACE_UNUSED_ARG (option);
00190   ACE_UNUSED_ARG (optval);
00191   ACE_UNUSED_ARG (optlen);
00192   return -1;
00193 #endif /* ACE_HAS_SVR4_TLI */
00194 }
00195 
00196 #endif /* ACE_HAS_TLI */

Generated on Mon Jun 16 11:21:54 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002