LibreOffice
LibreOffice 7.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 #include "osl/time.h"
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 /* error returns */
35 #define OSL_INADDR_NONE 0xffffffff
36 #define OSL_INVALID_PORT (-1)
37 
44 typedef struct oslSocketAddrImpl * oslSocketAddr;
45 
49 typedef enum {
55 
59 typedef enum {
66 } oslProtocol;
67 
71 typedef enum {
84 
85 
89 typedef enum {
121 
125 typedef enum {
131 
135 typedef enum {
144 
148 typedef enum {
155 
158 typedef enum {
194 
197 typedef enum {
206 
209 
216 typedef struct oslSocketImpl * oslSocket;
217 
225  oslAddrFamily Family,
226  oslSocketType Type,
227  oslProtocol Protocol);
228 
231 SAL_DLLPUBLIC void SAL_CALL osl_acquireSocket(oslSocket Socket);
232 
238 SAL_DLLPUBLIC void SAL_CALL osl_releaseSocket(oslSocket Socket);
239 
248 
256 
265  oslSocket Socket,
266  oslSocketAddr Addr);
267 
280  oslSocket Socket,
281  oslSocketAddr Addr,
282  const TimeValue* pTimeout);
283 
284 
294  oslSocket Socket,
295  sal_Int32 MaxPendingConnections);
296 
297 
306  oslSocket Socket,
307  oslSocketAddr* pAddr);
308 
327 SAL_DLLPUBLIC sal_Int32 SAL_CALL osl_receiveSocket(
328  oslSocket Socket,
329  void* pBuffer,
330  sal_uInt32 BytesToRead,
331  oslSocketMsgFlag Flag);
332 
353 SAL_DLLPUBLIC sal_Int32 SAL_CALL osl_receiveFromSocket(
354  oslSocket Socket,
355  oslSocketAddr SenderAddr,
356  void* pBuffer,
357  sal_uInt32 BufferSize,
358  oslSocketMsgFlag Flag);
359 
376 SAL_DLLPUBLIC sal_Int32 SAL_CALL osl_sendSocket(
377  oslSocket Socket,
378  const void* pBuffer,
379  sal_uInt32 BytesToSend,
380  oslSocketMsgFlag Flag);
381 
408 SAL_DLLPUBLIC sal_Int32 SAL_CALL osl_sendToSocket(
409  oslSocket Socket,
410  oslSocketAddr ReceiverAddr,
411  const void* pBuffer,
412  sal_uInt32 BytesToSend,
413  oslSocketMsgFlag Flag);
414 
428  oslSocket Socket,
429  const TimeValue* pTimeout);
430 
444  oslSocket Socket,
445  const TimeValue* pTimeout);
446 
459  oslSocket Socket,
460  const TimeValue* pTimeout);
461 
475  oslSocket Socket,
476  oslSocketDirection Direction);
477 
531 SAL_DLLPUBLIC sal_Int32 SAL_CALL osl_getSocketOption(
532  oslSocket Socket,
533  oslSocketOptionLevel Level,
534  oslSocketOption Option,
535  void* pBuffer,
536  sal_uInt32 BufferLen);
537 
556  oslSocket Socket,
557  oslSocketOptionLevel Level,
558  oslSocketOption Option,
559  void* pBuffer,
560  sal_uInt32 BufferLen);
561 
570  oslSocket Socket,
571  sal_Bool On);
572 
573 
581 
594 
601  oslSocket Socket,
602  rtl_uString **strError);
603 
611  oslSocket Socket);
612 
617 typedef struct oslSocketSetImpl * oslSocketSet;
618 
626 
632 
640 
641 
649 SAL_DLLPUBLIC void SAL_CALL osl_addToSocketSet(oslSocketSet Set, oslSocket Socket);
650 
659 
670 
687 SAL_DLLPUBLIC sal_Int32 SAL_CALL osl_demultiplexSocketEvents(
688  oslSocketSet IncomingSet,
689  oslSocketSet OutgoingSet,
690  oslSocketSet OutOfBandSet,
691  const TimeValue* pTimeout);
692 
697 SAL_DLLPUBLIC void SAL_CALL osl_closeSocket(oslSocket Socket);
698 
699 
711 SAL_DLLPUBLIC sal_Int32 SAL_CALL osl_readSocket(
712  oslSocket Socket,
713  void *pBuffer,
714  sal_Int32 nSize);
715 
716 
727 SAL_DLLPUBLIC sal_Int32 SAL_CALL osl_writeSocket(
728  oslSocket Socket,
729  const void *pBuffer,
730  sal_Int32 nSize);
731 
743  oslAddrFamily Family);
744 
745 
749  oslSocketAddr Addr);
750 
756  oslSocketAddr Addr1, oslSocketAddr Addr2);
757 
764  rtl_uString *strHostname);
765 
776  rtl_uString *strDottedAddr, sal_Int32 Port);
777 
778 
787  rtl_uString *strDottedAddr, sal_Int32 Port);
788 
789 
794  oslSocketAddr Addr);
795 
800 SAL_DLLPUBLIC sal_Int32 SAL_CALL osl_getServicePort(
801  rtl_uString *strServicename, rtl_uString *strProtocol);
802 
803 
804 
810  oslSocketAddr Addr);
811 
812 
817 SAL_DLLPUBLIC sal_Int32 SAL_CALL osl_getInetPortOfSocketAddr(
818  oslSocketAddr Addr);
819 
820 
827  oslSocketAddr Addr, sal_Int32 Port);
828 
829 
836  oslSocketAddr Addr, rtl_uString **strHostname);
837 
838 
850  oslSocketAddr Addr, rtl_uString **strDottedInetAddr);
851 
855  oslSocketAddr Addr, sal_Sequence *pByteSeq );
856 
865  oslSocketAddr Addr, sal_Sequence **ppByteSeq );
866 
867 /*
868  Opaque datatype HostAddr.
869 */
870 typedef struct oslHostAddrImpl * oslHostAddr;
871 
872 
879  rtl_uString *strHostname, const oslSocketAddr Addr);
880 
881 
889 SAL_DLLPUBLIC oslHostAddr SAL_CALL osl_createHostAddrByName(rtl_uString *strHostname);
890 
891 
900 
901 
906 
907 
911 SAL_DLLPUBLIC void SAL_CALL osl_destroyHostAddr(oslHostAddr Addr);
912 
913 
917 SAL_DLLPUBLIC void SAL_CALL osl_getHostnameOfHostAddr(const oslHostAddr Addr, rtl_uString **strHostname);
918 
919 
924 
930 SAL_DLLPUBLIC oslSocketResult SAL_CALL osl_getLocalHostname(rtl_uString **strLocalHostname);
931 
932 
936 #ifdef __cplusplus
937 }
938 #endif
939 
940 #endif // INCLUDED_OSL_SOCKET_H
941 
942 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Definition: socket.h:72
Definition: socket.h:115
oslProtocol
represent a specific protocol within an address-family
Definition: socket.h:59
Definition: socket.h:127
Definition: socket.h:141
SAL_DLLPUBLIC void osl_getLastSocketErrorDescription(oslSocket Socket, rtl_uString **strError)
returns a string which describes the last socket error.
Definition: socket.h:171
Definition: socket.h:151
SAL_DLLPUBLIC oslSocketAddr osl_copySocketAddr(oslSocketAddr Addr)
Creates a new SocketAddress and fills it from Addr.
SAL_DLLPUBLIC sal_Bool osl_isReceiveReady(oslSocket Socket, const TimeValue *pTimeout)
Checks if read operations will block.
SAL_DLLPUBLIC void osl_destroySocketAddr(oslSocketAddr Addr)
Frees all resources allocated by Addr.
oslSocketOption
Represents socket-options.
Definition: socket.h:89
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_getInetPortOfSocketAddr(oslSocketAddr Addr)
Retrieves the internet port-number of Addr.
Definition: socket.h:60
Definition: socket.h:198
Definition: socket.h:161
SAL_DLLPUBLIC sal_Int32 osl_getServicePort(rtl_uString *strServicename, rtl_uString *strProtocol)
Looks up the port-number designated to the specified service/protocol-pair.
Definition: socket.h:167
SAL_DLLPUBLIC oslAddrFamily osl_getFamilyOfSocketAddr(oslSocketAddr Addr)
Retrieves the address-family from the Addr.
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, if no error occurs.
oslSocketResult
Common return codes of socket related functions.
Definition: socket.h:197
SAL_DLLPUBLIC sal_Bool osl_setSocketOption(oslSocket Socket, oslSocketOptionLevel Level, oslSocketOption Option, void *pBuffer, sal_uInt32 BufferLen)
Sets the sockets attributes.
SAL_DLLPUBLIC oslSocket osl_createSocket(oslAddrFamily Family, oslSocketType Type, oslProtocol Protocol)
Create a socket of the specified Family and Type.
SAL_DLLPUBLIC void osl_destroySocketSet(oslSocketSet Set)
Destroys an oslSocketSet.
#define SAL_DLLPUBLIC
Definition: saldllapi.h:34
struct oslSocketSetImpl * oslSocketSet
Type for the representation of socket sets.
Definition: socket.h:616
Definition: socket.h:152
Definition: socket.h:61
Definition: socket.h:174
Definition: socket.h:186
Definition: socket.h:140
oslAddrFamily
Represents the address-family of a socket.
Definition: socket.h:49
Definition: socket.h:126
Definition: socket.h:202
Definition: socket.h:81
Definition: socket.h:204
Definition: socket.h:97
Definition: socket.h:63
SAL_DLLPUBLIC oslSocketResult osl_getAddrOfSocketAddr(oslSocketAddr Addr, sal_Sequence **ppByteSeq)
Returns the addr field in the struct sockaddr.
sal_uInt8 oslSocketIpxNetNumber[4]
Definition: socket.h:207
This is the binary specification of a SAL sequence.
Definition: types.h:303
SAL_DLLPUBLIC sal_Bool osl_isExceptionPending(oslSocket Socket, const TimeValue *pTimeout)
Checks if a request for out-of-band data will block.
Definition: socket.h:178
SAL_DLLPUBLIC sal_Bool osl_enableNonBlockingMode(oslSocket Socket, sal_Bool On)
Enables/disables non-blocking-mode of the socket.
SAL_DLLPUBLIC oslHostAddr osl_createHostAddr(rtl_uString *strHostname, const oslSocketAddr Addr)
Create an oslHostAddr from given hostname and socket address.
Definition: socket.h:162
Definition: socket.h:94
Definition: socket.h:53
Definition: socket.h:169
sal_uInt8 oslSocketIpxNodeNumber[6]
Definition: socket.h:208
Definition: socket.h:62
Definition: socket.h:173
Definition: socket.h:182
oslSocketOptionLevel
Represents the different socket-option levels.
Definition: socket.h:125
Definition: socket.h:159
Definition: socket.h:185
SAL_DLLPUBLIC oslSocketAddr osl_createInetBroadcastAddr(rtl_uString *strDottedAddr, sal_Int32 Port)
Create an internet address usable for sending broadcast datagrams.
Definition: socket.h:102
SAL_DLLPUBLIC void osl_addToSocketSet(oslSocketSet Set, oslSocket Socket)
Adds a socket to the set.
oslSocketType
Represents the type of a socket.
Definition: socket.h:71
Definition: socket.h:191
Definition: socket.h:201
SAL_DLLPUBLIC oslSocketSet osl_createSocketSet(void)
Creates a set of sockets to be used with osl_demultiplexSocketEvents().
SAL_DLLPUBLIC oslSocketAddr osl_getLocalAddrOfSocket(oslSocket Socket)
Retrieves the Address of the local end of the socket.
Definition: socket.h:74
SAL_DLLPUBLIC oslSocketResult osl_getDottedInetAddrOfSocketAddr(oslSocketAddr Addr, rtl_uString **strDottedInetAddr)
Gets the address in dotted decimal format.
SAL_DLLPUBLIC sal_Bool osl_isSendReady(oslSocket Socket, const TimeValue *pTimeout)
Checks if send operations will block.
Definition: socket.h:82
Definition: socket.h:92
Definition: socket.h:138
Definition: socket.h:78
Definition: socket.h:51
SAL_DLLPUBLIC oslSocket osl_acceptConnectionOnSocket(oslSocket Socket, oslSocketAddr *pAddr)
Waits for an ingoing connection on the socket.
Definition: socket.h:166
unsigned char sal_Bool
Definition: types.h:38
Definition: socket.h:175
Definition: socket.h:190
Definition: socket.h:189
SAL_DLLPUBLIC sal_Int32 osl_getSocketOption(oslSocket Socket, oslSocketOptionLevel Level, oslSocketOption Option, void *pBuffer, sal_uInt32 BufferLen)
Retrieves attributes associated with the socket.
Definition: socket.h:184
SAL_DLLPUBLIC void osl_getHostnameOfHostAddr(const oslHostAddr Addr, rtl_uString **strHostname)
Get the hostname member of Addr.
Definition: socket.h:96
SAL_DLLPUBLIC oslSocketAddr osl_createInetSocketAddr(rtl_uString *strDottedAddr, sal_Int32 Port)
Create an internet-address, consisting of host address and port.
Definition: socket.h:114
Definition: socket.h:50
SAL_DLLPUBLIC sal_Int32 osl_writeSocket(oslSocket Socket, const void *pBuffer, sal_Int32 nSize)
Writes n bytes from pBuffer to the stream.
Definition: socket.h:128
SAL_DLLPUBLIC sal_Bool osl_listenOnSocket(oslSocket Socket, sal_Int32 MaxPendingConnections)
Prepares the socket to act as an acceptor of incoming connections.
SAL_DLLPUBLIC sal_Int32 osl_demultiplexSocketEvents(oslSocketSet IncomingSet, oslSocketSet OutgoingSet, oslSocketSet OutOfBandSet, const TimeValue *pTimeout)
Checks multiple sockets for events.
oslSocketMsgFlag
Represents flags to be used with send/recv-calls.
Definition: socket.h:135
Definition: socket.h:109
Definition: socket.h:187
Definition: socket.h:164
Definition: socket.h:129
Definition: socket.h:179
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...
Definition: socket.h:119
Definition: socket.h:106
oslSocketError
Describes the various error socket error conditions, which may occur.
Definition: socket.h:158
SAL_DLLPUBLIC oslSocketResult osl_connectSocketTo(oslSocket Socket, oslSocketAddr Addr, const TimeValue *pTimeout)
Connects the socket to the given address.
SAL_DLLPUBLIC void osl_removeFromSocketSet(oslSocketSet Set, oslSocket Socket)
Removes a socket from the set.
Definition: socket.h:177
SAL_DLLPUBLIC void osl_acquireSocket(oslSocket Socket)
increases the refcount of the socket handle by one
Definition: socket.h:142
SAL_DLLPUBLIC sal_Bool osl_shutdownSocket(oslSocket Socket, oslSocketDirection Direction)
Shuts down communication on a connected socket.
Definition: time.h:72
Definition: socket.h:136
SAL_DLLPUBLIC sal_Bool osl_isInSocketSet(oslSocketSet Set, oslSocket Socket)
Checks if socket is in the set.
Definition: socket.h:203
SAL_DLLPUBLIC oslHostAddr osl_createHostAddrByAddr(const oslSocketAddr Addr)
Create an oslHostAddr by reverse resolution of the given Addr.
Definition: socket.h:139
Definition: socket.h:172
Definition: socket.h:91
struct oslSocketAddrImpl * oslSocketAddr
Opaque datatype SocketAddr.
Definition: socket.h:44
Definition: socket.h:188
SAL_DLLPUBLIC oslSocketResult osl_getHostnameOfSocketAddr(oslSocketAddr Addr, rtl_uString **strHostname)
Returns the hostname represented by Addr.
Definition: socket.h:113
Definition: socket.h:112
Definition: socket.h:104
SAL_DLLPUBLIC void osl_releaseSocket(oslSocket Socket)
decreases the refcount of the socket handle by one.
SAL_DLLPUBLIC oslHostAddr osl_copyHostAddr(const oslHostAddr Addr)
Create a copy of the given Addr.
SAL_DLLPUBLIC oslSocketResult osl_getLocalHostname(rtl_uString **strLocalHostname)
Retrieve this machines hostname (NOT the FQDN)
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 oslSocketAddr osl_getSocketAddrOfHostAddr(const oslHostAddr Addr)
Get the socket address member of Addr.
Definition: socket.h:93
SAL_DLLPUBLIC oslSocketError osl_getLastSocketError(oslSocket Socket)
Returns a constant describing the last error for the socket system.
SAL_DLLPUBLIC oslSocketAddr osl_getPeerAddrOfSocket(oslSocket Socket)
Retrieves the Address of the remote end of the socket.
SAL_DLLPUBLIC oslSocketType osl_getSocketType(oslSocket Socket)
Queries the socket for its type.
oslSocketDirection
Used by shutdown to denote which end of the socket to "close".
Definition: socket.h:148
SAL_DLLPUBLIC oslHostAddr osl_createHostAddrByName(rtl_uString *strHostname)
Create an oslHostAddr by resolving the given strHostname.
#define SAL_MAX_ENUM
Definition: types.h:205
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_bindAddrToSocket(oslSocket Socket, oslSocketAddr Addr)
Binds the given address to the socket.
Definition: socket.h:105
Definition: socket.h:73
struct oslHostAddrImpl * oslHostAddr
Definition: socket.h:868
Definition: socket.h:137
SAL_DLLPUBLIC sal_Bool osl_isNonBlockingMode(oslSocket Socket)
Query state of non-blocking-mode of the socket.
Definition: socket.h:99
struct oslSocketImpl * oslSocket
Definition: socket.h:215
Definition: socket.h:75
SAL_DLLPUBLIC void osl_destroyHostAddr(oslHostAddr Addr)
Frees all resources allocated by Addr.
Definition: socket.h:150
Definition: socket.h:64
SAL_DLLPUBLIC oslSocketResult osl_setAddrOfSocketAddr(oslSocketAddr Addr, sal_Sequence *pByteSeq)
Sets the addr field in the struct sockaddr with pByteSeq.
Definition: socket.h:149
Definition: socket.h:180
SAL_DLLPUBLIC void osl_clearSocketSet(oslSocketSet Set)
Clears the set from all previously added sockets.
Definition: socket.h:163
SAL_DLLPUBLIC oslSocketAddr osl_createEmptySocketAddr(oslAddrFamily Family)
Creates a socket-address for the given family.
Definition: socket.h:117
Definition: socket.h:165
Definition: socket.h:52
SAL_DLLPUBLIC sal_Bool osl_isEqualSocketAddr(oslSocketAddr Addr1, oslSocketAddr Addr2)
Compares the values of two SocketAddresses.
Definition: socket.h:168
Definition: socket.h:192
Definition: socket.h:153
Definition: socket.h:199
SAL_DLLPUBLIC void osl_closeSocket(oslSocket Socket)
Closes the socket terminating any ongoing dataflow.
Definition: socket.h:183
Definition: socket.h:160
SAL_DLLPUBLIC sal_Bool osl_setInetPortOfSocketAddr(oslSocketAddr Addr, sal_Int32 Port)
Sets the Port of Addr.
Definition: socket.h:90
SAL_DLLPUBLIC oslSocketAddr osl_resolveHostname(rtl_uString *strHostname)
Uses the systems name-service interface to find an address for strHostname.
Definition: socket.h:181
unsigned char sal_uInt8
Definition: types.h:44
Definition: socket.h:118