LibreOffice: osl/socket_decl.hxx Source File

LibreOffice LibreOffice 6.0 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
63 inline SocketAddr(const oslSocketAddr Addr, __osl_socket_NoCopy nocopy );
64
69 inline SocketAddr(oslSocketAddr Addr);
70
77 inline SocketAddr(const ::rtl::OUString& strAddrOrHostName, sal_Int32 nPort);
78
81 inline ~SocketAddr();
82
88 inline bool is() const;
89
100 inline ::rtl::OUString SAL_CALL getHostname(oslSocketResult *pResult = NULL) const;
101
109 inline bool SAL_CALL setHostname(const ::rtl::OUString &sDottedIpOrHostname);
110
115 inline sal_Int32 SAL_CALL getPort() const;
116
124 inline bool SAL_CALL setPort(sal_Int32 nPort);
125
131 inline bool SAL_CALL setAddr(const ::rtl::ByteSequence & address);
132
135 inline ::rtl::ByteSequence SAL_CALL getAddr(oslSocketResult *pResult = NULL) const;
136
139 inline SocketAddr & SAL_CALL operator= (oslSocketAddr Addr);
140
141 inline SocketAddr & SAL_CALL operator= (const SocketAddr& Addr);
142
143 #if defined LIBO_INTERNAL_ONLY
144 inline SocketAddr & operator =(SocketAddr && other);
145 #endif
146
151 inline SocketAddr & SAL_CALL assign( oslSocketAddr Addr, __osl_socket_NoCopy nocopy );
152
155 inline bool SAL_CALL operator== (oslSocketAddr Addr) const;
156
159 inline bool SAL_CALL operator== (const SocketAddr & Addr) const;
160
163 inline oslSocketAddr SAL_CALL getHandle() const;
164
170 static inline ::rtl::OUString SAL_CALL getLocalHostname( oslSocketResult *pResult = NULL);
171
176 static inline void SAL_CALL resolveHostname(
177 const ::rtl::OUString & strHostName , SocketAddr & Addr );
178
185 static inline sal_Int32 SAL_CALL getServicePort(
186 const ::rtl::OUString& strServiceName,
187 const ::rtl::OUString & strProtocolName= ::rtl::OUString("tcp") );
188 };
189
190
191 class Socket
192 {
193 protected:
194 oslSocket m_handle;
195 protected:
201 inline Socket(oslSocketType Type,
202 oslAddrFamily Family = osl_Socket_FamilyInet,
203 oslProtocol Protocol = osl_Socket_ProtocolIp);
204 public:
205 inline Socket( );
206
207 inline Socket( const Socket & socket );
208
209 inline Socket( oslSocket socketHandle );
210
216 inline Socket( oslSocket socketHandle, __sal_NoAcquire noacquire );
217
220 inline ~Socket();
221
225 inline Socket& SAL_CALL operator= ( oslSocket socketHandle);
226
230 inline Socket& SAL_CALL operator= (const Socket& sock);
231
236 inline bool SAL_CALL operator==( const Socket& rSocket ) const ;
237
242 inline bool SAL_CALL operator==( const oslSocket socketHandle ) const;
243
249 inline void SAL_CALL shutdown( oslSocketDirection Direction = osl_Socket_DirReadWrite );
250
256 inline void SAL_CALL close();
257
262 inline void SAL_CALL getLocalAddr( SocketAddr &Addr ) const;
263
267 inline sal_Int32 SAL_CALL getLocalPort() const;
268
272 inline ::rtl::OUString SAL_CALL getLocalHost() const;
273
277 inline void SAL_CALL getPeerAddr( SocketAddr & Addr) const;
278
282 inline sal_Int32 SAL_CALL getPeerPort() const;
283
287 inline ::rtl::OUString SAL_CALL getPeerHost() const;
288
293 inline bool SAL_CALL bind(const SocketAddr& LocalInterface);
294
305 inline bool SAL_CALL isRecvReady(const TimeValue *pTimeout = NULL) const;
306
317 inline bool SAL_CALL isSendReady(const TimeValue *pTimeout = NULL) const;
318
319
332 inline bool SAL_CALL isExceptionPending(const TimeValue *pTimeout = NULL) const;
333
334
344 inline oslSocketType SAL_CALL getType() const;
345
427 inline sal_Int32 SAL_CALL getOption(
428 oslSocketOption Option,
429 void* pBuffer,
430 sal_uInt32 BufferLen,
431 oslSocketOptionLevel Level= osl_Socket_LevelSocket) const;
432
474 inline bool SAL_CALL setOption( oslSocketOption Option,
475 void* pBuffer,
476 sal_uInt32 BufferLen,
477 oslSocketOptionLevel Level= osl_Socket_LevelSocket ) const;
478
482 inline bool setOption( oslSocketOption option, sal_Int32 nValue );
483
487 inline sal_Int32 getOption( oslSocketOption option ) const;
488
495 inline bool SAL_CALL enableNonBlockingMode( bool bNonBlockingMode);
496
500 inline bool SAL_CALL isNonBlockingMode() const;
501
502
505 inline void SAL_CALL clearError() const;
506
514 inline oslSocketError getError() const;
515
518 inline ::rtl::OUString getErrorAsString( ) const;
519
522 inline oslSocket getHandle() const;
523 };
524
525
526 class StreamSocket : public Socket
527 {
528 public:
537 inline StreamSocket(oslAddrFamily Family = osl_Socket_FamilyInet,
538 oslProtocol Protocol = osl_Socket_ProtocolIp,
539 oslSocketType Type = osl_Socket_TypeStream);
540
541 inline StreamSocket( const StreamSocket & );
542
543 inline StreamSocket( oslSocket Socket , __sal_NoAcquire noacquire );
544
545 inline StreamSocket( oslSocket Socket );
546
556 inline sal_Int32 SAL_CALL read(void* pBuffer, sal_uInt32 n);
557
565 inline sal_Int32 SAL_CALL write(const void* pBuffer, sal_uInt32 n);
566
567
584 inline sal_Int32 SAL_CALL recv(void* pBuffer,
585 sal_uInt32 BytesToRead,
586 oslSocketMsgFlag flags= osl_Socket_MsgNormal);
587
604 sal_Int32 SAL_CALL send(const void* pBuffer,
605 sal_uInt32 BytesToSend,
606 oslSocketMsgFlag= osl_Socket_MsgNormal);
607 };
608
609 class ConnectorSocket : public StreamSocket
610 {
611 public:
620 ConnectorSocket(oslAddrFamily Family = osl_Socket_FamilyInet,
621 oslProtocol Protocol = osl_Socket_ProtocolIp,
622 oslSocketType Type = osl_Socket_TypeStream);
623
624
634 oslSocketResult SAL_CALL connect(const SocketAddr& TargetHost, const TimeValue* pTimeout = NULL);
635 };
636
639 class AcceptorSocket : public Socket
640 {
641 public:
642 inline AcceptorSocket(oslAddrFamily Family = osl_Socket_FamilyInet,
643 oslProtocol Protocol = osl_Socket_ProtocolIp,
644 oslSocketType Type = osl_Socket_TypeStream);
645
653 inline bool SAL_CALL listen(sal_Int32 MaxPendingConnections= -1);
654
662 inline oslSocketResult SAL_CALL acceptConnection( StreamSocket& Connection);
663
673 inline oslSocketResult SAL_CALL acceptConnection( StreamSocket& Connection, SocketAddr & PeerAddr);
674 };
675
676
679 class DatagramSocket : public Socket
680 {
681 public:
682
688 inline DatagramSocket(oslAddrFamily Family= osl_Socket_FamilyInet,
689 oslProtocol Protocol= osl_Socket_ProtocolIp,
690 oslSocketType Type= osl_Socket_TypeDgram);
691
711 inline sal_Int32 SAL_CALL recvFrom(void* pBuffer,
712 sal_uInt32 BufferSize,
713 SocketAddr* pSenderAddr= NULL,
714 oslSocketMsgFlag Flag= osl_Socket_MsgNormal);
715
738 inline sal_Int32 SAL_CALL sendTo( const SocketAddr& ReceiverAddr,
739 const void* pBuffer,
740 sal_uInt32 BufferSize,
741 oslSocketMsgFlag Flag= osl_Socket_MsgNormal);
742 };
743
744 }
745
746 #endif
747
748 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
osl::SocketAddr::getHostname
inline ::rtl::OUString getHostname(oslSocketResult *pResult=NULL) const
Converts the address to a (human readable) domain-name.
Definition: socket.hxx:83
TimeValue
Definition: time.h:66
osl::Socket::~Socket
~Socket()
Destructor.
Definition: socket.hxx:228
osl::DatagramSocket::recvFrom
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:540
osl::SocketAddr::assign
SocketAddr & assign(oslSocketAddr Addr, __osl_socket_NoCopy nocopy)
Assigns the socket addr without copyconstructing it.
Definition: socket.hxx:154
osl::Socket::close
void close()
Closes a socket.
Definition: socket.hxx:267
osl::ConnectorSocket::ConnectorSocket
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:469
osl::AcceptorSocket
Allows to accept socket connections.
Definition: socket_decl.hxx:639
osl::SocketAddr::setPort
bool setPort(sal_Int32 nPort)
Sets the port number of the address.
Definition: socket.hxx:99
osl::StreamSocket::send
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:461
osl_Socket_FamilyInet
Definition: socket.h:46
osl::SocketAddr::getHandle
oslSocketAddr getHandle() const
Returns the underlying SocketAddr handle without copyconstructing it.
Definition: socket.hxx:168
osl::SAL_NO_COPY
Definition: socket_decl.hxx:33
osl::Socket::getType
oslSocketType getType() const
Queries the socket for its type.
Definition: socket.hxx:341
osl::SocketAddr::setHostname
bool setHostname(const ::rtl::OUString &sDottedIpOrHostname)
Sets the IP address or hostname of the SocketAddress.
Definition: socket.hxx:104
osl::SocketAddr::is
bool is() const
Checks if the SocketAddr was created successful.
Definition: socket.hxx:174
osl::Socket::operator==
bool operator==(const Socket &rSocket) const
Definition: socket.hxx:249
osl::Socket::isExceptionPending
bool isExceptionPending(const TimeValue *pTimeout=NULL) const
Checks if a request for out-of-band data will block.
Definition: socket.hxx:335
osl::AcceptorSocket::acceptConnection
oslSocketResult acceptConnection(StreamSocket &Connection)
Accepts incoming connections on the socket.
Definition: socket.hxx:496
oslSocketMsgFlag
oslSocketMsgFlag
Represents flags to be used with send/recv-calls.
Definition: socket.h:131
osl::SocketAddr::getPort
sal_Int32 getPort() const
Returns the port number of the address.
Definition: socket.hxx:93
osl::Socket::getErrorAsString
inline ::rtl::OUString getErrorAsString() const
Builds a string with the last error-message for the socket.
Definition: socket.hxx:405
osl::Socket::m_handle
oslSocket m_handle
Definition: socket_decl.hxx:194
osl::Socket
Definition: socket_decl.hxx:191
osl::Socket::enableNonBlockingMode
bool enableNonBlockingMode(bool bNonBlockingMode)
Enables/disables non-blocking mode of the socket.
Definition: socket.hxx:380
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:154
osl_Socket_MsgNormal
Definition: socket.h:132
oslSocket
struct oslSocketImpl * oslSocket
Definition: socket.h:211
osl::DatagramSocket::DatagramSocket
DatagramSocket(oslAddrFamily Family=osl_Socket_FamilyInet, oslProtocol Protocol=osl_Socket_ProtocolIp, oslSocketType Type=osl_Socket_TypeDgram)
Creates a datagram socket.
Definition: socket.hxx:533
osl::SocketAddr::~SocketAddr
~SocketAddr()
destroys underlying oslSocketAddress
Definition: socket.hxx:76
osl::Socket::getLocalPort
sal_Int32 getLocalPort() const
Get the local port of the socket.
Definition: socket.hxx:279
osl::StreamSocket::write
sal_Int32 write(const void *pBuffer, sal_uInt32 n)
Writes n bytes from pBuffer to the stream.
Definition: socket.hxx:447
osl::StreamSocket::StreamSocket
StreamSocket(oslAddrFamily Family=osl_Socket_FamilyInet, oslProtocol Protocol=osl_Socket_ProtocolIp, oslSocketType Type=osl_Socket_TypeStream)
Creates a socket.
Definition: socket.hxx:419
oslSocketAddr
struct oslSocketAddrImpl * oslSocketAddr
Opaque datatype SocketAddr.
Definition: socket.h:40
osl::ConnectorSocket
Definition: socket_decl.hxx:609
osl::SocketAddr::m_handle
oslSocketAddr m_handle
Definition: socket_decl.hxx:42
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:121
osl::Socket::getHandle
oslSocket getHandle() const
Returns the underlying handle unacquired (The caller must acquire it to keep it). ...
Definition: socket.hxx:413
osl::Socket::isNonBlockingMode
bool isNonBlockingMode() const
Query blocking mode of the socket.
Definition: socket.hxx:386
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
osl_Socket_TypeDgram
Definition: socket.h:69
osl
Definition: conditn.hxx:36
ustring.hxx
oslSocketDirection
oslSocketDirection
Used by shutdown to denote which end of the socket to "close".
Definition: socket.h:144
osl::AcceptorSocket::AcceptorSocket
AcceptorSocket(oslAddrFamily Family=osl_Socket_FamilyInet, oslProtocol Protocol=osl_Socket_ProtocolIp, oslSocketType Type=osl_Socket_TypeStream)
Definition: socket.hxx:483
oslProtocol
oslProtocol
represent a specific protocol within a address-family
Definition: socket.h:55
osl::SocketAddr::operator==
bool operator==(oslSocketAddr Addr) const
Returns true if the underlying handle is identical to the Addr handle.
Definition: socket.hxx:163
osl::Socket::getError
oslSocketError getError() const
returns a constant describing the last error for the socket system.
Definition: socket.hxx:399
osl_Socket_TypeStream
Definition: socket.h:68
osl::DatagramSocket
A connectionless socket to send and receive datagrams.
Definition: socket_decl.hxx:679
__sal_NoAcquire
__sal_NoAcquire
Definition: types.h:376
osl::StreamSocket::recv
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:453
osl::StreamSocket
Definition: socket_decl.hxx:526
oslSocketOption
oslSocketOption
Represents socket-options.
Definition: socket.h:85
osl::Socket::getOption
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:347
osl::Socket::setOption
bool setOption(oslSocketOption Option, void *pBuffer, sal_uInt32 BufferLen, oslSocketOptionLevel Level=osl_Socket_LevelSocket) const
Sets the sockets attributes.
Definition: socket.hxx:357
osl::Socket::getLocalAddr
void getLocalAddr(SocketAddr &Addr) const
Retrieves the address of the local interface of this socket.
Definition: socket.hxx:273
osl::__osl_socket_NoCopy
__osl_socket_NoCopy
Definition: socket_decl.hxx:33
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:194
osl_Socket_ProtocolIp
Definition: socket.h:56
osl::DatagramSocket::sendTo
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:560
osl::Socket::operator=
Socket & operator=(oslSocket socketHandle)
Assignment operator.
Definition: socket.hxx:234
osl::Socket::getPeerPort
sal_Int32 getPeerPort() const
Get the remote port of the socket.
Definition: socket.hxx:301
osl::Socket::getPeerAddr
void getPeerAddr(SocketAddr &Addr) const
Retrieves the address of the remote host of this socket.
Definition: socket.hxx:295
oslAddrFamily
oslAddrFamily
Represents the address-family of a socket.
Definition: socket.h:45
osl_Socket_DirReadWrite
Definition: socket.h:147
osl::Socket::isRecvReady
bool isRecvReady(const TimeValue *pTimeout=NULL) const
Checks if read operations will block.
Definition: socket.hxx:323
osl::SocketAddr::resolveHostname
static void resolveHostname(const ::rtl::OUString &strHostName, SocketAddr &Addr)
Tries to find an address for a host.
Definition: socket.hxx:188
osl_Socket_LevelSocket
Definition: socket.h:122
osl::ConnectorSocket::connect
oslSocketResult connect(const SocketAddr &TargetHost, const TimeValue *pTimeout=NULL)
Connects the socket to a (remote) host.
Definition: socket.hxx:476
config.h
osl::Socket::isSendReady
bool isSendReady(const TimeValue *pTimeout=NULL) const
Checks if send operations will block.
Definition: socket.hxx:329
osl::SocketAddr::operator=
SocketAddr & operator=(oslSocketAddr Addr)
assign the handle to this reference.
Definition: socket.hxx:127
oslSocketOptionLevel
oslSocketOptionLevel
Represents the different socket-option levels.
Definition: socket.h:121
osl::Socket::getLocalHost
inline ::rtl::OUString getLocalHost() const
Get the hostname for the local interface.
Definition: socket.hxx:287
oslSocketResult
oslSocketResult
Common return codes of socket related functions.
Definition: socket.h:193
osl::SocketAddr::SocketAddr
SocketAddr()
Creates socket address of unknown type.
Definition: socket.hxx:27
osl::Socket::getPeerHost
inline ::rtl::OUString getPeerHost() const
Get the hostname for the remote interface.
Definition: socket.hxx:309
osl::AcceptorSocket::listen
bool listen(sal_Int32 MaxPendingConnections=-1)
Prepare a socket for the accept-call.
Definition: socket.hxx:490
osl::Socket::shutdown
void shutdown(oslSocketDirection Direction=osl_Socket_DirReadWrite)
Closes a definite or both directions of the bidirectional stream.
Definition: socket.hxx:261
byteseq.hxx
osl::Socket::bind
bool bind(const SocketAddr &LocalInterface)
Binds the socket to the specified (local) interface.
Definition: socket.hxx:317
osl::StreamSocket::read
sal_Int32 read(void *pBuffer, sal_uInt32 n)
Retrieves n bytes from the stream and copies them into pBuffer.
Definition: socket.hxx:441
osl::Socket::clearError
void clearError() const
clears the error status
Definition: socket.hxx:392
osl::SocketAddr::getLocalHostname
static inline ::rtl::OUString getLocalHostname(oslSocketResult *pResult=NULL)
Get the hostname for the local interface.
Definition: socket.hxx:179
oslSocketType
oslSocketType
Represents the type of a socket.
Definition: socket.h:67
osl::Socket::Socket
Socket()
socket.h