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