PageRenderTime 48ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/OOO330_m20/sal/inc/osl/socket.h

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