LibreOfficeDev
LibreOfficeDev 27.2 SDK C/C++ API Reference
socket.h
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 /*
21  * This file is part of LibreOffice published API.
22  */
23 
24 #ifndef INCLUDED_OSL_SOCKET_H
25 #define INCLUDED_OSL_SOCKET_H
26 
27 #include "rtl/ustring.h"
28 
29 #if defined LIBO_INTERNAL_ONLY && defined __cplusplus
30 struct TimeValue;
31 #else
32 #include "osl/time.h"
33 #endif
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38 
39 /* error returns */
40 #define OSL_INADDR_NONE 0xffffffff
41 #define OSL_INVALID_PORT (-1)
42 
49 typedef struct oslSocketAddrImpl * oslSocketAddr;
50 
54 typedef enum {
60 
64 typedef enum {
72 
76 typedef enum {
89 
90 
94 typedef enum {
126 
130 typedef enum {
136 
140 typedef enum {
149 
153 typedef enum {
160 
163 typedef enum {
199 
202 typedef enum {
211 
214 
221 typedef struct oslSocketImpl * oslSocket;
222 
230  oslAddrFamily Family,
231  oslSocketType Type,
232  oslProtocol Protocol);
233 
237 
244 
253 
261 
270  oslSocket Socket,
271  oslSocketAddr Addr);
272 
285  oslSocket Socket,
286  oslSocketAddr Addr,
287  const TimeValue* pTimeout);
288 
289 
299  oslSocket Socket,
300  sal_Int32 MaxPendingConnections);
301 
302 
311  oslSocket Socket,
312  oslSocketAddr* pAddr);
313 
332 SAL_DLLPUBLIC sal_Int32 SAL_CALL osl_receiveSocket(
333  oslSocket Socket,
334  void* pBuffer,
335  sal_uInt32 BytesToRead,
336  oslSocketMsgFlag Flag);
337 
359  oslSocket Socket,
360  oslSocketAddr SenderAddr,
361  void* pBuffer,
362  sal_uInt32 BufferSize,
363  oslSocketMsgFlag Flag);
364 
381 SAL_DLLPUBLIC sal_Int32 SAL_CALL osl_sendSocket(
382  oslSocket Socket,
383  const void* pBuffer,
384  sal_uInt32 BytesToSend,
385  oslSocketMsgFlag Flag);
386 
413 SAL_DLLPUBLIC sal_Int32 SAL_CALL osl_sendToSocket(
414  oslSocket Socket,
415  oslSocketAddr ReceiverAddr,
416  const void* pBuffer,
417  sal_uInt32 BytesToSend,
418  oslSocketMsgFlag Flag);
419 
433  oslSocket Socket,
434  const TimeValue* pTimeout);
435 
449  oslSocket Socket,
450  const TimeValue* pTimeout);
451 
464  oslSocket Socket,
465  const TimeValue* pTimeout);
466 
480  oslSocket Socket,
481  oslSocketDirection Direction);
482 
537  oslSocket Socket,
538  oslSocketOptionLevel Level,
539  oslSocketOption Option,
540  void* pBuffer,
541  sal_uInt32 BufferLen);
542 
561  oslSocket Socket,
562  oslSocketOptionLevel Level,
563  oslSocketOption Option,
564  void* pBuffer,
565  sal_uInt32 BufferLen);
566 
575  oslSocket Socket,
576  sal_Bool On);
577 
578 
586 
599 
606  oslSocket Socket,
607  rtl_uString **strError);
608 
616  oslSocket Socket);
617 
623 
624 
636 SAL_DLLPUBLIC sal_Int32 SAL_CALL osl_readSocket(
637  oslSocket Socket,
638  void *pBuffer,
639  sal_Int32 nSize);
640 
641 
652 SAL_DLLPUBLIC sal_Int32 SAL_CALL osl_writeSocket(
653  oslSocket Socket,
654  const void *pBuffer,
655  sal_Int32 nSize);
656 
668  oslAddrFamily Family);
669 
670 
674  oslSocketAddr Addr);
675 
681  oslSocketAddr Addr1, oslSocketAddr Addr2);
682 
689  rtl_uString *strHostname);
690 
701  rtl_uString *strDottedAddr, sal_Int32 Port);
702 
703 
712  rtl_uString *strDottedAddr, sal_Int32 Port);
713 
714 
719  oslSocketAddr Addr);
720 
726  rtl_uString *strServicename, rtl_uString *strProtocol);
727 
728 
729 
735  oslSocketAddr Addr);
736 
737 
743  oslSocketAddr Addr);
744 
745 
752  oslSocketAddr Addr, sal_Int32 Port);
753 
754 
761  oslSocketAddr Addr, rtl_uString **strHostname);
762 
763 
775  oslSocketAddr Addr, rtl_uString **strDottedInetAddr);
776 
780  oslSocketAddr Addr, sal_Sequence *pByteSeq );
781 
790  oslSocketAddr Addr, sal_Sequence **ppByteSeq );
791 
792 /*
793  Opaque datatype HostAddr.
794 */
795 typedef struct oslHostAddrImpl * oslHostAddr;
796 
797 
804  rtl_uString *strHostname, const oslSocketAddr Addr);
805 
806 
814 SAL_DLLPUBLIC oslHostAddr SAL_CALL osl_createHostAddrByName(rtl_uString *strHostname);
815 
816 
825 
826 
831 
832 
837 
838 
843 SAL_DLLPUBLIC void SAL_CALL osl_getHostnameOfHostAddr(const oslHostAddr Addr, rtl_uString **strHostname);
844 
845 
850 
856 SAL_DLLPUBLIC oslSocketResult SAL_CALL osl_getLocalHostname(rtl_uString **strLocalHostname);
857 
858 
862 #ifdef __cplusplus
863 }
864 #endif
865 
866 #endif // INCLUDED_OSL_SOCKET_H
867 
868 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define SAL_DLLPUBLIC
Definition: saldllapi.h:34
#define SAL_MAX_ENUM
Definition: types.h:205
unsigned char sal_uInt8
Definition: types.h:44
unsigned char sal_Bool
Definition: types.h:38
oslSocketOption
Represents socket-options.
Definition: socket.h:94
@ osl_Socket_OptionSndBuf
Definition: socket.h:109
@ osl_Socket_OptionTcpNoDelay
Definition: socket.h:122
@ osl_Socket_OptionSndLowat
Definition: socket.h:111
@ osl_Socket_OptionSndTimeo
Definition: socket.h:117
@ osl_Socket_OptionDebug
Definition: socket.h:95
@ osl_Socket_OptionReuseAddr
Definition: socket.h:97
@ osl_Socket_OptionDontRoute
Definition: socket.h:99
@ osl_Socket_OptionRcvLowat
Definition: socket.h:114
@ osl_Socket_OptionRcvBuf
Definition: socket.h:110
@ osl_Socket_OptionType
Definition: socket.h:120
@ osl_Socket_OptionError
Definition: socket.h:119
@ osl_Socket_OptionAcceptConn
Definition: socket.h:96
@ osl_Socket_OptionInvalid
Definition: socket.h:123
@ osl_Socket_OptionKeepAlive
Definition: socket.h:98
@ osl_Socket_OptionOOBinLine
Definition: socket.h:107
@ osl_Socket_Option_FORCE_EQUAL_SIZE
Definition: socket.h:124
@ osl_Socket_OptionBroadcast
Definition: socket.h:101
@ osl_Socket_OptionLinger
Definition: socket.h:104
@ osl_Socket_OptionUseLoopback
Definition: socket.h:102
@ osl_Socket_OptionRcvTimeo
Definition: socket.h:118
SAL_DLLPUBLIC sal_Bool osl_setInetPortOfSocketAddr(oslSocketAddr Addr, sal_Int32 Port)
Sets the Port of Addr.
SAL_DLLPUBLIC sal_Int32 osl_getSocketOption(oslSocket Socket, oslSocketOptionLevel Level, oslSocketOption Option, void *pBuffer, sal_uInt32 BufferLen)
Retrieves attributes associated with the socket.
SAL_DLLPUBLIC sal_Int32 osl_getInetPortOfSocketAddr(oslSocketAddr Addr)
Retrieves the internet port-number of Addr.
SAL_DLLPUBLIC oslSocketResult osl_getAddrOfSocketAddr(oslSocketAddr Addr, sal_Sequence **ppByteSeq)
Returns the addr field in the struct sockaddr.
SAL_DLLPUBLIC sal_Bool osl_listenOnSocket(oslSocket Socket, sal_Int32 MaxPendingConnections)
Prepares the socket to act as an acceptor of incoming connections.
SAL_DLLPUBLIC oslHostAddr osl_createHostAddrByName(rtl_uString *strHostname)
Create an oslHostAddr by resolving the given strHostname.
SAL_DLLPUBLIC oslHostAddr osl_createHostAddrByAddr(const oslSocketAddr Addr)
Create an oslHostAddr by reverse resolution of the given Addr.
oslSocketResult
Common return codes of socket related functions.
Definition: socket.h:202
@ osl_Socket_InProgress
Definition: socket.h:208
@ osl_Socket_Ok
Definition: socket.h:203
@ osl_Socket_Error
Definition: socket.h:204
@ osl_Socket_FORCE_EQUAL_SIZE
Definition: socket.h:209
@ osl_Socket_TimedOut
Definition: socket.h:206
@ osl_Socket_Interrupted
Definition: socket.h:207
struct oslSocketAddrImpl * oslSocketAddr
Opaque datatype SocketAddr.
Definition: socket.h:49
SAL_DLLPUBLIC sal_Bool osl_bindAddrToSocket(oslSocket Socket, oslSocketAddr Addr)
Binds the given address to the socket.
SAL_DLLPUBLIC oslSocket osl_acceptConnectionOnSocket(oslSocket Socket, oslSocketAddr *pAddr)
Waits for an ingoing connection on the socket.
SAL_DLLPUBLIC void osl_getHostnameOfHostAddr(const oslHostAddr Addr, rtl_uString **strHostname)
Get the hostname member of Addr.
struct oslHostAddrImpl * oslHostAddr
Definition: socket.h:795
SAL_DLLPUBLIC void osl_closeSocket(oslSocket Socket)
Closes the socket terminating any ongoing dataflow.
SAL_DLLPUBLIC void osl_acquireSocket(oslSocket Socket)
increases the refcount of the socket handle by one
SAL_DLLPUBLIC oslHostAddr osl_createHostAddr(rtl_uString *strHostname, const oslSocketAddr Addr)
Create an oslHostAddr from given hostname and socket address.
SAL_DLLPUBLIC sal_Bool osl_isSendReady(oslSocket Socket, const TimeValue *pTimeout)
Checks if send operations will block.
SAL_DLLPUBLIC oslSocketResult osl_setAddrOfSocketAddr(oslSocketAddr Addr, sal_Sequence *pByteSeq)
Sets the addr field in the struct sockaddr with pByteSeq.
SAL_DLLPUBLIC oslSocketResult osl_getDottedInetAddrOfSocketAddr(oslSocketAddr Addr, rtl_uString **strDottedInetAddr)
Gets the address in dotted decimal format.
SAL_DLLPUBLIC void osl_releaseSocket(oslSocket Socket)
decreases the refcount of the socket handle by one.
oslSocketType
Represents the type of a socket.
Definition: socket.h:76
@ osl_Socket_TypeStream
Definition: socket.h:77
@ osl_Socket_TypeRdm
Definition: socket.h:80
@ osl_Socket_TypeSeqPacket
Definition: socket.h:83
@ osl_Socket_Type_FORCE_EQUAL_SIZE
Definition: socket.h:87
@ osl_Socket_TypeInvalid
Definition: socket.h:86
@ osl_Socket_TypeRaw
Definition: socket.h:79
@ osl_Socket_TypeDgram
Definition: socket.h:78
SAL_DLLPUBLIC oslSocketError osl_getLastSocketError(oslSocket Socket)
Returns a constant describing the last error for the socket system.
SAL_DLLPUBLIC oslSocketAddr osl_createInetBroadcastAddr(rtl_uString *strDottedAddr, sal_Int32 Port)
Create an internet address usable for sending broadcast datagrams.
SAL_DLLPUBLIC sal_Bool osl_isNonBlockingMode(oslSocket Socket)
Query state of non-blocking-mode of the socket.
SAL_DLLPUBLIC void osl_destroySocketAddr(oslSocketAddr Addr)
Frees all resources allocated by Addr.
SAL_DLLPUBLIC oslSocketAddr osl_getLocalAddrOfSocket(oslSocket Socket)
Retrieves the Address of the local end of the socket.
SAL_DLLPUBLIC sal_Bool osl_isReceiveReady(oslSocket Socket, const TimeValue *pTimeout)
Checks if read operations will block.
SAL_DLLPUBLIC oslSocketType osl_getSocketType(oslSocket Socket)
Queries the socket for its type.
SAL_DLLPUBLIC sal_Bool osl_setSocketOption(oslSocket Socket, oslSocketOptionLevel Level, oslSocketOption Option, void *pBuffer, sal_uInt32 BufferLen)
Sets the sockets attributes.
struct oslSocketImpl * oslSocket
Definition: socket.h:221
SAL_DLLPUBLIC sal_Int32 osl_receiveSocket(oslSocket Socket, void *pBuffer, sal_uInt32 BytesToRead, oslSocketMsgFlag Flag)
Tries to receive BytesToRead data from the connected socket, if no error occurs.
SAL_DLLPUBLIC oslSocket osl_createSocket(oslAddrFamily Family, oslSocketType Type, oslProtocol Protocol)
Create a socket of the specified Family and Type.
SAL_DLLPUBLIC sal_Int32 osl_writeSocket(oslSocket Socket, const void *pBuffer, sal_Int32 nSize)
Writes n bytes from pBuffer to the stream.
oslSocketOptionLevel
Represents the different socket-option levels.
Definition: socket.h:130
@ osl_Socket_LevelTcp
Definition: socket.h:132
@ osl_Socket_LevelInvalid
Definition: socket.h:133
@ osl_Socket_Level_FORCE_EQUAL_SIZE
Definition: socket.h:134
@ osl_Socket_LevelSocket
Definition: socket.h:131
SAL_DLLPUBLIC oslSocketAddr osl_createInetSocketAddr(rtl_uString *strDottedAddr, sal_Int32 Port)
Create an internet-address, consisting of host address and port.
SAL_DLLPUBLIC oslHostAddr osl_copyHostAddr(const oslHostAddr Addr)
Create a copy of the given Addr.
SAL_DLLPUBLIC oslSocketAddr osl_createEmptySocketAddr(oslAddrFamily Family)
Creates a socket-address for the given family.
SAL_DLLPUBLIC oslSocketAddr osl_getPeerAddrOfSocket(oslSocket Socket)
Retrieves the Address of the remote end of the socket.
oslSocketDirection
Used by shutdown to denote which end of the socket to "close".
Definition: socket.h:153
@ osl_Socket_DirRead
Definition: socket.h:154
@ osl_Socket_DirWrite
Definition: socket.h:155
@ osl_Socket_DirInvalid
Definition: socket.h:157
@ osl_Socket_Dir_FORCE_EQUAL_SIZE
Definition: socket.h:158
@ osl_Socket_DirReadWrite
Definition: socket.h:156
SAL_DLLPUBLIC sal_Int32 osl_readSocket(oslSocket Socket, void *pBuffer, sal_Int32 nSize)
Retrieves n bytes from the stream and copies them into pBuffer.
SAL_DLLPUBLIC sal_Int32 osl_sendToSocket(oslSocket Socket, oslSocketAddr ReceiverAddr, const void *pBuffer, sal_uInt32 BytesToSend, oslSocketMsgFlag Flag)
Tries to send one datagram with BytesToSend data to the given ReceiverAddr via the (implicitly unconn...
SAL_DLLPUBLIC sal_Int32 osl_sendSocket(oslSocket Socket, const void *pBuffer, sal_uInt32 BytesToSend, oslSocketMsgFlag Flag)
Tries to send BytesToSend data from the connected socket, if no error occurs.
SAL_DLLPUBLIC sal_Bool osl_enableNonBlockingMode(oslSocket Socket, sal_Bool On)
Enables/disables non-blocking-mode of the socket.
oslProtocol
represent a specific protocol within an address-family
Definition: socket.h:64
@ osl_Socket_ProtocolIpx
Definition: socket.h:66
@ osl_Socket_ProtocolInvalid
Definition: socket.h:69
@ osl_Socket_ProtocolSpx
Definition: socket.h:67
@ osl_Socket_Protocol_FORCE_EQUAL_SIZE
Definition: socket.h:70
@ osl_Socket_ProtocolSpxII
Definition: socket.h:68
@ osl_Socket_ProtocolIp
Definition: socket.h:65
oslSocketError
Describes the various error socket error conditions, which may occur.
Definition: socket.h:163
@ osl_Socket_E_ProtocolNoSupport
Definition: socket.h:170
@ osl_Socket_E_TimedOut
Definition: socket.h:189
@ osl_Socket_E_WouldBlock
Definition: socket.h:193
@ osl_Socket_E_NetUnreachable
Definition: socket.h:179
@ osl_Socket_E_DestAddrReq
Definition: socket.h:166
@ osl_Socket_E_Already
Definition: socket.h:194
@ osl_Socket_E_HostUnreachable
Definition: socket.h:192
@ osl_Socket_E_HostDown
Definition: socket.h:191
@ osl_Socket_E_NotSocket
Definition: socket.h:165
@ osl_Socket_E_IsConnected
Definition: socket.h:185
@ osl_Socket_E_Shutdown
Definition: socket.h:187
@ osl_Socket_E_ConnAborted
Definition: socket.h:182
@ osl_Socket_E_TooManyRefs
Definition: socket.h:188
@ osl_Socket_E_TypeNoSupport
Definition: socket.h:171
@ osl_Socket_E_MsgSize
Definition: socket.h:167
@ osl_Socket_E_NetReset
Definition: socket.h:180
@ osl_Socket_E_PfNoSupport
Definition: socket.h:173
@ osl_Socket_E_AfNoSupport
Definition: socket.h:174
@ osl_Socket_E_None
Definition: socket.h:164
@ osl_Socket_E_InProgress
Definition: socket.h:195
@ osl_Socket_E_AddrInUse
Definition: socket.h:176
@ osl_Socket_E_Prototype
Definition: socket.h:168
@ osl_Socket_E_ConnReset
Definition: socket.h:183
@ osl_Socket_E_NotConnected
Definition: socket.h:186
@ osl_Socket_E_NoBufferSpace
Definition: socket.h:184
@ osl_Socket_E_NoProtocol
Definition: socket.h:169
@ osl_Socket_E_OpNotSupport
Definition: socket.h:172
@ osl_Socket_E_ConnRefused
Definition: socket.h:190
@ osl_Socket_E_FORCE_EQUAL_SIZE
Definition: socket.h:197
@ osl_Socket_E_NetDown
Definition: socket.h:178
@ osl_Socket_E_InvalidError
Definition: socket.h:196
@ osl_Socket_E_AddrNotAvail
Definition: socket.h:177
sal_uInt8 oslSocketIpxNetNumber[4]
Definition: socket.h:212
SAL_DLLPUBLIC sal_Int32 osl_receiveFromSocket(oslSocket Socket, oslSocketAddr SenderAddr, void *pBuffer, sal_uInt32 BufferSize, oslSocketMsgFlag Flag)
Tries to receives BufferSize data from the (usually unconnected) (datagram-)socket,...
sal_uInt8 oslSocketIpxNodeNumber[6]
Definition: socket.h:213
oslAddrFamily
Represents the address-family of a socket.
Definition: socket.h:54
@ osl_Socket_FamilyInvalid
Definition: socket.h:57
@ osl_Socket_Family_FORCE_EQUAL_SIZE
Definition: socket.h:58
@ osl_Socket_FamilyInet
Definition: socket.h:55
@ osl_Socket_FamilyIpx
Definition: socket.h:56
SAL_DLLPUBLIC oslSocketResult osl_connectSocketTo(oslSocket Socket, oslSocketAddr Addr, const TimeValue *pTimeout)
Connects the socket to the given address.
SAL_DLLPUBLIC void osl_destroyHostAddr(oslHostAddr Addr)
Frees all resources allocated by Addr.
SAL_DLLPUBLIC oslSocketResult osl_getLocalHostname(rtl_uString **strLocalHostname)
Retrieve this machines hostname (NOT the FQDN)
SAL_DLLPUBLIC oslSocketAddr osl_getSocketAddrOfHostAddr(const oslHostAddr Addr)
Get the socket address member of Addr.
SAL_DLLPUBLIC sal_Int32 osl_getServicePort(rtl_uString *strServicename, rtl_uString *strProtocol)
Looks up the port-number designated to the specified service/protocol-pair.
SAL_DLLPUBLIC oslSocketAddr osl_resolveHostname(rtl_uString *strHostname)
Uses the systems name-service interface to find an address for strHostname.
SAL_DLLPUBLIC oslSocketResult osl_getHostnameOfSocketAddr(oslSocketAddr Addr, rtl_uString **strHostname)
Returns the hostname represented by Addr.
oslSocketMsgFlag
Represents flags to be used with send/recv-calls.
Definition: socket.h:140
@ osl_Socket_MsgDontRoute
Definition: socket.h:144
@ osl_Socket_MsgNormal
Definition: socket.h:141
@ osl_Socket_Msg_FORCE_EQUAL_SIZE
Definition: socket.h:147
@ osl_Socket_MsgInvalid
Definition: socket.h:146
@ osl_Socket_MsgMaxIOVLen
Definition: socket.h:145
@ osl_Socket_MsgPeek
Definition: socket.h:143
@ osl_Socket_MsgOOB
Definition: socket.h:142
SAL_DLLPUBLIC oslSocketAddr osl_copySocketAddr(oslSocketAddr Addr)
Creates a new SocketAddress and fills it from Addr.
SAL_DLLPUBLIC sal_Bool osl_isExceptionPending(oslSocket Socket, const TimeValue *pTimeout)
Checks if a request for out-of-band data will block.
SAL_DLLPUBLIC void osl_getLastSocketErrorDescription(oslSocket Socket, rtl_uString **strError)
returns a string which describes the last socket error.
SAL_DLLPUBLIC sal_Bool osl_isEqualSocketAddr(oslSocketAddr Addr1, oslSocketAddr Addr2)
Compares the values of two SocketAddresses.
SAL_DLLPUBLIC sal_Bool osl_shutdownSocket(oslSocket Socket, oslSocketDirection Direction)
Shuts down communication on a connected socket.
SAL_DLLPUBLIC oslAddrFamily osl_getFamilyOfSocketAddr(oslSocketAddr Addr)
Retrieves the address-family from the Addr.
This is the binary specification of a SAL sequence.
Definition: types.h:322
Time since Jan-01-1970.
Definition: time.h:76