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  * This file is part of the LibreOffice project.
00004  *
00005  * This Source Code Form is subject to the terms of the Mozilla Public
00006  * License, v. 2.0. If a copy of the MPL was not distributed with this
00007  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
00008  *
00009  * This file incorporates work covered by the following license notice:
00010  *
00011  *   Licensed to the Apache Software Foundation (ASF) under one or more
00012  *   contributor license agreements. See the NOTICE file distributed
00013  *   with this work for additional information regarding copyright
00014  *   ownership. The ASF licenses this file to you under the Apache
00015  *   License, Version 2.0 (the "License"); you may not use this file
00016  *   except in compliance with the License. You may obtain a copy of
00017  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
00018  */
00019 
00020 #ifndef _OSL_SOCKET_DECL_HXX_
00021 #define _OSL_SOCKET_DECL_HXX_
00022 
00023 #include <osl/socket.h>
00024 #include <rtl/ustring.hxx>
00025 #include <rtl/byteseq.hxx>
00026 
00027 namespace osl
00028 {
00029     enum __osl_socket_NoCopy { SAL_NO_COPY };
00030 
00035     class SocketAddr
00036     {
00037     protected:
00038         oslSocketAddr m_handle;
00039     public:
00040 
00043         inline SocketAddr();
00044 
00047         inline SocketAddr(const SocketAddr& Addr);
00048 
00054         inline SocketAddr(const oslSocketAddr , __osl_socket_NoCopy nocopy );
00055 
00058         inline SocketAddr(oslSocketAddr Addr);
00059 
00065         inline SocketAddr( const ::rtl::OUString& strAddrOrHostName, sal_Int32 nPort );
00066 
00069         inline ~SocketAddr();
00070 
00075         inline sal_Bool is() const;
00076 
00085         inline ::rtl::OUString SAL_CALL getHostname( oslSocketResult *pResult = 0 ) const;
00086 
00089         inline sal_Bool SAL_CALL setHostname( const ::rtl::OUString &sDottedIpOrHostname );
00090 
00094         inline sal_Int32 SAL_CALL getPort() const;
00095 
00099         inline sal_Bool SAL_CALL setPort( sal_Int32 nPort );
00100 
00104         inline sal_Bool SAL_CALL setAddr( const ::rtl::ByteSequence & address );
00105 
00108         inline ::rtl::ByteSequence  SAL_CALL getAddr( oslSocketResult *pResult = 0 ) const;
00109 
00112         inline SocketAddr & SAL_CALL operator= (oslSocketAddr Addr);
00113 
00116         inline SocketAddr & SAL_CALL operator= (const SocketAddr& Addr);
00117 
00121         inline SocketAddr & SAL_CALL assign( oslSocketAddr Addr, __osl_socket_NoCopy nocopy );
00122 
00125         inline sal_Bool SAL_CALL operator== (oslSocketAddr Addr) const;
00126 
00129         inline sal_Bool SAL_CALL operator== (const SocketAddr & Addr) const;
00130 
00133         inline oslSocketAddr SAL_CALL getHandle() const;
00134 
00140         static inline ::rtl::OUString SAL_CALL getLocalHostname( oslSocketResult *pResult = 0);
00141 
00146         static inline void SAL_CALL resolveHostname(
00147             const ::rtl::OUString & strHostName , SocketAddr & Addr );
00148 
00155         static inline sal_Int32 SAL_CALL getServicePort(
00156             const ::rtl::OUString& strServiceName,
00157             const ::rtl::OUString & strProtocolName= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("tcp")) );
00158     };
00159 
00160 
00161     class Socket
00162     {
00163     protected:
00164         oslSocket m_handle;
00165     protected:
00171         inline Socket(oslSocketType Type,
00172                       oslAddrFamily Family = osl_Socket_FamilyInet,
00173                       oslProtocol   Protocol = osl_Socket_ProtocolIp);
00174     public:
00175         inline Socket( );
00176 
00177         inline Socket( const Socket & socket );
00178 
00179         inline Socket( oslSocket socketHandle );
00180 
00185         inline Socket( oslSocket socketHandle, __sal_NoAcquire noacquire );
00186 
00189         inline ~Socket();
00190 
00194         inline Socket& SAL_CALL operator= ( oslSocket socketHandle);
00195 
00199         inline Socket& SAL_CALL operator= (const Socket& sock);
00200 
00205         inline sal_Bool SAL_CALL operator==( const Socket& rSocket ) const ;
00206 
00211         inline sal_Bool SAL_CALL operator==( const oslSocket socketHandle ) const;
00212 
00218         inline void SAL_CALL shutdown( oslSocketDirection Direction = osl_Socket_DirReadWrite );
00219 
00225         inline void SAL_CALL close();
00226 
00231         inline void SAL_CALL getLocalAddr( SocketAddr &Addr ) const;
00232 
00236         inline sal_Int32    SAL_CALL getLocalPort() const;
00237 
00241         inline ::rtl::OUString SAL_CALL getLocalHost() const;
00242 
00246         inline void SAL_CALL getPeerAddr( SocketAddr & Addr) const;
00247 
00251         inline sal_Int32    SAL_CALL getPeerPort() const;
00252 
00256         inline ::rtl::OUString SAL_CALL getPeerHost() const;
00257 
00262         inline sal_Bool SAL_CALL bind(const SocketAddr& LocalInterface);
00263 
00274         inline sal_Bool SAL_CALL isRecvReady(const TimeValue *pTimeout = 0) const;
00275 
00286         inline sal_Bool SAL_CALL isSendReady(const TimeValue *pTimeout = 0) const;
00287 
00288 
00301         inline sal_Bool SAL_CALL isExceptionPending(const TimeValue *pTimeout = 0) const;
00302 
00303 
00315         inline oslSocketType    SAL_CALL getType() const;
00316 
00398         inline sal_Int32 SAL_CALL getOption(
00399             oslSocketOption Option,
00400             void* pBuffer,
00401             sal_uInt32 BufferLen,
00402             oslSocketOptionLevel Level= osl_Socket_LevelSocket) const;
00403 
00445         inline sal_Bool SAL_CALL setOption( oslSocketOption Option,
00446                                             void* pBuffer,
00447                                             sal_uInt32 BufferLen,
00448                                             oslSocketOptionLevel Level= osl_Socket_LevelSocket ) const;
00449 
00453         inline sal_Bool setOption( oslSocketOption option, sal_Int32 nValue  );
00454 
00458         inline sal_Int32 getOption( oslSocketOption option ) const;
00459 
00466         inline sal_Bool SAL_CALL enableNonBlockingMode( sal_Bool bNonBlockingMode);
00467 
00471         inline sal_Bool SAL_CALL isNonBlockingMode() const;
00472 
00473 
00476         inline void SAL_CALL clearError() const;
00477 
00485         inline oslSocketError getError() const;
00486 
00489         inline ::rtl::OUString getErrorAsString( ) const;
00490 
00493         inline oslSocket getHandle() const;
00494     };
00495 
00496 
00497     class StreamSocket : public Socket
00498     {
00499     public:
00506           inline StreamSocket(oslAddrFamily Family = osl_Socket_FamilyInet,
00507                             oslProtocol Protocol = osl_Socket_ProtocolIp,
00508                             oslSocketType   Type = osl_Socket_TypeStream);
00509 
00510         inline StreamSocket( const StreamSocket & );
00511 
00512         inline StreamSocket( oslSocket Socket , __sal_NoAcquire noacquire );
00513 
00514         inline StreamSocket( oslSocket Socket );
00515 
00525         inline sal_Int32 SAL_CALL read(void* pBuffer, sal_uInt32 n);
00526 
00534         inline sal_Int32 SAL_CALL write(const void* pBuffer, sal_uInt32 n);
00535 
00536 
00553         inline sal_Int32 SAL_CALL recv(void* pBuffer,
00554                                        sal_uInt32 BytesToRead,
00555                                        oslSocketMsgFlag flags= osl_Socket_MsgNormal);
00556 
00573         sal_Int32 SAL_CALL send(const void* pBuffer,
00574                                 sal_uInt32 BytesToSend,
00575                                 oslSocketMsgFlag= osl_Socket_MsgNormal);
00576     };
00577 
00578     class ConnectorSocket : public StreamSocket
00579     {
00580     public:
00587           ConnectorSocket(oslAddrFamily Family = osl_Socket_FamilyInet,
00588                         oslProtocol Protocol = osl_Socket_ProtocolIp,
00589                         oslSocketType   Type = osl_Socket_TypeStream);
00590 
00591 
00601         oslSocketResult SAL_CALL connect(const SocketAddr& TargetHost, const TimeValue* pTimeout = 0);
00602     };
00603 
00606     class AcceptorSocket : public Socket
00607     {
00608     public:
00609         inline AcceptorSocket(oslAddrFamily Family = osl_Socket_FamilyInet,
00610                               oslProtocol   Protocol = osl_Socket_ProtocolIp,
00611                               oslSocketType Type = osl_Socket_TypeStream);
00612 
00620         inline sal_Bool SAL_CALL listen(sal_Int32 MaxPendingConnections= -1);
00621 
00629         inline oslSocketResult SAL_CALL acceptConnection( StreamSocket& Connection);
00630 
00640         inline oslSocketResult SAL_CALL acceptConnection( StreamSocket& Connection, SocketAddr & PeerAddr);
00641     };
00642 
00643 
00644 
00647     class DatagramSocket : public Socket
00648     {
00649     public:
00650 
00654         inline DatagramSocket(oslAddrFamily Family= osl_Socket_FamilyInet,
00655                               oslProtocol   Protocol= osl_Socket_ProtocolIp,
00656                               oslSocketType Type= osl_Socket_TypeDgram);
00657 
00677         inline sal_Int32 SAL_CALL recvFrom(void*  pBuffer,
00678                                            sal_uInt32 BufferSize,
00679                                            SocketAddr* pSenderAddr= 0,
00680                                            oslSocketMsgFlag Flag= osl_Socket_MsgNormal);
00681 
00704         inline sal_Int32    SAL_CALL sendTo( const SocketAddr& ReceiverAddr,
00705                                              const void* pBuffer,
00706                                              sal_uInt32 BufferSize,
00707                                              oslSocketMsgFlag Flag= osl_Socket_MsgNormal);
00708     };
00709 
00710 }
00711 
00712 #endif
00713 
00714 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines