LibreOffice
LibreOffice 24.2 SDK C/C++ API Reference
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
osl::Socket Class Reference

#include <socket_decl.hxx>

Inheritance diagram for osl::Socket:
osl::AcceptorSocket osl::DatagramSocket osl::StreamSocket osl::ConnectorSocket

Public Member Functions

 Socket ()
 
 Socket (const Socket &socket)
 
 Socket (oslSocket socketHandle)
 
 Socket (oslSocket socketHandle, __sal_NoAcquire noacquire)
 The instance takes over the handle's ownership without acquiring the handle, but releases it within the dtor. More...
 
 ~Socket ()
 Destructor. More...
 
Socketoperator= (oslSocket socketHandle)
 Assignment operator. More...
 
Socketoperator= (const Socket &sock)
 Assignment operator. More...
 
bool operator== (const Socket &rSocket) const
 
bool operator== (const oslSocket socketHandle) const
 
void shutdown (oslSocketDirection Direction=osl_Socket_DirReadWrite)
 Closes a definite or both directions of the bidirectional stream. More...
 
void close ()
 Closes a socket. More...
 
void getLocalAddr (SocketAddr &Addr) const
 Retrieves the address of the local interface of this socket. More...
 
sal_Int32 getLocalPort () const
 Get the local port of the socket. More...
 
inline ::rtl::OUString getLocalHost () const
 Get the hostname for the local interface. More...
 
void getPeerAddr (SocketAddr &Addr) const
 Retrieves the address of the remote host of this socket. More...
 
sal_Int32 getPeerPort () const
 Get the remote port of the socket. More...
 
inline ::rtl::OUString getPeerHost () const
 Get the hostname for the remote interface. More...
 
bool bind (const SocketAddr &LocalInterface)
 Binds the socket to the specified (local) interface. More...
 
bool isRecvReady (const TimeValue *pTimeout=NULL) const
 Checks if read operations will block. More...
 
bool isSendReady (const TimeValue *pTimeout=NULL) const
 Checks if send operations will block. More...
 
bool isExceptionPending (const TimeValue *pTimeout=NULL) const
 Checks if a request for out-of-band data will block. More...
 
oslSocketType getType () const
 Queries the socket for its type. More...
 
sal_Int32 getOption (oslSocketOption Option, void *pBuffer, sal_uInt32 BufferLen, oslSocketOptionLevel Level=osl_Socket_LevelSocket) const
 Retrieves option-attributes associated with the socket. More...
 
bool setOption (oslSocketOption Option, void *pBuffer, sal_uInt32 BufferLen, oslSocketOptionLevel Level=osl_Socket_LevelSocket) const
 Sets the sockets attributes. More...
 
bool setOption (oslSocketOption option, sal_Int32 nValue)
 Convenience function for setting sal_Bool and sal_Int32 option values. More...
 
sal_Int32 getOption (oslSocketOption option) const
 Convenience function for retrieving sal_Bool and sal_Int32 option values. More...
 
bool enableNonBlockingMode (bool bNonBlockingMode)
 Enables/disables non-blocking mode of the socket. More...
 
bool isNonBlockingMode () const
 Query blocking mode of the socket. More...
 
void clearError () const
 clears the error status More...
 
oslSocketError getError () const
 returns a constant describing the last error for the socket system. More...
 
inline ::rtl::OUString getErrorAsString () const
 Builds a string with the last error-message for the socket. More...
 
oslSocket getHandle () const
 Returns the underlying handle unacquired (The caller must acquire it to keep it). More...
 

Protected Member Functions

 Socket (oslSocketType Type, oslAddrFamily Family=osl_Socket_FamilyInet, oslProtocol Protocol=osl_Socket_ProtocolIp)
 Creates a socket. More...
 

Protected Attributes

oslSocket m_handle
 

Constructor & Destructor Documentation

◆ Socket() [1/5]

osl::Socket::Socket ( oslSocketType  Type,
oslAddrFamily  Family = osl_Socket_FamilyInet,
oslProtocol  Protocol = osl_Socket_ProtocolIp 
)
inlineprotected

Creates a socket.

Note it's protected.

Parameters
Type
Family
Protocol

◆ Socket() [2/5]

osl::Socket::Socket ( )
inline

◆ Socket() [3/5]

osl::Socket::Socket ( const Socket socket)
inline

◆ Socket() [4/5]

osl::Socket::Socket ( oslSocket  socketHandle)
inline

◆ Socket() [5/5]

osl::Socket::Socket ( oslSocket  socketHandle,
__sal_NoAcquire  noacquire 
)
inline

The instance takes over the handle's ownership without acquiring the handle, but releases it within the dtor.

Parameters
socketHandlethe handle
noacquireuse SAL_NO_ACQUIRE

◆ ~Socket()

osl::Socket::~Socket ( )
inline

Destructor.

Releases the underlying handle

Member Function Documentation

◆ bind()

bool osl::Socket::bind ( const SocketAddr LocalInterface)
inline

Binds the socket to the specified (local) interface.

Parameters
LocalInterfaceAddress of the Interface
Returns
True if bind was successful.

◆ clearError()

void osl::Socket::clearError ( ) const
inline

clears the error status

◆ close()

void osl::Socket::close ( )
inline

Closes a socket.

Note that closing a socket is identical to shutdown( osl_Socket_DirReadWrite ), as the operating system distinguish both cases, both functions or offered in this API.

See also
osl_closeSocket()

◆ enableNonBlockingMode()

bool osl::Socket::enableNonBlockingMode ( bool  bNonBlockingMode)
inline

Enables/disables non-blocking mode of the socket.

Parameters
bNonBlockingModeIf true, blocking mode will be switched off If false, the socket will become a blocking socket (which is the default behaviour of a socket).
Returns
true if mode could be set.

◆ getError()

oslSocketError osl::Socket::getError ( ) const
inline

returns a constant describing the last error for the socket system.

Returns
osl_Socket_E_NONE if no error occurred, invalid_SocketError if an unknown (unmapped) error occurred, otherwise an enum describing the error.
See also
osl_getLastSocketError()

◆ getErrorAsString()

rtl::OUString osl::Socket::getErrorAsString ( ) const
inline

Builds a string with the last error-message for the socket.

◆ getHandle()

oslSocket osl::Socket::getHandle ( ) const
inline

Returns the underlying handle unacquired (The caller must acquire it to keep it).

◆ getLocalAddr()

void osl::Socket::getLocalAddr ( SocketAddr Addr) const
inline

Retrieves the address of the local interface of this socket.

Parameters
Addr[out] receives the address.
See also
osl_getLocalAddrOfSocket()

◆ getLocalHost()

rtl::OUString osl::Socket::getLocalHost ( ) const
inline

Get the hostname for the local interface.

Returns
the hostname or an empty string ("").

◆ getLocalPort()

sal_Int32 osl::Socket::getLocalPort ( ) const
inline

Get the local port of the socket.

Usually used after bind().

Returns
the port number or OSL_INVALID_PORT on errors.

◆ getOption() [1/2]

sal_Int32 osl::Socket::getOption ( oslSocketOption  Option,
void *  pBuffer,
sal_uInt32  BufferLen,
oslSocketOptionLevel  Level = osl_Socket_LevelSocket 
) const
inline

Retrieves option-attributes associated with the socket.

