xref: /AOO41X/main/vos/source/socket.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir #include <stdio.h>
29*cdf0e10cSrcweir 
30*cdf0e10cSrcweir #include <rtl/memory.h>
31*cdf0e10cSrcweir #include <osl/time.h>
32*cdf0e10cSrcweir #include <vos/socket.hxx>
33*cdf0e10cSrcweir #include <vos/diagnose.hxx>
34*cdf0e10cSrcweir //#include <osl/tools.h>
35*cdf0e10cSrcweir 
36*cdf0e10cSrcweir using namespace vos;
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir VOS_IMPLEMENT_CLASSINFO(VOS_CLASSNAME(OSocketAddr, vos),
40*cdf0e10cSrcweir 						VOS_NAMESPACE(OSocketAddr, vos),
41*cdf0e10cSrcweir 						VOS_NAMESPACE(OObject, vos), 0);
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir /*****************************************************************************/
45*cdf0e10cSrcweir // OSocketAddr()
46*cdf0e10cSrcweir /*****************************************************************************/
47*cdf0e10cSrcweir OSocketAddr::OSocketAddr()
48*cdf0e10cSrcweir {
49*cdf0e10cSrcweir 	m_SockAddr= 0;
50*cdf0e10cSrcweir }
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir /*****************************************************************************/
53*cdf0e10cSrcweir // OSocketAddr()
54*cdf0e10cSrcweir /*****************************************************************************/
55*cdf0e10cSrcweir OSocketAddr::OSocketAddr(oslSocketAddr Addr)
56*cdf0e10cSrcweir {
57*cdf0e10cSrcweir 	m_SockAddr= Addr;
58*cdf0e10cSrcweir }
59*cdf0e10cSrcweir 
60*cdf0e10cSrcweir /*****************************************************************************/
61*cdf0e10cSrcweir // OSocketAddr()
62*cdf0e10cSrcweir /*****************************************************************************/
63*cdf0e10cSrcweir OSocketAddr::OSocketAddr(const OSocketAddr& Addr) :
64*cdf0e10cSrcweir ISocketAddr(), OObject()
65*cdf0e10cSrcweir {
66*cdf0e10cSrcweir 	m_SockAddr= osl_copySocketAddr((oslSocketAddr)Addr);
67*cdf0e10cSrcweir }
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir /*****************************************************************************/
70*cdf0e10cSrcweir // ~OSocketAddr()
71*cdf0e10cSrcweir /*****************************************************************************/
72*cdf0e10cSrcweir OSocketAddr::~OSocketAddr()
73*cdf0e10cSrcweir {
74*cdf0e10cSrcweir 	osl_destroySocketAddr(m_SockAddr);
75*cdf0e10cSrcweir }
76*cdf0e10cSrcweir 
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir /*****************************************************************************/
79*cdf0e10cSrcweir // getFamily()
80*cdf0e10cSrcweir /*****************************************************************************/
81*cdf0e10cSrcweir OSocketAddr::TAddrFamily OSocketAddr::getFamily() const
82*cdf0e10cSrcweir {
83*cdf0e10cSrcweir 	return (TAddrFamily)osl_getFamilyOfSocketAddr(m_SockAddr);
84*cdf0e10cSrcweir }
85*cdf0e10cSrcweir 
86*cdf0e10cSrcweir /*****************************************************************************/
87*cdf0e10cSrcweir // operator oslSocketAddr ()
88*cdf0e10cSrcweir /*****************************************************************************/
89*cdf0e10cSrcweir OSocketAddr::operator oslSocketAddr() const
90*cdf0e10cSrcweir {
91*cdf0e10cSrcweir 	return m_SockAddr;
92*cdf0e10cSrcweir }
93*cdf0e10cSrcweir 
94*cdf0e10cSrcweir /*****************************************************************************/
95*cdf0e10cSrcweir // getHostname()
96*cdf0e10cSrcweir /*****************************************************************************/
97*cdf0e10cSrcweir OSocketAddr::TResult OSocketAddr::getHostname(rtl::OUString& rBuffer ) const
98*cdf0e10cSrcweir {
99*cdf0e10cSrcweir 	return (TResult)osl_getHostnameOfSocketAddr(m_SockAddr, &rBuffer.pData );
100*cdf0e10cSrcweir }
101*cdf0e10cSrcweir 
102*cdf0e10cSrcweir /*****************************************************************************/
103*cdf0e10cSrcweir // getLocalHostname()
104*cdf0e10cSrcweir /*****************************************************************************/
105*cdf0e10cSrcweir OSocketAddr::TResult OSocketAddr::getLocalHostname( rtl::OUString& pBuffer )
106*cdf0e10cSrcweir {
107*cdf0e10cSrcweir 	return (TResult)osl_getLocalHostname( &pBuffer.pData );
108*cdf0e10cSrcweir }
109*cdf0e10cSrcweir 
110*cdf0e10cSrcweir /*****************************************************************************/
111*cdf0e10cSrcweir // resolveHostname()
112*cdf0e10cSrcweir /*****************************************************************************/
113*cdf0e10cSrcweir oslSocketAddr OSocketAddr::resolveHostname(const rtl::OUString& ustrHostname)
114*cdf0e10cSrcweir {
115*cdf0e10cSrcweir 	return osl_resolveHostname( ustrHostname.pData );
116*cdf0e10cSrcweir }
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir /*****************************************************************************/
119*cdf0e10cSrcweir // operator= (oslSocketAddr Addr)
120*cdf0e10cSrcweir /*****************************************************************************/
121*cdf0e10cSrcweir void OSocketAddr::operator= (oslSocketAddr Addr)
122*cdf0e10cSrcweir {
123*cdf0e10cSrcweir 	if(m_SockAddr) {
124*cdf0e10cSrcweir 		osl_destroySocketAddr(m_SockAddr);
125*cdf0e10cSrcweir 	}
126*cdf0e10cSrcweir 
127*cdf0e10cSrcweir 	m_SockAddr= Addr;
128*cdf0e10cSrcweir }
129*cdf0e10cSrcweir 
130*cdf0e10cSrcweir /*****************************************************************************/
131*cdf0e10cSrcweir // operator== (oslSocketAddr Addr)
132*cdf0e10cSrcweir /*****************************************************************************/
133*cdf0e10cSrcweir sal_Bool OSocketAddr::operator== (oslSocketAddr Addr)
134*cdf0e10cSrcweir {
135*cdf0e10cSrcweir 	return (osl_isEqualSocketAddr(m_SockAddr, Addr));
136*cdf0e10cSrcweir }
137*cdf0e10cSrcweir 
138*cdf0e10cSrcweir /*****************************************************************************/
139*cdf0e10cSrcweir // operator=(const OSocketAddr& Addr)
140*cdf0e10cSrcweir /*****************************************************************************/
141*cdf0e10cSrcweir OSocketAddr& OSocketAddr::operator=(const OSocketAddr& Addr)
142*cdf0e10cSrcweir {
143*cdf0e10cSrcweir 	if(m_SockAddr) {
144*cdf0e10cSrcweir 		osl_destroySocketAddr(m_SockAddr);
145*cdf0e10cSrcweir 	}
146*cdf0e10cSrcweir 
147*cdf0e10cSrcweir 	m_SockAddr= osl_copySocketAddr((oslSocketAddr)Addr);
148*cdf0e10cSrcweir 
149*cdf0e10cSrcweir 	return *this;
150*cdf0e10cSrcweir }
151*cdf0e10cSrcweir 
152*cdf0e10cSrcweir 
153*cdf0e10cSrcweir VOS_IMPLEMENT_CLASSINFO(VOS_CLASSNAME(OInetSocketAddr, vos),
154*cdf0e10cSrcweir 						VOS_NAMESPACE(OInetSocketAddr, vos),
155*cdf0e10cSrcweir 						VOS_NAMESPACE(OSocketAddr, vos), 0);
156*cdf0e10cSrcweir 
157*cdf0e10cSrcweir 
158*cdf0e10cSrcweir 
159*cdf0e10cSrcweir /*****************************************************************************/
160*cdf0e10cSrcweir // OInetSocketAddr
161*cdf0e10cSrcweir // creates arbitrary inet-address (INADDR_ANY)
162*cdf0e10cSrcweir /*****************************************************************************/
163*cdf0e10cSrcweir OInetSocketAddr::OInetSocketAddr()
164*cdf0e10cSrcweir {
165*cdf0e10cSrcweir 	m_SockAddr= osl_createEmptySocketAddr(osl_Socket_FamilyInet);
166*cdf0e10cSrcweir }
167*cdf0e10cSrcweir 
168*cdf0e10cSrcweir /*****************************************************************************/
169*cdf0e10cSrcweir // OInetSocketAddr
170*cdf0e10cSrcweir // uses the given oslSocketAddr as its own
171*cdf0e10cSrcweir /*****************************************************************************/
172*cdf0e10cSrcweir OInetSocketAddr::OInetSocketAddr(oslSocketAddr Addr) :
173*cdf0e10cSrcweir 	OSocketAddr(Addr)
174*cdf0e10cSrcweir {
175*cdf0e10cSrcweir 	VOS_ASSERT(osl_getFamilyOfSocketAddr(Addr) == osl_Socket_FamilyInet);
176*cdf0e10cSrcweir }
177*cdf0e10cSrcweir 
178*cdf0e10cSrcweir /*****************************************************************************/
179*cdf0e10cSrcweir // OInetSocketAddr
180*cdf0e10cSrcweir // Create a socket address either from a dotted decimal address
181*cdf0e10cSrcweir //(e.g. 141.99.128.50) or a hostname (e.g. www.stardiv.de).
182*cdf0e10cSrcweir /*****************************************************************************/
183*cdf0e10cSrcweir OInetSocketAddr::OInetSocketAddr(const rtl::OUString& ustrAddrOrHostname, sal_Int32 Port)
184*cdf0e10cSrcweir {
185*cdf0e10cSrcweir 	// first try as dotted address.
186*cdf0e10cSrcweir 	m_SockAddr= osl_createInetSocketAddr(ustrAddrOrHostname.pData, Port);
187*cdf0e10cSrcweir 
188*cdf0e10cSrcweir 	// create failed, maybe it's an hostname
189*cdf0e10cSrcweir 	if(m_SockAddr == 0)
190*cdf0e10cSrcweir 	{
191*cdf0e10cSrcweir 		m_SockAddr= osl_resolveHostname(ustrAddrOrHostname.pData);
192*cdf0e10cSrcweir 
193*cdf0e10cSrcweir 		// host found?
194*cdf0e10cSrcweir 		if(m_SockAddr)
195*cdf0e10cSrcweir 		{
196*cdf0e10cSrcweir 			// set port will fail if addrtype is not osl_Socket_FamilyInet
197*cdf0e10cSrcweir 			VOS_VERIFY(osl_setInetPortOfSocketAddr(m_SockAddr, Port));
198*cdf0e10cSrcweir 		}
199*cdf0e10cSrcweir 	}
200*cdf0e10cSrcweir }
201*cdf0e10cSrcweir 
202*cdf0e10cSrcweir /*****************************************************************************/
203*cdf0e10cSrcweir // OInetSocketAddr(const OInetSocketAddr&)
204*cdf0e10cSrcweir /*****************************************************************************/
205*cdf0e10cSrcweir OInetSocketAddr::OInetSocketAddr(const OInetSocketAddr& sa) :
206*cdf0e10cSrcweir 	OSocketAddr(sa)
207*cdf0e10cSrcweir {
208*cdf0e10cSrcweir 	VOS_ASSERT(getFamily() == TFamily_Inet);
209*cdf0e10cSrcweir }
210*cdf0e10cSrcweir 
211*cdf0e10cSrcweir /*****************************************************************************/
212*cdf0e10cSrcweir // OInetSocketAddr(const OSocketAddr&)
213*cdf0e10cSrcweir /*****************************************************************************/
214*cdf0e10cSrcweir OInetSocketAddr::OInetSocketAddr(const OSocketAddr& sa) :
215*cdf0e10cSrcweir 	OSocketAddr(sa)
216*cdf0e10cSrcweir {
217*cdf0e10cSrcweir 	VOS_ASSERT(sa.getFamily() == TFamily_Inet);
218*cdf0e10cSrcweir }
219*cdf0e10cSrcweir 
220*cdf0e10cSrcweir /*****************************************************************************/
221*cdf0e10cSrcweir // ~OInetSocketAddr
222*cdf0e10cSrcweir /*****************************************************************************/
223*cdf0e10cSrcweir OInetSocketAddr::~OInetSocketAddr()
224*cdf0e10cSrcweir {
225*cdf0e10cSrcweir }
226*cdf0e10cSrcweir 
227*cdf0e10cSrcweir /*****************************************************************************/
228*cdf0e10cSrcweir // operator= (oslSocketAddr Addr)
229*cdf0e10cSrcweir /*****************************************************************************/
230*cdf0e10cSrcweir void OInetSocketAddr::operator= (oslSocketAddr Addr)
231*cdf0e10cSrcweir {
232*cdf0e10cSrcweir 	VOS_PRECOND(osl_getFamilyOfSocketAddr(Addr) == osl_Socket_FamilyInet,
233*cdf0e10cSrcweir 				"oslSocketAddr not of type osl_Socket_FamilyInet!");
234*cdf0e10cSrcweir 
235*cdf0e10cSrcweir 	OSocketAddr::operator=(Addr);
236*cdf0e10cSrcweir }
237*cdf0e10cSrcweir 
238*cdf0e10cSrcweir /*****************************************************************************/
239*cdf0e10cSrcweir // operator== (oslSocketAddr Addr)
240*cdf0e10cSrcweir /*****************************************************************************/
241*cdf0e10cSrcweir sal_Bool OInetSocketAddr::operator== (oslSocketAddr Addr)
242*cdf0e10cSrcweir {
243*cdf0e10cSrcweir 	return (osl_isEqualSocketAddr(m_SockAddr, Addr));
244*cdf0e10cSrcweir }
245*cdf0e10cSrcweir 
246*cdf0e10cSrcweir /*****************************************************************************/
247*cdf0e10cSrcweir // operator=(const OInetSocketAddr& Addr)
248*cdf0e10cSrcweir /*****************************************************************************/
249*cdf0e10cSrcweir OInetSocketAddr& OInetSocketAddr::operator=(const OInetSocketAddr& Addr)
250*cdf0e10cSrcweir {
251*cdf0e10cSrcweir 	VOS_ASSERT(Addr.getFamily() == TFamily_Inet);
252*cdf0e10cSrcweir 
253*cdf0e10cSrcweir 	OSocketAddr::operator=(Addr);
254*cdf0e10cSrcweir 
255*cdf0e10cSrcweir 	return *this;
256*cdf0e10cSrcweir }
257*cdf0e10cSrcweir 
258*cdf0e10cSrcweir /*****************************************************************************/
259*cdf0e10cSrcweir // operator=(const OSocketAddr& Addr)
260*cdf0e10cSrcweir /*****************************************************************************/
261*cdf0e10cSrcweir OInetSocketAddr& OInetSocketAddr::operator=(const OSocketAddr& Addr)
262*cdf0e10cSrcweir {
263*cdf0e10cSrcweir 	VOS_ASSERT(Addr.getFamily() == TFamily_Inet);
264*cdf0e10cSrcweir 
265*cdf0e10cSrcweir 	OSocketAddr::operator=(Addr);
266*cdf0e10cSrcweir 
267*cdf0e10cSrcweir 	return *this;
268*cdf0e10cSrcweir }
269*cdf0e10cSrcweir 
270*cdf0e10cSrcweir /*****************************************************************************/
271*cdf0e10cSrcweir // getServicePort()
272*cdf0e10cSrcweir /*****************************************************************************/
273*cdf0e10cSrcweir sal_Int32 OInetSocketAddr::getServicePort(const rtl::OUString& ustrServiceName,
274*cdf0e10cSrcweir 									const rtl::OUString& ustrProtocolName)
275*cdf0e10cSrcweir {
276*cdf0e10cSrcweir 	return osl_getServicePort(ustrServiceName.pData, ustrProtocolName.pData);
277*cdf0e10cSrcweir }
278*cdf0e10cSrcweir 
279*cdf0e10cSrcweir 
280*cdf0e10cSrcweir /*****************************************************************************/
281*cdf0e10cSrcweir // getPort()
282*cdf0e10cSrcweir /*****************************************************************************/
283*cdf0e10cSrcweir sal_Int32 OInetSocketAddr::getPort () const
284*cdf0e10cSrcweir {
285*cdf0e10cSrcweir 	return osl_getInetPortOfSocketAddr(m_SockAddr);
286*cdf0e10cSrcweir }
287*cdf0e10cSrcweir 
288*cdf0e10cSrcweir 
289*cdf0e10cSrcweir /*****************************************************************************/
290*cdf0e10cSrcweir // setPort()
291*cdf0e10cSrcweir /*****************************************************************************/
292*cdf0e10cSrcweir sal_Bool OInetSocketAddr::setPort (sal_Int32 Port)
293*cdf0e10cSrcweir {
294*cdf0e10cSrcweir 	return osl_setInetPortOfSocketAddr(m_SockAddr, Port);
295*cdf0e10cSrcweir }
296*cdf0e10cSrcweir 
297*cdf0e10cSrcweir 
298*cdf0e10cSrcweir /*****************************************************************************/
299*cdf0e10cSrcweir // getDottedAddr()
300*cdf0e10cSrcweir /*****************************************************************************/
301*cdf0e10cSrcweir OSocketAddr::TResult OInetSocketAddr::getDottedAddr( rtl::OUString& pBuffer ) const
302*cdf0e10cSrcweir {
303*cdf0e10cSrcweir 	return (TResult)osl_getDottedInetAddrOfSocketAddr(m_SockAddr, &pBuffer.pData );
304*cdf0e10cSrcweir }
305*cdf0e10cSrcweir 
306*cdf0e10cSrcweir /*****************************************************************************/
307*cdf0e10cSrcweir // setAddr()
308*cdf0e10cSrcweir /*****************************************************************************/
309*cdf0e10cSrcweir sal_Bool OInetSocketAddr::setAddr(const rtl::OUString& ustrAddrOrHostname)
310*cdf0e10cSrcweir {
311*cdf0e10cSrcweir 	sal_Int32 Port = 0;
312*cdf0e10cSrcweir 
313*cdf0e10cSrcweir 	if(m_SockAddr) {
314*cdf0e10cSrcweir 
315*cdf0e10cSrcweir 		// retrieve old port
316*cdf0e10cSrcweir 		Port= getPort();
317*cdf0e10cSrcweir 
318*cdf0e10cSrcweir 		// free old address
319*cdf0e10cSrcweir 		osl_destroySocketAddr(m_SockAddr);
320*cdf0e10cSrcweir 		m_SockAddr= 0;
321*cdf0e10cSrcweir 	}
322*cdf0e10cSrcweir 
323*cdf0e10cSrcweir 	// first try as dotted address.
324*cdf0e10cSrcweir 	m_SockAddr= osl_createInetSocketAddr(ustrAddrOrHostname.pData, Port);
325*cdf0e10cSrcweir 
326*cdf0e10cSrcweir 	// create failed, maybe it's an hostname
327*cdf0e10cSrcweir 	if(m_SockAddr == 0)
328*cdf0e10cSrcweir 	{
329*cdf0e10cSrcweir 
330*cdf0e10cSrcweir 		m_SockAddr= osl_resolveHostname( ustrAddrOrHostname.pData );
331*cdf0e10cSrcweir 
332*cdf0e10cSrcweir 		// host found?
333*cdf0e10cSrcweir 		if(m_SockAddr==0)
334*cdf0e10cSrcweir 		{
335*cdf0e10cSrcweir 			return sal_False;
336*cdf0e10cSrcweir 		}
337*cdf0e10cSrcweir 
338*cdf0e10cSrcweir 		// set port will fail if addrtype is not osl_Socket_FamilyInet
339*cdf0e10cSrcweir 		VOS_VERIFY(osl_setInetPortOfSocketAddr(m_SockAddr, Port));
340*cdf0e10cSrcweir 
341*cdf0e10cSrcweir 	}
342*cdf0e10cSrcweir 
343*cdf0e10cSrcweir 	return sal_True;
344*cdf0e10cSrcweir }
345*cdf0e10cSrcweir 
346*cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////////////
347*cdf0e10cSrcweir // OIpxSocketAddr
348*cdf0e10cSrcweir 
349*cdf0e10cSrcweir VOS_IMPLEMENT_CLASSINFO(VOS_CLASSNAME(OIpxSocketAddr, vos),
350*cdf0e10cSrcweir 						VOS_NAMESPACE(OIpxSocketAddr, vos),
351*cdf0e10cSrcweir 						VOS_NAMESPACE(OSocketAddr, vos), 0);
352*cdf0e10cSrcweir 
353*cdf0e10cSrcweir 
354*cdf0e10cSrcweir /*****************************************************************************/
355*cdf0e10cSrcweir // OIpxSocketAddr()
356*cdf0e10cSrcweir /*****************************************************************************/
357*cdf0e10cSrcweir OIpxSocketAddr::OIpxSocketAddr()
358*cdf0e10cSrcweir {
359*cdf0e10cSrcweir 	m_SockAddr= osl_createEmptySocketAddr(osl_Socket_FamilyIpx);
360*cdf0e10cSrcweir }
361*cdf0e10cSrcweir 
362*cdf0e10cSrcweir /*****************************************************************************/
363*cdf0e10cSrcweir // OIpxSocketAddr(oslSocketAddr)
364*cdf0e10cSrcweir /*****************************************************************************/
365*cdf0e10cSrcweir OIpxSocketAddr::OIpxSocketAddr(oslSocketAddr Addr) :
366*cdf0e10cSrcweir 	OSocketAddr(Addr)
367*cdf0e10cSrcweir {
368*cdf0e10cSrcweir 	VOS_ASSERT(osl_getFamilyOfSocketAddr(Addr) == osl_Socket_FamilyIpx);
369*cdf0e10cSrcweir }
370*cdf0e10cSrcweir 
371*cdf0e10cSrcweir /*****************************************************************************/
372*cdf0e10cSrcweir // OIpxSocketAddr()
373*cdf0e10cSrcweir /*****************************************************************************/
374*cdf0e10cSrcweir OIpxSocketAddr::OIpxSocketAddr(const rtl::OUString&,
375*cdf0e10cSrcweir 							   const rtl::OUString&,
376*cdf0e10cSrcweir 							   sal_uInt32 )
377*cdf0e10cSrcweir {
378*cdf0e10cSrcweir 	// jbu : functionality removed from vos
379*cdf0e10cSrcweir }
380*cdf0e10cSrcweir 
381*cdf0e10cSrcweir /*****************************************************************************/
382*cdf0e10cSrcweir // OIpxSocketAddr(OIpxSocketAddr&)
383*cdf0e10cSrcweir /*****************************************************************************/
384*cdf0e10cSrcweir OIpxSocketAddr::OIpxSocketAddr(const OIpxSocketAddr& sa) :
385*cdf0e10cSrcweir 	OSocketAddr(sa)
386*cdf0e10cSrcweir {
387*cdf0e10cSrcweir 	VOS_ASSERT(sa.getFamily() == TFamily_Ipx);
388*cdf0e10cSrcweir }
389*cdf0e10cSrcweir 
390*cdf0e10cSrcweir 
391*cdf0e10cSrcweir /*****************************************************************************/
392*cdf0e10cSrcweir // OIpxSocketAddr(OSocketAddr&)
393*cdf0e10cSrcweir /*****************************************************************************/
394*cdf0e10cSrcweir OIpxSocketAddr::OIpxSocketAddr(const OSocketAddr& sa) :
395*cdf0e10cSrcweir 	OSocketAddr(sa)
396*cdf0e10cSrcweir {
397*cdf0e10cSrcweir 	VOS_ASSERT(sa.getFamily() == TFamily_Ipx);
398*cdf0e10cSrcweir }
399*cdf0e10cSrcweir 
400*cdf0e10cSrcweir /*****************************************************************************/
401*cdf0e10cSrcweir // ~OIpxSocketAddr()
402*cdf0e10cSrcweir /*****************************************************************************/
403*cdf0e10cSrcweir OIpxSocketAddr::~OIpxSocketAddr()
404*cdf0e10cSrcweir {
405*cdf0e10cSrcweir }
406*cdf0e10cSrcweir 
407*cdf0e10cSrcweir 
408*cdf0e10cSrcweir /*****************************************************************************/
409*cdf0e10cSrcweir // operator=()
410*cdf0e10cSrcweir /*****************************************************************************/
411*cdf0e10cSrcweir void OIpxSocketAddr::operator= (oslSocketAddr Addr)
412*cdf0e10cSrcweir {
413*cdf0e10cSrcweir 	VOS_PRECOND(osl_getFamilyOfSocketAddr(Addr) == osl_Socket_FamilyIpx,
414*cdf0e10cSrcweir 			"oslSocketAddr not of type osl_Socket_FamilyIpx!");
415*cdf0e10cSrcweir 
416*cdf0e10cSrcweir 	OSocketAddr::operator=(Addr);
417*cdf0e10cSrcweir }
418*cdf0e10cSrcweir 
419*cdf0e10cSrcweir /*****************************************************************************/
420*cdf0e10cSrcweir // operator== (oslSocketAddr Addr)
421*cdf0e10cSrcweir /*****************************************************************************/
422*cdf0e10cSrcweir sal_Bool OIpxSocketAddr::operator== (oslSocketAddr Addr)
423*cdf0e10cSrcweir {
424*cdf0e10cSrcweir 	return (osl_isEqualSocketAddr(m_SockAddr, Addr));
425*cdf0e10cSrcweir }
426*cdf0e10cSrcweir 
427*cdf0e10cSrcweir /*****************************************************************************/
428*cdf0e10cSrcweir // operator=(const OIpxSocketAddr& Addr)
429*cdf0e10cSrcweir /*****************************************************************************/
430*cdf0e10cSrcweir OIpxSocketAddr& OIpxSocketAddr::operator=(const OIpxSocketAddr& Addr)
431*cdf0e10cSrcweir {
432*cdf0e10cSrcweir 	VOS_ASSERT(Addr.getFamily() == TFamily_Ipx);
433*cdf0e10cSrcweir 
434*cdf0e10cSrcweir 	OSocketAddr::operator=(Addr);
435*cdf0e10cSrcweir 
436*cdf0e10cSrcweir 	return *this;
437*cdf0e10cSrcweir }
438*cdf0e10cSrcweir 
439*cdf0e10cSrcweir /*****************************************************************************/
440*cdf0e10cSrcweir // operator=(const OSocketAddr& Addr)
441*cdf0e10cSrcweir /*****************************************************************************/
442*cdf0e10cSrcweir OIpxSocketAddr& OIpxSocketAddr::operator=(const OSocketAddr& Addr)
443*cdf0e10cSrcweir {
444*cdf0e10cSrcweir 	VOS_ASSERT(Addr.getFamily() == TFamily_Ipx);
445*cdf0e10cSrcweir 
446*cdf0e10cSrcweir 	OSocketAddr::operator=(Addr);
447*cdf0e10cSrcweir 
448*cdf0e10cSrcweir 	return *this;
449*cdf0e10cSrcweir }
450*cdf0e10cSrcweir 
451*cdf0e10cSrcweir /*****************************************************************************/
452*cdf0e10cSrcweir // getNetNumber()
453*cdf0e10cSrcweir /*****************************************************************************/
454*cdf0e10cSrcweir OSocketAddr::TResult OIpxSocketAddr::getNetNumber(TIpxNetNumber&) const
455*cdf0e10cSrcweir {
456*cdf0e10cSrcweir 	// jbu : functionality removed from vos
457*cdf0e10cSrcweir 	return (TResult)0;
458*cdf0e10cSrcweir }
459*cdf0e10cSrcweir 
460*cdf0e10cSrcweir /*****************************************************************************/
461*cdf0e10cSrcweir // getNodeNumber()
462*cdf0e10cSrcweir /*****************************************************************************/
463*cdf0e10cSrcweir OSocketAddr::TResult OIpxSocketAddr::getNodeNumber(TIpxNodeNumber& ) const
464*cdf0e10cSrcweir {
465*cdf0e10cSrcweir 	// jbu : functionality removed from vos
466*cdf0e10cSrcweir 	return (TResult)0;
467*cdf0e10cSrcweir }
468*cdf0e10cSrcweir 
469*cdf0e10cSrcweir /*****************************************************************************/
470*cdf0e10cSrcweir // getSocketNumber()
471*cdf0e10cSrcweir /*****************************************************************************/
472*cdf0e10cSrcweir sal_uInt32 OIpxSocketAddr::getSocketNumber() const
473*cdf0e10cSrcweir {
474*cdf0e10cSrcweir //  	return osl_getIpxSocketNumber(m_SockAddr);
475*cdf0e10cSrcweir 	return (TResult)0;
476*cdf0e10cSrcweir }
477*cdf0e10cSrcweir 
478*cdf0e10cSrcweir 
479*cdf0e10cSrcweir /*****************************************************************************/
480*cdf0e10cSrcweir // getAddressString()
481*cdf0e10cSrcweir /*****************************************************************************/
482*cdf0e10cSrcweir //void OIpxSocketAddr::getAddressString(sal_Char* Buffer, sal_uInt32 Len) const
483*cdf0e10cSrcweir void OIpxSocketAddr::getAddressString( rtl::OUString& ) const
484*cdf0e10cSrcweir {
485*cdf0e10cSrcweir 	// jbu : functionality removed from vos
486*cdf0e10cSrcweir }
487*cdf0e10cSrcweir 
488*cdf0e10cSrcweir 
489*cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////////////
490*cdf0e10cSrcweir // Socket
491*cdf0e10cSrcweir 
492*cdf0e10cSrcweir 
493*cdf0e10cSrcweir VOS_IMPLEMENT_CLASSINFO(VOS_CLASSNAME(OSocket, vos),
494*cdf0e10cSrcweir 						VOS_NAMESPACE(OSocket, vos),
495*cdf0e10cSrcweir 						VOS_NAMESPACE(OObject, vos), 0);
496*cdf0e10cSrcweir 
497*cdf0e10cSrcweir /*****************************************************************************/
498*cdf0e10cSrcweir // OSocket()
499*cdf0e10cSrcweir /*****************************************************************************/
500*cdf0e10cSrcweir OSocket::OSocket()
501*cdf0e10cSrcweir {
502*cdf0e10cSrcweir 	m_pRecvTimeout = 0;
503*cdf0e10cSrcweir 	m_pSendTimeout = 0;
504*cdf0e10cSrcweir 
505*cdf0e10cSrcweir 	m_pSockRef= 0;
506*cdf0e10cSrcweir }
507*cdf0e10cSrcweir 
508*cdf0e10cSrcweir 
509*cdf0e10cSrcweir /*****************************************************************************/
510*cdf0e10cSrcweir // OSocket()
511*cdf0e10cSrcweir /*****************************************************************************/
512*cdf0e10cSrcweir OSocket::OSocket(TSocketType Type,
513*cdf0e10cSrcweir 				 TAddrFamily Family,
514*cdf0e10cSrcweir 				 TProtocol   Protocol)
515*cdf0e10cSrcweir {
516*cdf0e10cSrcweir 	m_pRecvTimeout = 0;
517*cdf0e10cSrcweir 	m_pSendTimeout = 0;
518*cdf0e10cSrcweir 
519*cdf0e10cSrcweir 	m_pSockRef=
520*cdf0e10cSrcweir 		new SockRef(osl_createSocket((oslAddrFamily)Family,
521*cdf0e10cSrcweir 									 (oslSocketType)Type,
522*cdf0e10cSrcweir 									 (oslProtocol)Protocol));
523*cdf0e10cSrcweir 
524*cdf0e10cSrcweir 	VOS_POSTCOND(m_pSockRef != 0, "OSocket(): new failed.\n");
525*cdf0e10cSrcweir 	VOS_POSTCOND((*m_pSockRef)(), "OSocket(): creation of socket failed!\n");
526*cdf0e10cSrcweir }
527*cdf0e10cSrcweir 
528*cdf0e10cSrcweir /*****************************************************************************/
529*cdf0e10cSrcweir // OSocket()
530*cdf0e10cSrcweir /*****************************************************************************/
531*cdf0e10cSrcweir OSocket::OSocket(const OSocket& sock) :
532*cdf0e10cSrcweir ISocketTypes(), OReference(), OObject()
533*cdf0e10cSrcweir {
534*cdf0e10cSrcweir 	m_pRecvTimeout = 0;
535*cdf0e10cSrcweir 	m_pSendTimeout = 0;
536*cdf0e10cSrcweir 	m_pSockRef=0;
537*cdf0e10cSrcweir 
538*cdf0e10cSrcweir 	VOS_ASSERT(sock.m_pSockRef != 0);
539*cdf0e10cSrcweir 
540*cdf0e10cSrcweir     if ( sock.m_pSockRef !=0 )
541*cdf0e10cSrcweir     {
542*cdf0e10cSrcweir         m_pSockRef= sock.m_pSockRef;
543*cdf0e10cSrcweir 
544*cdf0e10cSrcweir         setRecvTimeout(sock.m_pRecvTimeout);
545*cdf0e10cSrcweir         setSendTimeout(sock.m_pSendTimeout);
546*cdf0e10cSrcweir 
547*cdf0e10cSrcweir         m_pSockRef->acquire();
548*cdf0e10cSrcweir     }
549*cdf0e10cSrcweir }
550*cdf0e10cSrcweir 
551*cdf0e10cSrcweir /*****************************************************************************/
552*cdf0e10cSrcweir // OSocket()
553*cdf0e10cSrcweir /*****************************************************************************/
554*cdf0e10cSrcweir OSocket::OSocket(oslSocket Socket)
555*cdf0e10cSrcweir {
556*cdf0e10cSrcweir 	m_pRecvTimeout = 0;
557*cdf0e10cSrcweir 	m_pSendTimeout = 0;
558*cdf0e10cSrcweir 
559*cdf0e10cSrcweir 	m_pSockRef = new SockRef(Socket);
560*cdf0e10cSrcweir }
561*cdf0e10cSrcweir 
562*cdf0e10cSrcweir 
563*cdf0e10cSrcweir /*****************************************************************************/
564*cdf0e10cSrcweir // ~OSocket()
565*cdf0e10cSrcweir /*****************************************************************************/
566*cdf0e10cSrcweir OSocket::~OSocket()
567*cdf0e10cSrcweir {
568*cdf0e10cSrcweir 	close();
569*cdf0e10cSrcweir 
570*cdf0e10cSrcweir 	delete m_pRecvTimeout;
571*cdf0e10cSrcweir 	delete m_pSendTimeout;
572*cdf0e10cSrcweir }
573*cdf0e10cSrcweir 
574*cdf0e10cSrcweir 
575*cdf0e10cSrcweir /*****************************************************************************/
576*cdf0e10cSrcweir // create
577*cdf0e10cSrcweir /*****************************************************************************/
578*cdf0e10cSrcweir sal_Bool OSocket::create(TSocketType Type,
579*cdf0e10cSrcweir 						TAddrFamily Family,
580*cdf0e10cSrcweir 						TProtocol   Protocol)
581*cdf0e10cSrcweir {
582*cdf0e10cSrcweir 	// if this was a valid socket, decrease reference
583*cdf0e10cSrcweir 	if ((m_pSockRef) && (m_pSockRef->release() == 0))
584*cdf0e10cSrcweir 	{
585*cdf0e10cSrcweir 		osl_releaseSocket((*m_pSockRef)());
586*cdf0e10cSrcweir 		delete m_pSockRef;
587*cdf0e10cSrcweir 		m_pSockRef= 0;
588*cdf0e10cSrcweir 	}
589*cdf0e10cSrcweir 
590*cdf0e10cSrcweir 	m_pSockRef=
591*cdf0e10cSrcweir 		new SockRef(osl_createSocket((oslAddrFamily)Family,
592*cdf0e10cSrcweir 									 (oslSocketType)Type,
593*cdf0e10cSrcweir 									 (oslProtocol)Protocol));
594*cdf0e10cSrcweir 
595*cdf0e10cSrcweir 	VOS_POSTCOND(m_pSockRef != 0, "OSocket(): new failed.\n");
596*cdf0e10cSrcweir 
597*cdf0e10cSrcweir 	return (*m_pSockRef)() != 0;
598*cdf0e10cSrcweir }
599*cdf0e10cSrcweir 
600*cdf0e10cSrcweir /*****************************************************************************/
601*cdf0e10cSrcweir // operator=
602*cdf0e10cSrcweir /*****************************************************************************/
603*cdf0e10cSrcweir OSocket& OSocket::operator= (const OSocket& sock)
604*cdf0e10cSrcweir {
605*cdf0e10cSrcweir 	VOS_PRECOND(sock.m_pSockRef != 0, "OSocket::operator=: tried to assign an empty/invalid socket\n");
606*cdf0e10cSrcweir 
607*cdf0e10cSrcweir 	if (m_pSockRef == sock.m_pSockRef)
608*cdf0e10cSrcweir 		return *this;
609*cdf0e10cSrcweir 
610*cdf0e10cSrcweir 	// if this was a valid socket, decrease reference
611*cdf0e10cSrcweir 	if ((m_pSockRef) && (m_pSockRef->release() == 0))
612*cdf0e10cSrcweir 	{
613*cdf0e10cSrcweir 		osl_releaseSocket((*m_pSockRef)());
614*cdf0e10cSrcweir 		delete m_pSockRef;
615*cdf0e10cSrcweir 		m_pSockRef= 0;
616*cdf0e10cSrcweir 	}
617*cdf0e10cSrcweir 
618*cdf0e10cSrcweir 	m_pSockRef= sock.m_pSockRef;
619*cdf0e10cSrcweir 
620*cdf0e10cSrcweir 	setRecvTimeout(sock.m_pRecvTimeout);
621*cdf0e10cSrcweir 	setSendTimeout(sock.m_pSendTimeout);
622*cdf0e10cSrcweir 
623*cdf0e10cSrcweir 	m_pSockRef->acquire();
624*cdf0e10cSrcweir 
625*cdf0e10cSrcweir 	return *this;
626*cdf0e10cSrcweir }
627*cdf0e10cSrcweir 
628*cdf0e10cSrcweir /*****************************************************************************/
629*cdf0e10cSrcweir // operator oslSocket()
630*cdf0e10cSrcweir /*****************************************************************************/
631*cdf0e10cSrcweir OSocket::operator oslSocket() const
632*cdf0e10cSrcweir {
633*cdf0e10cSrcweir 	VOS_ASSERT(m_pSockRef);
634*cdf0e10cSrcweir 	return (*m_pSockRef)();
635*cdf0e10cSrcweir }
636*cdf0e10cSrcweir 
637*cdf0e10cSrcweir /*****************************************************************************/
638*cdf0e10cSrcweir // isValid()
639*cdf0e10cSrcweir /*****************************************************************************/
640*cdf0e10cSrcweir sal_Bool OSocket::isValid() const
641*cdf0e10cSrcweir {
642*cdf0e10cSrcweir 	return m_pSockRef != 0 && (*m_pSockRef)() != 0;
643*cdf0e10cSrcweir }
644*cdf0e10cSrcweir 
645*cdf0e10cSrcweir 
646*cdf0e10cSrcweir /*****************************************************************************/
647*cdf0e10cSrcweir // close
648*cdf0e10cSrcweir /*****************************************************************************/
649*cdf0e10cSrcweir void OSocket::close()
650*cdf0e10cSrcweir {
651*cdf0e10cSrcweir 	if (m_pSockRef && (*m_pSockRef)() && (m_pSockRef->release() == 0))
652*cdf0e10cSrcweir 	{
653*cdf0e10cSrcweir 		osl_releaseSocket((*m_pSockRef)());
654*cdf0e10cSrcweir 		delete m_pSockRef;
655*cdf0e10cSrcweir 	}
656*cdf0e10cSrcweir 
657*cdf0e10cSrcweir 	m_pSockRef= 0;
658*cdf0e10cSrcweir }
659*cdf0e10cSrcweir 
660*cdf0e10cSrcweir /*****************************************************************************/
661*cdf0e10cSrcweir // getLocalAddr
662*cdf0e10cSrcweir /*****************************************************************************/
663*cdf0e10cSrcweir void OSocket::getLocalAddr(OSocketAddr& sa) const
664*cdf0e10cSrcweir {
665*cdf0e10cSrcweir 	VOS_ASSERT(m_pSockRef && (*m_pSockRef)());
666*cdf0e10cSrcweir 
667*cdf0e10cSrcweir     if ( m_pSockRef && (*m_pSockRef)() )
668*cdf0e10cSrcweir     {
669*cdf0e10cSrcweir         sa= osl_getLocalAddrOfSocket((*m_pSockRef)());
670*cdf0e10cSrcweir     }
671*cdf0e10cSrcweir }
672*cdf0e10cSrcweir 
673*cdf0e10cSrcweir /*****************************************************************************/
674*cdf0e10cSrcweir // getLocalPort
675*cdf0e10cSrcweir /*****************************************************************************/
676*cdf0e10cSrcweir sal_Int32 OSocket::getLocalPort() const
677*cdf0e10cSrcweir {
678*cdf0e10cSrcweir 	VOS_ASSERT(m_pSockRef && (*m_pSockRef)());
679*cdf0e10cSrcweir 
680*cdf0e10cSrcweir 	sal_Int32 Port= OSL_INVALID_PORT;
681*cdf0e10cSrcweir 
682*cdf0e10cSrcweir     if ( m_pSockRef && (*m_pSockRef)() )
683*cdf0e10cSrcweir     {
684*cdf0e10cSrcweir         oslSocketAddr Addr= osl_getLocalAddrOfSocket((*m_pSockRef)());
685*cdf0e10cSrcweir 
686*cdf0e10cSrcweir         if(Addr)
687*cdf0e10cSrcweir         {
688*cdf0e10cSrcweir             Port= osl_getInetPortOfSocketAddr(Addr);
689*cdf0e10cSrcweir             osl_destroySocketAddr(Addr);
690*cdf0e10cSrcweir         }
691*cdf0e10cSrcweir     }
692*cdf0e10cSrcweir 
693*cdf0e10cSrcweir 	return Port;
694*cdf0e10cSrcweir }
695*cdf0e10cSrcweir 
696*cdf0e10cSrcweir /*****************************************************************************/
697*cdf0e10cSrcweir // getLocalHost
698*cdf0e10cSrcweir /*****************************************************************************/
699*cdf0e10cSrcweir OSocket::TResult OSocket::getLocalHost( rtl::OUString& pBuffer) const
700*cdf0e10cSrcweir {
701*cdf0e10cSrcweir 	VOS_ASSERT(m_pSockRef && (*m_pSockRef)());
702*cdf0e10cSrcweir 
703*cdf0e10cSrcweir     if ( m_pSockRef && (*m_pSockRef)() )
704*cdf0e10cSrcweir     {
705*cdf0e10cSrcweir         oslSocketAddr Addr= osl_getLocalAddrOfSocket((*m_pSockRef)());
706*cdf0e10cSrcweir 
707*cdf0e10cSrcweir         if(Addr)
708*cdf0e10cSrcweir         {
709*cdf0e10cSrcweir //	    	TResult Result= (TResult)osl_getHostnameOfSocketAddr(Addr,
710*cdf0e10cSrcweir //														pBuffer, BufferSize);
711*cdf0e10cSrcweir             TResult Result= (TResult)osl_getHostnameOfSocketAddr(Addr,
712*cdf0e10cSrcweir 															 &pBuffer.pData );
713*cdf0e10cSrcweir 
714*cdf0e10cSrcweir             osl_destroySocketAddr(Addr);
715*cdf0e10cSrcweir 
716*cdf0e10cSrcweir             return Result;
717*cdf0e10cSrcweir         }
718*cdf0e10cSrcweir     }
719*cdf0e10cSrcweir 
720*cdf0e10cSrcweir 	return TResult_Error;
721*cdf0e10cSrcweir }
722*cdf0e10cSrcweir 
723*cdf0e10cSrcweir /*****************************************************************************/
724*cdf0e10cSrcweir // getPeerAddr
725*cdf0e10cSrcweir /*****************************************************************************/
726*cdf0e10cSrcweir void OSocket::getPeerAddr(OSocketAddr& sa) const
727*cdf0e10cSrcweir {
728*cdf0e10cSrcweir 	VOS_ASSERT(m_pSockRef && (*m_pSockRef)());
729*cdf0e10cSrcweir 
730*cdf0e10cSrcweir     if ( m_pSockRef && (*m_pSockRef)() )
731*cdf0e10cSrcweir     {
732*cdf0e10cSrcweir         sa= osl_getPeerAddrOfSocket((*m_pSockRef)());
733*cdf0e10cSrcweir     }
734*cdf0e10cSrcweir }
735*cdf0e10cSrcweir 
736*cdf0e10cSrcweir /*****************************************************************************/
737*cdf0e10cSrcweir // getPeerPort
738*cdf0e10cSrcweir /*****************************************************************************/
739*cdf0e10cSrcweir sal_Int32 OSocket::getPeerPort() const
740*cdf0e10cSrcweir {
741*cdf0e10cSrcweir 	VOS_ASSERT(m_pSockRef && (*m_pSockRef)());
742*cdf0e10cSrcweir 
743*cdf0e10cSrcweir     sal_Int32 Port= OSL_INVALID_PORT;
744*cdf0e10cSrcweir 
745*cdf0e10cSrcweir     if ( m_pSockRef && (*m_pSockRef)() )
746*cdf0e10cSrcweir     {
747*cdf0e10cSrcweir         oslSocketAddr Addr= osl_getPeerAddrOfSocket((*m_pSockRef)());
748*cdf0e10cSrcweir 
749*cdf0e10cSrcweir         if(Addr)
750*cdf0e10cSrcweir         {
751*cdf0e10cSrcweir             Port= osl_getInetPortOfSocketAddr(Addr);
752*cdf0e10cSrcweir             osl_destroySocketAddr(Addr);
753*cdf0e10cSrcweir         }
754*cdf0e10cSrcweir     }
755*cdf0e10cSrcweir 
756*cdf0e10cSrcweir 	return Port;
757*cdf0e10cSrcweir }
758*cdf0e10cSrcweir 
759*cdf0e10cSrcweir /*****************************************************************************/
760*cdf0e10cSrcweir // getPeerHost
761*cdf0e10cSrcweir /*****************************************************************************/
762*cdf0e10cSrcweir OSocket::TResult OSocket::getPeerHost( rtl::OUString& pBuffer ) const
763*cdf0e10cSrcweir {
764*cdf0e10cSrcweir 	VOS_ASSERT(m_pSockRef && (*m_pSockRef)());
765*cdf0e10cSrcweir 
766*cdf0e10cSrcweir     if ( m_pSockRef && (*m_pSockRef)() )
767*cdf0e10cSrcweir     {
768*cdf0e10cSrcweir         oslSocketAddr Addr= osl_getPeerAddrOfSocket((*m_pSockRef)());
769*cdf0e10cSrcweir 
770*cdf0e10cSrcweir         if(Addr)
771*cdf0e10cSrcweir         {
772*cdf0e10cSrcweir //		    TResult Result= (TResult)osl_getHostnameOfSocketAddr(Addr,
773*cdf0e10cSrcweir //														pBuffer, BufferSize);
774*cdf0e10cSrcweir             TResult Result= (TResult)osl_getHostnameOfSocketAddr(Addr,
775*cdf0e10cSrcweir 															 &pBuffer.pData );
776*cdf0e10cSrcweir 
777*cdf0e10cSrcweir             osl_destroySocketAddr(Addr);
778*cdf0e10cSrcweir 
779*cdf0e10cSrcweir             return Result;
780*cdf0e10cSrcweir         }
781*cdf0e10cSrcweir     }
782*cdf0e10cSrcweir 
783*cdf0e10cSrcweir 	return TResult_Error;
784*cdf0e10cSrcweir }
785*cdf0e10cSrcweir 
786*cdf0e10cSrcweir /*****************************************************************************/
787*cdf0e10cSrcweir // bind
788*cdf0e10cSrcweir /*****************************************************************************/
789*cdf0e10cSrcweir sal_Bool OSocket::bind(const OSocketAddr& Addr)
790*cdf0e10cSrcweir {
791*cdf0e10cSrcweir 	VOS_ASSERT(m_pSockRef && (*m_pSockRef)());
792*cdf0e10cSrcweir 
793*cdf0e10cSrcweir     if ( m_pSockRef && (*m_pSockRef)() )
794*cdf0e10cSrcweir     {
795*cdf0e10cSrcweir         return osl_bindAddrToSocket((*m_pSockRef)(), (oslSocketAddr)Addr);
796*cdf0e10cSrcweir     }
797*cdf0e10cSrcweir 
798*cdf0e10cSrcweir 	return sal_False;
799*cdf0e10cSrcweir }
800*cdf0e10cSrcweir 
801*cdf0e10cSrcweir 
802*cdf0e10cSrcweir /*****************************************************************************/
803*cdf0e10cSrcweir // setSendTimeout
804*cdf0e10cSrcweir /*****************************************************************************/
805*cdf0e10cSrcweir void OSocket::setSendTimeout(const TimeValue* pTimeout)
806*cdf0e10cSrcweir {
807*cdf0e10cSrcweir 	delete m_pSendTimeout;
808*cdf0e10cSrcweir 
809*cdf0e10cSrcweir 	if (pTimeout)
810*cdf0e10cSrcweir 		m_pSendTimeout = new TimeValue(*pTimeout);
811*cdf0e10cSrcweir 	else
812*cdf0e10cSrcweir 		m_pSendTimeout = 0;
813*cdf0e10cSrcweir }
814*cdf0e10cSrcweir 
815*cdf0e10cSrcweir /*****************************************************************************/
816*cdf0e10cSrcweir // setRecvTimeout
817*cdf0e10cSrcweir /*****************************************************************************/
818*cdf0e10cSrcweir void OSocket::setRecvTimeout(const TimeValue* pTimeout)
819*cdf0e10cSrcweir {
820*cdf0e10cSrcweir 	delete m_pRecvTimeout;
821*cdf0e10cSrcweir 
822*cdf0e10cSrcweir 	if (pTimeout)
823*cdf0e10cSrcweir 		m_pRecvTimeout = new TimeValue(*pTimeout);
824*cdf0e10cSrcweir 	else
825*cdf0e10cSrcweir 		m_pRecvTimeout = 0;
826*cdf0e10cSrcweir }
827*cdf0e10cSrcweir 
828*cdf0e10cSrcweir /*****************************************************************************/
829*cdf0e10cSrcweir // isRecvReady
830*cdf0e10cSrcweir /*****************************************************************************/
831*cdf0e10cSrcweir sal_Bool OSocket::isRecvReady(const TimeValue* pTimeout) const
832*cdf0e10cSrcweir {
833*cdf0e10cSrcweir 	VOS_ASSERT(m_pSockRef && (*m_pSockRef)());
834*cdf0e10cSrcweir 
835*cdf0e10cSrcweir     if ( m_pSockRef && (*m_pSockRef)() )
836*cdf0e10cSrcweir     {
837*cdf0e10cSrcweir         return osl_isReceiveReady((*m_pSockRef)(), pTimeout);
838*cdf0e10cSrcweir     }
839*cdf0e10cSrcweir 
840*cdf0e10cSrcweir     return sal_False;
841*cdf0e10cSrcweir }
842*cdf0e10cSrcweir 
843*cdf0e10cSrcweir /*****************************************************************************/
844*cdf0e10cSrcweir // isSendReady
845*cdf0e10cSrcweir /*****************************************************************************/
846*cdf0e10cSrcweir sal_Bool OSocket::isSendReady(const TimeValue* pTimeout) const
847*cdf0e10cSrcweir {
848*cdf0e10cSrcweir 	VOS_ASSERT(m_pSockRef && (*m_pSockRef)());
849*cdf0e10cSrcweir 
850*cdf0e10cSrcweir     if ( m_pSockRef && (*m_pSockRef)() )
851*cdf0e10cSrcweir     {
852*cdf0e10cSrcweir         return osl_isSendReady((*m_pSockRef)(), pTimeout);
853*cdf0e10cSrcweir     }
854*cdf0e10cSrcweir 
855*cdf0e10cSrcweir     return sal_False;
856*cdf0e10cSrcweir }
857*cdf0e10cSrcweir 
858*cdf0e10cSrcweir /*****************************************************************************/
859*cdf0e10cSrcweir // isExceptionPending
860*cdf0e10cSrcweir /*****************************************************************************/
861*cdf0e10cSrcweir sal_Bool OSocket::isExceptionPending(const TimeValue* pTimeout) const
862*cdf0e10cSrcweir {
863*cdf0e10cSrcweir 	VOS_ASSERT(m_pSockRef && (*m_pSockRef)());
864*cdf0e10cSrcweir 
865*cdf0e10cSrcweir     if ( m_pSockRef && (*m_pSockRef)() )
866*cdf0e10cSrcweir     {
867*cdf0e10cSrcweir         return osl_isExceptionPending((*m_pSockRef)(), pTimeout);
868*cdf0e10cSrcweir     }
869*cdf0e10cSrcweir 
870*cdf0e10cSrcweir     return sal_False;
871*cdf0e10cSrcweir }
872*cdf0e10cSrcweir 
873*cdf0e10cSrcweir 
874*cdf0e10cSrcweir /*****************************************************************************/
875*cdf0e10cSrcweir // getOption
876*cdf0e10cSrcweir /*****************************************************************************/
877*cdf0e10cSrcweir sal_Int32 OSocket::getOption(TSocketOption Option,
878*cdf0e10cSrcweir 					   	   void* pBuffer,
879*cdf0e10cSrcweir 					       sal_uInt32 BufferLen,
880*cdf0e10cSrcweir 					       TSocketOptionLevel Level) const
881*cdf0e10cSrcweir {
882*cdf0e10cSrcweir 	VOS_ASSERT(m_pSockRef && (*m_pSockRef)());
883*cdf0e10cSrcweir 
884*cdf0e10cSrcweir     if ( m_pSockRef && (*m_pSockRef)() )
885*cdf0e10cSrcweir     {
886*cdf0e10cSrcweir         return osl_getSocketOption((*m_pSockRef)(),
887*cdf0e10cSrcweir                                    (oslSocketOptionLevel)Level,
888*cdf0e10cSrcweir                                    (oslSocketOption)Option,
889*cdf0e10cSrcweir                                    pBuffer,
890*cdf0e10cSrcweir                                    BufferLen);
891*cdf0e10cSrcweir     }
892*cdf0e10cSrcweir 
893*cdf0e10cSrcweir     return sal_False;
894*cdf0e10cSrcweir }
895*cdf0e10cSrcweir 
896*cdf0e10cSrcweir /*****************************************************************************/
897*cdf0e10cSrcweir // setOption
898*cdf0e10cSrcweir /*****************************************************************************/
899*cdf0e10cSrcweir sal_Bool OSocket::setOption(TSocketOption Option,
900*cdf0e10cSrcweir 						   void* pBuffer,
901*cdf0e10cSrcweir 						   sal_uInt32 BufferLen,
902*cdf0e10cSrcweir 						   TSocketOptionLevel Level) const
903*cdf0e10cSrcweir {
904*cdf0e10cSrcweir 	VOS_ASSERT(m_pSockRef && (*m_pSockRef)());
905*cdf0e10cSrcweir 
906*cdf0e10cSrcweir     if ( m_pSockRef && (*m_pSockRef)() )
907*cdf0e10cSrcweir     {
908*cdf0e10cSrcweir         return osl_setSocketOption((*m_pSockRef)(),
909*cdf0e10cSrcweir                                    (oslSocketOptionLevel)Level,
910*cdf0e10cSrcweir                                    (oslSocketOption)Option,
911*cdf0e10cSrcweir                                    pBuffer,
912*cdf0e10cSrcweir                                    BufferLen);
913*cdf0e10cSrcweir     }
914*cdf0e10cSrcweir 
915*cdf0e10cSrcweir     return sal_False;
916*cdf0e10cSrcweir }
917*cdf0e10cSrcweir 
918*cdf0e10cSrcweir 
919*cdf0e10cSrcweir /*****************************************************************************/
920*cdf0e10cSrcweir // enableNonBlockingMode
921*cdf0e10cSrcweir /*****************************************************************************/
922*cdf0e10cSrcweir sal_Bool OSocket::enableNonBlockingMode(sal_Bool On)
923*cdf0e10cSrcweir {
924*cdf0e10cSrcweir 	VOS_ASSERT(m_pSockRef && (*m_pSockRef)());
925*cdf0e10cSrcweir 
926*cdf0e10cSrcweir     if ( m_pSockRef && (*m_pSockRef)() )
927*cdf0e10cSrcweir     {
928*cdf0e10cSrcweir         return osl_enableNonBlockingMode((*m_pSockRef)(), On);
929*cdf0e10cSrcweir     }
930*cdf0e10cSrcweir 
931*cdf0e10cSrcweir     return sal_False;
932*cdf0e10cSrcweir }
933*cdf0e10cSrcweir 
934*cdf0e10cSrcweir /*****************************************************************************/
935*cdf0e10cSrcweir // isNonBlockingMode
936*cdf0e10cSrcweir /*****************************************************************************/
937*cdf0e10cSrcweir sal_Bool OSocket::isNonBlockingMode() const
938*cdf0e10cSrcweir {
939*cdf0e10cSrcweir 	VOS_ASSERT(m_pSockRef && (*m_pSockRef)());
940*cdf0e10cSrcweir 
941*cdf0e10cSrcweir     if ( m_pSockRef && (*m_pSockRef)() )
942*cdf0e10cSrcweir     {
943*cdf0e10cSrcweir         return osl_isNonBlockingMode((*m_pSockRef)());
944*cdf0e10cSrcweir     }
945*cdf0e10cSrcweir 
946*cdf0e10cSrcweir     return sal_False;
947*cdf0e10cSrcweir }
948*cdf0e10cSrcweir 
949*cdf0e10cSrcweir /*****************************************************************************/
950*cdf0e10cSrcweir // getType
951*cdf0e10cSrcweir /*****************************************************************************/
952*cdf0e10cSrcweir OSocket::TSocketType OSocket::getType() const
953*cdf0e10cSrcweir {
954*cdf0e10cSrcweir 	VOS_ASSERT(m_pSockRef && (*m_pSockRef)());
955*cdf0e10cSrcweir 
956*cdf0e10cSrcweir     if ( m_pSockRef && (*m_pSockRef)() )
957*cdf0e10cSrcweir     {
958*cdf0e10cSrcweir         return (TSocketType)osl_getSocketType((*m_pSockRef)());
959*cdf0e10cSrcweir     }
960*cdf0e10cSrcweir 
961*cdf0e10cSrcweir     return TType_Invalid;
962*cdf0e10cSrcweir }
963*cdf0e10cSrcweir 
964*cdf0e10cSrcweir /*****************************************************************************/
965*cdf0e10cSrcweir // clearError
966*cdf0e10cSrcweir /*****************************************************************************/
967*cdf0e10cSrcweir sal_Int32 OSocket::clearError() const
968*cdf0e10cSrcweir {
969*cdf0e10cSrcweir 	sal_Int32 err = 0;
970*cdf0e10cSrcweir 
971*cdf0e10cSrcweir 	getOption(TOption_Error, &err, sizeof(err));
972*cdf0e10cSrcweir 
973*cdf0e10cSrcweir 	return err;
974*cdf0e10cSrcweir }
975*cdf0e10cSrcweir 
976*cdf0e10cSrcweir /*****************************************************************************/
977*cdf0e10cSrcweir // setDebug
978*cdf0e10cSrcweir /*****************************************************************************/
979*cdf0e10cSrcweir sal_Int32 OSocket::setDebug(sal_Int32 opt) const
980*cdf0e10cSrcweir {
981*cdf0e10cSrcweir 	sal_Int32 old= 0;
982*cdf0e10cSrcweir 
983*cdf0e10cSrcweir 	getOption(TOption_Debug, &old, sizeof(old));
984*cdf0e10cSrcweir 
985*cdf0e10cSrcweir 	if (opt != -1)
986*cdf0e10cSrcweir 		setOption(TOption_Debug, &opt, sizeof(opt));
987*cdf0e10cSrcweir 
988*cdf0e10cSrcweir 	return old;
989*cdf0e10cSrcweir }
990*cdf0e10cSrcweir 
991*cdf0e10cSrcweir /*****************************************************************************/
992*cdf0e10cSrcweir // setReuseAddr
993*cdf0e10cSrcweir /*****************************************************************************/
994*cdf0e10cSrcweir sal_Int32 OSocket::setReuseAddr(sal_Int32 opt) const
995*cdf0e10cSrcweir {
996*cdf0e10cSrcweir 	sal_Int32 old = 0;
997*cdf0e10cSrcweir 
998*cdf0e10cSrcweir 	getOption(TOption_ReuseAddr, &old, sizeof(old));
999*cdf0e10cSrcweir 
1000*cdf0e10cSrcweir 	if (opt != -1)
1001*cdf0e10cSrcweir 		setOption(TOption_ReuseAddr, &opt, sizeof(opt));
1002*cdf0e10cSrcweir 
1003*cdf0e10cSrcweir 	return (old);
1004*cdf0e10cSrcweir }
1005*cdf0e10cSrcweir 
1006*cdf0e10cSrcweir /*****************************************************************************/
1007*cdf0e10cSrcweir // setKeepAlive
1008*cdf0e10cSrcweir /*****************************************************************************/
1009*cdf0e10cSrcweir sal_Int32 OSocket::setKeepAlive(sal_Int32 opt) const
1010*cdf0e10cSrcweir {
1011*cdf0e10cSrcweir 	sal_Int32 old = 0;
1012*cdf0e10cSrcweir 
1013*cdf0e10cSrcweir 	getOption(TOption_KeepAlive, &old, sizeof(old));
1014*cdf0e10cSrcweir 
1015*cdf0e10cSrcweir 	if (opt != -1)
1016*cdf0e10cSrcweir 		setOption(TOption_KeepAlive, &opt, sizeof(opt));
1017*cdf0e10cSrcweir 
1018*cdf0e10cSrcweir 	return (old);
1019*cdf0e10cSrcweir }
1020*cdf0e10cSrcweir 
1021*cdf0e10cSrcweir /*****************************************************************************/
1022*cdf0e10cSrcweir // setDontRoute
1023*cdf0e10cSrcweir /*****************************************************************************/
1024*cdf0e10cSrcweir sal_Int32 OSocket::setDontRoute(sal_Int32 opt) const
1025*cdf0e10cSrcweir {
1026*cdf0e10cSrcweir 	sal_Int32 old = 0;
1027*cdf0e10cSrcweir 
1028*cdf0e10cSrcweir 	getOption(TOption_DontRoute, &old, sizeof(old));
1029*cdf0e10cSrcweir 
1030*cdf0e10cSrcweir 	if (opt != -1)
1031*cdf0e10cSrcweir 		setOption(TOption_DontRoute, &opt, sizeof(opt));
1032*cdf0e10cSrcweir 
1033*cdf0e10cSrcweir 	return (old);
1034*cdf0e10cSrcweir }
1035*cdf0e10cSrcweir 
1036*cdf0e10cSrcweir /*****************************************************************************/
1037*cdf0e10cSrcweir // setBroadcast
1038*cdf0e10cSrcweir /*****************************************************************************/
1039*cdf0e10cSrcweir sal_Int32 OSocket::setBroadcast(sal_Int32 opt) const
1040*cdf0e10cSrcweir {
1041*cdf0e10cSrcweir 	sal_Int32 old = 0;
1042*cdf0e10cSrcweir 
1043*cdf0e10cSrcweir 	getOption(TOption_Broadcast, &old, sizeof(old));
1044*cdf0e10cSrcweir 
1045*cdf0e10cSrcweir 	if (opt != -1)
1046*cdf0e10cSrcweir 		setOption(TOption_Broadcast, &opt, sizeof(opt));
1047*cdf0e10cSrcweir 
1048*cdf0e10cSrcweir 	return (old);
1049*cdf0e10cSrcweir }
1050*cdf0e10cSrcweir 
1051*cdf0e10cSrcweir /*****************************************************************************/
1052*cdf0e10cSrcweir // setOobinline
1053*cdf0e10cSrcweir /*****************************************************************************/
1054*cdf0e10cSrcweir sal_Int32 OSocket::setOobinline(sal_Int32 opt) const
1055*cdf0e10cSrcweir {
1056*cdf0e10cSrcweir 	sal_Int32 old = 0;
1057*cdf0e10cSrcweir 
1058*cdf0e10cSrcweir 	getOption(TOption_OOBinLine, &old, sizeof(old));
1059*cdf0e10cSrcweir 
1060*cdf0e10cSrcweir 	if (opt != -1)
1061*cdf0e10cSrcweir 		setOption(TOption_OOBinLine, &opt, sizeof(opt));
1062*cdf0e10cSrcweir 
1063*cdf0e10cSrcweir 	return (old);
1064*cdf0e10cSrcweir }
1065*cdf0e10cSrcweir 
1066*cdf0e10cSrcweir /*****************************************************************************/
1067*cdf0e10cSrcweir // setLinger
1068*cdf0e10cSrcweir /*****************************************************************************/
1069*cdf0e10cSrcweir sal_Int32 OSocket::setLinger(sal_Int32 time) const
1070*cdf0e10cSrcweir {
1071*cdf0e10cSrcweir 	/* local decl. of linger-struct */
1072*cdf0e10cSrcweir 	struct SockLinger
1073*cdf0e10cSrcweir 	{
1074*cdf0e10cSrcweir 		sal_Int32 m_onoff;    // option on/off
1075*cdf0e10cSrcweir 		sal_Int32 m_linger;   // linger time
1076*cdf0e10cSrcweir 	};
1077*cdf0e10cSrcweir 
1078*cdf0e10cSrcweir 
1079*cdf0e10cSrcweir 	SockLinger  old = { 0, 0 };
1080*cdf0e10cSrcweir 
1081*cdf0e10cSrcweir 	getOption(TOption_Linger, &old, sizeof(old));
1082*cdf0e10cSrcweir 
1083*cdf0e10cSrcweir 	if (time > 0) // enable linger with wait-times > 0
1084*cdf0e10cSrcweir 	{
1085*cdf0e10cSrcweir 		SockLinger nw = { 1, time };
1086*cdf0e10cSrcweir 		setOption(TOption_Linger, &nw, sizeof(nw));
1087*cdf0e10cSrcweir 	}
1088*cdf0e10cSrcweir 	else if (time == 0) // disable linger with wait-time == 0
1089*cdf0e10cSrcweir 	{
1090*cdf0e10cSrcweir 		SockLinger nw = { 0, old.m_linger };
1091*cdf0e10cSrcweir 		setOption(TOption_Linger, &nw, sizeof(nw));
1092*cdf0e10cSrcweir 	}
1093*cdf0e10cSrcweir 
1094*cdf0e10cSrcweir 	// returns 0 if linger was off, else the linger-time
1095*cdf0e10cSrcweir 	return (old.m_onoff ? old.m_linger : 0);
1096*cdf0e10cSrcweir }
1097*cdf0e10cSrcweir 
1098*cdf0e10cSrcweir /*****************************************************************************/
1099*cdf0e10cSrcweir // setSendBufSize
1100*cdf0e10cSrcweir /*****************************************************************************/
1101*cdf0e10cSrcweir sal_Int32 OSocket::setSendBufSize(sal_Int32 sz) const
1102*cdf0e10cSrcweir {
1103*cdf0e10cSrcweir 	sal_Int32 old = 0;
1104*cdf0e10cSrcweir 
1105*cdf0e10cSrcweir 	getOption(TOption_SndBuf, &old, sizeof(old));
1106*cdf0e10cSrcweir 
1107*cdf0e10cSrcweir 	if (sz >= 0)
1108*cdf0e10cSrcweir 		setOption(TOption_SndBuf, &sz, sizeof(sz));
1109*cdf0e10cSrcweir 
1110*cdf0e10cSrcweir 	return (old);
1111*cdf0e10cSrcweir }
1112*cdf0e10cSrcweir 
1113*cdf0e10cSrcweir /*****************************************************************************/
1114*cdf0e10cSrcweir // setRecvBufSize
1115*cdf0e10cSrcweir /*****************************************************************************/
1116*cdf0e10cSrcweir sal_Int32 OSocket::setRecvBufSize(sal_Int32 sz) const
1117*cdf0e10cSrcweir {
1118*cdf0e10cSrcweir 	sal_Int32 old = 0;
1119*cdf0e10cSrcweir 
1120*cdf0e10cSrcweir 	getOption(TOption_RcvBuf, &old, sizeof(old));
1121*cdf0e10cSrcweir 
1122*cdf0e10cSrcweir 	if (sz >= 0)
1123*cdf0e10cSrcweir 		setOption(TOption_RcvBuf, &sz, sizeof(sz));
1124*cdf0e10cSrcweir 
1125*cdf0e10cSrcweir 	return (old);
1126*cdf0e10cSrcweir }
1127*cdf0e10cSrcweir 
1128*cdf0e10cSrcweir /*****************************************************************************/
1129*cdf0e10cSrcweir // setTcpNoDelay
1130*cdf0e10cSrcweir /*****************************************************************************/
1131*cdf0e10cSrcweir sal_Int32 OSocket::setTcpNoDelay(sal_Int32 sz) const
1132*cdf0e10cSrcweir {
1133*cdf0e10cSrcweir 	sal_Int32 old = 0;
1134*cdf0e10cSrcweir 
1135*cdf0e10cSrcweir 	getOption(TOption_TcpNoDelay, &old, sizeof(old), TLevel_Tcp);
1136*cdf0e10cSrcweir 
1137*cdf0e10cSrcweir 	if (sz >= 0)
1138*cdf0e10cSrcweir 		setOption(TOption_TcpNoDelay, &sz, sizeof(sz), TLevel_Tcp);
1139*cdf0e10cSrcweir 
1140*cdf0e10cSrcweir 	return (old);
1141*cdf0e10cSrcweir }
1142*cdf0e10cSrcweir 
1143*cdf0e10cSrcweir /*****************************************************************************/
1144*cdf0e10cSrcweir // getError
1145*cdf0e10cSrcweir /*****************************************************************************/
1146*cdf0e10cSrcweir //void OSocket::getError(sal_Char* pBuffer, sal_uInt32 nSize) const
1147*cdf0e10cSrcweir void OSocket::getError( rtl::OUString& pBuffer ) const
1148*cdf0e10cSrcweir {
1149*cdf0e10cSrcweir 	VOS_ASSERT(m_pSockRef && (*m_pSockRef)());
1150*cdf0e10cSrcweir 
1151*cdf0e10cSrcweir     if (m_pSockRef && (*m_pSockRef)())
1152*cdf0e10cSrcweir 		osl_getLastSocketErrorDescription((*m_pSockRef)(), &pBuffer.pData );
1153*cdf0e10cSrcweir 	else
1154*cdf0e10cSrcweir 		osl_getLastSocketErrorDescription(NULL, &pBuffer.pData );
1155*cdf0e10cSrcweir }
1156*cdf0e10cSrcweir 
1157*cdf0e10cSrcweir /*****************************************************************************/
1158*cdf0e10cSrcweir // getError
1159*cdf0e10cSrcweir /*****************************************************************************/
1160*cdf0e10cSrcweir OSocket::TSocketError OSocket::getError() const
1161*cdf0e10cSrcweir {
1162*cdf0e10cSrcweir 	VOS_ASSERT(m_pSockRef && (*m_pSockRef)());
1163*cdf0e10cSrcweir 
1164*cdf0e10cSrcweir     if (m_pSockRef && (*m_pSockRef)())
1165*cdf0e10cSrcweir 		return (TSocketError)osl_getLastSocketError((*m_pSockRef)());
1166*cdf0e10cSrcweir 	else
1167*cdf0e10cSrcweir 		return (TSocketError)osl_getLastSocketError(NULL);
1168*cdf0e10cSrcweir }
1169*cdf0e10cSrcweir 
1170*cdf0e10cSrcweir 
1171*cdf0e10cSrcweir 
1172*cdf0e10cSrcweir VOS_IMPLEMENT_CLASSINFO(VOS_CLASSNAME(OAcceptorSocket, vos),
1173*cdf0e10cSrcweir 						VOS_NAMESPACE(OAcceptorSocket, vos),
1174*cdf0e10cSrcweir 						VOS_NAMESPACE(OSocket, vos), 0);
1175*cdf0e10cSrcweir 
1176*cdf0e10cSrcweir 
1177*cdf0e10cSrcweir /*****************************************************************************/
1178*cdf0e10cSrcweir // OAcceptorSocket
1179*cdf0e10cSrcweir /*****************************************************************************/
1180*cdf0e10cSrcweir OAcceptorSocket::OAcceptorSocket(TAddrFamily Family,
1181*cdf0e10cSrcweir 								 TProtocol   Protocol,
1182*cdf0e10cSrcweir 								 TSocketType Type) :
1183*cdf0e10cSrcweir 	OSocket(Type, Family, Protocol)
1184*cdf0e10cSrcweir {
1185*cdf0e10cSrcweir }
1186*cdf0e10cSrcweir 
1187*cdf0e10cSrcweir /*****************************************************************************/
1188*cdf0e10cSrcweir // OAcceptorSocket
1189*cdf0e10cSrcweir /*****************************************************************************/
1190*cdf0e10cSrcweir OAcceptorSocket::OAcceptorSocket(const OAcceptorSocket& sock) :
1191*cdf0e10cSrcweir 	OSocket(sock)
1192*cdf0e10cSrcweir {
1193*cdf0e10cSrcweir }
1194*cdf0e10cSrcweir 
1195*cdf0e10cSrcweir /*****************************************************************************/
1196*cdf0e10cSrcweir // ~OAcceptorSocket
1197*cdf0e10cSrcweir /*****************************************************************************/
1198*cdf0e10cSrcweir OAcceptorSocket::~OAcceptorSocket()
1199*cdf0e10cSrcweir {
1200*cdf0e10cSrcweir 	if (m_pSockRef && (*m_pSockRef)() && (m_pSockRef->release() == 0))
1201*cdf0e10cSrcweir 	{
1202*cdf0e10cSrcweir         /* mfe: prepare for forthcoming api change */
1203*cdf0e10cSrcweir 		osl_closeSocket((*m_pSockRef)());
1204*cdf0e10cSrcweir 		osl_releaseSocket((*m_pSockRef)());
1205*cdf0e10cSrcweir 		delete m_pSockRef;
1206*cdf0e10cSrcweir 		m_pSockRef = 0;
1207*cdf0e10cSrcweir 	}
1208*cdf0e10cSrcweir }
1209*cdf0e10cSrcweir 
1210*cdf0e10cSrcweir /*****************************************************************************/
1211*cdf0e10cSrcweir // close
1212*cdf0e10cSrcweir /*****************************************************************************/
1213*cdf0e10cSrcweir void OAcceptorSocket::close()
1214*cdf0e10cSrcweir {
1215*cdf0e10cSrcweir 	if (m_pSockRef && (*m_pSockRef)() && (m_pSockRef->release() == 0))
1216*cdf0e10cSrcweir 	{
1217*cdf0e10cSrcweir 		osl_closeSocket((*m_pSockRef)());
1218*cdf0e10cSrcweir 	}
1219*cdf0e10cSrcweir 
1220*cdf0e10cSrcweir 	m_pSockRef= 0;
1221*cdf0e10cSrcweir }
1222*cdf0e10cSrcweir 
1223*cdf0e10cSrcweir /*****************************************************************************/
1224*cdf0e10cSrcweir // listen
1225*cdf0e10cSrcweir /*****************************************************************************/
1226*cdf0e10cSrcweir sal_Bool OAcceptorSocket::listen(sal_Int32 MaxPendingConnections)
1227*cdf0e10cSrcweir {
1228*cdf0e10cSrcweir 	VOS_ASSERT(m_pSockRef && (*m_pSockRef)());
1229*cdf0e10cSrcweir 
1230*cdf0e10cSrcweir     if ( m_pSockRef && (*m_pSockRef)() )
1231*cdf0e10cSrcweir     {
1232*cdf0e10cSrcweir         return osl_listenOnSocket((*m_pSockRef)(), MaxPendingConnections);
1233*cdf0e10cSrcweir     }
1234*cdf0e10cSrcweir 
1235*cdf0e10cSrcweir     return sal_False;
1236*cdf0e10cSrcweir }
1237*cdf0e10cSrcweir 
1238*cdf0e10cSrcweir 
1239*cdf0e10cSrcweir /*****************************************************************************/
1240*cdf0e10cSrcweir // acceptConnection
1241*cdf0e10cSrcweir /*****************************************************************************/
1242*cdf0e10cSrcweir OSocket::TResult OAcceptorSocket::acceptConnection(OStreamSocket& connection)
1243*cdf0e10cSrcweir {
1244*cdf0e10cSrcweir 	if (m_pRecvTimeout && ! isRecvReady(m_pRecvTimeout))
1245*cdf0e10cSrcweir 		return TResult_TimedOut;
1246*cdf0e10cSrcweir 
1247*cdf0e10cSrcweir 	VOS_ASSERT(m_pSockRef && (*m_pSockRef)());
1248*cdf0e10cSrcweir     OStreamSocket aSocket;
1249*cdf0e10cSrcweir 
1250*cdf0e10cSrcweir     if ( m_pSockRef && (*m_pSockRef)() )
1251*cdf0e10cSrcweir     {
1252*cdf0e10cSrcweir         aSocket = osl_acceptConnectionOnSocket((*m_pSockRef)(), 0);
1253*cdf0e10cSrcweir     }
1254*cdf0e10cSrcweir 
1255*cdf0e10cSrcweir 	if( aSocket.isValid() )
1256*cdf0e10cSrcweir     {
1257*cdf0e10cSrcweir         connection = aSocket;
1258*cdf0e10cSrcweir 		return TResult_Ok;
1259*cdf0e10cSrcweir     }
1260*cdf0e10cSrcweir 	else
1261*cdf0e10cSrcweir     {
1262*cdf0e10cSrcweir 		return TResult_Error;
1263*cdf0e10cSrcweir     }
1264*cdf0e10cSrcweir 
1265*cdf0e10cSrcweir }
1266*cdf0e10cSrcweir 
1267*cdf0e10cSrcweir /*****************************************************************************/
1268*cdf0e10cSrcweir // acceptConnection
1269*cdf0e10cSrcweir /*****************************************************************************/
1270*cdf0e10cSrcweir OSocket::TResult OAcceptorSocket::acceptConnection(OStreamSocket& connection,
1271*cdf0e10cSrcweir 												   OSocketAddr& sa)
1272*cdf0e10cSrcweir {
1273*cdf0e10cSrcweir 	oslSocketAddr PeerAddr = 0;
1274*cdf0e10cSrcweir 	oslSocket     Socket = 0;
1275*cdf0e10cSrcweir 
1276*cdf0e10cSrcweir 	if (m_pRecvTimeout && ! isRecvReady(m_pRecvTimeout))
1277*cdf0e10cSrcweir 		return TResult_TimedOut;
1278*cdf0e10cSrcweir 
1279*cdf0e10cSrcweir 	VOS_ASSERT(m_pSockRef && (*m_pSockRef)());
1280*cdf0e10cSrcweir 
1281*cdf0e10cSrcweir     if ( m_pSockRef && (*m_pSockRef)() )
1282*cdf0e10cSrcweir     {
1283*cdf0e10cSrcweir         Socket= osl_acceptConnectionOnSocket((*m_pSockRef)(), &PeerAddr);
1284*cdf0e10cSrcweir     }
1285*cdf0e10cSrcweir 
1286*cdf0e10cSrcweir 	if (Socket)
1287*cdf0e10cSrcweir 	{
1288*cdf0e10cSrcweir 		sa= PeerAddr;
1289*cdf0e10cSrcweir 		connection= Socket;
1290*cdf0e10cSrcweir 		return TResult_Ok;
1291*cdf0e10cSrcweir 	}
1292*cdf0e10cSrcweir 	else
1293*cdf0e10cSrcweir 	{
1294*cdf0e10cSrcweir 		return TResult_Error;
1295*cdf0e10cSrcweir 	}
1296*cdf0e10cSrcweir }
1297*cdf0e10cSrcweir 
1298*cdf0e10cSrcweir 
1299*cdf0e10cSrcweir VOS_IMPLEMENT_CLASSINFO(VOS_CLASSNAME(OStreamSocket, vos),
1300*cdf0e10cSrcweir 						VOS_NAMESPACE(OStreamSocket, vos),
1301*cdf0e10cSrcweir 						VOS_NAMESPACE(OSocket, vos), 0);
1302*cdf0e10cSrcweir 
1303*cdf0e10cSrcweir 
1304*cdf0e10cSrcweir 
1305*cdf0e10cSrcweir /*****************************************************************************/
1306*cdf0e10cSrcweir // OStreamSocket
1307*cdf0e10cSrcweir /*****************************************************************************/
1308*cdf0e10cSrcweir OStreamSocket::OStreamSocket()
1309*cdf0e10cSrcweir {
1310*cdf0e10cSrcweir }
1311*cdf0e10cSrcweir 
1312*cdf0e10cSrcweir /*****************************************************************************/
1313*cdf0e10cSrcweir // OStreamSocket
1314*cdf0e10cSrcweir /*****************************************************************************/
1315*cdf0e10cSrcweir OStreamSocket::OStreamSocket(TAddrFamily Family,
1316*cdf0e10cSrcweir 							 TProtocol   Protocol,
1317*cdf0e10cSrcweir 							 TSocketType Type) :
1318*cdf0e10cSrcweir 	OSocket(Type, Family, Protocol)
1319*cdf0e10cSrcweir {
1320*cdf0e10cSrcweir }
1321*cdf0e10cSrcweir 
1322*cdf0e10cSrcweir 
1323*cdf0e10cSrcweir /*****************************************************************************/
1324*cdf0e10cSrcweir // OStreamSocket
1325*cdf0e10cSrcweir /*****************************************************************************/
1326*cdf0e10cSrcweir OStreamSocket::OStreamSocket(oslSocket Socket) :
1327*cdf0e10cSrcweir 	OSocket(Socket)
1328*cdf0e10cSrcweir {
1329*cdf0e10cSrcweir }
1330*cdf0e10cSrcweir 
1331*cdf0e10cSrcweir /*****************************************************************************/
1332*cdf0e10cSrcweir // OStreamSocket
1333*cdf0e10cSrcweir // copy constructor
1334*cdf0e10cSrcweir /*****************************************************************************/
1335*cdf0e10cSrcweir OStreamSocket::OStreamSocket(const OStreamSocket& sock) :
1336*cdf0e10cSrcweir 	OSocket(sock), IStream()
1337*cdf0e10cSrcweir {
1338*cdf0e10cSrcweir }
1339*cdf0e10cSrcweir 
1340*cdf0e10cSrcweir /*****************************************************************************/
1341*cdf0e10cSrcweir // OStreamSocket
1342*cdf0e10cSrcweir // copy constructor
1343*cdf0e10cSrcweir /*****************************************************************************/
1344*cdf0e10cSrcweir OStreamSocket::OStreamSocket(const OSocket& sock) :
1345*cdf0e10cSrcweir 	OSocket(sock)
1346*cdf0e10cSrcweir {
1347*cdf0e10cSrcweir }
1348*cdf0e10cSrcweir 
1349*cdf0e10cSrcweir /*****************************************************************************/
1350*cdf0e10cSrcweir // ~OStreamSocket
1351*cdf0e10cSrcweir /*****************************************************************************/
1352*cdf0e10cSrcweir OStreamSocket::~OStreamSocket()
1353*cdf0e10cSrcweir {
1354*cdf0e10cSrcweir }
1355*cdf0e10cSrcweir 
1356*cdf0e10cSrcweir /*****************************************************************************/
1357*cdf0e10cSrcweir // close
1358*cdf0e10cSrcweir /*****************************************************************************/
1359*cdf0e10cSrcweir void OStreamSocket::close()
1360*cdf0e10cSrcweir {
1361*cdf0e10cSrcweir 	if (m_pSockRef && (*m_pSockRef)() && (m_pSockRef->release() == 0))
1362*cdf0e10cSrcweir 	{
1363*cdf0e10cSrcweir 		shutdown();
1364*cdf0e10cSrcweir 		osl_releaseSocket((*m_pSockRef)());
1365*cdf0e10cSrcweir 		delete m_pSockRef;
1366*cdf0e10cSrcweir 	}
1367*cdf0e10cSrcweir 
1368*cdf0e10cSrcweir 	m_pSockRef= 0;
1369*cdf0e10cSrcweir }
1370*cdf0e10cSrcweir 
1371*cdf0e10cSrcweir 
1372*cdf0e10cSrcweir /*****************************************************************************/
1373*cdf0e10cSrcweir // operator=(oslSocket)
1374*cdf0e10cSrcweir /*****************************************************************************/
1375*cdf0e10cSrcweir OStreamSocket& OStreamSocket::operator=(oslSocket Socket)
1376*cdf0e10cSrcweir {
1377*cdf0e10cSrcweir 	OSocket::operator=(Socket);
1378*cdf0e10cSrcweir 
1379*cdf0e10cSrcweir 	return *this;
1380*cdf0e10cSrcweir }
1381*cdf0e10cSrcweir 
1382*cdf0e10cSrcweir /*****************************************************************************/
1383*cdf0e10cSrcweir // operator=
1384*cdf0e10cSrcweir /*****************************************************************************/
1385*cdf0e10cSrcweir OStreamSocket& OStreamSocket::operator= (const OSocket& sock)
1386*cdf0e10cSrcweir {
1387*cdf0e10cSrcweir 	OSocket::operator=(sock);
1388*cdf0e10cSrcweir 
1389*cdf0e10cSrcweir 	return *this;
1390*cdf0e10cSrcweir }
1391*cdf0e10cSrcweir 
1392*cdf0e10cSrcweir /*****************************************************************************/
1393*cdf0e10cSrcweir // operator=
1394*cdf0e10cSrcweir /*****************************************************************************/
1395*cdf0e10cSrcweir OStreamSocket& OStreamSocket::operator= (const OStreamSocket& sock)
1396*cdf0e10cSrcweir {
1397*cdf0e10cSrcweir 	OSocket::operator=(sock);
1398*cdf0e10cSrcweir 
1399*cdf0e10cSrcweir 	return *this;
1400*cdf0e10cSrcweir }
1401*cdf0e10cSrcweir 
1402*cdf0e10cSrcweir /*****************************************************************************/
1403*cdf0e10cSrcweir // read
1404*cdf0e10cSrcweir /*****************************************************************************/
1405*cdf0e10cSrcweir sal_Int32 OStreamSocket::read(void* pBuffer, sal_uInt32 n) const
1406*cdf0e10cSrcweir {
1407*cdf0e10cSrcweir 	sal_uInt8 *Ptr = (sal_uInt8  *)pBuffer;
1408*cdf0e10cSrcweir 
1409*cdf0e10cSrcweir 	if (m_pRecvTimeout && ! isRecvReady(m_pRecvTimeout))
1410*cdf0e10cSrcweir 		return 0;
1411*cdf0e10cSrcweir 
1412*cdf0e10cSrcweir 	VOS_ASSERT(m_pSockRef && (*m_pSockRef)());
1413*cdf0e10cSrcweir 
1414*cdf0e10cSrcweir     if ( ! ( m_pSockRef && (*m_pSockRef)() ) )
1415*cdf0e10cSrcweir     {
1416*cdf0e10cSrcweir         return -1;
1417*cdf0e10cSrcweir     }
1418*cdf0e10cSrcweir 
1419*cdf0e10cSrcweir 	/* loop until all desired bytes were read or an error occured */
1420*cdf0e10cSrcweir 	sal_uInt32 BytesRead= 0;
1421*cdf0e10cSrcweir 	sal_uInt32 BytesToRead= n;
1422*cdf0e10cSrcweir 	while (BytesToRead > 0)
1423*cdf0e10cSrcweir 	{
1424*cdf0e10cSrcweir 		sal_Int32 RetVal;
1425*cdf0e10cSrcweir 		RetVal= osl_receiveSocket((*m_pSockRef)(),
1426*cdf0e10cSrcweir 								   Ptr,
1427*cdf0e10cSrcweir 								   BytesToRead,
1428*cdf0e10cSrcweir 								   osl_Socket_MsgNormal);
1429*cdf0e10cSrcweir 
1430*cdf0e10cSrcweir 		/* error occured? */
1431*cdf0e10cSrcweir 		if(RetVal <= 0)
1432*cdf0e10cSrcweir 		{
1433*cdf0e10cSrcweir 			break;
1434*cdf0e10cSrcweir 		}
1435*cdf0e10cSrcweir 
1436*cdf0e10cSrcweir 		BytesToRead -= RetVal;
1437*cdf0e10cSrcweir 		BytesRead += RetVal;
1438*cdf0e10cSrcweir 		Ptr += RetVal;
1439*cdf0e10cSrcweir 
1440*cdf0e10cSrcweir 		/* wait for next available data or timeout */
1441*cdf0e10cSrcweir 		if ( BytesToRead > 0 && m_pRecvTimeout && ! isRecvReady(m_pRecvTimeout))
1442*cdf0e10cSrcweir 			break;
1443*cdf0e10cSrcweir 
1444*cdf0e10cSrcweir 	}
1445*cdf0e10cSrcweir 
1446*cdf0e10cSrcweir 	return BytesRead;
1447*cdf0e10cSrcweir }
1448*cdf0e10cSrcweir 
1449*cdf0e10cSrcweir /*****************************************************************************/
1450*cdf0e10cSrcweir // write
1451*cdf0e10cSrcweir /*****************************************************************************/
1452*cdf0e10cSrcweir sal_Int32 OStreamSocket::write(const void* pBuffer, sal_uInt32 n)
1453*cdf0e10cSrcweir {
1454*cdf0e10cSrcweir 	sal_uInt8 *Ptr = (sal_uInt8 *)pBuffer;
1455*cdf0e10cSrcweir 
1456*cdf0e10cSrcweir 	if (m_pSendTimeout && ! isSendReady(m_pSendTimeout))
1457*cdf0e10cSrcweir 		return 0;
1458*cdf0e10cSrcweir 
1459*cdf0e10cSrcweir 	VOS_ASSERT(m_pSockRef && (*m_pSockRef)());
1460*cdf0e10cSrcweir 
1461*cdf0e10cSrcweir     if ( ! ( m_pSockRef && (*m_pSockRef)() ) )
1462*cdf0e10cSrcweir     {
1463*cdf0e10cSrcweir         return -1;
1464*cdf0e10cSrcweir     }
1465*cdf0e10cSrcweir 
1466*cdf0e10cSrcweir 	/* loop until all desired bytes were send or an error occured */
1467*cdf0e10cSrcweir 	sal_uInt32 BytesSend= 0;
1468*cdf0e10cSrcweir 	sal_uInt32 BytesToSend= n;
1469*cdf0e10cSrcweir 	while (BytesToSend > 0)
1470*cdf0e10cSrcweir 	{
1471*cdf0e10cSrcweir 		sal_Int32 RetVal;
1472*cdf0e10cSrcweir 
1473*cdf0e10cSrcweir 		RetVal= osl_sendSocket((*m_pSockRef)(),
1474*cdf0e10cSrcweir 								Ptr,
1475*cdf0e10cSrcweir 								BytesToSend,
1476*cdf0e10cSrcweir 								osl_Socket_MsgNormal);
1477*cdf0e10cSrcweir 
1478*cdf0e10cSrcweir 		/* error occured? */
1479*cdf0e10cSrcweir 		if(RetVal <= 0)
1480*cdf0e10cSrcweir 		{
1481*cdf0e10cSrcweir 			break;
1482*cdf0e10cSrcweir 		}
1483*cdf0e10cSrcweir 
1484*cdf0e10cSrcweir 		BytesToSend -= RetVal;
1485*cdf0e10cSrcweir 		BytesSend += RetVal;
1486*cdf0e10cSrcweir 		Ptr += RetVal;
1487*cdf0e10cSrcweir 
1488*cdf0e10cSrcweir 		/* wait till new data is available or timeout occures */
1489*cdf0e10cSrcweir 		if ( BytesToSend > 0 && m_pSendTimeout && ! isSendReady(m_pSendTimeout))
1490*cdf0e10cSrcweir 			break;
1491*cdf0e10cSrcweir 	}
1492*cdf0e10cSrcweir 
1493*cdf0e10cSrcweir 	return BytesSend;
1494*cdf0e10cSrcweir }
1495*cdf0e10cSrcweir 
1496*cdf0e10cSrcweir sal_Bool OStreamSocket::isEof() const
1497*cdf0e10cSrcweir {
1498*cdf0e10cSrcweir 	return isValid();
1499*cdf0e10cSrcweir 	// BHO not enough
1500*cdf0e10cSrcweir }
1501*cdf0e10cSrcweir 
1502*cdf0e10cSrcweir /*****************************************************************************/
1503*cdf0e10cSrcweir // recv
1504*cdf0e10cSrcweir /*****************************************************************************/
1505*cdf0e10cSrcweir sal_Int32 OStreamSocket::recv(void* pBuffer,
1506*cdf0e10cSrcweir 						    sal_uInt32 BytesToRead,
1507*cdf0e10cSrcweir 						    TSocketMsgFlag Flag)
1508*cdf0e10cSrcweir {
1509*cdf0e10cSrcweir 	if (m_pRecvTimeout && ! isRecvReady(m_pRecvTimeout))
1510*cdf0e10cSrcweir 		return 0;
1511*cdf0e10cSrcweir 
1512*cdf0e10cSrcweir 	VOS_ASSERT(m_pSockRef && (*m_pSockRef)());
1513*cdf0e10cSrcweir 
1514*cdf0e10cSrcweir     if ( ! ( m_pSockRef && (*m_pSockRef)() ) )
1515*cdf0e10cSrcweir     {
1516*cdf0e10cSrcweir         return -1;
1517*cdf0e10cSrcweir     }
1518*cdf0e10cSrcweir 
1519*cdf0e10cSrcweir 	return osl_receiveSocket((*m_pSockRef)(),
1520*cdf0e10cSrcweir 							 pBuffer,
1521*cdf0e10cSrcweir 							 BytesToRead,
1522*cdf0e10cSrcweir 							 (oslSocketMsgFlag)Flag);
1523*cdf0e10cSrcweir }
1524*cdf0e10cSrcweir 
1525*cdf0e10cSrcweir /*****************************************************************************/
1526*cdf0e10cSrcweir // send
1527*cdf0e10cSrcweir /*****************************************************************************/
1528*cdf0e10cSrcweir sal_Int32 OStreamSocket::send(const void* pBuffer,
1529*cdf0e10cSrcweir 						    sal_uInt32 BytesToSend,
1530*cdf0e10cSrcweir 						    TSocketMsgFlag Flag)
1531*cdf0e10cSrcweir {
1532*cdf0e10cSrcweir 	if (m_pSendTimeout && ! isSendReady(m_pSendTimeout))
1533*cdf0e10cSrcweir 		return 0;
1534*cdf0e10cSrcweir 
1535*cdf0e10cSrcweir 	VOS_ASSERT(m_pSockRef && (*m_pSockRef)());
1536*cdf0e10cSrcweir 
1537*cdf0e10cSrcweir     if ( ! ( m_pSockRef && (*m_pSockRef)() ) )
1538*cdf0e10cSrcweir     {
1539*cdf0e10cSrcweir         return -1;
1540*cdf0e10cSrcweir     }
1541*cdf0e10cSrcweir 
1542*cdf0e10cSrcweir 	return osl_sendSocket((*m_pSockRef)(),
1543*cdf0e10cSrcweir 						  pBuffer,
1544*cdf0e10cSrcweir 						  BytesToSend,
1545*cdf0e10cSrcweir 						  (oslSocketMsgFlag)Flag);
1546*cdf0e10cSrcweir }
1547*cdf0e10cSrcweir 
1548*cdf0e10cSrcweir /*****************************************************************************/
1549*cdf0e10cSrcweir // shutdown
1550*cdf0e10cSrcweir /*****************************************************************************/
1551*cdf0e10cSrcweir sal_Bool OStreamSocket::shutdown(TSocketDirection Direction)
1552*cdf0e10cSrcweir {
1553*cdf0e10cSrcweir 	VOS_ASSERT(m_pSockRef && (*m_pSockRef)());
1554*cdf0e10cSrcweir 
1555*cdf0e10cSrcweir     if ( m_pSockRef && (*m_pSockRef)() )
1556*cdf0e10cSrcweir     {
1557*cdf0e10cSrcweir         return osl_shutdownSocket((*m_pSockRef)(), (oslSocketDirection)Direction);
1558*cdf0e10cSrcweir     }
1559*cdf0e10cSrcweir 
1560*cdf0e10cSrcweir     return sal_False;
1561*cdf0e10cSrcweir }
1562*cdf0e10cSrcweir 
1563*cdf0e10cSrcweir 
1564*cdf0e10cSrcweir 
1565*cdf0e10cSrcweir VOS_IMPLEMENT_CLASSINFO(VOS_CLASSNAME(OConnectorSocket, vos),
1566*cdf0e10cSrcweir 						VOS_NAMESPACE(OConnectorSocket, vos),
1567*cdf0e10cSrcweir 						VOS_NAMESPACE(OStreamSocket, vos), 0);
1568*cdf0e10cSrcweir 
1569*cdf0e10cSrcweir 
1570*cdf0e10cSrcweir 
1571*cdf0e10cSrcweir /*****************************************************************************/
1572*cdf0e10cSrcweir // OConnectorSocket
1573*cdf0e10cSrcweir /*****************************************************************************/
1574*cdf0e10cSrcweir OConnectorSocket::OConnectorSocket(TAddrFamily Family,
1575*cdf0e10cSrcweir 								   TProtocol   Protocol,
1576*cdf0e10cSrcweir 								   TSocketType Type) :
1577*cdf0e10cSrcweir 	OStreamSocket(Family, Protocol, Type)
1578*cdf0e10cSrcweir {
1579*cdf0e10cSrcweir }
1580*cdf0e10cSrcweir 
1581*cdf0e10cSrcweir /*****************************************************************************/
1582*cdf0e10cSrcweir // OConnectorSocket
1583*cdf0e10cSrcweir /*****************************************************************************/
1584*cdf0e10cSrcweir OConnectorSocket::OConnectorSocket(const OConnectorSocket& sock) :
1585*cdf0e10cSrcweir 	OStreamSocket(sock)
1586*cdf0e10cSrcweir {
1587*cdf0e10cSrcweir }
1588*cdf0e10cSrcweir 
1589*cdf0e10cSrcweir /*****************************************************************************/
1590*cdf0e10cSrcweir // ~OConnectorSocket
1591*cdf0e10cSrcweir /*****************************************************************************/
1592*cdf0e10cSrcweir OConnectorSocket::~OConnectorSocket()
1593*cdf0e10cSrcweir {
1594*cdf0e10cSrcweir }
1595*cdf0e10cSrcweir 
1596*cdf0e10cSrcweir /*****************************************************************************/
1597*cdf0e10cSrcweir // connect
1598*cdf0e10cSrcweir /*****************************************************************************/
1599*cdf0e10cSrcweir OSocket::TResult OConnectorSocket::connect(const OSocketAddr& Addr,
1600*cdf0e10cSrcweir 										   const TimeValue* pTimeout)
1601*cdf0e10cSrcweir {
1602*cdf0e10cSrcweir 
1603*cdf0e10cSrcweir 	VOS_ASSERT(m_pSockRef && (*m_pSockRef)());
1604*cdf0e10cSrcweir 
1605*cdf0e10cSrcweir     if ( m_pSockRef && (*m_pSockRef)() )
1606*cdf0e10cSrcweir     {
1607*cdf0e10cSrcweir         return (TResult)osl_connectSocketTo((*m_pSockRef)(),
1608*cdf0e10cSrcweir                                             (oslSocketAddr)Addr,
1609*cdf0e10cSrcweir                                             pTimeout);
1610*cdf0e10cSrcweir     }
1611*cdf0e10cSrcweir 
1612*cdf0e10cSrcweir     return TResult_Error;
1613*cdf0e10cSrcweir }
1614*cdf0e10cSrcweir 
1615*cdf0e10cSrcweir 
1616*cdf0e10cSrcweir VOS_IMPLEMENT_CLASSINFO(VOS_CLASSNAME(ODatagramSocket, vos),
1617*cdf0e10cSrcweir 						VOS_NAMESPACE(ODatagramSocket, vos),
1618*cdf0e10cSrcweir 						VOS_NAMESPACE(OSocket, vos), 0);
1619*cdf0e10cSrcweir 
1620*cdf0e10cSrcweir 
1621*cdf0e10cSrcweir /*****************************************************************************/
1622*cdf0e10cSrcweir // ODatagramSocket
1623*cdf0e10cSrcweir /*****************************************************************************/
1624*cdf0e10cSrcweir ODatagramSocket::ODatagramSocket(TAddrFamily Family,
1625*cdf0e10cSrcweir 								 TProtocol   Protocol,
1626*cdf0e10cSrcweir 								 TSocketType Type) :
1627*cdf0e10cSrcweir 	OSocket(Type, Family, Protocol)
1628*cdf0e10cSrcweir {
1629*cdf0e10cSrcweir }
1630*cdf0e10cSrcweir 
1631*cdf0e10cSrcweir /*****************************************************************************/
1632*cdf0e10cSrcweir // ODatagramSocket
1633*cdf0e10cSrcweir /*****************************************************************************/
1634*cdf0e10cSrcweir ODatagramSocket::ODatagramSocket(const ODatagramSocket& sock) :
1635*cdf0e10cSrcweir 	OSocket(sock)
1636*cdf0e10cSrcweir {
1637*cdf0e10cSrcweir }
1638*cdf0e10cSrcweir 
1639*cdf0e10cSrcweir /*****************************************************************************/
1640*cdf0e10cSrcweir // ~ODatagramSocket
1641*cdf0e10cSrcweir /*****************************************************************************/
1642*cdf0e10cSrcweir ODatagramSocket::~ODatagramSocket()
1643*cdf0e10cSrcweir {
1644*cdf0e10cSrcweir }
1645*cdf0e10cSrcweir 
1646*cdf0e10cSrcweir 
1647*cdf0e10cSrcweir /*****************************************************************************/
1648*cdf0e10cSrcweir // recvFrom
1649*cdf0e10cSrcweir /*****************************************************************************/
1650*cdf0e10cSrcweir sal_Int32 ODatagramSocket::recvFrom(void* pBuffer,
1651*cdf0e10cSrcweir 					              sal_uInt32 BufferSize,
1652*cdf0e10cSrcweir 					  			  OSocketAddr* pSenderAddr,
1653*cdf0e10cSrcweir 					  			  TSocketMsgFlag Flag)
1654*cdf0e10cSrcweir {
1655*cdf0e10cSrcweir 
1656*cdf0e10cSrcweir 	if (m_pRecvTimeout && ! isRecvReady(m_pRecvTimeout))
1657*cdf0e10cSrcweir 		return 0;
1658*cdf0e10cSrcweir 
1659*cdf0e10cSrcweir 	VOS_ASSERT(m_pSockRef && (*m_pSockRef)());
1660*cdf0e10cSrcweir 
1661*cdf0e10cSrcweir     if ( ! ( m_pSockRef && (*m_pSockRef)() ) )
1662*cdf0e10cSrcweir     {
1663*cdf0e10cSrcweir         return -1;
1664*cdf0e10cSrcweir     }
1665*cdf0e10cSrcweir 
1666*cdf0e10cSrcweir 	sal_Int32 BytesRead;
1667*cdf0e10cSrcweir 
1668*cdf0e10cSrcweir 	if(pSenderAddr)
1669*cdf0e10cSrcweir 	{
1670*cdf0e10cSrcweir 		// we are interested in the senders address
1671*cdf0e10cSrcweir 		oslSocketAddr SenderAddr= osl_createEmptySocketAddr(osl_Socket_FamilyInet);
1672*cdf0e10cSrcweir 
1673*cdf0e10cSrcweir 		BytesRead=
1674*cdf0e10cSrcweir 			osl_receiveFromSocket((*m_pSockRef)(),
1675*cdf0e10cSrcweir 								   SenderAddr,
1676*cdf0e10cSrcweir 								   pBuffer,
1677*cdf0e10cSrcweir 								   BufferSize,
1678*cdf0e10cSrcweir 								   (oslSocketMsgFlag)Flag);
1679*cdf0e10cSrcweir 
1680*cdf0e10cSrcweir 		*pSenderAddr= SenderAddr;
1681*cdf0e10cSrcweir 	}
1682*cdf0e10cSrcweir 	else
1683*cdf0e10cSrcweir 	{
1684*cdf0e10cSrcweir 		// we don't want to know the senders address
1685*cdf0e10cSrcweir 
1686*cdf0e10cSrcweir 		BytesRead=
1687*cdf0e10cSrcweir 			osl_receiveFromSocket((*m_pSockRef)(),
1688*cdf0e10cSrcweir 								   0,
1689*cdf0e10cSrcweir 								   pBuffer,
1690*cdf0e10cSrcweir 								   BufferSize,
1691*cdf0e10cSrcweir 								   (oslSocketMsgFlag)Flag);
1692*cdf0e10cSrcweir 	}
1693*cdf0e10cSrcweir 
1694*cdf0e10cSrcweir 	return BytesRead;
1695*cdf0e10cSrcweir }
1696*cdf0e10cSrcweir 
1697*cdf0e10cSrcweir 
1698*cdf0e10cSrcweir /*****************************************************************************/
1699*cdf0e10cSrcweir // sendTo
1700*cdf0e10cSrcweir /*****************************************************************************/
1701*cdf0e10cSrcweir sal_Int32 ODatagramSocket::sendTo(const OSocketAddr& ReceiverAddr,
1702*cdf0e10cSrcweir 							    const void* pBuffer,
1703*cdf0e10cSrcweir 							    sal_uInt32 BufferSize,
1704*cdf0e10cSrcweir 							    TSocketMsgFlag Flag)
1705*cdf0e10cSrcweir {
1706*cdf0e10cSrcweir 	if (m_pSendTimeout && ! isSendReady(m_pSendTimeout))
1707*cdf0e10cSrcweir 		return 0;
1708*cdf0e10cSrcweir 
1709*cdf0e10cSrcweir 	VOS_ASSERT(m_pSockRef && (*m_pSockRef)());
1710*cdf0e10cSrcweir 
1711*cdf0e10cSrcweir     if ( ( m_pSockRef && (*m_pSockRef)() ) )
1712*cdf0e10cSrcweir     {
1713*cdf0e10cSrcweir 
1714*cdf0e10cSrcweir         return osl_sendToSocket((*m_pSockRef)(),
1715*cdf0e10cSrcweir                                 (oslSocketAddr)ReceiverAddr,
1716*cdf0e10cSrcweir                                 pBuffer,
1717*cdf0e10cSrcweir                                 BufferSize,
1718*cdf0e10cSrcweir                                 (oslSocketMsgFlag)Flag);
1719*cdf0e10cSrcweir     }
1720*cdf0e10cSrcweir 
1721*cdf0e10cSrcweir     return -1;
1722*cdf0e10cSrcweir }
1723*cdf0e10cSrcweir 
1724