LibreOffice
LibreOffice 6.3 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 #ifndef INCLUDED_OSL_SOCKET_H
21 #define INCLUDED_OSL_SOCKET_H
22 
23 #include "rtl/ustring.h"
24 #include "osl/time.h"
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
30 /* error returns */
31 #define OSL_INADDR_NONE 0xffffffff
32 #define OSL_INVALID_PORT (-1)
33 
37 typedef struct oslSocketAddrImpl * oslSocketAddr;
38 
42 typedef enum {
48 
52 typedef enum {
59 } oslProtocol;
60 
64 typedef enum {
77 
78 
82 typedef enum {
114 
118 typedef enum {
124 
128 typedef enum {
137 
141 typedef enum {
148 
151 typedef enum {
187 
190 typedef enum {
199 
202 
209 typedef struct oslSocketImpl * oslSocket;
210 
218  oslAddrFamily Family,
219  oslSocketType Type,
220  oslProtocol Protocol);
221 
224 SAL_DLLPUBLIC void SAL_CALL osl_acquireSocket(oslSocket Socket);
225 
231 SAL_DLLPUBLIC void SAL_CALL osl_releaseSocket(oslSocket Socket);
232 
241 
249 
258  oslSocket Socket,
259  oslSocketAddr Addr);
260 
273  oslSocket Socket,
274  oslSocketAddr Addr,
275  const TimeValue* pTimeout);
276 
277 
287  oslSocket Socket,
288  sal_Int32 MaxPendingConnections);
289 
290 
299  oslSocket Socket,
300  oslSocketAddr* pAddr);
301 
320 SAL_DLLPUBLIC sal_Int32 SAL_CALL osl_receiveSocket(
321  oslSocket Socket,
322  void* pBuffer,
323  sal_uInt32 BytesToRead,
324  oslSocketMsgFlag Flag);
325 
346 SAL_DLLPUBLIC sal_Int32 SAL_CALL osl_receiveFromSocket(
347  oslSocket Socket,
348  oslSocketAddr SenderAddr,
349  void* pBuffer,
350  sal_uInt32 BufferSize,
351  oslSocketMsgFlag Flag);
352 
369 SAL_DLLPUBLIC sal_Int32 SAL_CALL osl_sendSocket(
370  oslSocket Socket,
371  const void* pBuffer,
372  sal_uInt32 BytesToSend,
373  oslSocketMsgFlag Flag);
374 
401 SAL_DLLPUBLIC sal_Int32 SAL_CALL osl_sendToSocket(
402  oslSocket Socket,
403  oslSocketAddr ReceiverAddr,
404  const void* pBuffer,
405  sal_uInt32 BytesToSend,
406  oslSocketMsgFlag Flag);
407 
421  oslSocket Socket,
422  const TimeValue* pTimeout);
423 
437  oslSocket Socket,
438  const TimeValue* pTimeout);
439 
452  oslSocket Socket,
453  const TimeValue* pTimeout);
454 
468  oslSocket Socket,
469  oslSocketDirection Direction);
470 
524 SAL_DLLPUBLIC sal_Int32 SAL_CALL osl_getSocketOption(
525  oslSocket Socket,
526  oslSocketOptionLevel Level,
527  oslSocketOption Option,
528  void* pBuffer,
529  sal_uInt32 BufferLen);
530 
549  oslSocket Socket,
550  oslSocketOptionLevel Level,
551  oslSocketOption Option,
552  void* pBuffer,
553  sal_uInt32 BufferLen);
554 
563  oslSocket Socket,
564  sal_Bool On);
565 
566 
574 
587 
594  oslSocket Socket,
595  rtl_uString **strError);
596 
604  oslSocket Socket);
605 
608 typedef struct oslSocketSetImpl * oslSocketSet;
609 
615 
619 
625 
626 
632 SAL_DLLPUBLIC void SAL_CALL osl_addToSocketSet(oslSocketSet Set, oslSocket Socket);
633 
640 
649 
664 SAL_DLLPUBLIC sal_Int32 SAL_CALL osl_demultiplexSocketEvents(
665  oslSocketSet IncomingSet,
666  oslSocketSet OutgoingSet,
667  oslSocketSet OutOfBandSet,
668  const TimeValue* pTimeout);
669 
674 SAL_DLLPUBLIC void SAL_CALL osl_closeSocket(oslSocket Socket);
675 
676 
688 SAL_DLLPUBLIC sal_Int32 SAL_CALL osl_readSocket(
689  oslSocket Socket,
690  void *pBuffer,
691  sal_Int32 nSize);
692 
693 
704 SAL_DLLPUBLIC sal_Int32 SAL_CALL osl_writeSocket(
705  oslSocket Socket,
706  const void *pBuffer,
707  sal_Int32 nSize);
708 
720  oslAddrFamily Family);
721 
722 
726  oslSocketAddr Addr);
727 
733  oslSocketAddr Addr1, oslSocketAddr Addr2);
734 
741  rtl_uString *strHostname);
742 
753  rtl_uString *strDottedAddr, sal_Int32 Port);
754 
755 
764  rtl_uString *strDottedAddr, sal_Int32 Port);
765 
766 
771  oslSocketAddr Addr);
772 
777 SAL_DLLPUBLIC sal_Int32 SAL_CALL osl_getServicePort(
778  rtl_uString *strServicename, rtl_uString *strProtocol);
779 
780 
781 
787  oslSocketAddr Addr);
788 
789 
794 SAL_DLLPUBLIC sal_Int32 SAL_CALL osl_getInetPortOfSocketAddr(
795  oslSocketAddr Addr);
796 
797 
804  oslSocketAddr Addr, sal_Int32 Port);
805 
806 
813  oslSocketAddr Addr, rtl_uString **strHostname);
814 
815 
827  oslSocketAddr Addr, rtl_uString **strDottedInetAddr);
828 
832  oslSocketAddr Addr, sal_Sequence *pByteSeq );
833 
842  oslSocketAddr Addr, sal_Sequence **ppByteSeq );
843 
844 /*
845  Opaque datatype HostAddr.
846 */
847 typedef struct oslHostAddrImpl * oslHostAddr;
848 
849 
856  rtl_uString *strHostname, const oslSocketAddr Addr);
857 
858 
866 SAL_DLLPUBLIC oslHostAddr SAL_CALL osl_createHostAddrByName(rtl_uString *strHostname);
867 
868 
877 
878 
883 
884 
888 SAL_DLLPUBLIC void SAL_CALL osl_destroyHostAddr(oslHostAddr Addr);
889 
890 
894 SAL_DLLPUBLIC void SAL_CALL osl_getHostnameOfHostAddr(const oslHostAddr Addr, rtl_uString **strHostname);
895 
896 
901 
908 SAL_DLLPUBLIC oslSocketResult SAL_CALL osl_getLocalHostname(rtl_uString **strLocalHostname);
909 
910 
914 #ifdef __cplusplus
915 }
916 #endif
917 
918 #endif // INCLUDED_OSL_SOCKET_H
919 
920 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
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.
SAL_DLLPUBLIC oslSocketSet osl_createSocketSet(void)
Creates a set of sockets to be used with osl_demultiplexSocketEvents().
Definition: socket.h:71
Definition: socket.h:168
Definition: socket.h:183
Definition: socket.h:102
Definition: socket.h:180
Definition: socket.h:172
SAL_DLLPUBLIC void osl_removeFromSocketSet(oslSocketSet Set, oslSocket Socket)
Removes a socket from the set.
Definition: socket.h:43
Definition: socket.h:121
Definition: socket.h:99
SAL_DLLPUBLIC sal_Bool osl_shutdownSocket(oslSocket Socket, oslSocketDirection Direction)
Shuts down communication on a connected socket.
SAL_DLLPUBLIC oslHostAddr osl_createHostAddrByAddr(const oslSocketAddr Addr)
Create an oslHostAddr by reverse resolution of the given Addr.
Definition: socket.h:157
Definition: socket.h:122
Definition: socket.h:135
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:128
Definition: socket.h:196
Definition: socket.h:132
Definition: socket.h:112
Definition: socket.h:165
SAL_DLLPUBLIC oslHostAddr osl_copyHostAddr(const oslHostAddr Addr)
Create a copy of the given Addr.
#define SAL_DLLPUBLIC
Definition: saldllapi.h:30
SAL_DLLPUBLIC oslSocketResult osl_getLocalHostname(rtl_uString **strLocalHostname)
Retrieve this machines hostname.
Definition: socket.h:106
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:105
Definition: socket.h:97
Definition: socket.h:170
oslSocketError
Describes the various error socket error conditions, which may occur.
Definition: socket.h:151
SAL_DLLPUBLIC oslSocketResult osl_connectSocketTo(oslSocket Socket, oslSocketAddr Addr, const TimeValue *pTimeout)
Connects the socket to the given address.
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:129
struct oslHostAddrImpl * oslHostAddr
Definition: socket.h:845
struct oslSocketImpl * oslSocket
Definition: socket.h:208
SAL_DLLPUBLIC void osl_destroyHostAddr(oslHostAddr Addr)
Frees all resources allocated by Addr.
Definition: socket.h:84
SAL_DLLPUBLIC void osl_acquireSocket(oslSocket Socket)
increases the refcount of the socket handle by one
Definition: socket.h:181
Definition: socket.h:98
SAL_DLLPUBLIC void osl_clearSocketSet(oslSocketSet Set)
Clears the set from all previously added sockets.
Definition: socket.h:130
SAL_DLLPUBLIC sal_Bool osl_isInSocketSet(oslSocketSet Set, oslSocket Socket)
Checks if socket is in the set.
SAL_DLLPUBLIC oslSocketAddr osl_createEmptySocketAddr(oslAddrFamily Family)
Creates a socket-address for the given family.
Definition: socket.h:92
SAL_DLLPUBLIC sal_Bool osl_isEqualSocketAddr(oslSocketAddr Addr1, oslSocketAddr Addr2)
Compares the values of two SocketAddresses.
struct oslSocketAddrImpl * oslSocketAddr
Opaque datatype SocketAddr.
Definition: socket.h:37
SAL_DLLPUBLIC sal_Bool osl_setInetPortOfSocketAddr(oslSocketAddr Addr, sal_Int32 Port)
Sets the Port of Addr.
Definition: socket.h:156
Definition: socket.h:110
Definition: socket.h:86
Definition: socket.h:158
SAL_DLLPUBLIC void osl_releaseSocket(oslSocket Socket)
decreases the refcount of the socket handle by one.
Definition: socket.h:45
Definition: socket.h:185
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.
Definition: socket.h:146
Definition: socket.h:192
Definition: socket.h:176
Definition: socket.h:153
SAL_DLLPUBLIC oslSocketAddr osl_getSocketAddrOfHostAddr(const oslHostAddr Addr)
Get the socket address member of Addr.
Definition: socket.h:66
Definition: socket.h:83
SAL_DLLPUBLIC oslSocketError osl_getLastSocketError(oslSocket Socket)
Returns a constant describing the last error for the socket system.
Definition: socket.h:68
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.
Definition: time.h:66
Definition: socket.h:143
oslSocketDirection
Used by shutdown to denote which end of the socket to "close".
Definition: socket.h:141
Definition: socket.h:57
SAL_DLLPUBLIC oslHostAddr osl_createHostAddrByName(rtl_uString *strHostname)
Create an oslHostAddr by resolving the given strHostname.
Definition: socket.h:142
Definition: socket.h:173
oslProtocol
represent a specific protocol within a address-family
Definition: socket.h:52
SAL_DLLPUBLIC sal_Bool osl_isNonBlockingMode(oslSocket Socket)
Query state of non-blocking-mode of the socket.
Definition: socket.h:65
Definition: socket.h:161
unsigned char sal_Bool
Definition: types.h:38
Definition: socket.h:108
SAL_DLLPUBLIC oslSocketResult osl_setAddrOfSocketAddr(oslSocketAddr Addr, sal_Sequence *pByteSeq)
Sets the addr field in the struct sockaddr with pByteSeq.
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:82
SAL_DLLPUBLIC sal_Int32 osl_readSocket(oslSocket Socket, void *pBuffer, sal_Int32 nSize)
Retrieves n bytes from the stream and copies them into pBuffer.
Definition: socket.h:174
Definition: socket.h:111
SAL_DLLPUBLIC void osl_closeSocket(oslSocket Socket)
Closes the socket terminating any ongoing dataflow.
SAL_DLLPUBLIC oslSocketAddr osl_resolveHostname(rtl_uString *strHostname)
Uses the systems name-service interface to find an address for strHostname.
Definition: socket.h:53
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,...
Definition: socket.h:154
SAL_DLLPUBLIC sal_Bool osl_setSocketOption(oslSocket Socket, oslSocketOptionLevel Level, oslSocketOption Option, void *pBuffer, sal_uInt32 BufferLen)
Sets the sockets attributes.
Definition: socket.h:120
Definition: socket.h:134
struct oslSocketSetImpl * oslSocketSet
Type for the representation of socket sets.
Definition: socket.h:607
oslAddrFamily
Represents the address-family of a socket.
Definition: socket.h:42
Definition: socket.h:164
Definition: socket.h:144
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:200
SAL_DLLPUBLIC void osl_getLastSocketErrorDescription(oslSocket Socket, rtl_uString **strError)
returns a string which describes the last socket error.
Definition: socket.h:145
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:54
Definition: socket.h:167
Definition: socket.h:191
SAL_DLLPUBLIC sal_Bool osl_enableNonBlockingMode(oslSocket Socket, sal_Bool On)
Enables/disables non-blocking-mode of the socket.
Definition: socket.h:133
Definition: socket.h:119
Definition: socket.h:74
Definition: socket.h:197
SAL_DLLPUBLIC oslSocketAddr osl_copySocketAddr(oslSocketAddr Addr)
Creates a new SocketAddress and fills it from Addr.
Definition: socket.h:160
Definition: socket.h:171
SAL_DLLPUBLIC sal_Int32 osl_getInetPortOfSocketAddr(oslSocketAddr Addr)
Retrieves the internet port-number of Addr.
oslSocketOptionLevel
Represents the different socket-option levels.
Definition: socket.h:118
Definition: socket.h:155
Definition: socket.h:87
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:46
SAL_DLLPUBLIC oslSocketAddr osl_createInetBroadcastAddr(rtl_uString *strDottedAddr, sal_Int32 Port)
Create an internet address usable for sending broadcast datagrams.
Definition: socket.h:166
oslSocketResult
Common return codes of socket related functions.
Definition: socket.h:190
Definition: socket.h:179
Definition: socket.h:195
SAL_DLLPUBLIC oslSocket osl_createSocket(oslAddrFamily Family, oslSocketType Type, oslProtocol Protocol)
Create a socket of the specified Family and Type.
Definition: socket.h:90
Definition: socket.h:56
Definition: socket.h:152
SAL_DLLPUBLIC void osl_addToSocketSet(oslSocketSet Set, oslSocket Socket)
Adds a socket to the set.
SAL_DLLPUBLIC void osl_destroySocketSet(oslSocketSet Set)
Destroys an oslSocketSet.
Definition: socket.h:95
SAL_DLLPUBLIC oslSocketAddr osl_getLocalAddrOfSocket(oslSocket Socket)
Retrieves the Address of the local end of the socket.
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:162
Definition: socket.h:55
Definition: socket.h:175
SAL_DLLPUBLIC oslHostAddr osl_createHostAddr(rtl_uString *strHostname, const oslSocketAddr Addr)
Create an oslHostAddr from given hostname and socket address.
#define SAL_MAX_ENUM
Definition: types.h:223
This is the binary specification of a SAL sequence.
Definition: types.h:321
Definition: socket.h:75
Definition: socket.h:178
sal_uInt8 oslSocketIpxNodeNumber[6]
Definition: socket.h:201
Definition: socket.h:85
SAL_DLLPUBLIC oslSocket osl_acceptConnectionOnSocket(oslSocket Socket, oslSocketAddr *pAddr)
Waits for an ingoing connection on the socket.
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 void osl_getHostnameOfHostAddr(const oslHostAddr Addr, rtl_uString **strHostname)
Get the hostname member of Addr.
Definition: socket.h:131
Definition: socket.h:44
Definition: socket.h:184
Definition: socket.h:159
SAL_DLLPUBLIC oslSocketAddr osl_createInetSocketAddr(rtl_uString *strDottedAddr, sal_Int32 Port)
Create an internet-address, consisting of host address and port.
Definition: socket.h:194
Definition: socket.h:182
Definition: socket.h:177
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:67
Definition: socket.h:89
oslSocketType
Represents the type of a socket.
Definition: socket.h:64
unsigned char sal_uInt8
Definition: types.h:44
Definition: socket.h:107