UDK 3.2.7 C/C++ API Reference
osl/socket_decl.hxx
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
00002 /*************************************************************************
00003  *
00004  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
00005  *
00006  * Copyright 2000, 2010 Oracle and/or its affiliates.
00007  *
00008  * OpenOffice.org - a multi-platform office productivity suite
00009  *
00010  * This file is part of OpenOffice.org.
00011  *
00012  * OpenOffice.org is free software: you can redistribute it and/or modify
00013  * it under the terms of the GNU Lesser General Public License version 3
00014  * only, as published by the Free Software Foundation.
00015  *
00016  * OpenOffice.org is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU Lesser General Public License version 3 for more details
00020  * (a copy is included in the LICENSE file that accompanied this code).
00021  *
00022  * You should have received a copy of the GNU Lesser General Public License
00023  * version 3 along with OpenOffice.org.  If not, see
00024  * <http://www.openoffice.org/license.html>
00025  * for a copy of the LGPLv3 License.
00026  *
00027  ************************************************************************/
00028 
00029 #ifndef _OSL_SOCKET_DECL_HXX_
00030 #define _OSL_SOCKET_DECL_HXX_
00031 
00032 #include <osl/socket.h>
00033 #include <rtl/ustring.hxx>
00034 #include <rtl/byteseq.hxx>
00035 
00036 namespace osl
00037 {
00038     enum __osl_socket_NoCopy { SAL_NO_COPY };
00039 
00044     class SocketAddr
00045     {
00046     protected:
00047         oslSocketAddr m_handle;
00048     public:
00049 
00052         inline SocketAddr();
00053 
00056         inline SocketAddr(const SocketAddr& Addr);
00057 
00063         inline SocketAddr(const oslSocketAddr , __osl_socket_NoCopy nocopy );
00064 
00067         inline SocketAddr(oslSocketAddr Addr);
00068 
00074         inline SocketAddr( const ::rtl::OUString& strAddrOrHostName, sal_Int32 nPort );
00075 
00078         inline ~SocketAddr();
00079 
00084         inline sal_Bool is() const;
00085 
00094         inline ::rtl::OUString SAL_CALL getHostname( oslSocketResult *pResult = 0 ) const;
00095 
00098         inline sal_Bool SAL_CALL setHostname( const ::rtl::OUString &sDottedIpOrHostname );
00099 
00103         inline sal_Int32 SAL_CALL getPort() const;
00104 
00108         inline sal_Bool SAL_CALL setPort( sal_Int32 nPort );
00109 
00113         inline sal_Bool SAL_CALL setAddr( const ::rtl::ByteSequence & address );
00114 
00117         inline ::rtl::ByteSequence  SAL_CALL getAddr( oslSocketResult *pResult = 0 ) const;
00118 
00121         inline SocketAddr & SAL_CALL operator= (oslSocketAddr Addr);
00122 
00125         inline SocketAddr & SAL_CALL operator= (const SocketAddr& Addr);
00126 
00130         inline SocketAddr & SAL_CALL assign( oslSocketAddr Addr, __osl_socket_NoCopy nocopy );
00131 
00134         inline sal_Bool SAL_CALL operator== (oslSocketAddr Addr) const;
00135 
00138         inline sal_Bool SAL_CALL operator== (const SocketAddr & Addr) const;
00139 
00142         inline oslSocketAddr SAL_CALL getHandle() const;
00143 
00149         static inline ::rtl::OUString SAL_CALL getLocalHostname( oslSocketResult *pResult = 0);
00150 
00155         static inline void SAL_CALL resolveHostname(
00156             const ::rtl::OUString & strHostName , SocketAddr & Addr );
00157 
00164         static inline sal_Int32 SAL_CALL getServicePort(
00165             const ::rtl::OUString& strServiceName,
00166             const ::rtl::OUString & strProtocolName= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("tcp")) );
00167     };
00168 
00169 
00170     class Socket
00171     {
00172     protected:
00173         oslSocket m_handle;
00174     protected:
00180         inline Socket(oslSocketType Type,
00181                       oslAddrFamily Family = osl_Socket_FamilyInet,
00182                       oslProtocol   Protocol = osl_Socket_ProtocolIp);
00183     public:
00184         inline Socket( );
00185 
00186         inline Socket( const Socket & socket );
00187 
00188         inline Socket( oslSocket socketHandle );
00189 
00194         inline Socket( oslSocket socketHandle, __sal_NoAcquire noacquire );
00195 
00198         inline ~Socket();
00199 
00203         inline Socket& SAL_CALL operator= ( oslSocket socketHandle);
00204 
00208         inline Socket& SAL_CALL operator= (const Socket& sock);
00209 
00214         inline sal_Bool SAL_CALL operator==( const Socket& rSocket ) const ;
00215 
00220         inline sal_Bool SAL_CALL operator==( const oslSocket socketHandle ) const;
00221 
00227         inline void SAL_CALL shutdown( oslSocketDirection Direction = osl_Socket_DirReadWrite );
00228 
00234         inline void SAL_CALL close();
00235 
00240         inline void SAL_CALL getLocalAddr( SocketAddr &Addr ) const;
00241 
00245         inline sal_Int32    SAL_CALL getLocalPort() const;
00246 
00250         inline ::rtl::OUString SAL_CALL getLocalHost() const;
00251 
00255         inline void SAL_CALL getPeerAddr( SocketAddr & Addr) const;
00256 
00260         inline sal_Int32    SAL_CALL getPeerPort() const;
00261 
00265         inline ::rtl::OUString SAL_CALL getPeerHost() const;
00266 
00271         inline sal_Bool SAL_CALL bind(const SocketAddr& LocalInterface);
00272 
00283         inline sal_Bool SAL_CALL isRecvReady(const TimeValue *pTimeout = 0) const;
00284 
00295         inline sal_Bool SAL_CALL isSendReady(const TimeValue *pTimeout = 0) const;
00296 
00297 
00310         inline sal_Bool SAL_CALL isExceptionPending(const TimeValue *pTimeout = 0) const;
00311 
00312 
00324         inline oslSocketType    SAL_CALL getType() const;
00325 
00407         inline sal_Int32 SAL_CALL getOption(
00408             oslSocketOption Option,
00409             void* pBuffer,
00410             sal_uInt32 BufferLen,
00411             oslSocketOptionLevel Level= osl_Socket_LevelSocket) const;
00412 
00454         inline sal_Bool SAL_CALL setOption( oslSocketOption Option,
00455                                             void* pBuffer,
00456                                             sal_uInt32 BufferLen,
00457                                             oslSocketOptionLevel Level= osl_Socket_LevelSocket ) const;
00458 
00462         inline sal_Bool setOption( oslSocketOption option, sal_Int32 nValue  );
00463 
00467         inline sal_Int32 getOption( oslSocketOption option ) const;
00468 
00475         inline sal_Bool SAL_CALL enableNonBlockingMode( sal_Bool bNonBlockingMode);
00476 
00480         inline sal_Bool SAL_CALL isNonBlockingMode() const;
00481 
00482 
00485         inline void SAL_CALL clearError() const;
00486 
00494         inline oslSocketError getError() const;
00495 
00498         inline ::rtl::OUString getErrorAsString( ) const;
00499 
00502         inline oslSocket getHandle() const;
00503     };
00504 
00505 
00506     class StreamSocket : public Socket
00507     {
00508     public:
00515           inline StreamSocket(oslAddrFamily Family = osl_Socket_FamilyInet,
00516                             oslProtocol Protocol = osl_Socket_ProtocolIp,
00517                             oslSocketType   Type = osl_Socket_TypeStream);
00518 
00519         inline StreamSocket( const StreamSocket & );
00520 
00521         inline StreamSocket( oslSocket Socket , __sal_NoAcquire noacquire );
00522 
00523         inline StreamSocket( oslSocket Socket );
00524 
00534         inline sal_Int32 SAL_CALL read(void* pBuffer, sal_uInt32 n);
00535 
00543         inline sal_Int32 SAL_CALL write(const void* pBuffer, sal_uInt32 n);
00544 
00545 
00562         inline sal_Int32 SAL_CALL recv(void* pBuffer,
00563                                        sal_uInt32 BytesToRead,
00564                                        oslSocketMsgFlag flags= osl_Socket_MsgNormal);
00565 
00582         sal_Int32 SAL_CALL send(const void* pBuffer,
00583                                 sal_uInt32 BytesToSend,
00584                                 oslSocketMsgFlag= osl_Socket_MsgNormal);
00585     };
00586 
00587     class ConnectorSocket : public StreamSocket
00588     {
00589     public:
00596           ConnectorSocket(oslAddrFamily Family = osl_Socket_FamilyInet,
00597                         oslProtocol Protocol = osl_Socket_ProtocolIp,
00598                         oslSocketType   Type = osl_Socket_TypeStream);
00599 
00600 
00610         oslSocketResult SAL_CALL connect(const SocketAddr& TargetHost, const TimeValue* pTimeout = 0);
00611     };
00612 
00615     class AcceptorSocket : public Socket
00616     {
00617     public:
00618         inline AcceptorSocket(oslAddrFamily Family = osl_Socket_FamilyInet,
00619                               oslProtocol   Protocol = osl_Socket_ProtocolIp,
00620                               oslSocketType Type = osl_Socket_TypeStream);
00621 
00629         inline sal_Bool SAL_CALL listen(sal_Int32 MaxPendingConnections= -1);
00630 
00638         inline oslSocketResult SAL_CALL acceptConnection( StreamSocket& Connection);
00639 
00649         inline oslSocketResult SAL_CALL acceptConnection( StreamSocket& Connection, SocketAddr & PeerAddr);
00650     };
00651 
00652 
00653 
00656     class DatagramSocket : public Socket
00657     {
00658     public:
00659 
00663         inline DatagramSocket(oslAddrFamily Family= osl_Socket_FamilyInet,
00664                               oslProtocol   Protocol= osl_Socket_ProtocolIp,
00665                               oslSocketType Type= osl_Socket_TypeDgram);
00666 
00686         inline sal_Int32 SAL_CALL recvFrom(void*  pBuffer,
00687                                            sal_uInt32 BufferSize,
00688                                            SocketAddr* pSenderAddr= 0,
00689                                            oslSocketMsgFlag Flag= osl_Socket_MsgNormal);
00690 
00713         inline sal_Int32    SAL_CALL sendTo( const SocketAddr& ReceiverAddr,
00714                                              const void* pBuffer,
00715                                              sal_uInt32 BufferSize,
00716                                              oslSocketMsgFlag Flag= osl_Socket_MsgNormal);
00717     };
00718 
00719 }
00720 
00721 #endif
00722 
00723 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines