AlterOffice
AlterOffice 3.4 SDK C/C++ API Reference
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
4 #ifndef INCLUDED_OSL_SOCKET_DECL_HXX
5 #define INCLUDED_OSL_SOCKET_DECL_HXX
6 
7 #include "sal/config.h"
8 
9 #include <cstddef>
10 
11 #include "osl/socket.h"
12 #include "rtl/ustring.hxx"
13 #include "rtl/byteseq.hxx"
14 
15 namespace osl
16 {
18 
23  class SocketAddr
24  {
25  protected:
27  public:
28 
31  inline SocketAddr();
32 
35  inline SocketAddr(const SocketAddr& Addr);
36 
37 #if defined LIBO_INTERNAL_ONLY
38  inline SocketAddr(SocketAddr && other) noexcept;
39 #endif
40 
47  inline SocketAddr(const oslSocketAddr Addr, __osl_socket_NoCopy nocopy );
48 
53  inline SocketAddr(oslSocketAddr Addr);
54 
61  inline SocketAddr(const ::rtl::OUString& strAddrOrHostName, sal_Int32 nPort);
62 
65  inline ~SocketAddr();
66 
72  inline bool is() const;
73 
84  inline ::rtl::OUString SAL_CALL getHostname(oslSocketResult *pResult = NULL) const;
85 
93  inline bool SAL_CALL setHostname(const ::rtl::OUString &sDottedIpOrHostname);
94 
99  inline sal_Int32 SAL_CALL getPort() const;
100 
108  inline bool SAL_CALL setPort(sal_Int32 nPort);
109 
115  inline bool SAL_CALL setAddr(const ::rtl::ByteSequence & address);
116 
119  inline ::rtl::ByteSequence SAL_CALL getAddr(oslSocketResult *pResult = NULL) const;
120 
123  inline SocketAddr & SAL_CALL operator= (oslSocketAddr Addr);
124 
125  inline SocketAddr & SAL_CALL operator= (const SocketAddr& Addr);
126 
127 #if defined LIBO_INTERNAL_ONLY
128  inline SocketAddr & operator =(SocketAddr && other) noexcept;
129 #endif
130 
135  inline SocketAddr & SAL_CALL assign( oslSocketAddr Addr, __osl_socket_NoCopy nocopy );
136 
139  inline bool SAL_CALL operator== (oslSocketAddr Addr) const;
140 
143  inline bool SAL_CALL operator== (const SocketAddr & Addr) const;
144 
147  inline oslSocketAddr SAL_CALL getHandle() const;
148 
154  static inline ::rtl::OUString SAL_CALL getLocalHostname( oslSocketResult *pResult = NULL);
155 
162  static inline void SAL_CALL resolveHostname(
163  const ::rtl::OUString & strHostName , SocketAddr & Addr );
164 
171  static inline sal_Int32 SAL_CALL getServicePort(
172  const ::rtl::OUString& strServiceName,
173  const ::rtl::OUString & strProtocolName= ::rtl::OUString("tcp") );
174  };
175 
176 
177  class Socket
178  {
179  protected:
181  protected:
187  inline Socket(oslSocketType Type,
190  public:
191  inline Socket( );
192 
193  inline Socket( const Socket & socket );
194 
195  inline Socket( oslSocket socketHandle );
196 
202  inline Socket( oslSocket socketHandle, __sal_NoAcquire noacquire );
203 
206  inline ~Socket();
207 
211  inline Socket& SAL_CALL operator= ( oslSocket socketHandle);
212 
216  inline Socket& SAL_CALL operator= (const Socket& sock);
217 
222  inline bool SAL_CALL operator==( const Socket& rSocket ) const ;
223 
228  inline bool SAL_CALL operator==( const oslSocket socketHandle ) const;
229 
235  inline void SAL_CALL shutdown( oslSocketDirection Direction = osl_Socket_DirReadWrite );
236 
242  inline void SAL_CALL close();
243 
248  inline void SAL_CALL getLocalAddr( SocketAddr &Addr ) const;
249 
253  inline sal_Int32 SAL_CALL getLocalPort() const;
254 
258  inline ::rtl::OUString SAL_CALL getLocalHost() const;
259 
263  inline void SAL_CALL getPeerAddr( SocketAddr & Addr) const;
264 
268  inline sal_Int32 SAL_CALL getPeerPort() const;
269 
273  inline ::rtl::OUString SAL_CALL getPeerHost() const;
274 
279  inline bool SAL_CALL bind(const SocketAddr& LocalInterface);
280 
291  inline bool SAL_CALL isRecvReady(const TimeValue *pTimeout = NULL) const;
292 
303  inline bool SAL_CALL isSendReady(const TimeValue *pTimeout = NULL) const;
304 
305 
318  inline bool SAL_CALL isExceptionPending(const TimeValue *pTimeout = NULL) const;
319 
320 
330  inline oslSocketType SAL_CALL getType() const;
331 
413  inline sal_Int32 SAL_CALL getOption(
414  oslSocketOption Option,
415  void* pBuffer,
416  sal_uInt32 BufferLen,
418 
460  inline bool SAL_CALL setOption( oslSocketOption Option,
461  void* pBuffer,
462  sal_uInt32 BufferLen,
464 
468  inline bool setOption( oslSocketOption option, sal_Int32 nValue );
469 
473  inline sal_Int32 getOption( oslSocketOption option ) const;
474 
481  inline bool SAL_CALL enableNonBlockingMode( bool bNonBlockingMode);
482 
486  inline bool SAL_CALL isNonBlockingMode() const;
487 
488 
491  inline void SAL_CALL clearError() const;
492 
500  inline oslSocketError getError() const;
501 
504  inline ::rtl::OUString getErrorAsString( ) const;
505 
508  inline oslSocket getHandle() const;
509  };
510 
511 
512  class StreamSocket : public Socket
513  {
514  public:
526 
527  inline StreamSocket( oslSocket Socket , __sal_NoAcquire noacquire );
528 
529  inline StreamSocket( oslSocket Socket );
530 
540  inline sal_Int32 SAL_CALL read(void* pBuffer, sal_uInt32 n);
541 
549  inline sal_Int32 SAL_CALL write(const void* pBuffer, sal_uInt32 n);
550 
551 
568  inline sal_Int32 SAL_CALL recv(void* pBuffer,
569  sal_uInt32 BytesToRead,
571 
588  sal_Int32 SAL_CALL send(const void* pBuffer,
589  sal_uInt32 BytesToSend,
591  };
592 
594  {
595  public:
607 
608 
618  oslSocketResult SAL_CALL connect(const SocketAddr& TargetHost, const TimeValue* pTimeout = NULL);
619  };
620 
623  class AcceptorSocket : public Socket
624  {
625  public:
629 
637  inline bool SAL_CALL listen(sal_Int32 MaxPendingConnections= -1);
638 
646  inline oslSocketResult SAL_CALL acceptConnection( StreamSocket& Connection);
647 
657  inline oslSocketResult SAL_CALL acceptConnection( StreamSocket& Connection, SocketAddr & PeerAddr);
658  };
659 
660 
663  class DatagramSocket : public Socket
664  {
665  public:
666 
675 
695  inline sal_Int32 SAL_CALL recvFrom(void* pBuffer,
696  sal_uInt32 BufferSize,
697  SocketAddr* pSenderAddr= NULL,
699 
722  inline sal_Int32 SAL_CALL sendTo( const SocketAddr& ReceiverAddr,
723  const void* pBuffer,
724  sal_uInt32 BufferSize,
726  };
727 
728 }
729 
730 #endif
731 
732 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ConnectorSocket(oslAddrFamily Family=osl_Socket_FamilyInet, oslProtocol Protocol=osl_Socket_ProtocolIp, oslSocketType Type=osl_Socket_TypeStream)
Creates a socket that can connect to a (remote) host.
Definition: socket.hxx:450
bool operator==(const Socket &rSocket) const
Definition: socket.hxx:235
oslSocketMsgFlag
Represents flags to be used with send/recv-calls.
Definition: socket.h:115
bool listen(sal_Int32 MaxPendingConnections=-1)
Prepare a socket for the accept-call.
Definition: socket.hxx:471
Socket & operator=(oslSocket socketHandle)
Assignment operator.
Definition: socket.hxx:219
void getPeerAddr(SocketAddr &Addr) const
Retrieves the address of the remote host of this socket.
Definition: socket.hxx:281
oslAddrFamily
Represents the address-family of a socket.
Definition: socket.h:29
oslSocketOptionLevel
Represents the different socket-option levels.
Definition: socket.h:105
Time since Jan-01-1970.
Definition: time.h:56
sal_Int32 recv(void *pBuffer, sal_uInt32 BytesToRead, oslSocketMsgFlag flags=osl_Socket_MsgNormal)
Tries to receive BytesToRead data from the connected socket,.
Definition: socket.hxx:434
void shutdown(oslSocketDirection Direction=osl_Socket_DirReadWrite)
Closes a definite or both directions of the bidirectional stream.
Definition: socket.hxx:247
oslSocketResult acceptConnection(StreamSocket &Connection)
Accepts incoming connections on the socket.
Definition: socket.hxx:477
Definition: socket.h:106
This String class provides base functionality for C++ like Unicode character array handling...
Definition: ustring.hxx:182
sal_Int32 write(const void *pBuffer, sal_uInt32 n)
Writes n bytes from pBuffer to the stream.
Definition: socket.hxx:428
inline::rtl::OUString getLocalHost() const
Get the hostname for the local interface.
Definition: socket.hxx:273
oslSocketError
Describes the various error socket error conditions, which may occur.
Definition: socket.h:138
__sal_NoAcquire
Definition: types.h:332
oslSocketAddr m_handle
Definition: socket_decl.hxx:26
sal_Int32 sendTo(const SocketAddr &ReceiverAddr, const void *pBuffer, sal_uInt32 BufferSize, oslSocketMsgFlag Flag=osl_Socket_MsgNormal)
Tries to send one datagram with BytesToSend size to the given ReceiverAddr.
Definition: socket.hxx:541
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:179
bool setPort(sal_Int32 nPort)
Sets the port number of the address.
Definition: socket.hxx:84
bool is() const
Checks if the SocketAddr was created successful.
Definition: socket.hxx:159
bool setAddr(const ::rtl::ByteSequence &address)
Sets the address of the underlying socket address struct in network byte order.
Definition: socket.hxx:96
DatagramSocket(oslAddrFamily Family=osl_Socket_FamilyInet, oslProtocol Protocol=osl_Socket_ProtocolIp, oslSocketType Type=osl_Socket_TypeDgram)
Creates a datagram socket.
Definition: socket.hxx:514
SocketAddr()
Creates socket address of unknown type.
Definition: socket.hxx:12
oslSocketResult
Common return codes of socket related functions.
Definition: socket.h:177
Definition: socket_decl.hxx:512
oslSocket getHandle() const
Returns the underlying handle unacquired (The caller must acquire it to keep it). ...
Definition: socket.hxx:399
sal_Int32 recvFrom(void *pBuffer, sal_uInt32 BufferSize, SocketAddr *pSenderAddr=NULL, oslSocketMsgFlag Flag=osl_Socket_MsgNormal)
Tries to receives BufferSize data from the socket, if no error occurs.
Definition: socket.hxx:521
Definition: socket_decl.hxx:17
~SocketAddr()
destroys underlying oslSocketAddress
Definition: socket.hxx:61
SocketAddr & assign(oslSocketAddr Addr, __osl_socket_NoCopy nocopy)
Assigns the socket addr without copyconstructing it.
Definition: socket.hxx:139
Definition: socket.h:40
bool bind(const SocketAddr &LocalInterface)
Binds the socket to the specified (local) interface.
Definition: socket.hxx:303
inline::rtl::OUString getPeerHost() const
Get the hostname for the remote interface.
Definition: socket.hxx:295
inline::rtl::OUString getHostname(oslSocketResult *pResult=NULL) const
Converts the address to a (human readable) domain-name.
Definition: socket.hxx:68
oslSocketDirection
Used by shutdown to denote which end of the socket to &quot;close&quot;.
Definition: socket.h:128
void close()
Closes a socket.
Definition: socket.hxx:253
The class should be understood as a reference to a socket address handle (struct sockaddr).
Definition: socket_decl.hxx:23
Allows to accept socket connections.
Definition: socket_decl.hxx:623
inline::rtl::ByteSequence getAddr(oslSocketResult *pResult=NULL) const
Returns the address of the underlying socket in network byte order.
Definition: socket.hxx:102
void clearError() const
clears the error status
Definition: socket.hxx:378
SocketAddr & operator=(oslSocketAddr Addr)
assign the handle to this reference.
Definition: socket.hxx:112
__osl_socket_NoCopy
Definition: socket_decl.hxx:17
void getLocalAddr(SocketAddr &Addr) const
Retrieves the address of the local interface of this socket.
Definition: socket.hxx:259
bool setOption(oslSocketOption Option, void *pBuffer, sal_uInt32 BufferLen, oslSocketOptionLevel Level=osl_Socket_LevelSocket) const
Sets the sockets attributes.
Definition: socket.hxx:343
Definition: socket_decl.hxx:593
oslSocketResult connect(const SocketAddr &TargetHost, const TimeValue *pTimeout=NULL)
Connects the socket to a (remote) host.
Definition: socket.hxx:457
Definition: socket.h:116
sal_Int32 getPeerPort() const
Get the remote port of the socket.
Definition: socket.hxx:287
sal_Int32 getOption(oslSocketOption Option, void *pBuffer, sal_uInt32 BufferLen, oslSocketOptionLevel Level=osl_Socket_LevelSocket) const
Retrieves option-attributes associated with the socket.
Definition: socket.hxx:333
inline::rtl::OUString getErrorAsString() const
Builds a string with the last error-message for the socket.
Definition: socket.hxx:391
sal_Int32 send(const void *pBuffer, sal_uInt32 BytesToSend, oslSocketMsgFlag=osl_Socket_MsgNormal)
Tries to send BytesToSend data to the connected socket.
Definition: socket.hxx:442
static inline::rtl::OUString getLocalHostname(oslSocketResult *pResult=NULL)
Get the hostname for the local interface.
Definition: socket.hxx:164
struct oslSocketAddrImpl * oslSocketAddr
Opaque datatype SocketAddr.
Definition: socket.h:24
oslSocketError getError() const
returns a constant describing the last error for the socket system.
Definition: socket.hxx:385
sal_Int32 read(void *pBuffer, sal_uInt32 n)
Retrieves n bytes from the stream and copies them into pBuffer.
Definition: socket.hxx:422
bool isSendReady(const TimeValue *pTimeout=NULL) const
Checks if send operations will block.
Definition: socket.hxx:315
sal_Int32 getPort() const
Returns the port number of the address.
Definition: socket.hxx:78
bool enableNonBlockingMode(bool bNonBlockingMode)
Enables/disables non-blocking mode of the socket.
Definition: socket.hxx:366
bool setHostname(const ::rtl::OUString &sDottedIpOrHostname)
Sets the IP address or hostname of the SocketAddress.
Definition: socket.hxx:89
AcceptorSocket(oslAddrFamily Family=osl_Socket_FamilyInet, oslProtocol Protocol=osl_Socket_ProtocolIp, oslSocketType Type=osl_Socket_TypeStream)
Definition: socket.hxx:464
Definition: socket.h:52
StreamSocket(oslAddrFamily Family=osl_Socket_FamilyInet, oslProtocol Protocol=osl_Socket_ProtocolIp, oslSocketType Type=osl_Socket_TypeStream)
Creates a socket.
Definition: socket.hxx:405
oslSocketOption
Represents socket-options.
Definition: socket.h:69
oslSocketType getType() const
Queries the socket for its type.
Definition: socket.hxx:327
bool operator==(oslSocketAddr Addr) const
Returns true if the underlying handle is identical to the Addr handle.
Definition: socket.hxx:148
Definition: socket.h:30
sal_Int32 getLocalPort() const
Get the local port of the socket.
Definition: socket.hxx:265
oslSocketType
Represents the type of a socket.
Definition: socket.h:51
oslProtocol
represent a specific protocol within an address-family
Definition: socket.h:39
Definition: socket.h:53
Definition: socket_decl.hxx:177
bool isExceptionPending(const TimeValue *pTimeout=NULL) const
Checks if a request for out-of-band data will block.
Definition: socket.hxx:321
struct oslSocketImpl * oslSocket
Definition: socket.h:195
static void resolveHostname(const ::rtl::OUString &strHostName, SocketAddr &Addr)
Tries to find an address for a host.
Definition: socket.hxx:173
bool isNonBlockingMode() const
Query blocking mode of the socket.
Definition: socket.hxx:372
Definition: socket.h:131
bool isRecvReady(const TimeValue *pTimeout=NULL) const
Checks if read operations will block.
Definition: socket.hxx:309
~Socket()
Destructor.
Definition: socket.hxx:213
A connectionless socket to send and receive datagrams.
Definition: socket_decl.hxx:663
oslSocketAddr getHandle() const
Returns the underlying SocketAddr handle without copyconstructing it.
Definition: socket.hxx:153
oslSocket m_handle
Definition: socket_decl.hxx:180