Parameters
OptionThe attribute to query. Valid values (depending on the Level) are:
  • osl_Socket_Option_Debug
    (sal_Bool) Socket debug flag 1 = enabled, 0 = disabled.

  • osl_Socket_OptionAcceptConn
  • osl_Socket_OptionReuseAddr
    (sal_Bool) Allows the socket to be bound to an address that is already in use. 1 = multiple bound allowed, 0 = no multiple bounds allowed

  • osl_Socket_OptionKeepAlive
    (sal_Bool) Keepalive packets are sent by the underlying socket. 1 = enabled, 0 = disabled

  • osl_Socket_OptionDontRoute
    (sal_Bool) Do not route: send directly to interface. 1 = do not route , 0 = routing possible

  • osl_Socket_OptionBroadcast
    (sal_Bool) Transmission of broadcast messages are allowed on the socket. 1 = transmission allowed, 0 = transmission disallowed

  • osl_Socket_OptionUseLoopback

  • osl_Socket_OptionLinger
    (linger) Linger on close if unsent data is present. linger has two members: l_onoff, l_linger l_onoff = 0 is off, l_onoff > 0 and l_linger= timeout in seconds.

  • osl_Socket_OptionOOBinLine

  • osl_Socket_OptionSndBuf
    (sal_Int32) Size of the send buffer in bytes. Data is sent after SndTimeo or when the buffer is full. This allows faster writing to the socket.

  • osl_Socket_OptionRcvBuf
    (sal_Int32) Size of the receive buffer in bytes. Data is sent after SndTimeo or when the buffer is full. This allows faster writing to the socket and larger packet sizes.

  • osl_Socket_OptionSndLowat

  • osl_Socket_OptionRcvLowat

  • osl_Socket_OptionSndTimeo
    (sal_Int32) Data is sent after this timeout. This allows gathering of data to send larger packages but increases latency times.

  • osl_Socket_OptionRcvTimeo

  • osl_Socket_OptionError
  • osl_Socket_OptionType

  • osl_Socket_OptionTcpNoDelay
    Disables the Nagle algorithm for send coalescing. (Do not collect data until a packet is full, instead send immediately. This increases network traffic but might improve latency-times.) 1 = disables the algorithm, 0 = keeps it enabled.

If not above mentioned otherwise, the options are only valid for level osl_Socket_LevelSocket.

Parameters
pBufferThe Buffer will be filled with the attribute.
BufferLenThe size of pBuffer.
LevelThe option level.

Valid values are:

  • osl_Socket_LevelSocket : Socket Level
  • osl_Socket_LevelTcp : Level of Transmission Control Protocol
Returns
The size of the attribute copied into pBuffer or -1 if an error occurred.

◆ getOption() [2/2]

sal_Int32 osl::Socket::getOption ( oslSocketOption  option) const
inline

Convenience function for retrieving sal_Bool and sal_Int32 option values.

See also
setOption()

◆ getPeerAddr()

void osl::Socket::getPeerAddr ( SocketAddr Addr) const
inline

Retrieves the address of the remote host of this socket.

Parameters
Addr[out] receives the address.

◆ getPeerHost()

rtl::OUString osl::Socket::getPeerHost ( ) const
inline

Get the hostname for the remote interface.

Returns
the hostname or an empty string ("").

◆ getPeerPort()

sal_Int32 osl::Socket::getPeerPort ( ) const
inline

Get the remote port of the socket.

Returns
the port number or OSL_INVALID_PORT on errors.

◆ getType()

oslSocketType osl::Socket::getType ( ) const
inline

Queries the socket for its type.

Return values
osl_Socket_TypeStream
osl_Socket_TypeDgram
osl_Socket_TypeRaw
osl_Socket_TypeRdm
osl_Socket_TypeSeqPacket
osl_invalid_SocketTypeif an error occurred

◆ isExceptionPending()

bool osl::Socket::isExceptionPending ( const TimeValue pTimeout = NULL) const
inline

Checks if a request for out-of-band data will block.

You can specify a timeout-value in seconds/nanoseconds that denotes how the operation will block if the Socket has no pending OOB data.

Returns
true if OOB-request operations (recv with appropriate flags) on the Socket will NOT block; false if it would block or if an error occurred.
Parameters
pTimeoutif 0, the operation will block without a timeout. Otherwise the specified amount of time.

◆ isNonBlockingMode()

bool osl::Socket::isNonBlockingMode ( ) const
inline

