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