PageRenderTime 49ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/sal/inc/osl/socket.h

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