LibreOffice
LibreOffice 5.4 SDK C/C++ API Reference
socket_decl.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #ifndef INCLUDED_OSL_SOCKET_DECL_HXX
21 #define INCLUDED_OSL_SOCKET_DECL_HXX
22 
23 #include <sal/config.h>
24 
25 #include <cstddef>
26 
27 #include <osl/socket.h>
28 #include <rtl/ustring.hxx>
29 #include <rtl/byteseq.hxx>
30 
31 namespace osl
32 {
34 
39  class SocketAddr
40  {
41  protected:
43  public:
44 
47  inline SocketAddr();
48 
51  inline SocketAddr(const SocketAddr& Addr);
52 
53 #if defined LIBO_INTERNAL_ONLY
54  inline SocketAddr(SocketAddr && other);
55 #endif
56 
62  inline SocketAddr(const oslSocketAddr Addr, __osl_socket_NoCopy nocopy );
63 
66  inline SocketAddr(oslSocketAddr Addr);
67 
73  inline SocketAddr( const ::rtl::OUString& strAddrOrHostName, sal_Int32 nPort );
74 
77  inline ~SocketAddr();
78 
83  inline bool is() const;
84 
93  inline ::rtl::OUString SAL_CALL getHostname( oslSocketResult *pResult = NULL ) const;
94 
97  inline bool SAL_CALL setHostname( const ::rtl::OUString &sDottedIpOrHostname );
98 
102  inline sal_Int32 SAL_CALL getPort() const;
103 
107  inline bool SAL_CALL setPort( sal_Int32 nPort );
108 
112  inline bool SAL_CALL setAddr( const ::rtl::ByteSequence & address );
113 
116  inline ::rtl::ByteSequence SAL_CALL getAddr( oslSocketResult *pResult = NULL ) const;
117 
120  inline SocketAddr & SAL_CALL operator= (oslSocketAddr Addr);
121 
122  inline SocketAddr & SAL_CALL operator= (const SocketAddr& Addr);
123 
124 #if defined LIBO_INTERNAL_ONLY
125  inline SocketAddr & operator =(SocketAddr && other);
126 #endif
127 
132  inline SocketAddr & SAL_CALL assign( oslSocketAddr Addr, __osl_socket_NoCopy nocopy );
133 
136  inline bool SAL_CALL operator== (oslSocketAddr Addr) const;
137 
140  inline bool SAL_CALL operator== (const SocketAddr & Addr) const;
141 
144  inline oslSocketAddr SAL_CALL getHandle() const;
145 
151  static inline ::rtl::OUString SAL_CALL getLocalHostname( oslSocketResult *pResult = NULL);
152 
157  static inline void SAL_CALL resolveHostname(
158  const ::rtl::OUString & strHostName , SocketAddr & Addr );
159 
166  static inline sal_Int32 SAL_CALL getServicePort(
167  const ::rtl::OUString& strServiceName,
168  const ::rtl::OUString & strProtocolName= ::rtl::OUString("tcp") );
169  };
170 
171 
172  class Socket
173  {
174  protected:
176  protected:
182  inline Socket(oslSocketType Type,
185  public:
186  inline Socket( );
187 
188  inline Socket( const Socket & socket );
189 
190  inline Socket( oslSocket socketHandle );
191 
197  inline Socket( oslSocket socketHandle, __sal_NoAcquire noacquire );
198 
201  inline ~Socket();
202 
206  inline Socket& SAL_CALL operator= ( oslSocket socketHandle);
207 
211  inline Socket& SAL_CALL operator= (const Socket& sock);
212 
217  inline bool SAL_CALL operator==( const Socket& rSocket ) const ;
218 
223  inline bool SAL_CALL operator==( const oslSocket socketHandle ) const;
224 
230  inline void SAL_CALL shutdown( oslSocketDirection Direction = osl_Socket_DirReadWrite );
231 
237  inline void SAL_CALL close();
238 
243  inline void SAL_CALL getLocalAddr( SocketAddr &Addr ) const;
244 
248  inline sal_Int32 SAL_CALL getLocalPort() const;
249 
253  inline ::rtl::OUString SAL_CALL getLocalHost() const;
254 
258  inline void SAL_CALL getPeerAddr( SocketAddr & Addr) const;
259 
263  inline sal_Int32 SAL_CALL getPeerPort() const;
264 
268  inline ::rtl::OUString SAL_CALL getPeerHost() const;
269 
274  inline bool SAL_CALL bind(const SocketAddr& LocalInterface);
275 
286  inline bool SAL_CALL isRecvReady(const TimeValue *pTimeout = NULL) const;
287 
298  inline bool SAL_CALL isSendReady(const TimeValue *pTimeout = NULL) const;
299 
300 
313  inline bool SAL_CALL isExceptionPending(const TimeValue *pTimeout = NULL) const;
314 
315 
327  inline oslSocketType SAL_CALL getType() const;
328 
410  inline sal_Int32 SAL_CALL getOption(
411  oslSocketOption Option,
412  void* pBuffer,
413  sal_uInt32 BufferLen,
415 
457  inline bool SAL_CALL setOption( oslSocketOption Option,
458  void* pBuffer,
459  sal_uInt32 BufferLen,
461 
465  inline bool setOption( oslSocketOption option, sal_Int32 nValue );
466 
470  inline sal_Int32 getOption( oslSocketOption option ) const;
471 
478  inline bool SAL_CALL enableNonBlockingMode( bool bNonBlockingMode);
479 
483  inline bool SAL_CALL isNonBlockingMode() const;
484 
485 
488  inline void SAL_CALL clearError() const;
489 
497  inline oslSocketError getError() const;
498 
501  inline ::rtl::OUString getErrorAsString( ) const;
502 
505  inline oslSocket getHandle() const;
506  };
507 
508 
509  class StreamSocket : public Socket
510  {
511  public:
523 
524  inline StreamSocket( const StreamSocket & );
525 
526  inline StreamSocket( oslSocket Socket , __sal_NoAcquire noacquire );
527 
528  inline StreamSocket( oslSocket Socket );
529 
539  inline sal_Int32 SAL_CALL read(void* pBuffer, sal_uInt32 n);
540 
548  inline sal_Int32 SAL_CALL write(const void* pBuffer, sal_uInt32 n);
549 
550 
567  inline sal_Int32 SAL_CALL recv(void* pBuffer,
568  sal_uInt32 BytesToRead,
570 
587  sal_Int32 SAL_CALL send(const void* pBuffer,
588  sal_uInt32 BytesToSend,
590  };
591 
593  {
594  public:
606 
607 
617  oslSocketResult SAL_CALL connect(const SocketAddr& TargetHost, const TimeValue* pTimeout = NULL);
618  };
619 
622  class AcceptorSocket : public Socket
623  {
624  public:
628 
636  inline bool SAL_CALL listen(sal_Int32 MaxPendingConnections= -1);
637 
645  inline oslSocketResult SAL_CALL acceptConnection( StreamSocket& Connection);
646 
656  inline oslSocketResult SAL_CALL acceptConnection( StreamSocket& Connection, SocketAddr & PeerAddr);
657  };
658 
659 
662  class DatagramSocket : public Socket
663  {
664  public:
665 
674 
694  inline sal_Int32 SAL_CALL recvFrom(void* pBuffer,
695  sal_uInt32 BufferSize,
696  SocketAddr* pSenderAddr= NULL,
698 
721  inline sal_Int32 SAL_CALL sendTo( const SocketAddr& ReceiverAddr,
722  const void* pBuffer,
723  sal_uInt32 BufferSize,
725  };
726 
727 }
728 
729 #endif
730 
731 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
~SocketAddr()
destroys underlying oslSocketAddress
Definition: socket.hxx:76
SocketAddr & assign(oslSocketAddr Addr, __osl_socket_NoCopy nocopy)
Assigns the socket addr without copyconstructing it.
Definition: socket.hxx:154
bool setPort(sal_Int32 nPort)
Sets the port number of the address.
Definition: socket.hxx:99
Definition: socket.h:47
oslSocketAddr getHandle() const
Returns the underlying SocketAddr handle without copyconstructing it.
Definition: socket.hxx:168
SocketAddr()
Creates socket address of unknown type.
Definition: socket.hxx:27
Definition: time.h:66
bool operator==(oslSocketAddr Addr) const
Returns true if the underlying handle is identical to the Addr handle.
Definition: socket.hxx:163
oslSocketMsgFlag
Represents flags to be used with send/recv-calls.
Definition: socket.h:120
bool setAddr(const ::rtl::ByteSequence &address)
Sets the address of the underlying socket address struct in network byte order.
Definition: socket.hxx:111
oslSocketError
Describes the various error socket error conditions, which may occur.
Definition: socket.h:143
static sal_Int32 getServicePort(const ::rtl::OUString &strServiceName, const ::rtl::OUString &strProtocolName=::rtl::OUString("tcp"))
Tries to find the port associated with the given service/protocol- pair (e.g.
Definition: socket.hxx:194
static inline ::rtl::OUString getLocalHostname(oslSocketResult *pResult=NULL)
Get the hostname for the local interface.
Definition: socket.hxx:179
Definition: socket.h:121
inline ::rtl::OUString getHostname(oslSocketResult *pResult=NULL) const
Converts the address to a (human readable) domain-name.
Definition: socket.hxx:83
struct oslSocketImpl * oslSocket
Definition: socket.h:405
inline ::rtl::ByteSequence getAddr(oslSocketResult *pResult=NULL) const
Returns the address of the underlying socket in network byte order.
Definition: socket.hxx:117
struct oslSocketAddrImpl * oslSocketAddr
Opaque datatype SocketAddr.
Definition: socket.h:40
oslSocketAddr m_handle
Definition: socket_decl.hxx:42
Definition: socket.h:71
oslSocketDirection
Used by shutdown to denote which end of the socket to "close".
Definition: socket.h:133
__osl_socket_NoCopy
Definition: socket_decl.hxx:33
oslProtocol
represent a specific protocol within a address-family
Definition: socket.h:56
sal_Int32 getPort() const
Returns the port number of the address.
Definition: socket.hxx:93
Definition: socket.h:70
__sal_NoAcquire
Definition: types.h:366
oslSocketOption
Represents socket-options.
Definition: socket.h:83
Definition: socket_decl.hxx:592
bool is() const
checks, if the SocketAddr was created successful.
Definition: socket.hxx:174
Definition: socket.h:57
Definition: conditn.hxx:37
SocketAddr & operator=(oslSocketAddr Addr)
assign the handle to this reference.
Definition: socket.hxx:127
oslAddrFamily
Represents the address-family of a socket.
Definition: socket.h:46
Definition: socket.h:136
Definition: socket.h:110
Definition: socket_decl.hxx:33
oslSocket m_handle
Definition: socket_decl.hxx:175
The class should be understood as a reference to a socket address handle ( struct sockaddr )...
Definition: socket_decl.hxx:39
This String class provides base functionality for C++ like Unicode character array handling...
Definition: ustring.hxx:120
oslSocketOptionLevel
Represents the different socket-option levels.
Definition: socket.h:109
oslSocketResult
Common return codes of socket related functions.
Definition: socket.h:182
A connectionless socket to send and receive datagrams.
Definition: socket_decl.hxx:662
Definition: socket_decl.hxx:509
bool setHostname(const ::rtl::OUString &sDottedIpOrHostname)
Sets the ipaddress or hostname of the SocketAddress.
Definition: socket.hxx:104
static void resolveHostname(const ::rtl::OUString &strHostName, SocketAddr &Addr)
Tries to find an address for a host.
Definition: socket.hxx:188
Allows to accept socket connections.
Definition: socket_decl.hxx:622
Definition: socket_decl.hxx:172
oslSocketType
Represents the type of a socket.
Definition: socket.h:69