1 // Defines the member functions for the base class of the ACE_TLI
5 #include "ace/Log_Category.h"
6 #include "ace/OS_Memory.h"
7 #include "ace/OS_TLI.h"
8 #include "ace/OS_NS_string.h"
9 #include "ace/OS_NS_sys_socket.h"
10 #include "ace/Auto_Ptr.h"
14 #if defined (ACE_HAS_TLI)
16 #if !defined (__ACE_INLINE__)
17 #include "ace/TLI.inl"
18 #endif /* __ACE_INLINE__ */
20 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
22 ACE_ALLOC_HOOK_DEFINE(ACE_TLI
)
25 ACE_TLI::dump (void) const
27 #if defined (ACE_HAS_DUMP)
28 ACE_TRACE ("ACE_TLI::dump");
29 #endif /* ACE_HAS_DUMP */
32 ACE_TLI::ACE_TLI (void)
34 ACE_TRACE ("ACE_TLI::ACE_TLI");
35 #if defined (ACE_HAS_SVR4_TLI)
36 // Solaris 2.4 ACE_TLI option handling is broken. Thus, we must do
37 // the memory allocation ourselves... Thanks to John P. Hearn
38 // (jph@ccrl.nj.nec.com) for the help.
40 this->so_opt_req
.opt
.maxlen
= sizeof (opthdr
) + sizeof (long);
41 ACE_NEW (this->so_opt_req
.opt
.buf
,
42 char[this->so_opt_req
.opt
.maxlen
]);
44 this->so_opt_ret
.opt
.maxlen
= sizeof (opthdr
) + sizeof (long);
45 ACE_NEW (this->so_opt_ret
.opt
.buf
,
46 char[this->so_opt_ret
.opt
.maxlen
]);
48 if (this->so_opt_ret
.opt
.buf
== 0)
50 delete [] this->so_opt_req
.opt
.buf
;
51 this->so_opt_req
.opt
.buf
= 0;
53 #endif /* ACE_HAS_SVR4_TLI */
57 ACE_TLI::open (const char device
[], int oflag
, struct t_info
*info
)
59 ACE_TRACE ("ACE_TLI::open");
62 this->set_handle (ACE_OS::t_open ((char *) device
, oflag
, info
));
64 return this->get_handle ();
67 ACE_TLI::~ACE_TLI (void)
69 ACE_TRACE ("ACE_TLI::~ACE_TLI");
70 #if defined (ACE_HAS_SVR4_TLI)
71 if (this->so_opt_req
.opt
.buf
)
73 delete [] this->so_opt_req
.opt
.buf
;
74 delete [] this->so_opt_ret
.opt
.buf
;
75 this->so_opt_req
.opt
.buf
= 0;
76 this->so_opt_ret
.opt
.buf
= 0;
78 #endif /* ACE_HAS_SVR4_TLI */
81 ACE_TLI::ACE_TLI (const char device
[], int oflag
, struct t_info
*info
)
83 ACE_TRACE ("ACE_TLI::ACE_TLI");
84 if (this->open (device
, oflag
, info
) == ACE_INVALID_HANDLE
)
85 ACELIB_ERROR ((LM_ERROR
,
87 ACE_TEXT ("ACE_TLI::ACE_TLI")));
91 ACE_TLI::get_local_addr (ACE_Addr
&sa
) const
93 ACE_TRACE ("ACE_TLI::get_local_addr");
96 name
.maxlen
= sa
.get_size ();
97 name
.buf
= (char *) sa
.get_addr ();
99 if (ACE_OS::t_getname (this->get_handle (), &name
, LOCALNAME
) == -1)
106 ACE_TLI::close (void)
108 ACE_TRACE ("ACE_TLI::close");
109 int result
= 0; // Geisler: result must be int
111 if (this->get_handle () != ACE_INVALID_HANDLE
)
113 result
= ACE_OS::t_close (this->get_handle ());
114 this->set_handle (ACE_INVALID_HANDLE
);
120 ACE_TLI::set_option (int level
, int option
, void *optval
, int optlen
)
122 /* Set up options for ACE_TLI */
123 ACE_TRACE ("ACE_TLI::set_option");
125 #if defined (ACE_HAS_XTI)
126 // ret will get the negotiated option back after attempting to set it.
127 // Assume this will fit in the requested size.
128 struct t_optmgmt req
, ret
;
129 ACE_NEW_RETURN (req
.opt
.buf
, char[sizeof (struct t_opthdr
) + optlen
], -1);
130 # if (_XOPEN_SOURCE - 0 >= 500)
131 auto_ptr
<char> req_opt_buf_p (reinterpret_cast<char*> (req
.opt
.buf
));
133 ACE_Auto_Array_Ptr
<char> req_opt_buf_p (req
.opt
.buf
);
134 # endif /* XPG5 vs XPG4 */
135 struct t_opthdr
*opthdr
=
136 reinterpret_cast<struct t_opthdr
*> (req
.opt
.buf
);
137 ACE_NEW_RETURN (ret
.opt
.buf
, char[sizeof (struct t_opthdr
) + optlen
], -1);
138 # if (_XOPEN_SOURCE - 0 >= 500)
139 auto_ptr
<char> ret_opt_buf_p (reinterpret_cast<char*> (ret
.opt
.buf
));
141 ACE_Auto_Array_Ptr
<char> ret_opt_buf_p (ret
.opt
.buf
);
142 # endif /* XPG5 vs XPG4 */
144 req
.flags
= T_NEGOTIATE
;
145 req
.opt
.len
= sizeof *opthdr
+ optlen
;
146 ret
.opt
.maxlen
= req
.opt
.len
;
147 opthdr
->level
= level
;
148 opthdr
->name
= option
;
149 opthdr
->len
= req
.opt
.len
; // We only request one option at a time.
150 ACE_OS::memcpy (&opthdr
[1], optval
, optlen
);
151 return ACE_OS::t_optmgmt (this->get_handle (), &req
, &ret
);
153 #elif defined (ACE_HAS_SVR4_TLI)
154 struct opthdr
*opthdr
= 0; /* See <sys/socket.h> for info on this format */
156 this->so_opt_req
.flags
= T_NEGOTIATE
;
157 this->so_opt_req
.opt
.len
= sizeof *opthdr
+ OPTLEN (optlen
);
159 if (this->so_opt_req
.opt
.len
> this->so_opt_req
.opt
.maxlen
)
161 # if !defined (ACE_HAS_SET_T_ERRNO)
164 set_t_errno (TBUFOVFLW
);
165 # endif /* ACE_HAS_SET_T_ERRNO */
169 opthdr
= reinterpret_cast<struct opthdr
*> (this->so_opt_req
.opt
.buf
);
170 opthdr
->level
= level
;
171 opthdr
->name
= option
;
172 opthdr
->len
= OPTLEN (optlen
);
173 ACE_OS::memcpy (OPTVAL (opthdr
), optval
, optlen
);
175 return ACE_OS::t_optmgmt (this->get_handle (),
179 ACE_UNUSED_ARG (level
);
180 ACE_UNUSED_ARG (option
);
181 ACE_UNUSED_ARG (optval
);
182 ACE_UNUSED_ARG (optlen
);
184 #endif /* ACE_HAS_XTI, else ACE_HAS_SVR4_TLI */
188 ACE_TLI::get_option (int level
, int option
, void *optval
, int &optlen
)
190 ACE_TRACE ("ACE_TLI::get_option");
191 #if defined (ACE_HAS_XTI)
192 // ret will get the option requested in req.
193 struct t_optmgmt req
, ret
;
194 ACE_NEW_RETURN (req
.opt
.buf
, char[sizeof (struct t_opthdr
)], -1);
195 # if (_XOPEN_SOURCE - 0 >= 500)
196 auto_ptr
<char> req_opt_buf_p (reinterpret_cast<char*> (req
.opt
.buf
));
198 ACE_Auto_Array_Ptr
<char> req_opt_buf_p (req
.opt
.buf
);
199 # endif /* XPG5 vs XPG4 */
200 struct t_opthdr
*opthdr
=
201 reinterpret_cast<struct t_opthdr
*> (req
.opt
.buf
);
202 ACE_NEW_RETURN (ret
.opt
.buf
, char[sizeof (struct t_opthdr
) + optlen
], -1);
203 # if (_XOPEN_SOURCE - 0 >= 500)
204 auto_ptr
<char> ret_opt_buf_p (reinterpret_cast<char*> (ret
.opt
.buf
));
206 ACE_Auto_Array_Ptr
<char> ret_opt_buf_p (ret
.opt
.buf
);
207 # endif /* XPG5 vs XPG4 */
209 req
.flags
= T_CURRENT
;
210 req
.opt
.len
= sizeof *opthdr
;
211 ret
.opt
.maxlen
= sizeof (struct t_opthdr
) + optlen
;
212 opthdr
->level
= level
;
213 opthdr
->name
= option
;
214 opthdr
->len
= sizeof (*opthdr
); // Just the header on the request
215 if (ACE_OS::t_optmgmt (this->get_handle (), &req
, &ret
) == -1)
219 opthdr
= reinterpret_cast<struct t_opthdr
*> (ret
.opt
.buf
);
220 if (opthdr
->status
== T_NOTSUPPORT
)
227 ACE_OS::memcpy (optval
, &opthdr
[1], optlen
);
232 #elif defined (ACE_HAS_SVR4_TLI)
233 struct opthdr
*opthdr
= 0; /* See <sys/socket.h> for details on this format */
235 this->so_opt_req
.flags
= T_CHECK
;
236 this->so_opt_ret
.opt
.len
= sizeof *opthdr
+ OPTLEN (optlen
);
238 if (this->so_opt_ret
.opt
.len
> this->so_opt_ret
.opt
.maxlen
)
240 #if !defined (ACE_HAS_SET_T_ERRNO)
243 set_t_errno (TBUFOVFLW
);
244 #endif /* ACE_HAS_SET_T_ERRNO */
248 opthdr
= (struct opthdr
*) this->so_opt_req
.opt
.buf
;
249 opthdr
->level
= level
;
250 opthdr
->name
= option
;
251 opthdr
->len
= OPTLEN (optlen
);
252 if (ACE_OS::t_optmgmt (this->get_handle (), &this->so_opt_req
, &this->so_opt_ret
) == -1)
256 ACE_OS::memcpy (optval
, OPTVAL (opthdr
), optlen
);
260 ACE_UNUSED_ARG (level
);
261 ACE_UNUSED_ARG (option
);
262 ACE_UNUSED_ARG (optval
);
263 ACE_UNUSED_ARG (optlen
);
265 #endif /* ACE_HAS_SVR4_TLI */
268 ACE_END_VERSIONED_NAMESPACE_DECL
270 #endif /* ACE_HAS_TLI */