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 28 #ifndef _OSL_SOCKET_DECL_HXX_ 29 #define _OSL_SOCKET_DECL_HXX_ 30 31 #include <osl/socket.h> 32 #include <rtl/ustring.hxx> 33 #include <rtl/byteseq.hxx> 34 35 /** @HTML 36 */ 37 namespace osl 38 { 39 enum __osl_socket_NoCopy { SAL_NO_COPY }; 40 41 /** The class should be understood as a reference to a socket address handle ( struct sockaddr ). 42 43 The handle is mutable. 44 */ 45 class SocketAddr 46 { 47 protected: 48 oslSocketAddr m_handle; 49 public: 50 51 /** Creates socket address of unknown type. 52 */ 53 inline SocketAddr(); 54 55 /** Copy constructor. 56 */ 57 inline SocketAddr(const SocketAddr& Addr); 58 59 /** The SocketAddr takes over the responsibility of the handle ( which means, 60 that the handle gets destructed by the destructor of this reference) 61 62 @param nocopy use SAL_NO_COPY 63 */ 64 inline SocketAddr(const oslSocketAddr , __osl_socket_NoCopy nocopy ); 65 66 /** Copyconstructs the oslSocketAddr handle. 67 */ 68 inline SocketAddr(oslSocketAddr Addr); 69 70 /** tcpip-specif constructor. 71 @param strAddrOrHostName strAddrOrHostName hostname or dotted ip-number of the network 72 interface, the socket shall be created on. 73 @param nPort tcp-ip port number 74 */ 75 inline SocketAddr( const ::rtl::OUString& strAddrOrHostName, sal_Int32 nPort ); 76 77 /** destroys underlying oslSocketAddress 78 */ 79 inline ~SocketAddr(); 80 81 /** checks, if the SocketAddr was created successful. 82 @return <code>sal_True</code> if there is a valid underlying handle, 83 otherwise sal_False. 84 */ 85 inline sal_Bool is() const; 86 87 /** Converts the address to a (human readable) domain-name. 88 89 @param pResult 0, if you are not interested in errors, 90 otherwise *pResult contains an error code on failure 91 or osl_Socket_Ok on success 92 @return the hostname of this SocketAddr or an empty string on failure. 93 @see osl_getHostnameOfSocketAddr() 94 */ 95 inline ::rtl::OUString SAL_CALL getHostname( oslSocketResult *pResult = 0 ) const; 96 97 /** Sets the ipaddress or hostname of the SocketAddress 98 */ 99 inline sal_Bool SAL_CALL setHostname( const ::rtl::OUString &sDottedIpOrHostname ); 100 101 /** Returns the port number of the address. 102 @return the port in host-byte order or or OSL_INVALID_PORT on errors. 103 */ 104 inline sal_Int32 SAL_CALL getPort() const; 105 106 /** Sets the port number of the address. 107 @return true if successfule. 108 */ 109 inline sal_Bool SAL_CALL setPort( sal_Int32 nPort ); 110 111 /** Sets the address of the underlying socket address struct in network byte order. 112 @return true on success, false signales falure. 113 */ 114 inline sal_Bool SAL_CALL setAddr( const ::rtl::ByteSequence & address ); 115 116 /** Returns the address of the underlying socket in network byte order 117 */ 118 inline ::rtl::ByteSequence SAL_CALL getAddr( oslSocketResult *pResult = 0 ) const; 119 120 /** assign the handle to this reference. The previous handle is released. 121 */ 122 inline SocketAddr & SAL_CALL operator= (oslSocketAddr Addr); 123 124 /** 125 */ 126 inline SocketAddr & SAL_CALL operator= (const SocketAddr& Addr); 127 128 /** Assigns the socket addr without copyconstructing it. 129 @param nocopy use SAL_NO_COPY 130 */ 131 inline SocketAddr & SAL_CALL assign( oslSocketAddr Addr, __osl_socket_NoCopy nocopy ); 132 133 /** Returns true if the underlying handle is identical to the Addr handle. 134 */ 135 inline sal_Bool SAL_CALL operator== (oslSocketAddr Addr) const; 136 137 /** Returns true if the underlying handle is identical to the Addr handle. 138 */ 139 inline sal_Bool SAL_CALL operator== (const SocketAddr & Addr) const; 140 141 /** Returns the underlying SocketAddr handle without copyconstructing it. 142 */ 143 inline oslSocketAddr SAL_CALL getHandle() const; 144 145 /** Get the hostname for the local interface. 146 @param after the call *pResult contains osl_Socket_Ok on success or 147 an error on failure. 148 @return the hostname 149 */ 150 static inline ::rtl::OUString SAL_CALL getLocalHostname( oslSocketResult *pResult = 0); 151 152 /** Tries to find an address for a host. 153 @see osl_resolveHostname() 154 @return A new created socket-address or 0 if the name could not be found. 155 */ 156 static inline void SAL_CALL resolveHostname( 157 const ::rtl::OUString & strHostName , SocketAddr & Addr ); 158 159 /** 160 Tries to find the port associated with the given service/protocol- 161 pair (e.g. "ftp"/"tcp"). 162 @return the port number in host-byte order or <code>OSL_INVALID_PORT</code> 163 if no service/protocol pair could be found. 164 */ 165 static inline sal_Int32 SAL_CALL getServicePort( 166 const ::rtl::OUString& strServiceName, 167 const ::rtl::OUString & strProtocolName= ::rtl::OUString::createFromAscii( "tcp" ) ); 168 }; 169 170 171 class Socket 172 { 173 protected: 174 oslSocket m_handle; 175 protected: 176 /** Creates a socket. Note it's protected. 177 @param Type 178 @param Family 179 @param Protocol 180 */ 181 inline Socket(oslSocketType Type, 182 oslAddrFamily Family = osl_Socket_FamilyInet, 183 oslProtocol Protocol = osl_Socket_ProtocolIp); 184 public: 185 inline Socket( ); 186 187 inline Socket( const Socket & socket ); 188 189 inline Socket( oslSocket socketHandle ); 190 191 /** The instance takes over the handle's ownership without acquiring the 192 handle, but releases it within the dtor. 193 @param noacquire use SAL_NO_ACQUIRE 194 */ 195 inline Socket( oslSocket socketHandle, __sal_NoAcquire noacquire ); 196 197 /** Destructor. Releases the underlying handle 198 */ 199 inline ~Socket(); 200 201 /** Assignment operator. If socket was already created, the old one will 202 be discarded. 203 */ 204 inline Socket& SAL_CALL operator= ( oslSocket socketHandle); 205 206 /** Assignment operator. If socket was already created, the old one will 207 be discarded. 208 */ 209 inline Socket& SAL_CALL operator= (const Socket& sock); 210 211 /** 212 @return <code>sal_True</code>, when the underlying handle of both 213 Socket instances are identical, <code>sal_False</code> otherwise. 214 */ 215 inline sal_Bool SAL_CALL operator==( const Socket& rSocket ) const ; 216 217 /** 218 @return <code>sal_True</code>, when the underlying handle of both 219 Socket instances are identical, <code>sal_False</code> otherwise. 220 */ 221 inline sal_Bool SAL_CALL operator==( const oslSocket socketHandle ) const; 222 223 /** Closes a definite or both directions of the bidirectional stream. 224 225 @param Direction 226 @see osl_shutdownSocket() 227 */ 228 inline void SAL_CALL shutdown( oslSocketDirection Direction = osl_Socket_DirReadWrite ); 229 230 /** Closes a socket. 231 Note that closing a socket is identical to shutdown( osl_Socket_DirReadWrite ), 232 as the operating system distinguish both cases, both functions or offered in this API. 233 @see osl_closeSocket() 234 */ 235 inline void SAL_CALL close(); 236 237 /** Retrieves the address of the local interface of this socket. 238 @param Addr [out] receives the address. 239 @see osl_getLocalAddrOfSocket() 240 */ 241 inline void SAL_CALL getLocalAddr( SocketAddr &Addr ) const; 242 243 /** Get the local port of the socket. Usually used after bind(). 244 @return the port number or OSL_INVALID_PORT on errors. 245 */ 246 inline sal_Int32 SAL_CALL getLocalPort() const; 247 248 /** Get the hostname for the local interface. 249 @return the hostname or an empty string (""). 250 */ 251 inline ::rtl::OUString SAL_CALL getLocalHost() const; 252 253 /** Retrieves the address of the remote host of this socket. 254 @param Addr [out] receives the address. 255 */ 256 inline void SAL_CALL getPeerAddr( SocketAddr & Addr) const; 257 258 /** Get the remote port of the socket. 259 @return the port number or OSL_INVALID_PORT on errors. 260 */ 261 inline sal_Int32 SAL_CALL getPeerPort() const; 262 263 /** Get the hostname for the remote interface. 264 @return the hostname or an empty string (""). 265 */ 266 inline ::rtl::OUString SAL_CALL getPeerHost() const; 267 268 /** Binds the socket to the specified (local) interface. 269 @param LocalInterface Address of the Interface 270 @return True if bind was successful. 271 */ 272 inline sal_Bool SAL_CALL bind(const SocketAddr& LocalInterface); 273 274 /** Checks if read operations will block. 275 276 You can specify a timeout-value in seconds/nanoseconds that denotes 277 how the operation will block if the Socket is not ready. 278 @return <code>sal_True</code> if read operations (recv, recvFrom, accept) on the Socket 279 will NOT block; <code>sal_False</code> if it would block or if an error occured. 280 281 @param pTimeout if 0, the operation will block without a timeout. Otherwise 282 the specified amout of time. 283 */ 284 inline sal_Bool SAL_CALL isRecvReady(const TimeValue *pTimeout = 0) const; 285 286 /** Checks if send operations will block. 287 288 You can specify a timeout-value in seconds/nanoseconds that denotes 289 how the operation will block if the Socket is not ready. 290 @return <code>sal_True</code> if send operations (send, sendTo) on the Socket 291 will NOT block; <code>sal_False</code> if it would block or if an error occured. 292 293 @param pTimeout if 0, the operation will block without a timeout. Otherwise 294 the specified amout of time. 295 */ 296 inline sal_Bool SAL_CALL isSendReady(const TimeValue *pTimeout = 0) const; 297 298 299 /** Checks if a request for out-of-band data will block. 300 301 You can specify a timeout-value in seconds/nanoseconds that denotes 302 how the operation will block if the Socket has no pending OOB data. 303 304 @return <code>sal_True</code> if OOB-request operations (recv with appropriate flags) 305 on the Socket will NOT block; <code>sal_False</code> if it would block or if 306 an error occured. 307 308 @param pTimeout if 0, the operation will block without a timeout. Otherwise 309 the specified amout of time. 310 */ 311 inline sal_Bool SAL_CALL isExceptionPending(const TimeValue *pTimeout = 0) const; 312 313 314 /** Queries the socket for its type. 315 @return one of: 316 <ul> 317 <li> <code>osl_Socket_TypeStream</code> 318 <li> <code>osl_Socket_TypeDgram</code> 319 <li> <code>osl_Socket_TypeRaw</code> 320 <li> <code>osl_Socket_TypeRdm</code> 321 <li> <code>osl_Socket_TypeSeqPacket</code> 322 <li> <code>osl_invalid_SocketType</code>, if an error occured 323 </ul> 324 */ 325 inline oslSocketType SAL_CALL getType() const; 326 327 /** Retrieves option-attributes associated with the socket. 328 @param Option The attribute to query. 329 Valid values (depending on the Level) are: 330 <ul> 331 <li> <code>osl_Socket_Option_Debug</code><br> 332 (sal_Bool) Socket debug flag 1 = enabled, 0 = disabled. 333 334 <li> <code>osl_Socket_OptionAcceptConn</code><br> 335 <li> <code>osl_Socket_OptionReuseAddr</code><br> 336 (sal_Bool) Allows the socket to be bound to an address that is 337 already in use. 338 1 = multiple bound allowed, 0 = no multiple bounds allowed 339 340 <li><code>osl_Socket_OptionKeepAlive</code><br> 341 (sal_Bool) Keepalive packets are sent by the underlying socket. 342 1 = enabled, 0 = disabled 343 344 <li><code>osl_Socket_OptionDontRoute</code><br> 345 (sal_Bool) Do not route: send directly to interface. 346 1 = do not route , 0 = routing possible 347 348 <li><code>osl_Socket_OptionBroadcast</code><br> 349 (sal_Bool) Transmission of broadcast messages are allowed on the socket. 350 1 = transmission allowed, 0 = transmission disallowed 351 352 <li><code>osl_Socket_OptionUseLoopback</code><br> 353 354 <li><code>osl_Socket_OptionLinger</code><br> 355 (linger) Linger on close if unsent data is present. 356 linger has two members: l_onoff, l_linger 357 l_onoff = 0 is off, l_onoff > 0 and l_linger= timeout in seconds. 358 359 <li><code>osl_Socket_OptionOOBinLine</code><br> 360 361 362 <li><code>osl_Socket_OptionSndBuf</code><br> 363 (sal_Int32) Size of the send buffer in bytes. Data is sent after 364 SndTimeo or when the buffer is full. This allows faster writing 365 to the socket. 366 367 <li><code>osl_Socket_OptionRcvBuf</code><br> 368 (sal_Int32) Size of the receive buffer in bytes. Data is sent after 369 SndTimeo or when the buffer is full. This allows faster writing 370 to the socket and larger packet sizes. 371 372 <li><code>osl_Socket_OptionSndLowat</code><br> 373 374 <li><code>osl_Socket_OptionRcvLowat</code><br> 375 376 <li><code>osl_Socket_OptionSndTimeo</code><br> 377 (sal_Int32) Data is sent after this timeout. This allows gathering 378 of data to send larger packages but increases latency times. 379 380 <li><code>osl_Socket_OptionRcvTimeo</code><br> 381 382 <li><code>osl_Socket_OptionError</code><br> 383 <li><code>osl_Socket_OptionType</code><br> 384 385 <li><code>osl_Socket_OptionTcpNoDelay</code><br> 386 Disables the Nagle algorithm for send coalescing. (Do not 387 collect data until a packet is full, instead send immediatly. 388 This increases network traffic but might improve latency-times.) 389 1 = disables the algorithm, 0 = keeps it enabled. 390 </ul> 391 392 If not above mentioned otherwise, the options are only valid for 393 level <code>osl_Socket_LevelSocket</code>. 394 @param pBuffer The Buffer will be filled with the attribute. 395 396 @param BufferSize The size of pBuffer. 397 398 @param Level The option level. 399 400 Valid values are: 401 <ul> 402 <li><code>osl_Socket_LevelSocket</code> : Socket Level 403 <li><code>osl_Socket_LevelTcp</code> : Level of Transmission Control Protocol 404 </ul> 405 @return The size of the attribute copied into pBuffer or -1 if an error 406 occured. 407 */ 408 inline sal_Int32 SAL_CALL getOption( 409 oslSocketOption Option, 410 void* pBuffer, 411 sal_uInt32 BufferLen, 412 oslSocketOptionLevel Level= osl_Socket_LevelSocket) const; 413 414 /** Sets the sockets attributes. 415 416 @param Option denotes the option to modify. 417 Valid values (depending on the Level) are: 418 <ul> 419 <li> osl_Socket_Option_Debug 420 <li> osl_Socket_OptionAcceptConn 421 <li> osl_Socket_OptionReuseAddr 422 <li> osl_Socket_OptionKeepAlive 423 <li> osl_Socket_OptionDontRoute 424 <li> osl_Socket_OptionBroadcast 425 <li> osl_Socket_OptionUseLoopback 426 <li> osl_Socket_OptionLinger 427 <li> osl_Socket_OptionOOBinLine 428 <li> osl_Socket_OptionSndBuf 429 <li> osl_Socket_OptionRcvBuf 430 <li> osl_Socket_OptionSndLowat 431 <li> osl_Socket_OptionRcvLowat 432 <li> osl_Socket_OptionSndTimeo 433 <li> osl_Socket_OptionRcvTimeo 434 <li> osl_Socket_OptionError 435 <li> osl_Socket_OptionType 436 <li> osl_Socket_OptionTcpNoDelay 437 </ul> 438 439 If not above mentioned otherwise, the options are only valid for 440 level osl_Socket_LevelSocket. 441 442 @param pBuffer Pointer to a Buffer which contains the attribute-value. 443 444 @param BufferSize contains the length of the Buffer. 445 446 @param Level selects the level for which an option should be changed. 447 Valid values are: 448 <ul> 449 <li> osl_Socket_evel_Socket : Socket Level 450 <li> osl_Socket_Level_Tcp : Level of Transmission Control Protocol 451 </ul> 452 453 @return True if the option could be changed. 454 */ 455 inline sal_Bool SAL_CALL setOption( oslSocketOption Option, 456 void* pBuffer, 457 sal_uInt32 BufferLen, 458 oslSocketOptionLevel Level= osl_Socket_LevelSocket ) const; 459 460 /** Convenience function for setting sal_Bool and sal_Int32 option values. 461 @see setOption() 462 */ 463 inline sal_Bool setOption( oslSocketOption option, sal_Int32 nValue ); 464 465 /** Convenience function for retrieving sal_Bool and sal_Int32 option values. 466 @see setOption() 467 */ 468 inline sal_Int32 getOption( oslSocketOption option ) const; 469 470 /** Enables/disables non-blocking mode of the socket. 471 @param bNonBlockingMode If <code>sal_True</code>, blocking mode will be switched off 472 If <code>sal_False</code>, the socket will become a blocking 473 socket (which is the default behaviour of a socket). 474 @return <code>sal_True</code> if mode could be set. 475 */ 476 inline sal_Bool SAL_CALL enableNonBlockingMode( sal_Bool bNonBlockingMode); 477 478 /** Query blocking mode of the socket. 479 @return <code>sal_True</code> if non-blocking mode is set. 480 */ 481 inline sal_Bool SAL_CALL isNonBlockingMode() const; 482 483 484 /** clears the error status 485 */ 486 inline void SAL_CALL clearError() const; 487 488 /** returns a constant decribing the last error for the socket system. 489 490 @return osl_Socket_E_NONE if no error occured, invalid_SocketError if 491 an unknown (unmapped) error occured, otherwise an enum describing the 492 error. 493 @see osl_getLastSocketError() 494 */ 495 inline oslSocketError getError() const; 496 497 /** Builds a string with the last error-message for the socket. 498 */ 499 inline ::rtl::OUString getErrorAsString( ) const; 500 501 /** Returns the underlying handle unacquired (The caller must acquire it to keep it). 502 */ 503 inline oslSocket getHandle() const; 504 }; 505 506 507 class StreamSocket : public Socket 508 { 509 public: 510 /** Creates a socket. 511 @param Type For some protocols it might be desirable to 512 use a different type than <code>osl_Socket_TypeStream</code> 513 (like <code>osl_Socket_TypeSeqPacket</code>). 514 Therefore this parameter is not hidden. 515 */ 516 inline StreamSocket(oslAddrFamily Family = osl_Socket_FamilyInet, 517 oslProtocol Protocol = osl_Socket_ProtocolIp, 518 oslSocketType Type = osl_Socket_TypeStream); 519 520 inline StreamSocket( const StreamSocket & ); 521 522 inline StreamSocket( oslSocket Socket , __sal_NoAcquire noacquire ); 523 524 inline StreamSocket( oslSocket Socket ); 525 526 /** Retrieves n bytes from the stream and copies them into pBuffer. 527 The method avoids incomplete reads due to packet boundaries and is thus 528 blocking. 529 @param pBuffer receives the read data. pBuffer must be large enough 530 to hold n bytes. 531 @param n the number of bytes to read. 532 @return the number of read bytes. The number will only be smaller than 533 n if an exceptional condition (e.g. connection closed) occurs. 534 */ 535 inline sal_Int32 SAL_CALL read(void* pBuffer, sal_uInt32 n); 536 537 /** Writes n bytes from pBuffer to the stream. The method avoids 538 incomplete writes due to packet boundaries and is thus blocking. 539 @param pBuffer contains the data to be written. 540 @param n the number of bytes to write. 541 @return the number of written bytes. The number will only be smaller than 542 n if an exceptional condition (e.g. connection closed) occurs. 543 */ 544 inline sal_Int32 SAL_CALL write(const void* pBuffer, sal_uInt32 n); 545 546 547 /** Tries to receive BytesToRead data from the connected socket, 548 549 @param pBuffer [out] Points to a buffer that will be filled with the received 550 data. pBuffer must have at least have a size of BytesToRead. 551 @param BytesToRead [in] The number of bytes to read. 552 @param Flag [in] Modifier for the call. Valid values are: 553 554 <ul> 555 <li><code>osl_Socket_MsgNormal</code> 556 <li><code>osl_Socket_MsgOOB</code> 557 <li><code>osl_Socket_MsgPeek</code> 558 <li><code>osl_Socket_MsgDontRoute</code> 559 <li><code>osl_Socket_MsgMaxIOVLen</code> 560 </ul> 561 @return the number of received bytes, which may be less than BytesToRead. 562 */ 563 inline sal_Int32 SAL_CALL recv(void* pBuffer, 564 sal_uInt32 BytesToRead, 565 oslSocketMsgFlag flags= osl_Socket_MsgNormal); 566 567 /** Tries to send BytesToSend data to the connected socket. 568 569 @param pBuffer [in] Points to a buffer that contains the send-data. 570 @param BytesToSend [in] The number of bytes to send. pBuffer must have at least 571 this size. 572 @param Flag [in] Modifier for the call. Valid values are: 573 <ul> 574 <li><code>osl_Socket_MsgNormal</code> 575 <li><code>osl_Socket_MsgOOB</code> 576 <li><code>osl_Socket_MsgPeek</code> 577 <li><code>osl_Socket_MsgDontRoute</code> 578 <li><code>osl_Socket_MsgMaxIOVLen</code> 579 </ul> 580 581 @return the number of transfered bytes. It may be less than BytesToSend. 582 */ 583 sal_Int32 SAL_CALL send(const void* pBuffer, 584 sal_uInt32 BytesToSend, 585 oslSocketMsgFlag= osl_Socket_MsgNormal); 586 }; 587 588 class ConnectorSocket : public StreamSocket 589 { 590 public: 591 /** Creates a socket that can connect to a (remote) host. 592 @param Type For some protocols it might be desirable to 593 use a different type than sock_stream <code>osl_Socket_TypeSeqPacket</code> 594 (like <code>osl_Socket_TypeSeqPacket</code>). 595 Therefore we do not hide this parameter here. 596 */ 597 ConnectorSocket(oslAddrFamily Family = osl_Socket_FamilyInet, 598 oslProtocol Protocol = osl_Socket_ProtocolIp, 599 oslSocketType Type = osl_Socket_TypeStream); 600 601 602 /** Connects the socket to a (remote) host. 603 @param TargetHost The address of the target. 604 @param pTimeOut The timeout for blocking. If 0, a default system dependent timeout 605 us used. 606 @return <code> osl_Socket_Ok</code> if connected successfully, 607 <code>osl_Socket_TimedOut</code> on timeout, 608 <code>osl_Socket_Interrupted</code> if unblocked forcefully (by osl::Socket::close()), 609 <code>osl_Socket_Error</code> if connect failed. 610 */ 611 oslSocketResult SAL_CALL connect(const SocketAddr& TargetHost, const TimeValue* pTimeout = 0); 612 }; 613 614 /** Allows to accept socket connections. 615 */ 616 class AcceptorSocket : public Socket 617 { 618 public: 619 inline AcceptorSocket(oslAddrFamily Family = osl_Socket_FamilyInet, 620 oslProtocol Protocol = osl_Socket_ProtocolIp, 621 oslSocketType Type = osl_Socket_TypeStream); 622 623 /** Prepare a socket for the accept-call. The socket must have been 624 bound before to the local address. 625 @param MaxPendingConnections The maximum number of pending 626 connections (waiting to be accepted) on this socket. If you use 627 -1, a system default value is used. 628 @return <code>sal_True</code> if call was successful. 629 */ 630 inline sal_Bool SAL_CALL listen(sal_Int32 MaxPendingConnections= -1); 631 632 /** Accepts incoming connections on the socket. You must 633 precede this call with osl::Socket::bind() and listen(). 634 @param Connection receives the incoming connection. 635 @return <code>osl_Socket_Ok</code>, if a connection has been accepted, 636 <code>osl_Socket_TimedOut</code>, if m_RecvTimeout milliseconds passed without connect, 637 <code>osl_Socket_Error</code> on errors. 638 */ 639 inline oslSocketResult SAL_CALL acceptConnection( StreamSocket& Connection); 640 641 /** Accepts incoming connections on the socket. You must 642 precede this call with osl::Socket::bind() and listen(). 643 @param PeerAddr receives the address of the connecting entity 644 (your communication partner). 645 @param Connection receives the incoming connection. 646 @return <code>osl_Socket_Ok</code>, if a connection has been accepted, 647 <code>osl_Socket_TimedOut</code>, if m_RecvTimeout milliseconds passed without connect, 648 <code>osl_Socket_Error</code> on errors. 649 */ 650 inline oslSocketResult SAL_CALL acceptConnection( StreamSocket& Connection, SocketAddr & PeerAddr); 651 }; 652 653 654 655 /** A connectionless socket to send and receive datagrams. 656 */ 657 class DatagramSocket : public Socket 658 { 659 public: 660 661 /** Creates a datagram socket. 662 @param Type is sock_dgram by default. 663 */ 664 inline DatagramSocket(oslAddrFamily Family= osl_Socket_FamilyInet, 665 oslProtocol Protocol= osl_Socket_ProtocolIp, 666 oslSocketType Type= osl_Socket_TypeDgram); 667 668 /** Tries to receives BufferSize data from the socket, if no error occurs. 669 670 @param pSenderAddr [out] You must provide pointer to a SocketAddr. 671 It will be filled with the address of the datagrams sender. 672 If pSenderAddr is 0, it is ignored. 673 @param pBuffer [out] Points to a buffer that will be filled with the received 674 datagram. 675 @param BufferSize [in] The size of pBuffer. 676 @param Flag [in] Modifier for the call. Valid values are: 677 <ul> 678 <li><code>osl_Socket_MsgNormal</code> 679 <li><code>osl_Socket_MsgOOB</code> 680 <li><code>osl_Socket_MsgPeek</code> 681 <li><code>osl_Socket_MsgDontRoute</code> 682 <li><code>osl_Socket_MsgMaxIOVLen</code> 683 </ul> 684 685 @return the number of received bytes. 686 */ 687 inline sal_Int32 SAL_CALL recvFrom(void* pBuffer, 688 sal_uInt32 BufferSize, 689 SocketAddr* pSenderAddr= 0, 690 oslSocketMsgFlag Flag= osl_Socket_MsgNormal); 691 692 /** Tries to send one datagram with BytesToSend size to the given ReceiverAddr. 693 Since there is only send one packet, the function doesn't care about 694 packet boundaries. 695 696 @param ReceiverAddr [in] A SocketAddr that contains 697 the destination address for this send. 698 699 @param pBuffer [in] Points to a buffer that contains the send-data. 700 @param BufferSize [in] The number of bytes to send. pBuffer must have at least 701 this size. 702 @param Flag [in] Modifier for the call. Valid values are: 703 704 <ul> 705 <li><code>osl_Socket_MsgNormal</code> 706 <li><code>osl_Socket_MsgOOB</code> 707 <li><code>osl_Socket_MsgPeek</code> 708 <li><code>osl_Socket_MsgDontRoute</code> 709 <li><code>osl_Socket_MsgMaxIOVLen</code> 710 </ul> 711 712 @return the number of transfered bytes. 713 */ 714 inline sal_Int32 SAL_CALL sendTo( const SocketAddr& ReceiverAddr, 715 const void* pBuffer, 716 sal_uInt32 BufferSize, 717 oslSocketMsgFlag Flag= osl_Socket_MsgNormal); 718 }; 719 720 } 721 722 #endif 723