1 // Defines the member functions for the base class of the ACE_TLI
4 #include "ace/Log_Category.h"
5 #include "ace/OS_Memory.h"
6 #include "ace/OS_TLI.h"
7 #include "ace/OS_NS_string.h"
8 #include "ace/OS_NS_sys_socket.h"
11 #if defined (ACE_HAS_TLI)
13 #if !defined (__ACE_INLINE__)
14 #include "ace/TLI.inl"
15 #endif /* __ACE_INLINE__ */
17 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
19 ACE_ALLOC_HOOK_DEFINE(ACE_TLI
)
22 ACE_TLI::dump () const
24 #if defined (ACE_HAS_DUMP)
25 ACE_TRACE ("ACE_TLI::dump");
26 #endif /* ACE_HAS_DUMP */
31 ACE_TRACE ("ACE_TLI::ACE_TLI");
35 ACE_TLI::open (const char device
[], int oflag
, struct t_info
*info
)
37 ACE_TRACE ("ACE_TLI::open");
40 this->set_handle (ACE_OS::t_open ((char *) device
, oflag
, info
));
42 return this->get_handle ();
47 ACE_TRACE ("ACE_TLI::~ACE_TLI");
50 ACE_TLI::ACE_TLI (const char device
[], int oflag
, struct t_info
*info
)
52 ACE_TRACE ("ACE_TLI::ACE_TLI");
53 if (this->open (device
, oflag
, info
) == ACE_INVALID_HANDLE
)
54 ACELIB_ERROR ((LM_ERROR
,
56 ACE_TEXT ("ACE_TLI::ACE_TLI")));
60 ACE_TLI::get_local_addr (ACE_Addr
&sa
) const
62 ACE_TRACE ("ACE_TLI::get_local_addr");
65 name
.maxlen
= sa
.get_size ();
66 name
.buf
= (char *) sa
.get_addr ();
68 if (ACE_OS::t_getname (this->get_handle (), &name
, LOCALNAME
) == -1)
77 ACE_TRACE ("ACE_TLI::close");
78 int result
= 0; // Geisler: result must be int
80 if (this->get_handle () != ACE_INVALID_HANDLE
)
82 result
= ACE_OS::t_close (this->get_handle ());
83 this->set_handle (ACE_INVALID_HANDLE
);
89 ACE_TLI::set_option (int level
, int option
, void *optval
, int optlen
)
91 /* Set up options for ACE_TLI */
92 ACE_TRACE ("ACE_TLI::set_option");
94 #if defined (ACE_HAS_XTI)
95 // ret will get the negotiated option back after attempting to set it.
96 // Assume this will fit in the requested size.
97 struct t_optmgmt req
, ret
;
98 ACE_NEW_RETURN (req
.opt
.buf
, char[sizeof (struct t_opthdr
) + optlen
], -1);
99 # if (_XOPEN_SOURCE - 0 >= 500)
100 std::unique_ptr
<char> req_opt_buf_p (reinterpret_cast<char*> (req
.opt
.buf
));
102 std::unique_ptr
<char[]> req_opt_buf_p (req
.opt
.buf
);
103 # endif /* XPG5 vs XPG4 */
104 struct t_opthdr
*opthdr
=
105 reinterpret_cast<struct t_opthdr
*> (req
.opt
.buf
);
106 ACE_NEW_RETURN (ret
.opt
.buf
, char[sizeof (struct t_opthdr
) + optlen
], -1);
107 # if (_XOPEN_SOURCE - 0 >= 500)
108 std::unique_ptr
<char> ret_opt_buf_p (reinterpret_cast<char*> (ret
.opt
.buf
));
110 std::unique_ptr
<char[]> ret_opt_buf_p (ret
.opt
.buf
);
111 # endif /* XPG5 vs XPG4 */
113 req
.flags
= T_NEGOTIATE
;
114 req
.opt
.len
= sizeof *opthdr
+ optlen
;
115 ret
.opt
.maxlen
= req
.opt
.len
;
116 opthdr
->level
= level
;
117 opthdr
->name
= option
;
118 opthdr
->len
= req
.opt
.len
; // We only request one option at a time.
119 ACE_OS::memcpy (&opthdr
[1], optval
, optlen
);
120 return ACE_OS::t_optmgmt (this->get_handle (), &req
, &ret
);
122 ACE_UNUSED_ARG (level
);
123 ACE_UNUSED_ARG (option
);
124 ACE_UNUSED_ARG (optval
);
125 ACE_UNUSED_ARG (optlen
);
127 #endif /* ACE_HAS_XTI */
131 ACE_TLI::get_option (int level
, int option
, void *optval
, int &optlen
)
133 ACE_TRACE ("ACE_TLI::get_option");
134 #if defined (ACE_HAS_XTI)
135 // ret will get the option requested in req.
136 struct t_optmgmt req
, ret
;
137 ACE_NEW_RETURN (req
.opt
.buf
, char[sizeof (struct t_opthdr
)], -1);
138 # if (_XOPEN_SOURCE - 0 >= 500)
139 std::unique_ptr
<char> req_opt_buf_p (reinterpret_cast<char*> (req
.opt
.buf
));
141 std::unique_ptr
<char[]> req_opt_buf_p (req
.opt
.buf
);
142 # endif /* XPG5 vs XPG4 */
143 struct t_opthdr
*opthdr
=
144 reinterpret_cast<struct t_opthdr
*> (req
.opt
.buf
);
145 ACE_NEW_RETURN (ret
.opt
.buf
, char[sizeof (struct t_opthdr
) + optlen
], -1);
146 # if (_XOPEN_SOURCE - 0 >= 500)
147 std::unique_ptr
<char> ret_opt_buf_p (reinterpret_cast<char*> (ret
.opt
.buf
));
149 std::unique_ptr
<char[]> ret_opt_buf_p (ret
.opt
.buf
);
150 # endif /* XPG5 vs XPG4 */
152 req
.flags
= T_CURRENT
;
153 req
.opt
.len
= sizeof *opthdr
;
154 ret
.opt
.maxlen
= sizeof (struct t_opthdr
) + optlen
;
155 opthdr
->level
= level
;
156 opthdr
->name
= option
;
157 opthdr
->len
= sizeof (*opthdr
); // Just the header on the request
158 if (ACE_OS::t_optmgmt (this->get_handle (), &req
, &ret
) == -1)
162 opthdr
= reinterpret_cast<struct t_opthdr
*> (ret
.opt
.buf
);
163 if (opthdr
->status
== T_NOTSUPPORT
)
170 ACE_OS::memcpy (optval
, &opthdr
[1], optlen
);
175 ACE_UNUSED_ARG (level
);
176 ACE_UNUSED_ARG (option
);
177 ACE_UNUSED_ARG (optval
);
178 ACE_UNUSED_ARG (optlen
);
180 #endif /* ACE_HAS_XTI */
183 ACE_END_VERSIONED_NAMESPACE_DECL
185 #endif /* ACE_HAS_TLI */