xref: /trunk/main/sal/inc/osl/socket.h (revision cdf0e10c)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir #ifndef _OSL_SOCKET_H_
29*cdf0e10cSrcweir #define _OSL_SOCKET_H_
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <rtl/ustring.h>
32*cdf0e10cSrcweir #include <rtl/byteseq.h>
33*cdf0e10cSrcweir 
34*cdf0e10cSrcweir #include <osl/time.h>
35*cdf0e10cSrcweir #include <rtl/tencinfo.h>
36*cdf0e10cSrcweir 
37*cdf0e10cSrcweir #ifdef __cplusplus
38*cdf0e10cSrcweir extern "C" {
39*cdf0e10cSrcweir #endif
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir /* error returns */
42*cdf0e10cSrcweir #define OSL_INADDR_NONE				0xffffffff
43*cdf0e10cSrcweir #define OSL_INVALID_PORT (-1)
44*cdf0e10cSrcweir #define OSL_INVALID_IPX_SOCKET_NO	0xffffffff
45*cdf0e10cSrcweir 
46*cdf0e10cSrcweir /**@HTML
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir */
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir /**
51*cdf0e10cSrcweir 	Opaque datatype SocketAddr.
52*cdf0e10cSrcweir */
53*cdf0e10cSrcweir typedef struct oslSocketAddrImpl * oslSocketAddr;
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir 
56*cdf0e10cSrcweir /**
57*cdf0e10cSrcweir 	Represents the address-family of a socket
58*cdf0e10cSrcweir */
59*cdf0e10cSrcweir typedef enum {
60*cdf0e10cSrcweir 	osl_Socket_FamilyInet,  	/* IP */
61*cdf0e10cSrcweir 	osl_Socket_FamilyIpx,	  	/* Novell IPX/SPX */
62*cdf0e10cSrcweir 	osl_Socket_FamilyInvalid,	/* always last entry in enum! */
63*cdf0e10cSrcweir 	osl_Socket_Family_FORCE_EQUAL_SIZE = SAL_MAX_ENUM
64*cdf0e10cSrcweir } oslAddrFamily;
65*cdf0e10cSrcweir 
66*cdf0e10cSrcweir /**
67*cdf0e10cSrcweir 	represent a specific protocol within a address-family
68*cdf0e10cSrcweir */
69*cdf0e10cSrcweir typedef enum {
70*cdf0e10cSrcweir 	osl_Socket_ProtocolIp,	   	/* for all af_inet */
71*cdf0e10cSrcweir 	osl_Socket_ProtocolIpx,	   	/* af_ipx datagram sockets (IPX) */
72*cdf0e10cSrcweir 	osl_Socket_ProtocolSpx,	   	/* af_ipx seqpacket or stream for SPX */
73*cdf0e10cSrcweir 	osl_Socket_ProtocolSpxII,  	/* af_ipx seqpacket or stream for SPX II */
74*cdf0e10cSrcweir 	osl_Socket_ProtocolInvalid,
75*cdf0e10cSrcweir 	osl_Socket_Protocol_FORCE_EQUAL_SIZE = SAL_MAX_ENUM
76*cdf0e10cSrcweir } oslProtocol;
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir 
79*cdf0e10cSrcweir /**
80*cdf0e10cSrcweir 	Represents the type of a socket
81*cdf0e10cSrcweir */
82*cdf0e10cSrcweir typedef enum {
83*cdf0e10cSrcweir 	osl_Socket_TypeStream,
84*cdf0e10cSrcweir 	osl_Socket_TypeDgram,
85*cdf0e10cSrcweir 	osl_Socket_TypeRaw,
86*cdf0e10cSrcweir 	osl_Socket_TypeRdm,
87*cdf0e10cSrcweir 	osl_Socket_TypeSeqPacket,
88*cdf0e10cSrcweir 	osl_Socket_TypeInvalid,		/* always last entry in enum! */
89*cdf0e10cSrcweir 	osl_Socket_Type_FORCE_EQUAL_SIZE = SAL_MAX_ENUM
90*cdf0e10cSrcweir } oslSocketType;
91*cdf0e10cSrcweir 
92*cdf0e10cSrcweir 
93*cdf0e10cSrcweir /**
94*cdf0e10cSrcweir 	Represents socket-options
95*cdf0e10cSrcweir */
96*cdf0e10cSrcweir typedef enum {
97*cdf0e10cSrcweir 	osl_Socket_OptionDebug,
98*cdf0e10cSrcweir 	osl_Socket_OptionAcceptConn,
99*cdf0e10cSrcweir 	osl_Socket_OptionReuseAddr,
100*cdf0e10cSrcweir 	osl_Socket_OptionKeepAlive,
101*cdf0e10cSrcweir 	osl_Socket_OptionDontRoute,
102*cdf0e10cSrcweir 	osl_Socket_OptionBroadcast,
103*cdf0e10cSrcweir 	osl_Socket_OptionUseLoopback,
104*cdf0e10cSrcweir 	osl_Socket_OptionLinger,
105*cdf0e10cSrcweir 	osl_Socket_OptionOOBinLine,
106*cdf0e10cSrcweir 	osl_Socket_OptionSndBuf,
107*cdf0e10cSrcweir 	osl_Socket_OptionRcvBuf,
108*cdf0e10cSrcweir 	osl_Socket_OptionSndLowat,
109*cdf0e10cSrcweir 	osl_Socket_OptionRcvLowat,
110*cdf0e10cSrcweir 	osl_Socket_OptionSndTimeo,
111*cdf0e10cSrcweir 	osl_Socket_OptionRcvTimeo,
112*cdf0e10cSrcweir 	osl_Socket_OptionError,
113*cdf0e10cSrcweir 	osl_Socket_OptionType,
114*cdf0e10cSrcweir 	osl_Socket_OptionTcpNoDelay,
115*cdf0e10cSrcweir 	osl_Socket_OptionInvalid,		/* always last entry in enum! */
116*cdf0e10cSrcweir 	osl_Socket_Option_FORCE_EQUAL_SIZE = SAL_MAX_ENUM
117*cdf0e10cSrcweir } oslSocketOption;
118*cdf0e10cSrcweir 
119*cdf0e10cSrcweir /**
120*cdf0e10cSrcweir 	Represents the different socket-option levels
121*cdf0e10cSrcweir */
122*cdf0e10cSrcweir typedef enum  {
123*cdf0e10cSrcweir 	osl_Socket_LevelSocket,
124*cdf0e10cSrcweir 	osl_Socket_LevelTcp,
125*cdf0e10cSrcweir 	osl_Socket_LevelInvalid,			/* always last entry in enum! */
126*cdf0e10cSrcweir 	osl_Socket_Level_FORCE_EQUAL_SIZE = SAL_MAX_ENUM
127*cdf0e10cSrcweir } oslSocketOptionLevel;
128*cdf0e10cSrcweir 
129*cdf0e10cSrcweir 
130*cdf0e10cSrcweir /**
131*cdf0e10cSrcweir 	Represents flags to be used with send/recv-calls.
132*cdf0e10cSrcweir */
133*cdf0e10cSrcweir typedef enum {
134*cdf0e10cSrcweir 	osl_Socket_MsgNormal,
135*cdf0e10cSrcweir 	osl_Socket_MsgOOB,
136*cdf0e10cSrcweir 	osl_Socket_MsgPeek,
137*cdf0e10cSrcweir 	osl_Socket_MsgDontRoute,
138*cdf0e10cSrcweir 	osl_Socket_MsgMaxIOVLen,
139*cdf0e10cSrcweir 	osl_Socket_MsgInvalid,			/* always last entry in enum! */
140*cdf0e10cSrcweir 	osl_Socket_Msg_FORCE_EQUAL_SIZE = SAL_MAX_ENUM
141*cdf0e10cSrcweir } oslSocketMsgFlag;
142*cdf0e10cSrcweir 
143*cdf0e10cSrcweir /**
144*cdf0e10cSrcweir 	Used by shutdown to denote which end of the socket to "close".
145*cdf0e10cSrcweir */
146*cdf0e10cSrcweir typedef enum {
147*cdf0e10cSrcweir 	osl_Socket_DirRead,
148*cdf0e10cSrcweir 	osl_Socket_DirWrite,
149*cdf0e10cSrcweir 	osl_Socket_DirReadWrite,
150*cdf0e10cSrcweir 	osl_Socket_DirInvalid,			/* always last entry in enum! */
151*cdf0e10cSrcweir 	osl_Socket_Dir_FORCE_EQUAL_SIZE = SAL_MAX_ENUM
152*cdf0e10cSrcweir } oslSocketDirection;
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir /** Describes the various error socket error conditions, which may
155*cdf0e10cSrcweir 	occur */
156*cdf0e10cSrcweir typedef enum {
157*cdf0e10cSrcweir 	osl_Socket_E_None,				/* no error */
158*cdf0e10cSrcweir 	osl_Socket_E_NotSocket,			/* Socket operation on non-socket */
159*cdf0e10cSrcweir 	osl_Socket_E_DestAddrReq,		/* Destination address required */
160*cdf0e10cSrcweir 	osl_Socket_E_MsgSize,			/* Message too long */
161*cdf0e10cSrcweir 	osl_Socket_E_Prototype,			/* Protocol wrong type for socket */
162*cdf0e10cSrcweir 	osl_Socket_E_NoProtocol,		/* Protocol not available */
163*cdf0e10cSrcweir 	osl_Socket_E_ProtocolNoSupport,	/* Protocol not supported */
164*cdf0e10cSrcweir 	osl_Socket_E_TypeNoSupport,		/* Socket type not supported */
165*cdf0e10cSrcweir 	osl_Socket_E_OpNotSupport,		/* Operation not supported on socket */
166*cdf0e10cSrcweir 	osl_Socket_E_PfNoSupport,		/* Protocol family not supported */
167*cdf0e10cSrcweir 	osl_Socket_E_AfNoSupport,		/* Address family not supported by */
168*cdf0e10cSrcweir 									/* protocol family */
169*cdf0e10cSrcweir 	osl_Socket_E_AddrInUse,			/* Address already in use */
170*cdf0e10cSrcweir 	osl_Socket_E_AddrNotAvail,		/* Can't assign requested address */
171*cdf0e10cSrcweir 	osl_Socket_E_NetDown,			/* Network is down */
172*cdf0e10cSrcweir 	osl_Socket_E_NetUnreachable, 	/* Network is unreachable */
173*cdf0e10cSrcweir 	osl_Socket_E_NetReset,			/* Network dropped connection because */
174*cdf0e10cSrcweir 									/* of reset */
175*cdf0e10cSrcweir 	osl_Socket_E_ConnAborted,		/* Software caused connection abort */
176*cdf0e10cSrcweir 	osl_Socket_E_ConnReset,			/* Connection reset by peer */
177*cdf0e10cSrcweir 	osl_Socket_E_NoBufferSpace,		/* No buffer space available */
178*cdf0e10cSrcweir 	osl_Socket_E_IsConnected,		/* Socket is already connected */
179*cdf0e10cSrcweir 	osl_Socket_E_NotConnected,		/* Socket is not connected */
180*cdf0e10cSrcweir 	osl_Socket_E_Shutdown,			/* Can't send after socket shutdown */
181*cdf0e10cSrcweir 	osl_Socket_E_TooManyRefs,		/* Too many references: can't splice */
182*cdf0e10cSrcweir 	osl_Socket_E_TimedOut,			/* Connection timed out */
183*cdf0e10cSrcweir 	osl_Socket_E_ConnRefused,		/* Connection refused */
184*cdf0e10cSrcweir 	osl_Socket_E_HostDown,			/* Host is down */
185*cdf0e10cSrcweir 	osl_Socket_E_HostUnreachable,	/* No route to host */
186*cdf0e10cSrcweir 	osl_Socket_E_WouldBlock,		/* call would block on non-blocking socket */
187*cdf0e10cSrcweir 	osl_Socket_E_Already,			/* operation already in progress */
188*cdf0e10cSrcweir 	osl_Socket_E_InProgress,		/* operation now in progress */
189*cdf0e10cSrcweir 	osl_Socket_E_InvalidError,		/* unmapped error: always last entry in enum! */
190*cdf0e10cSrcweir 	osl_Socket_E_FORCE_EQUAL_SIZE = SAL_MAX_ENUM
191*cdf0e10cSrcweir } oslSocketError;
192*cdf0e10cSrcweir 
193*cdf0e10cSrcweir /** Common return codes of socket related functions.
194*cdf0e10cSrcweir  */
195*cdf0e10cSrcweir typedef enum {
196*cdf0e10cSrcweir     osl_Socket_Ok,          /* successful completion */
197*cdf0e10cSrcweir     osl_Socket_Error,       /* error occured, check osl_getLastSocketError() for details */
198*cdf0e10cSrcweir 	osl_Socket_TimedOut,    /* blocking operation timed out */
199*cdf0e10cSrcweir     osl_Socket_Interrupted, /* blocking operation was interrupted */
200*cdf0e10cSrcweir     osl_Socket_InProgress,	/* nonblocking operation is in progress */
201*cdf0e10cSrcweir 	osl_Socket_FORCE_EQUAL_SIZE = SAL_MAX_ENUM
202*cdf0e10cSrcweir } oslSocketResult;
203*cdf0e10cSrcweir 
204*cdf0e10cSrcweir typedef sal_uInt8 oslSocketIpxNetNumber[4];
205*cdf0e10cSrcweir typedef sal_uInt8 oslSocketIpxNodeNumber[6];
206*cdf0e10cSrcweir 
207*cdf0e10cSrcweir /**@} end section types
208*cdf0e10cSrcweir */
209*cdf0e10cSrcweir 
210*cdf0e10cSrcweir /**@{ begin section oslSocketAddr
211*cdf0e10cSrcweir */
212*cdf0e10cSrcweir 
213*cdf0e10cSrcweir /**	Creates a socket-address for the given family.
214*cdf0e10cSrcweir 	@param family If family == osl_Socket_FamilyInet the address is
215*cdf0e10cSrcweir 	              set to INADDR_ANY	port 0.
216*cdf0e10cSrcweir 	@return 0 if address could not be created.
217*cdf0e10cSrcweir */
218*cdf0e10cSrcweir oslSocketAddr SAL_CALL osl_createEmptySocketAddr(oslAddrFamily Family);
219*cdf0e10cSrcweir 
220*cdf0e10cSrcweir 
221*cdf0e10cSrcweir /**	Creates a new SocketAddress and fills it from Addr.
222*cdf0e10cSrcweir */
223*cdf0e10cSrcweir oslSocketAddr SAL_CALL osl_copySocketAddr(oslSocketAddr Addr);
224*cdf0e10cSrcweir 
225*cdf0e10cSrcweir /**	Compares the values of two SocketAddresses.
226*cdf0e10cSrcweir 	@return <code>sal_True</code> if both addresses denote the same socket address,
227*cdf0e10cSrcweir 	        <code>sal_False</code> otherwise.
228*cdf0e10cSrcweir */
229*cdf0e10cSrcweir sal_Bool SAL_CALL osl_isEqualSocketAddr(
230*cdf0e10cSrcweir 	oslSocketAddr Addr1, oslSocketAddr Addr2);
231*cdf0e10cSrcweir 
232*cdf0e10cSrcweir /** Uses the systems name-service interface to find an address for strHostname.
233*cdf0e10cSrcweir 	@param strHostname [in] The name for which you search for an address.
234*cdf0e10cSrcweir 	@return The desired address if one could be found, otherwise 0.
235*cdf0e10cSrcweir 	Don't forget to destroy the address if you don't need it any longer.
236*cdf0e10cSrcweir */
237*cdf0e10cSrcweir oslSocketAddr SAL_CALL osl_resolveHostname(rtl_uString *strHostname);
238*cdf0e10cSrcweir 
239*cdf0e10cSrcweir /** Create an internet address usable for sending broadcast datagrams.
240*cdf0e10cSrcweir     To limit the broadcast to your subnet, pass your hosts IP address
241*cdf0e10cSrcweir 	in dotted decimal notation as first argument.
242*cdf0e10cSrcweir     @see    osl_sendToSocket()
243*cdf0e10cSrcweir 	@see    oslSocketAddr
244*cdf0e10cSrcweir     @param  strDottedAddr [in] dotted decimal internet address, may be 0.
245*cdf0e10cSrcweir 	@param  Port          [in] port number in host byte order.
246*cdf0e10cSrcweir 	@return 0 if address could not be created.
247*cdf0e10cSrcweir */
248*cdf0e10cSrcweir oslSocketAddr SAL_CALL osl_createInetBroadcastAddr (
249*cdf0e10cSrcweir 	rtl_uString *strDottedAddr, sal_Int32 Port);
250*cdf0e10cSrcweir 
251*cdf0e10cSrcweir 
252*cdf0e10cSrcweir /**	Create an internet-address, consisting of hostaddress and port.
253*cdf0e10cSrcweir 	We interpret strDottedAddr as a dotted-decimal inet-addr
254*cdf0e10cSrcweir 	(e.g. "141.99.128.50").
255*cdf0e10cSrcweir 	@param strDottedAddr [in] String with dotted address.
256*cdf0e10cSrcweir 	@param Port [in] portnumber in host byte order.
257*cdf0e10cSrcweir 	@return 0 if address could not be created.
258*cdf0e10cSrcweir */
259*cdf0e10cSrcweir oslSocketAddr SAL_CALL osl_createInetSocketAddr (
260*cdf0e10cSrcweir 	rtl_uString *strDottedAddr, sal_Int32 Port);
261*cdf0e10cSrcweir 
262*cdf0e10cSrcweir 
263*cdf0e10cSrcweir /** Frees all resources allocated by Addr. The handle Addr must not
264*cdf0e10cSrcweir 	be used after the call anymore.
265*cdf0e10cSrcweir */
266*cdf0e10cSrcweir void SAL_CALL osl_destroySocketAddr(oslSocketAddr Addr);
267*cdf0e10cSrcweir 
268*cdf0e10cSrcweir /**	Looks up the port-number designated to the specified service/protocol-pair.
269*cdf0e10cSrcweir 	(e.g. "ftp" "tcp").
270*cdf0e10cSrcweir 	@return OSL_INVALID_PORT if no appropriate entry was found, otherwise the port-number.
271*cdf0e10cSrcweir */
272*cdf0e10cSrcweir sal_Int32 SAL_CALL osl_getServicePort(rtl_uString *strServicename, rtl_uString *strProtocol);
273*cdf0e10cSrcweir 
274*cdf0e10cSrcweir 
275*cdf0e10cSrcweir 
276*cdf0e10cSrcweir /** Retrieves the address-family from the Addr.
277*cdf0e10cSrcweir 	@return the family of the socket-address.
278*cdf0e10cSrcweir 	In case of an unknown family you get <code>osl_Socket_FamilyInvalid</code>.
279*cdf0e10cSrcweir */
280*cdf0e10cSrcweir oslAddrFamily SAL_CALL osl_getFamilyOfSocketAddr(oslSocketAddr Addr);
281*cdf0e10cSrcweir 
282*cdf0e10cSrcweir 
283*cdf0e10cSrcweir /** Retrieves the internet port-number of Addr.
284*cdf0e10cSrcweir 	@return the port-number of the address in host-byte order. If Addr
285*cdf0e10cSrcweir 	is not an address of type <code>osl_Socket_FamilyInet</code>, it returns <code>OSL_INVALID_PORT</code>
286*cdf0e10cSrcweir */
287*cdf0e10cSrcweir sal_Int32 SAL_CALL osl_getInetPortOfSocketAddr(oslSocketAddr Addr);
288*cdf0e10cSrcweir 
289*cdf0e10cSrcweir 
290*cdf0e10cSrcweir /** Sets the Port of Addr.
291*cdf0e10cSrcweir 	@param Port [in] is expected in host byte-order.
292*cdf0e10cSrcweir 	@return <code>sal_False</code> if Addr is not an inet-addr.
293*cdf0e10cSrcweir */
294*cdf0e10cSrcweir sal_Bool SAL_CALL osl_setInetPortOfSocketAddr(oslSocketAddr Addr, sal_Int32 Port);
295*cdf0e10cSrcweir 
296*cdf0e10cSrcweir 
297*cdf0e10cSrcweir /** Returns the hostname represented by Addr.
298*cdf0e10cSrcweir 	@param strHostname out-parameter. The hostname represented by the address. If
299*cdf0e10cSrcweir 	there is no hostname to be found, it returns 0.
300*cdf0e10cSrcweir */
301*cdf0e10cSrcweir oslSocketResult	SAL_CALL osl_getHostnameOfSocketAddr(oslSocketAddr Addr, rtl_uString **strHostname);
302*cdf0e10cSrcweir 
303*cdf0e10cSrcweir 
304*cdf0e10cSrcweir /** Gets the address in dotted decimal format.
305*cdf0e10cSrcweir 	@param strDottedInetAddr out-parameter. Contains the dotted decimal address
306*cdf0e10cSrcweir 	(e.g. 141.99.20.34) represented	by the address.
307*cdf0e10cSrcweir 	If the address is invalid or not of type <code>osl_Socket_FamilyInet</code>,
308*cdf0e10cSrcweir 	it returns 0.
309*cdf0e10cSrcweir 	@return <code>osl_Socket_Ok</code> or <code>osl_Socket_Error</code>
310*cdf0e10cSrcweir */
311*cdf0e10cSrcweir oslSocketResult	SAL_CALL osl_getDottedInetAddrOfSocketAddr(oslSocketAddr Addr, rtl_uString **strDottedInetAddr);
312*cdf0e10cSrcweir 
313*cdf0e10cSrcweir /** Sets the addr field in the struct sockaddr with pByteSeq. pByteSeq must be in network byte order.
314*cdf0e10cSrcweir  */
315*cdf0e10cSrcweir oslSocketResult SAL_CALL osl_setAddrOfSocketAddr( oslSocketAddr Addr, sal_Sequence *pByteSeq );
316*cdf0e10cSrcweir 
317*cdf0e10cSrcweir /** Returns the addr field in the struct sockaddr.
318*cdf0e10cSrcweir 	@param ppByteSeq out parameter. After the call, *ppByteSeq contains the ipadrress
319*cdf0e10cSrcweir 	                 in network byteorder. *ppByteSeq may be 0 in case of an invalid socket handle.
320*cdf0e10cSrcweir 	@return <code>osl_Socket_Ok</code> or <code>osl_Socket_Error</code>
321*cdf0e10cSrcweir  */
322*cdf0e10cSrcweir oslSocketResult SAL_CALL osl_getAddrOfSocketAddr( oslSocketAddr Addr, sal_Sequence **ppByteSeq );
323*cdf0e10cSrcweir 
324*cdf0e10cSrcweir /*
325*cdf0e10cSrcweir 	Opaque datatype HostAddr.
326*cdf0e10cSrcweir */
327*cdf0e10cSrcweir typedef struct oslHostAddrImpl * oslHostAddr;
328*cdf0e10cSrcweir 
329*cdf0e10cSrcweir 
330*cdf0e10cSrcweir /** Create an oslHostAddr from given hostname and socket address.
331*cdf0e10cSrcweir     @param strHostname [in] The hostname to be stored.
332*cdf0e10cSrcweir 	@param Addr [in] The socket address to be stored.
333*cdf0e10cSrcweir 	@return The created address or 0 upon failure.
334*cdf0e10cSrcweir */
335*cdf0e10cSrcweir oslHostAddr SAL_CALL osl_createHostAddr(rtl_uString *strHostname, const oslSocketAddr Addr);
336*cdf0e10cSrcweir 
337*cdf0e10cSrcweir 
338*cdf0e10cSrcweir /** Create an oslHostAddr by resolving the given strHostname.
339*cdf0e10cSrcweir     Successful name resolution should result in the fully qualified
340*cdf0e10cSrcweir 	domain name (FQDN) and it's address as hostname and socket address
341*cdf0e10cSrcweir 	members of the resulting oslHostAddr.
342*cdf0e10cSrcweir     @param strHostname [in] The hostname to be resolved.
343*cdf0e10cSrcweir 	@return The resulting address or 0 upon failure.
344*cdf0e10cSrcweir */
345*cdf0e10cSrcweir oslHostAddr SAL_CALL osl_createHostAddrByName(rtl_uString *strHostname);
346*cdf0e10cSrcweir 
347*cdf0e10cSrcweir 
348*cdf0e10cSrcweir /** Create an oslHostAddr by reverse resolution of the given Addr.
349*cdf0e10cSrcweir     Successful name resolution should result in the fully qualified
350*cdf0e10cSrcweir 	domain name (FQDN) and it's address as hostname and socket address
351*cdf0e10cSrcweir 	members of the resulting oslHostAddr.
352*cdf0e10cSrcweir     @param Addr [in] The socket address to be reverse resolved.
353*cdf0e10cSrcweir 	@return The resulting address or 0 upon failure.
354*cdf0e10cSrcweir */
355*cdf0e10cSrcweir oslHostAddr SAL_CALL osl_createHostAddrByAddr(const oslSocketAddr Addr);
356*cdf0e10cSrcweir 
357*cdf0e10cSrcweir 
358*cdf0e10cSrcweir /**	Create a copy of the given Addr.
359*cdf0e10cSrcweir     @return The copied address or 0 upon failure.
360*cdf0e10cSrcweir */
361*cdf0e10cSrcweir oslHostAddr SAL_CALL osl_copyHostAddr(const oslHostAddr Addr);
362*cdf0e10cSrcweir 
363*cdf0e10cSrcweir 
364*cdf0e10cSrcweir /** Frees all resources allocated by Addr. The handle Addr must not
365*cdf0e10cSrcweir 	be used after the call anymore.
366*cdf0e10cSrcweir */
367*cdf0e10cSrcweir void SAL_CALL osl_destroyHostAddr(oslHostAddr Addr);
368*cdf0e10cSrcweir 
369*cdf0e10cSrcweir 
370*cdf0e10cSrcweir /** Get the hostname member of Addr.
371*cdf0e10cSrcweir     @return The hostname or 0 upon failure.
372*cdf0e10cSrcweir */
373*cdf0e10cSrcweir void SAL_CALL osl_getHostnameOfHostAddr(const oslHostAddr Addr, rtl_uString **strHostname);
374*cdf0e10cSrcweir 
375*cdf0e10cSrcweir 
376*cdf0e10cSrcweir /** Get the socket address member of Addr.
377*cdf0e10cSrcweir     @return The socket address or 0 upon failure.
378*cdf0e10cSrcweir */
379*cdf0e10cSrcweir oslSocketAddr SAL_CALL osl_getSocketAddrOfHostAddr(const oslHostAddr Addr);
380*cdf0e10cSrcweir 
381*cdf0e10cSrcweir /** Retrieve this machines hostname.
382*cdf0e10cSrcweir     May not always be a fully qualified domain name (FQDN).
383*cdf0e10cSrcweir 	@param  strLocalHostname out-parameter. The string that receives the local host name.
384*cdf0e10cSrcweir 	@return <code>sal_True</code> upon success, <code>sal_False</code> otherwise.
385*cdf0e10cSrcweir */
386*cdf0e10cSrcweir oslSocketResult SAL_CALL osl_getLocalHostname(rtl_uString **strLocalHostname);
387*cdf0e10cSrcweir 
388*cdf0e10cSrcweir 
389*cdf0e10cSrcweir /**@} end section oslHostAddr
390*cdf0e10cSrcweir */
391*cdf0e10cSrcweir 
392*cdf0e10cSrcweir /**@{ begin section oslSocket
393*cdf0e10cSrcweir */
394*cdf0e10cSrcweir 
395*cdf0e10cSrcweir 
396*cdf0e10cSrcweir /*-***************************************************************************/
397*cdf0e10cSrcweir /* oslSocket */
398*cdf0e10cSrcweir /*-***************************************************************************/
399*cdf0e10cSrcweir 
400*cdf0e10cSrcweir typedef struct oslSocketImpl * oslSocket;
401*cdf0e10cSrcweir 
402*cdf0e10cSrcweir /** increases the refcount of the socket handle by one
403*cdf0e10cSrcweir  */
404*cdf0e10cSrcweir void SAL_CALL osl_acquireSocket( oslSocket Socket );
405*cdf0e10cSrcweir 
406*cdf0e10cSrcweir /** decreases the refcount of the socket handle by one.
407*cdf0e10cSrcweir 
408*cdf0e10cSrcweir 	If the refcount drops to zero, the underlying socket handle
409*cdf0e10cSrcweir 	is destroyed and becomes invalid.
410*cdf0e10cSrcweir  */
411*cdf0e10cSrcweir void SAL_CALL osl_releaseSocket( oslSocket Socket );
412*cdf0e10cSrcweir 
413*cdf0e10cSrcweir /** Create a socket of the specified Family and Type. The semantic of
414*cdf0e10cSrcweir 	the Protocol parameter depends on the given family and type.
415*cdf0e10cSrcweir 	@return 0 if socket could not be created, otherwise you get a handle
416*cdf0e10cSrcweir 	to the allocated socket-datastructure.
417*cdf0e10cSrcweir */
418*cdf0e10cSrcweir oslSocket SAL_CALL osl_createSocket(oslAddrFamily	Family,
419*cdf0e10cSrcweir 						            oslSocketType	Type,
420*cdf0e10cSrcweir 						            oslProtocol     Protocol);
421*cdf0e10cSrcweir 
422*cdf0e10cSrcweir /**	Retrieves the Address of the local end of the socket.
423*cdf0e10cSrcweir 	Note that a socket must be bound or connected before
424*cdf0e10cSrcweir 	a vaild address can be returned.
425*cdf0e10cSrcweir 	@return 0 if socket-address could not be created, otherwise you get
426*cdf0e10cSrcweir 	the created Socket-Address.
427*cdf0e10cSrcweir */
428*cdf0e10cSrcweir oslSocketAddr SAL_CALL osl_getLocalAddrOfSocket(oslSocket Socket);
429*cdf0e10cSrcweir 
430*cdf0e10cSrcweir /**	Retrieves the Address of the remote end of the socket.
431*cdf0e10cSrcweir 	Note that a socket must be connected before
432*cdf0e10cSrcweir 	a vaild address can be returned.
433*cdf0e10cSrcweir 	@return 0 if socket-address could not be created, otherwise you get
434*cdf0e10cSrcweir 	the created Socket-Address.
435*cdf0e10cSrcweir */
436*cdf0e10cSrcweir oslSocketAddr SAL_CALL osl_getPeerAddrOfSocket(oslSocket Socket);
437*cdf0e10cSrcweir 
438*cdf0e10cSrcweir /** Binds the given address to the socket.
439*cdf0e10cSrcweir 	@param Socket [in]
440*cdf0e10cSrcweir 	@param Address [in]
441*cdf0e10cSrcweir 	@return <code>sal_False</code> if the bind failed, <code> sal_True</code> if successful.
442*cdf0e10cSrcweir 	@see osl_getLastSocketError()
443*cdf0e10cSrcweir */
444*cdf0e10cSrcweir sal_Bool SAL_CALL osl_bindAddrToSocket(oslSocket Socket,
445*cdf0e10cSrcweir 									   oslSocketAddr Addr);
446*cdf0e10cSrcweir 
447*cdf0e10cSrcweir /** Connects the socket to the given address.
448*cdf0e10cSrcweir 
449*cdf0e10cSrcweir     @param Socket [in] a bound socket.
450*cdf0e10cSrcweir     @param Addr [in] the peer address.
451*cdf0e10cSrcweir 	@param pTimeout Timeout value or NULL for blocking.
452*cdf0e10cSrcweir 
453*cdf0e10cSrcweir 	@return <code>osl_Socket_Ok</code> on successful connection,
454*cdf0e10cSrcweir 	        <code>osl_Socket_TimedOut</code> if operation timed out,
455*cdf0e10cSrcweir             <code>osl_Socket_Interrupted</code> if operation was interrupted
456*cdf0e10cSrcweir             <code>osl_Socket_Error</code> if the connection failed.
457*cdf0e10cSrcweir */
458*cdf0e10cSrcweir oslSocketResult SAL_CALL osl_connectSocketTo(oslSocket Socket,
459*cdf0e10cSrcweir 							                 oslSocketAddr Addr,
460*cdf0e10cSrcweir 							                 const TimeValue* pTimeout);
461*cdf0e10cSrcweir 
462*cdf0e10cSrcweir 
463*cdf0e10cSrcweir /** Prepares the socket to act as an acceptor of incoming connections.
464*cdf0e10cSrcweir 	You should call "listen" before you use "accept".
465*cdf0e10cSrcweir 	@param MaxPendingConnections [in] denotes the length of the queue of
466*cdf0e10cSrcweir 	pending connections for this socket. If MaxPendingConnections is
467*cdf0e10cSrcweir 	-1, the systems default value will be used (Usually 5).
468*cdf0e10cSrcweir 	@return <code>sal_False</code> if the listen failed.
469*cdf0e10cSrcweir */
470*cdf0e10cSrcweir sal_Bool SAL_CALL osl_listenOnSocket(oslSocket Socket,
471*cdf0e10cSrcweir 						   sal_Int32 MaxPendingConnections);
472*cdf0e10cSrcweir 
473*cdf0e10cSrcweir 
474*cdf0e10cSrcweir /** Waits for an ingoing connection on the socket.
475*cdf0e10cSrcweir 	This call blocks if there is no incoming connection present.
476*cdf0e10cSrcweir 	@param pAddr [in] if pAddr is != 0, the peers address is returned.
477*cdf0e10cSrcweir 	@return 0 if the accept-call failed, otherwise you get a socket
478*cdf0e10cSrcweir 	representing the new connection.
479*cdf0e10cSrcweir */
480*cdf0e10cSrcweir oslSocket SAL_CALL osl_acceptConnectionOnSocket(oslSocket Socket,
481*cdf0e10cSrcweir 									   oslSocketAddr* pAddr);
482*cdf0e10cSrcweir 
483*cdf0e10cSrcweir /** Tries to receive BytesToRead data from the connected socket,
484*cdf0e10cSrcweir 	if no error occurs. Note that incomplete recvs due to
485*cdf0e10cSrcweir 	packet boundaries may occur.
486*cdf0e10cSrcweir 
487*cdf0e10cSrcweir 	@param Socket [in] A connected socket to be used to listen on.
488*cdf0e10cSrcweir     @param pBuffer [out] Points to a buffer that will be filled with the received
489*cdf0e10cSrcweir 	data.
490*cdf0e10cSrcweir 	@param BytesToRead [in] The number of bytes to read. pBuffer must have at least
491*cdf0e10cSrcweir 	this size.
492*cdf0e10cSrcweir 	@param Flag [in] Modifier for the call. Valid values are:
493*cdf0e10cSrcweir 	<ul>
494*cdf0e10cSrcweir 	<li><code>osl_Socket_MsgNormal</code>
495*cdf0e10cSrcweir 	<li><code>osl_Socket_MsgOOB</code>
496*cdf0e10cSrcweir 	<li><code>osl_Socket_MsgPeek</code>
497*cdf0e10cSrcweir 	<li><code>osl_Socket_MsgDontRoute</code>
498*cdf0e10cSrcweir 	<li><code>osl_Socket_MsgMaxIOVLen</code>
499*cdf0e10cSrcweir 	</ul>
500*cdf0e10cSrcweir 
501*cdf0e10cSrcweir     @return the number of received bytes.
502*cdf0e10cSrcweir */
503*cdf0e10cSrcweir sal_Int32 SAL_CALL osl_receiveSocket(oslSocket Socket,
504*cdf0e10cSrcweir 	    				  void* pBuffer,
505*cdf0e10cSrcweir 		 			      sal_uInt32 BytesToRead,
506*cdf0e10cSrcweir 					      oslSocketMsgFlag Flag);
507*cdf0e10cSrcweir 
508*cdf0e10cSrcweir /** Tries to receives BufferSize data from the (usually unconnected)
509*cdf0e10cSrcweir 	(datagram-)socket, if no error occurs.
510*cdf0e10cSrcweir 
511*cdf0e10cSrcweir 	@param Socket [in] A bound socket to be used to listen for a datagram.
512*cdf0e10cSrcweir 	@param pSenderAddr [out] An pointer to a created oslSocketAddr handle
513*cdf0e10cSrcweir 	or to a null handle. After the call, it will contain the constructed
514*cdf0e10cSrcweir 	oslSocketAddr of the datagrams sender. If pSenderAddr itself is 0,
515*cdf0e10cSrcweir 	it is ignored.
516*cdf0e10cSrcweir 	@param pBuffer [out] Points to a buffer that will be filled with the received
517*cdf0e10cSrcweir 	datagram.
518*cdf0e10cSrcweir 	@param BufferSize [in] The size of pBuffer.
519*cdf0e10cSrcweir 	@param Flag [in] Modifier for the call. Valid values are:
520*cdf0e10cSrcweir 	<ul>
521*cdf0e10cSrcweir 	<li><code>osl_Socket_MsgNormal</code>
522*cdf0e10cSrcweir 	<li><code>osl_Socket_MsgOOB</code>
523*cdf0e10cSrcweir 	<li><code>osl_Socket_MsgPeek</code>
524*cdf0e10cSrcweir 	<li><code>osl_Socket_MsgDontRoute</code>
525*cdf0e10cSrcweir 	<li><code>osl_Socket_MsgMaxIOVLen</code>
526*cdf0e10cSrcweir 	</ul>
527*cdf0e10cSrcweir 
528*cdf0e10cSrcweir 	@return the number of received bytes.
529*cdf0e10cSrcweir */
530*cdf0e10cSrcweir sal_Int32 SAL_CALL osl_receiveFromSocket(oslSocket Socket,
531*cdf0e10cSrcweir 		 				      oslSocketAddr SenderAddr,
532*cdf0e10cSrcweir 						      void* pBuffer,
533*cdf0e10cSrcweir 						      sal_uInt32 BufferSize,
534*cdf0e10cSrcweir 						      oslSocketMsgFlag Flag);
535*cdf0e10cSrcweir 
536*cdf0e10cSrcweir /** Tries to send BytesToSend data from the connected socket,
537*cdf0e10cSrcweir 	if no error occurs.
538*cdf0e10cSrcweir 
539*cdf0e10cSrcweir 	@param Socket [in] A connected socket.
540*cdf0e10cSrcweir     @param pBuffer [in] Points to a buffer that contains the send-data.
541*cdf0e10cSrcweir 	@param BytesToSend [in] The number of bytes to send. pBuffer must have at least
542*cdf0e10cSrcweir 	this size.
543*cdf0e10cSrcweir 	@param Flag [in] Modifier for the call. Valid values are:
544*cdf0e10cSrcweir 	<ul>
545*cdf0e10cSrcweir 	<li><code>osl_Socket_MsgNormal</code>
546*cdf0e10cSrcweir 	<li><code>osl_Socket_MsgOOB</code>
547*cdf0e10cSrcweir 	<li><code>osl_Socket_MsgPeek</code>
548*cdf0e10cSrcweir 	<li><code>osl_Socket_MsgDontRoute</code>
549*cdf0e10cSrcweir 	<li><code>osl_Socket_MsgMaxIOVLen</code>
550*cdf0e10cSrcweir 	</ul>
551*cdf0e10cSrcweir 
552*cdf0e10cSrcweir 	@return the number of transfered bytes.
553*cdf0e10cSrcweir */
554*cdf0e10cSrcweir sal_Int32 SAL_CALL osl_sendSocket(oslSocket Socket,
555*cdf0e10cSrcweir 	    			   const void* pBuffer,
556*cdf0e10cSrcweir 		 		       sal_uInt32 BytesToSend,
557*cdf0e10cSrcweir 				       oslSocketMsgFlag Flag);
558*cdf0e10cSrcweir 
559*cdf0e10cSrcweir /** Tries to send one datagram with BytesToSend data to the given ReceiverAddr
560*cdf0e10cSrcweir 	via the (implicitly unconnected) datagram-socket.
561*cdf0e10cSrcweir 	Since there is only sent one packet, the function sends the data always complete
562*cdf0e10cSrcweir 	even with incomplete packet boundaries.
563*cdf0e10cSrcweir 
564*cdf0e10cSrcweir     @param Socket [in] A bound or unbound socket. Socket will be bound
565*cdf0e10cSrcweir 	after a successful call.
566*cdf0e10cSrcweir 
567*cdf0e10cSrcweir 	@param ReceiverAddr [in] An initialized oslSocketAddress that contains
568*cdf0e10cSrcweir 	the destination address for this send.
569*cdf0e10cSrcweir 
570*cdf0e10cSrcweir     @param pBuffer [in] Points to a buffer that contains the send-data.
571*cdf0e10cSrcweir 	@param BytesToSend [in] The number of bytes to send. pBuffer must have at least
572*cdf0e10cSrcweir 	this size.
573*cdf0e10cSrcweir 	@param Flag [in] Modifier for the call. Valid values are:
574*cdf0e10cSrcweir 	<ul>
575*cdf0e10cSrcweir 	<li><code>osl_Socket_MsgNormal</code>
576*cdf0e10cSrcweir 	<li><code>osl_Socket_MsgOOB</code>
577*cdf0e10cSrcweir 	<li><code>osl_Socket_MsgPeek</code>
578*cdf0e10cSrcweir 	<li><code>osl_Socket_MsgDontRoute</code>
579*cdf0e10cSrcweir 	<li><code>osl_Socket_MsgMaxIOVLen</code>
580*cdf0e10cSrcweir 	</ul>
581*cdf0e10cSrcweir 
582*cdf0e10cSrcweir 	@return the number of transfered bytes.
583*cdf0e10cSrcweir */
584*cdf0e10cSrcweir sal_Int32 SAL_CALL osl_sendToSocket(oslSocket Socket,
585*cdf0e10cSrcweir 	    				 oslSocketAddr ReceiverAddr,
586*cdf0e10cSrcweir 		 			     const void* pBuffer,
587*cdf0e10cSrcweir 					     sal_uInt32 BytesToSend,
588*cdf0e10cSrcweir 					     oslSocketMsgFlag Flag);
589*cdf0e10cSrcweir 
590*cdf0e10cSrcweir /** Checks if read operations will block.
591*cdf0e10cSrcweir 
592*cdf0e10cSrcweir 	You can specify a timeout-value in seconds/microseconds that denotes
593*cdf0e10cSrcweir 	how long the operation will block if the Socket is not ready.
594*cdf0e10cSrcweir 
595*cdf0e10cSrcweir 	@return <code>sal_True</code> if read operations (recv, recvFrom, accept) on the Socket
596*cdf0e10cSrcweir 	will NOT block; <code>sal_False</code> if it would block or if an error occured.
597*cdf0e10cSrcweir 
598*cdf0e10cSrcweir 	@param Socket the Socket to perfom the operation on.
599*cdf0e10cSrcweir 	@param pTimeout if NULL, the operation will block without a timeout.
600*cdf0e10cSrcweir */
601*cdf0e10cSrcweir sal_Bool SAL_CALL osl_isReceiveReady(oslSocket Socket, const TimeValue* pTimeout);
602*cdf0e10cSrcweir 
603*cdf0e10cSrcweir /** Checks if send operations will block.
604*cdf0e10cSrcweir 	You can specify a timeout-value in seconds/microseconds that denotes
605*cdf0e10cSrcweir 	how long the operation will block if the Socket is not ready.
606*cdf0e10cSrcweir 	@return <code>sal_True</code> if send operations (send, sendTo) on the Socket
607*cdf0e10cSrcweir 	will NOT block; <code>sal_False</code> if it would block or if an error occured.
608*cdf0e10cSrcweir 
609*cdf0e10cSrcweir 	@param Socket the Socket to perfom the operation on.
610*cdf0e10cSrcweir 	@param pTimeout if NULL, the operation will block without a timeout. Otherwise
611*cdf0e10cSrcweir 	the time define by timeout value.
612*cdf0e10cSrcweir */
613*cdf0e10cSrcweir sal_Bool SAL_CALL osl_isSendReady(oslSocket Socket, const TimeValue* pTimeout);
614*cdf0e10cSrcweir 
615*cdf0e10cSrcweir /** Checks if a request for out-of-band data will block.
616*cdf0e10cSrcweir 	You can specify a timeout-value in seconds/microseconds that denotes
617*cdf0e10cSrcweir 	how long the operation will block if the Socket has no pending OOB data.
618*cdf0e10cSrcweir 	@return <code>sal_True</code> if OOB-request operations (recv with appropriate flags)
619*cdf0e10cSrcweir 	on the Socket will NOT block; <code>sal_False</code> if it would block or if an error occured.
620*cdf0e10cSrcweir 
621*cdf0e10cSrcweir 	@param Socket the Socket to perfom the operation on.
622*cdf0e10cSrcweir 	@param pTimeout if NULL, the operation will block without a timeout.
623*cdf0e10cSrcweir */
624*cdf0e10cSrcweir sal_Bool SAL_CALL osl_isExceptionPending(oslSocket Socket, const TimeValue* pTimeout);
625*cdf0e10cSrcweir 
626*cdf0e10cSrcweir /** Shuts down communication on a connected socket.
627*cdf0e10cSrcweir 	@param Direction denotes which end of the socket
628*cdf0e10cSrcweir 	should be closed:
629*cdf0e10cSrcweir 	<ul>
630*cdf0e10cSrcweir 	<li> <code>osl_Socket_DirRead</code>	closes read operations.
631*cdf0e10cSrcweir 	<li> <code>osl_Socket_DirReadWrite</code> closes write operations.
632*cdf0e10cSrcweir 	<li> <code>osl_Socket_DirWrite</code> closes read and write operations.
633*cdf0e10cSrcweir 	</ul>
634*cdf0e10cSrcweir 	@return <code>sal_True</code> if the socket could be closed down.
635*cdf0e10cSrcweir */
636*cdf0e10cSrcweir sal_Bool SAL_CALL osl_shutdownSocket(oslSocket Socket,
637*cdf0e10cSrcweir 						   oslSocketDirection Direction);
638*cdf0e10cSrcweir 
639*cdf0e10cSrcweir /** Retrieves attributes associated with the socket.
640*cdf0e10cSrcweir 	@param Socket is the socket to query.
641*cdf0e10cSrcweir 
642*cdf0e10cSrcweir 	@param Level selects the level for which an option should be queried.
643*cdf0e10cSrcweir 	Valid values are:
644*cdf0e10cSrcweir 	<ul>
645*cdf0e10cSrcweir 	<li> osl_sol_socket:	Socket Level
646*cdf0e10cSrcweir 	<li> osl_sol_tcp:		Level of Transmission Control Protocol
647*cdf0e10cSrcweir 	</ul>
648*cdf0e10cSrcweir 
649*cdf0e10cSrcweir 	@param Option denotes the option to query.
650*cdf0e10cSrcweir 	Valid values (depending on the Level) are:
651*cdf0e10cSrcweir 	<ul>
652*cdf0e10cSrcweir 	<li> <code>osl_Socket_Option_Debug</code><br>
653*cdf0e10cSrcweir 	(sal_Bool) Socket debug flag 1 = enabled, 0 = disabled.
654*cdf0e10cSrcweir 
655*cdf0e10cSrcweir 	<li> <code>osl_Socket_OptionAcceptConn</code><br>
656*cdf0e10cSrcweir 	<li> <code>osl_Socket_OptionReuseAddr</code><br>
657*cdf0e10cSrcweir 	(sal_Bool) Allows the socket to be bound to an address that is
658*cdf0e10cSrcweir 	already in use.
659*cdf0e10cSrcweir 	1 = multiple bound allowed, 0 = no multiple bounds allowed
660*cdf0e10cSrcweir 
661*cdf0e10cSrcweir 	<li><code>osl_Socket_OptionKeepAlive</code><br>
662*cdf0e10cSrcweir 	(sal_Bool) Keepalive packets are sent by the underlying socket.
663*cdf0e10cSrcweir 	1 = enabled, 0 = disabled
664*cdf0e10cSrcweir 
665*cdf0e10cSrcweir 	<li><code>osl_Socket_OptionDontRoute</code><br>
666*cdf0e10cSrcweir 	(sal_Bool) Do not route: send directly to interface.
667*cdf0e10cSrcweir 	1 = do not route , 0 = routing possible
668*cdf0e10cSrcweir 
669*cdf0e10cSrcweir 	<li><code>osl_Socket_OptionBroadcast</code><br>
670*cdf0e10cSrcweir 	(sal_Bool) Transmission of broadcast messages are allowed on the socket.
671*cdf0e10cSrcweir 	1 = transmission allowed, 0 = transmission disallowed
672*cdf0e10cSrcweir 
673*cdf0e10cSrcweir 	<li><code>osl_Socket_OptionUseLoopback</code><br>
674*cdf0e10cSrcweir 
675*cdf0e10cSrcweir 	<li><code>osl_Socket_OptionLinger</code><br>
676*cdf0e10cSrcweir 	(sal_Int32) Linger on close if unsent data is present.
677*cdf0e10cSrcweir 	0 = linger is off, > 0  = timeout in seconds.
678*cdf0e10cSrcweir 
679*cdf0e10cSrcweir 	<li><code>osl_Socket_OptionOOBinLine</code><br>
680*cdf0e10cSrcweir 
681*cdf0e10cSrcweir 
682*cdf0e10cSrcweir 	<li><code>osl_Socket_OptionSndBuf</code><br>
683*cdf0e10cSrcweir 	(sal_Int32) Size of the send buffer in bytes. Data is sent after
684*cdf0e10cSrcweir 	SndTimeo or when the buffer is full. This allows faster writing
685*cdf0e10cSrcweir 	to the socket.
686*cdf0e10cSrcweir 
687*cdf0e10cSrcweir 	<li><code>osl_Socket_OptionRcvBuf</code><br>
688*cdf0e10cSrcweir 	(sal_Int32) Size of the receive buffer in bytes. Data is sent after
689*cdf0e10cSrcweir 	SndTimeo or when the buffer is full. This allows faster writing
690*cdf0e10cSrcweir 	to the socket and larger packet sizes.
691*cdf0e10cSrcweir 
692*cdf0e10cSrcweir 	<li><code>osl_Socket_OptionSndLowat</code><br>
693*cdf0e10cSrcweir 
694*cdf0e10cSrcweir 	<li><code>osl_Socket_OptionRcvLowat</code><br>
695*cdf0e10cSrcweir 
696*cdf0e10cSrcweir 	<li><code>osl_Socket_OptionSndTimeo</code><br>
697*cdf0e10cSrcweir 	(sal_Int32) Data is sent after this timeout. This allows gathering
698*cdf0e10cSrcweir 	of data to send larger packages but increases latency times.
699*cdf0e10cSrcweir 
700*cdf0e10cSrcweir 	<li><code>osl_Socket_OptionRcvTimeo</code><br>
701*cdf0e10cSrcweir 
702*cdf0e10cSrcweir 	<li><code>osl_Socket_OptionError</code><br>
703*cdf0e10cSrcweir 	<li><code>osl_Socket_OptionType</code><br>
704*cdf0e10cSrcweir 
705*cdf0e10cSrcweir 	<li><code>osl_Socket_OptionTcpNoDelay</code><br>
706*cdf0e10cSrcweir 	Disables the Nagle algorithm for send coalescing. (Do not
707*cdf0e10cSrcweir 	collect data until a packet is full, instead send immediatly.
708*cdf0e10cSrcweir 	This increases network traffic but might improve latency-times.)
709*cdf0e10cSrcweir 	1 = disables the algorithm, 0 = keeps it enabled.
710*cdf0e10cSrcweir 	</ul>
711*cdf0e10cSrcweir 	If not above mentioned otherwise, the options are only valid for
712*cdf0e10cSrcweir 	level <code>osl_Socket_LevelSocket</code>.
713*cdf0e10cSrcweir 
714*cdf0e10cSrcweir 	@param pBuffer Pointer to a buffer large enough to take the desired
715*cdf0e10cSrcweir 	attribute-value.
716*cdf0e10cSrcweir 
717*cdf0e10cSrcweir 	@param BufferSize contains the length of the Buffer.
718*cdf0e10cSrcweir 
719*cdf0e10cSrcweir 	@return -1 if an error occured or else the size of the data copied into
720*cdf0e10cSrcweir 	pBuffer.
721*cdf0e10cSrcweir 	@see osl_setSocketOption()
722*cdf0e10cSrcweir */
723*cdf0e10cSrcweir sal_Int32 SAL_CALL osl_getSocketOption(oslSocket            Socket,
724*cdf0e10cSrcweir    					        oslSocketOptionLevel Level,
725*cdf0e10cSrcweir 						    oslSocketOption		 Option,
726*cdf0e10cSrcweir 						    void*				 pBuffer,
727*cdf0e10cSrcweir 						    sal_uInt32				 BufferLen);
728*cdf0e10cSrcweir 
729*cdf0e10cSrcweir /** Sets the sockets attributes.
730*cdf0e10cSrcweir 
731*cdf0e10cSrcweir 	@param Socket is the socket to modify.
732*cdf0e10cSrcweir 
733*cdf0e10cSrcweir 	@param Level selects the level for which an option should be changed.
734*cdf0e10cSrcweir 	Valid values are:
735*cdf0e10cSrcweir 	<ul>
736*cdf0e10cSrcweir 	<li> osl_sol_socket:	Socket Level
737*cdf0e10cSrcweir 	<li> osl_sol_tcp:		Level of Transmission Control Protocol
738*cdf0e10cSrcweir 	</ul>
739*cdf0e10cSrcweir 
740*cdf0e10cSrcweir 	@param Option denotes the option to modify. See osl_setSocketOption() for more
741*cdf0e10cSrcweir 	details.
742*cdf0e10cSrcweir 
743*cdf0e10cSrcweir 	@param pBuffer Pointer to a Buffer which contains the attribute-value.
744*cdf0e10cSrcweir 
745*cdf0e10cSrcweir 	@param BufferSize contains the length of the Buffer.
746*cdf0e10cSrcweir 
747*cdf0e10cSrcweir 	@return True if the option could be changed.
748*cdf0e10cSrcweir */
749*cdf0e10cSrcweir sal_Bool SAL_CALL osl_setSocketOption(oslSocket Socket,
750*cdf0e10cSrcweir 							oslSocketOptionLevel	Level,
751*cdf0e10cSrcweir 							oslSocketOption			Option,
752*cdf0e10cSrcweir 							void*					pBuffer,
753*cdf0e10cSrcweir 							sal_uInt32					BufferLen);
754*cdf0e10cSrcweir 
755*cdf0e10cSrcweir /** Enables/disables non-blocking-mode of the socket.
756*cdf0e10cSrcweir 	@param Socket Change mode for this socket.
757*cdf0e10cSrcweir 	@param On <code>sal_True</code> enables non-blocking mode,
758*cdf0e10cSrcweir 	          <code>sal_False</code> disables non-blocking mode.
759*cdf0e10cSrcweir 	@return <code>sal_True</code> if mode could be changed.
760*cdf0e10cSrcweir */
761*cdf0e10cSrcweir sal_Bool SAL_CALL osl_enableNonBlockingMode(oslSocket Socket,
762*cdf0e10cSrcweir 								  sal_Bool On);
763*cdf0e10cSrcweir 
764*cdf0e10cSrcweir 
765*cdf0e10cSrcweir /** Query state of non-blocking-mode of the socket.
766*cdf0e10cSrcweir 	@param Socket Query mode for this socket.
767*cdf0e10cSrcweir 	@return True if non-blocking-mode is enabled.
768*cdf0e10cSrcweir */
769*cdf0e10cSrcweir sal_Bool SAL_CALL osl_isNonBlockingMode(oslSocket Socket);
770*cdf0e10cSrcweir 
771*cdf0e10cSrcweir 
772*cdf0e10cSrcweir /** Queries the socket for its type.
773*cdf0e10cSrcweir 	@return one of:
774*cdf0e10cSrcweir 	<ul>
775*cdf0e10cSrcweir 	<li> osl_Socket_TypeStream
776*cdf0e10cSrcweir 	<li> osl_Socket_TypeDgram
777*cdf0e10cSrcweir 	<li> osl_Socket_TypeRaw
778*cdf0e10cSrcweir 	<li> osl_Socket_TypeRdm
779*cdf0e10cSrcweir 	<li> osl_Socket_TypeSeqPacket
780*cdf0e10cSrcweir 	<li> osl_invalid_SocketType, if an error occured
781*cdf0e10cSrcweir 	</ul>
782*cdf0e10cSrcweir 
783*cdf0e10cSrcweir */
784*cdf0e10cSrcweir oslSocketType SAL_CALL osl_getSocketType(oslSocket Socket);
785*cdf0e10cSrcweir 
786*cdf0e10cSrcweir /** returns  a string which describes the last socket error.
787*cdf0e10cSrcweir 	@param strError out-parameter. The string that receives the error message.
788*cdf0e10cSrcweir */
789*cdf0e10cSrcweir void SAL_CALL osl_getLastSocketErrorDescription(oslSocket Socket, rtl_uString **strError);
790*cdf0e10cSrcweir 
791*cdf0e10cSrcweir /** returns a constant decribing the last error for the socket system.
792*cdf0e10cSrcweir 	@return <code>osl_Socket_E_NONE</code> if no error occured,
793*cdf0e10cSrcweir 	        <code>osl_invalid_SocketError</code> if	an unknown (unmapped)
794*cdf0e10cSrcweir 			error occured, otherwise an enum describing the	error.
795*cdf0e10cSrcweir */
796*cdf0e10cSrcweir oslSocketError SAL_CALL osl_getLastSocketError(oslSocket Socket);
797*cdf0e10cSrcweir 
798*cdf0e10cSrcweir /** Type for the representation of socket sets.
799*cdf0e10cSrcweir */
800*cdf0e10cSrcweir typedef struct oslSocketSetImpl * oslSocketSet;
801*cdf0e10cSrcweir 
802*cdf0e10cSrcweir /** Creates a set of sockets to be used with osl_demultiplexSocketEvents().
803*cdf0e10cSrcweir 	@return A oslSocketSet or 0 if creation failed.
804*cdf0e10cSrcweir */
805*cdf0e10cSrcweir oslSocketSet SAL_CALL osl_createSocketSet(void);
806*cdf0e10cSrcweir 
807*cdf0e10cSrcweir /** Destroys a oslSocketSet.
808*cdf0e10cSrcweir */
809*cdf0e10cSrcweir void SAL_CALL osl_destroySocketSet(oslSocketSet Set);
810*cdf0e10cSrcweir 
811*cdf0e10cSrcweir /** Clears the set from all previously added sockets.
812*cdf0e10cSrcweir 	@param Set the set to be cleared.
813*cdf0e10cSrcweir */
814*cdf0e10cSrcweir void SAL_CALL osl_clearSocketSet(oslSocketSet Set);
815*cdf0e10cSrcweir 
816*cdf0e10cSrcweir 
817*cdf0e10cSrcweir /** Adds a socket to the set.
818*cdf0e10cSrcweir 	@param Set the set were the socket is added.
819*cdf0e10cSrcweir 	@param Socket the socket to be added.
820*cdf0e10cSrcweir */
821*cdf0e10cSrcweir void SAL_CALL osl_addToSocketSet(oslSocketSet Set, oslSocket Socket);
822*cdf0e10cSrcweir 
823*cdf0e10cSrcweir /** Removes a socket from the set.
824*cdf0e10cSrcweir 	@param Set the set were the socket is removed from.
825*cdf0e10cSrcweir 	@param Socket the socket to be removed.
826*cdf0e10cSrcweir */
827*cdf0e10cSrcweir void SAL_CALL osl_removeFromSocketSet(oslSocketSet Set, oslSocket Socket);
828*cdf0e10cSrcweir 
829*cdf0e10cSrcweir /** Checks if socket is in the set.
830*cdf0e10cSrcweir 	@param Set the set to be checked.
831*cdf0e10cSrcweir 	@param Socket check if this socket is in the set.
832*cdf0e10cSrcweir 	@return <code>sal_True</code> if socket is in the set.
833*cdf0e10cSrcweir */
834*cdf0e10cSrcweir sal_Bool SAL_CALL osl_isInSocketSet(oslSocketSet Set, oslSocket Socket);
835*cdf0e10cSrcweir 
836*cdf0e10cSrcweir /** Checks multiple sockets for events.
837*cdf0e10cSrcweir 	@param IncomingSet Checks the sockets in this set
838*cdf0e10cSrcweir 	for incoming events (read, accept). If the set is 0,
839*cdf0e10cSrcweir 	it is just skipped.
840*cdf0e10cSrcweir 	@param OutgoingSet Checks the sockets in this set
841*cdf0e10cSrcweir 	for outgoing events (write, connect). If the set is 0,
842*cdf0e10cSrcweir 	it is just skipped.
843*cdf0e10cSrcweir 	@param OutOfBandSet Checks the sockets in this set
844*cdf0e10cSrcweir 	for out-of-band events. If the set is 0, it is just skipped.
845*cdf0e10cSrcweir 	@param msTimeout Number of milliseconds to wait for events. If
846*cdf0e10cSrcweir 	msTimeout is -1, the call will block until an event or an error
847*cdf0e10cSrcweir 	occurs.
848*cdf0e10cSrcweir 	@return -1 on errors, otherwise the number of sockets with
849*cdf0e10cSrcweir 	pending events. In case of timeout, the number might be 0.
850*cdf0e10cSrcweir */
851*cdf0e10cSrcweir sal_Int32 SAL_CALL osl_demultiplexSocketEvents(oslSocketSet IncomingSet,
852*cdf0e10cSrcweir 									oslSocketSet OutgoingSet,
853*cdf0e10cSrcweir 									oslSocketSet OutOfBandSet,
854*cdf0e10cSrcweir 									const TimeValue* pTimeout);
855*cdf0e10cSrcweir 
856*cdf0e10cSrcweir /** Closes the socket terminating any ongoing dataflow.
857*cdf0e10cSrcweir  */
858*cdf0e10cSrcweir void SAL_CALL osl_closeSocket(oslSocket Socket);
859*cdf0e10cSrcweir 
860*cdf0e10cSrcweir 
861*cdf0e10cSrcweir /** Retrieves n bytes from the stream and copies them into pBuffer.
862*cdf0e10cSrcweir 	The function avoids incomplete reads due to packet boundaries.
863*cdf0e10cSrcweir 	@param pBuffer receives the read data.
864*cdf0e10cSrcweir 	@param n the number of bytes to read. pBuffer must be large enough
865*cdf0e10cSrcweir 	to hold the n bytes!
866*cdf0e10cSrcweir 	@return	the number of read bytes. The number will only be smaller than
867*cdf0e10cSrcweir 	n if an exceptional condition (e.g. connection closed) occurs.
868*cdf0e10cSrcweir */
869*cdf0e10cSrcweir sal_Int32 SAL_CALL osl_readSocket( oslSocket Socket, void *pBuffer, sal_Int32 nSize );
870*cdf0e10cSrcweir 
871*cdf0e10cSrcweir 
872*cdf0e10cSrcweir /** Writes n bytes from pBuffer to the stream. The method avoids
873*cdf0e10cSrcweir 	incomplete writes due to packet boundaries.
874*cdf0e10cSrcweir 	@param pBuffer contains the data to be written.
875*cdf0e10cSrcweir 	@param n the number of bytes to write.
876*cdf0e10cSrcweir 	@return the number of written bytes. The number will only be smaller than
877*cdf0e10cSrcweir 	n if an exceptional condition (e.g. connection closed) occurs.
878*cdf0e10cSrcweir */
879*cdf0e10cSrcweir sal_Int32 SAL_CALL osl_writeSocket( oslSocket Socket, const void *pBuffer, sal_Int32 nSize );
880*cdf0e10cSrcweir 
881*cdf0e10cSrcweir /**@} end section oslSocket
882*cdf0e10cSrcweir */
883*cdf0e10cSrcweir 
884*cdf0e10cSrcweir 
885*cdf0e10cSrcweir 
886*cdf0e10cSrcweir #ifdef __cplusplus
887*cdf0e10cSrcweir }
888*cdf0e10cSrcweir #endif
889*cdf0e10cSrcweir 
890*cdf0e10cSrcweir #endif	/* _OSL_SOCKET_H_ */
891*cdf0e10cSrcweir 
892