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