Query blocking mode of the socket.

Returns
true if non-blocking mode is set.

◆ isRecvReady()

bool osl::Socket::isRecvReady ( const TimeValue pTimeout = NULL) const
inline

Checks if read operations will block.

You can specify a timeout-value in seconds/nanoseconds that denotes how the operation will block if the Socket is not ready.

Returns
true if read operations (recv, recvFrom, accept) on the Socket will NOT block; false if it would block or if an error occurred.
Parameters
pTimeoutif 0, the operation will block without a timeout. Otherwise the specified amount of time.

◆ isSendReady()

bool osl::Socket::isSendReady ( const TimeValue pTimeout = NULL) const
inline

Checks if send operations will block.

You can specify a timeout-value in seconds/nanoseconds that denotes how the operation will block if the Socket is not ready.

Returns
true if send operations (send, sendTo) on the Socket will NOT block; false if it would block or if an error occurred.
Parameters
pTimeoutif 0, the operation will block without a timeout. Otherwise the specified amount of time.

◆ operator=() [1/2]

Socket & osl::Socket::operator= ( oslSocket  socketHandle)
inline

Assignment operator.

If socket was already created, the old one will be discarded.

◆ operator=() [2/2]

Socket & osl::Socket::operator= ( const Socket sock)
inline

Assignment operator.

If socket was already created, the old one will be discarded.

◆ operator==() [1/2]

bool osl::Socket::operator== ( const Socket rSocket) const
inline
Returns
true, when the underlying handle of both Socket instances are identical, false otherwise.

◆ operator==() [2/2]

bool osl::Socket::operator== ( const oslSocket  socketHandle) const
inline
Returns
true, when the underlying handle of both Socket instances are identical, false otherwise.

◆ setOption() [1/2]

bool osl::Socket::setOption ( oslSocketOption  Option,
void *  pBuffer,
sal_uInt32  BufferLen,
oslSocketOptionLevel  Level = osl_Socket_LevelSocket 
) const
inline

Sets the sockets attributes.

Parameters
Optiondenotes the option to modify. Valid values (depending on the Level) are:
  • osl_Socket_Option_Debug
  • osl_Socket_OptionAcceptConn
  • osl_Socket_OptionReuseAddr
  • osl_Socket_OptionKeepAlive
  • osl_Socket_OptionDontRoute
  • osl_Socket_OptionBroadcast
  • osl_Socket_OptionUseLoopback
  • osl_Socket_OptionLinger
  • osl_Socket_OptionOOBinLine
  • osl_Socket_OptionSndBuf
  • osl_Socket_OptionRcvBuf
  • osl_Socket_OptionSndLowat
  • osl_Socket_OptionRcvLowat
  • osl_Socket_OptionSndTimeo
  • osl_Socket_OptionRcvTimeo
  • osl_Socket_OptionError
  • osl_Socket_OptionType
  • osl_Socket_OptionTcpNoDelay

If not above mentioned otherwise, the options are only valid for level osl_Socket_LevelSocket.

Parameters
pBufferPointer to a Buffer which contains the attribute-value.
BufferLencontains the length of the Buffer.
Levelselects the level for which an option should be changed. Valid values are:
  • osl_Socket_evel_Socket : Socket Level
  • osl_Socket_Level_Tcp : Level of Transmission Control Protocol
Returns
True if the option could be changed.

◆ setOption() [2/2]

bool osl::Socket::setOption ( oslSocketOption  option,
sal_Int32  nValue 
)
inline

Convenience function for setting sal_Bool and sal_Int32 option values.

See also
setOption()

◆ shutdown()

void osl::Socket::shutdown ( oslSocketDirection  Direction = osl_Socket_DirReadWrite)
inline

Closes a definite or both directions of the bidirectional stream.

Parameters
Direction
See also
osl_shutdownSocket()

Member Data Documentation

◆ m_handle

oslSocket osl::Socket::m_handle
protected

The documentation for this class was generated from the following files: