LibreOffice LibreOffice 5.3 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 {
33 enum __osl_socket_NoCopy { SAL_NO_COPY };
34
39 class SocketAddr
40 {
41 protected:
42 oslSocketAddr m_handle;
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
124 inline SocketAddr & SAL_CALL operator= (const SocketAddr& Addr);
125
126 #if defined LIBO_INTERNAL_ONLY
127 inline SocketAddr & operator =(SocketAddr && other);
128 #endif
129
134 inline SocketAddr & SAL_CALL assign( oslSocketAddr Addr, __osl_socket_NoCopy nocopy );
135
138 inline bool SAL_CALL operator== (oslSocketAddr Addr) const;
139
142 inline bool SAL_CALL operator== (const SocketAddr & Addr) const;
143
146 inline oslSocketAddr SAL_CALL getHandle() const;
147
153 static inline ::rtl::OUString SAL_CALL getLocalHostname( oslSocketResult *pResult = NULL);
154
159 static inline void SAL_CALL resolveHostname(
160 const ::rtl::OUString & strHostName , SocketAddr & Addr );
161
168 static inline sal_Int32 SAL_CALL getServicePort(
169 const ::rtl::OUString& strServiceName,
170 const ::rtl::OUString & strProtocolName= ::rtl::OUString("tcp") );
171 };
172
173
174 class Socket
175 {
176 protected:
177 oslSocket m_handle;
178 protected:
184 inline Socket(oslSocketType Type,
185 oslAddrFamily Family = osl_Socket_FamilyInet,
186 oslProtocol Protocol = osl_Socket_ProtocolIp);
187 public:
188 inline Socket( );
189
190 inline Socket( const Socket & socket );
191
192 inline Socket( oslSocket socketHandle );
193
199 inline Socket( oslSocket socketHandle, __sal_NoAcquire noacquire );
200
203 inline ~Socket();
204
208 inline Socket& SAL_CALL operator= ( oslSocket socketHandle);
209
213 inline Socket& SAL_CALL operator= (const Socket& sock);
214
219 inline bool SAL_CALL operator==( const Socket& rSocket ) const ;
220
225 inline bool SAL_CALL operator==( const oslSocket socketHandle ) const;
226
232 inline void SAL_CALL shutdown( oslSocketDirection Direction = osl_Socket_DirReadWrite );
233
239 inline void SAL_CALL close();
240
245 inline void SAL_CALL getLocalAddr( SocketAddr &Addr ) const;
246
250 inline sal_Int32 SAL_CALL getLocalPort() const;
251
255 inline ::rtl::OUString SAL_CALL getLocalHost() const;
256
260 inline void SAL_CALL getPeerAddr( SocketAddr & Addr) const;
261
265 inline sal_Int32 SAL_CALL getPeerPort() const;
266
270 inline ::rtl::OUString SAL_CALL getPeerHost() const;
271
276 inline bool SAL_CALL bind(const SocketAddr& LocalInterface);
277
288 inline bool SAL_CALL isRecvReady(const TimeValue *pTimeout = NULL) const;
289
300 inline bool SAL_CALL isSendReady(const TimeValue *pTimeout = NULL) const;
301
302
315 inline bool SAL_CALL isExceptionPending(const TimeValue *pTimeout = NULL) const;
316
317
329 inline oslSocketType SAL_CALL getType() const;
330
412 inline sal_Int32 SAL_CALL getOption(
413 oslSocketOption Option,
414 void* pBuffer,
415 sal_uInt32 BufferLen,
416 oslSocketOptionLevel Level= osl_Socket_LevelSocket) const;
417
459 inline bool SAL_CALL setOption( oslSocketOption Option,
460 void* pBuffer,
461 sal_uInt32 BufferLen,
462 oslSocketOptionLevel Level= osl_Socket_LevelSocket ) const;
463
467 inline bool setOption( oslSocketOption option, sal_Int32 nValue );
468
472 inline sal_Int32 getOption( oslSocketOption option ) const;
473
480 inline bool SAL_CALL enableNonBlockingMode( bool bNonBlockingMode);
481
485 inline bool SAL_CALL isNonBlockingMode() const;
486
487
490 inline void SAL_CALL clearError() const;
491
499 inline oslSocketError getError() const;
500
503 inline ::rtl::OUString getErrorAsString( ) const;
504
507 inline oslSocket getHandle() const;
508 };
509
510
511 class StreamSocket : public Socket
512 {
513 public:
522 inline StreamSocket(oslAddrFamily Family = osl_Socket_FamilyInet,
523 oslProtocol Protocol = osl_Socket_ProtocolIp,
524 oslSocketType Type = osl_Socket_TypeStream);
525
526 inline StreamSocket( const StreamSocket & );
527
528 inline StreamSocket( oslSocket Socket , __sal_NoAcquire noacquire );
529
530 inline StreamSocket( oslSocket Socket );
531
541 inline sal_Int32 SAL_CALL read(void* pBuffer, sal_uInt32 n);
542
550 inline sal_Int32 SAL_CALL write(const void* pBuffer, sal_uInt32 n);
551
552
569 inline sal_Int32 SAL_CALL recv(void* pBuffer,
570 sal_uInt32 BytesToRead,
571 oslSocketMsgFlag flags= osl_Socket_MsgNormal);
572
589 sal_Int32 SAL_CALL send(const void* pBuffer,
590 sal_uInt32 BytesToSend,
591 oslSocketMsgFlag= osl_Socket_MsgNormal);
592 };
593
594 class ConnectorSocket : public StreamSocket
595 {
596 public:
605 ConnectorSocket(oslAddrFamily Family = osl_Socket_FamilyInet,
606 oslProtocol Protocol = osl_Socket_ProtocolIp,
607 oslSocketType Type = osl_Socket_TypeStream);
608
609
619 oslSocketResult SAL_CALL connect(const SocketAddr& TargetHost, const TimeValue* pTimeout = NULL);
620 };
621
624 class AcceptorSocket : public Socket
625 {
626 public:
627 inline AcceptorSocket(oslAddrFamily Family = osl_Socket_FamilyInet,
628 oslProtocol Protocol = osl_Socket_ProtocolIp,
629 oslSocketType Type = osl_Socket_TypeStream);
630
638 inline bool SAL_CALL listen(sal_Int32 MaxPendingConnections= -1);
639
647 inline oslSocketResult SAL_CALL acceptConnection( StreamSocket& Connection);
648
658 inline oslSocketResult SAL_CALL acceptConnection( StreamSocket& Connection, SocketAddr & PeerAddr);
659 };
660
661
664 class DatagramSocket : public Socket
665 {
666 public:
667
673 inline DatagramSocket(oslAddrFamily Family= osl_Socket_FamilyInet,
674 oslProtocol Protocol= osl_Socket_ProtocolIp,
675 oslSocketType Type= osl_Socket_TypeDgram);
676
696 inline sal_Int32 SAL_CALL recvFrom(void* pBuffer,
697 sal_uInt32 BufferSize,
698 SocketAddr* pSenderAddr= NULL,
699 oslSocketMsgFlag Flag= osl_Socket_MsgNormal);
700
723 inline sal_Int32 SAL_CALL sendTo( const SocketAddr& ReceiverAddr,
724 const void* pBuffer,
725 sal_uInt32 BufferSize,
726 oslSocketMsgFlag Flag= osl_Socket_MsgNormal);
727 };
728
729 }
730
731 #endif
732
733 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
osl::SocketAddr::~SocketAddr
~SocketAddr()
destroys underlying oslSocketAddress
Definition: socket.hxx:76
osl::SocketAddr::assign
SocketAddr & assign(oslSocketAddr Addr, __osl_socket_NoCopy nocopy)
Assigns the socket addr without copyconstructing it.
Definition: socket.hxx:154
osl::SocketAddr::setPort
bool setPort(sal_Int32 nPort)
Sets the port number of the address.
Definition: socket.hxx:99
osl_Socket_FamilyInet
Definition: socket.h:47
osl::SocketAddr::getHandle
oslSocketAddr getHandle() const
Returns the underlying SocketAddr handle without copyconstructing it.
Definition: socket.hxx:168
osl::SocketAddr::SocketAddr
SocketAddr()
Creates socket address of unknown type.
Definition: socket.hxx:27
TimeValue
Definition: time.h:70
osl::SocketAddr::operator==
bool operator==(oslSocketAddr Addr) const
Returns true if the underlying handle is identical to the Addr handle.
Definition: socket.hxx:163
oslSocketMsgFlag
oslSocketMsgFlag
Represents flags to be used with send/recv-calls.
Definition: socket.h:120
osl::SocketAddr::setAddr
bool setAddr(const ::rtl::ByteSequence &address)
Sets the address of the underlying socket address struct in network byte order.
Definition: socket.hxx:111
oslSocketError
oslSocketError
Describes the various error socket error conditions, which may occur.
Definition: socket.h:143
osl::SocketAddr::getServicePort
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:197
osl::SocketAddr::getLocalHostname
static inline ::rtl::OUString getLocalHostname(oslSocketResult *pResult=NULL)
Get the hostname for the local interface.
Definition: socket.hxx:180
osl_Socket_MsgNormal
Definition: socket.h:121
osl::SocketAddr::getHostname
inline ::rtl::OUString getHostname(oslSocketResult *pResult=NULL) const
Converts the address to a (human readable) domain-name.
Definition: socket.hxx:83
oslSocket
struct oslSocketImpl * oslSocket
Definition: socket.h:402
osl::SocketAddr::getAddr
inline ::rtl::ByteSequence getAddr(oslSocketResult *pResult=NULL) const
Returns the address of the underlying socket in network byte order.
Definition: socket.hxx:117
oslSocketAddr
struct oslSocketAddrImpl * oslSocketAddr
Opaque datatype SocketAddr.
Definition: socket.h:40
osl::SocketAddr::m_handle
oslSocketAddr m_handle
Definition: socket_decl.hxx:42
osl_Socket_TypeDgram
Definition: socket.h:71
ustring.hxx
oslSocketDirection
oslSocketDirection
Used by shutdown to denote which end of the socket to "close".
Definition: socket.h:133
osl::__osl_socket_NoCopy
__osl_socket_NoCopy
Definition: socket_decl.hxx:33
oslProtocol
oslProtocol
represent a specific protocol within a address-family
Definition: socket.h:56
osl::SocketAddr::getPort
sal_Int32 getPort() const
Returns the port number of the address.
Definition: socket.hxx:93
osl_Socket_TypeStream
Definition: socket.h:70
__sal_NoAcquire
__sal_NoAcquire
Definition: types.h:384
oslSocketOption
oslSocketOption
Represents socket-options.
Definition: socket.h:83
osl::ConnectorSocket
Definition: socket_decl.hxx:594
osl::SocketAddr::is
bool is() const
checks, if the SocketAddr was created successful.
Definition: socket.hxx:174
osl_Socket_ProtocolIp
Definition: socket.h:57
osl
Definition: conditn.hxx:32
osl::SocketAddr::operator=
SocketAddr & operator=(oslSocketAddr Addr)
assign the handle to this reference.
Definition: socket.hxx:127
oslAddrFamily
oslAddrFamily
Represents the address-family of a socket.
Definition: socket.h:46
osl_Socket_DirReadWrite
Definition: socket.h:136
osl_Socket_LevelSocket
Definition: socket.h:110
config.h
osl::SAL_NO_COPY
Definition: socket_decl.hxx:33
osl::Socket::m_handle
oslSocket m_handle
Definition: socket_decl.hxx:177
osl::SocketAddr
The class should be understood as a reference to a socket address handle ( struct sockaddr )...
Definition: socket_decl.hxx:39
rtl::OUString
This String class provides base functionality for C++ like Unicode character array handling...
Definition: ustring.hxx:106
oslSocketOptionLevel
oslSocketOptionLevel
Represents the different socket-option levels.
Definition: socket.h:109
oslSocketResult
oslSocketResult
Common return codes of socket related functions.
Definition: socket.h:182
osl::DatagramSocket
A connectionless socket to send and receive datagrams.
Definition: socket_decl.hxx:664
byteseq.hxx
osl::StreamSocket
Definition: socket_decl.hxx:511
osl::SocketAddr::setHostname
bool setHostname(const ::rtl::OUString &sDottedIpOrHostname)
Sets the ipaddress or hostname of the SocketAddress.
Definition: socket.hxx:104
osl::SocketAddr::resolveHostname
static void resolveHostname(const ::rtl::OUString &strHostName, SocketAddr &Addr)
Tries to find an address for a host.
Definition: socket.hxx:190
osl::AcceptorSocket
Allows to accept socket connections.
Definition: socket_decl.hxx:624
osl::Socket
Definition: socket_decl.hxx:174
oslSocketType
oslSocketType
Represents the type of a socket.
Definition: socket.h:69
socket.h