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