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