Update git submodules
[LibreOffice.git] / include / osl / socket_decl.hxx
blob1ff2bababa29a36f35d4b196f08506aa6e578ad7
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 * This file is part of LibreOffice published API.
24 #ifndef INCLUDED_OSL_SOCKET_DECL_HXX
25 #define INCLUDED_OSL_SOCKET_DECL_HXX
27 #include "sal/config.h"
29 #include <cstddef>
31 #include "osl/socket.h"
32 #include "rtl/ustring.hxx"
33 #include "rtl/byteseq.hxx"
35 namespace osl
37 enum __osl_socket_NoCopy { SAL_NO_COPY };
39 /** The class should be understood as a reference to a socket address handle (struct sockaddr).
41 The handle is mutable.
43 class SocketAddr
45 protected:
46 oslSocketAddr m_handle;
47 public:
49 /** Creates socket address of unknown type.
51 inline SocketAddr();
53 /** Copy constructor.
55 inline SocketAddr(const SocketAddr& Addr);
57 #if defined LIBO_INTERNAL_ONLY
58 inline SocketAddr(SocketAddr && other) noexcept;
59 #endif
61 /** The SocketAddr takes over the responsibility of the handle (which means
62 that the handle gets destructed by the destructor of this reference)
64 @param Addr a handle
65 @param nocopy use SAL_NO_COPY
67 inline SocketAddr(const oslSocketAddr Addr, __osl_socket_NoCopy nocopy );
69 /** Copyconstructs the oslSocketAddr handle.
71 @param Addr a handle
73 inline SocketAddr(oslSocketAddr Addr);
75 /** TCP/IP-specific constructor.
77 @param strAddrOrHostName strAddrOrHostName hostname or dotted ip-number of the network
78 interface, the socket shall be created on.
79 @param nPort tcp-ip port number
81 inline SocketAddr(const ::rtl::OUString& strAddrOrHostName, sal_Int32 nPort);
83 /** destroys underlying oslSocketAddress
85 inline ~SocketAddr();
87 /** Checks if the SocketAddr was created successful.
89 @retval true if there is a valid underlying handle
90 @retval false no valid underlying handle
92 inline bool is() const;
94 /** Converts the address to a (human readable) domain-name.
96 @param[out] pResult value of 0 if you are not interested in errors,
97 otherwise *pResult contains an error code on failure
98 or osl_Socket_Ok on success
100 @return the hostname of this SocketAddr or an empty string on failure.
102 @see osl_getHostnameOfSocketAddr
104 inline ::rtl::OUString SAL_CALL getHostname(oslSocketResult *pResult = NULL) const;
106 /** Sets the IP address or hostname of the SocketAddress
108 @param[in] sDottedIpOrHostname IP address or hostname
110 @retval true success
111 @retval false failure
113 inline bool SAL_CALL setHostname(const ::rtl::OUString &sDottedIpOrHostname);
115 /** Returns the port number of the address.
117 @return the port in host-byte order or OSL_INVALID_PORT on errors.
119 inline sal_Int32 SAL_CALL getPort() const;
121 /** Sets the port number of the address.
123 @param[in] nPort port number
125 @retval true success
126 @retval false failure
128 inline bool SAL_CALL setPort(sal_Int32 nPort);
130 /** Sets the address of the underlying socket address struct in network byte order.
132 @retval true success
133 @retval false failure
135 inline bool SAL_CALL setAddr(const ::rtl::ByteSequence & address);
137 /** Returns the address of the underlying socket in network byte order
139 inline ::rtl::ByteSequence SAL_CALL getAddr(oslSocketResult *pResult = NULL) const;
141 /** assign the handle to this reference. The previous handle is released.
143 inline SocketAddr & SAL_CALL operator= (oslSocketAddr Addr);
145 inline SocketAddr & SAL_CALL operator= (const SocketAddr& Addr);
147 #if defined LIBO_INTERNAL_ONLY
148 inline SocketAddr & operator =(SocketAddr && other) noexcept;
149 #endif
151 /** Assigns the socket addr without copyconstructing it.
152 @param Addr the socket address.
153 @param nocopy use SAL_NO_COPY
155 inline SocketAddr & SAL_CALL assign( oslSocketAddr Addr, __osl_socket_NoCopy nocopy );
157 /** Returns true if the underlying handle is identical to the Addr handle.
159 inline bool SAL_CALL operator== (oslSocketAddr Addr) const;
161 /** Returns true if the underlying handle is identical to the Addr handle.
163 inline bool SAL_CALL operator== (const SocketAddr & Addr) const;
165 /** Returns the underlying SocketAddr handle without copyconstructing it.
167 inline oslSocketAddr SAL_CALL getHandle() const;
169 /** Get the hostname for the local interface.
170 @param pResult after the call *pResult contains osl_Socket_Ok on success or
171 an error on failure.
172 @return the hostname
174 static inline ::rtl::OUString SAL_CALL getLocalHostname( oslSocketResult *pResult = NULL);
176 /** Tries to find an address for a host.
178 @see osl_resolveHostname()
179 @param strHostName hostname
180 @param Addr A newly created socket-address or 0 if the name could not be found.
182 static inline void SAL_CALL resolveHostname(
183 const ::rtl::OUString & strHostName , SocketAddr & Addr );
186 Tries to find the port associated with the given service/protocol-
187 pair (e.g. "ftp"/"tcp").
188 @return the port number in host-byte order or <code>OSL_INVALID_PORT</code>
189 if no service/protocol pair could be found.
191 static inline sal_Int32 SAL_CALL getServicePort(
192 const ::rtl::OUString& strServiceName,
193 const ::rtl::OUString & strProtocolName= ::rtl::OUString("tcp") );
197 class Socket
199 protected:
200 oslSocket m_handle;
201 protected:
202 /** Creates a socket. Note it's protected.
203 @param Type
204 @param Family
205 @param Protocol
207 inline Socket(oslSocketType Type,
208 oslAddrFamily Family = osl_Socket_FamilyInet,
209 oslProtocol Protocol = osl_Socket_ProtocolIp);
210 public:
211 inline Socket( );
213 inline Socket( const Socket & socket );
215 inline Socket( oslSocket socketHandle );
217 /** The instance takes over the handle's ownership without acquiring the
218 handle, but releases it within the dtor.
219 @param socketHandle the handle
220 @param noacquire use SAL_NO_ACQUIRE
222 inline Socket( oslSocket socketHandle, __sal_NoAcquire noacquire );
224 /** Destructor. Releases the underlying handle
226 inline ~Socket();
228 /** Assignment operator. If socket was already created, the old one will
229 be discarded.
231 inline Socket& SAL_CALL operator= ( oslSocket socketHandle);
233 /** Assignment operator. If socket was already created, the old one will
234 be discarded.
236 inline Socket& SAL_CALL operator= (const Socket& sock);
239 @return <code>true</code>, when the underlying handle of both
240 Socket instances are identical, <code>false</code> otherwise.
242 inline bool SAL_CALL operator==( const Socket& rSocket ) const ;
245 @return <code>true</code>, when the underlying handle of both
246 Socket instances are identical, <code>false</code> otherwise.
248 inline bool SAL_CALL operator==( const oslSocket socketHandle ) const;
250 /** Closes a definite or both directions of the bidirectional stream.
252 @param Direction
253 @see osl_shutdownSocket()
255 inline void SAL_CALL shutdown( oslSocketDirection Direction = osl_Socket_DirReadWrite );
257 /** Closes a socket.
258 Note that closing a socket is identical to shutdown( osl_Socket_DirReadWrite ),
259 as the operating system distinguish both cases, both functions or offered in this API.
260 @see osl_closeSocket()
262 inline void SAL_CALL close();
264 /** Retrieves the address of the local interface of this socket.
265 @param Addr [out] receives the address.
266 @see osl_getLocalAddrOfSocket()
268 inline void SAL_CALL getLocalAddr( SocketAddr &Addr ) const;
270 /** Get the local port of the socket. Usually used after bind().
271 @return the port number or OSL_INVALID_PORT on errors.
273 inline sal_Int32 SAL_CALL getLocalPort() const;
275 /** Get the hostname for the local interface.
276 @return the hostname or an empty string ("").
278 inline ::rtl::OUString SAL_CALL getLocalHost() const;
280 /** Retrieves the address of the remote host of this socket.
281 @param Addr [out] receives the address.
283 inline void SAL_CALL getPeerAddr( SocketAddr & Addr) const;
285 /** Get the remote port of the socket.
286 @return the port number or OSL_INVALID_PORT on errors.
288 inline sal_Int32 SAL_CALL getPeerPort() const;
290 /** Get the hostname for the remote interface.
291 @return the hostname or an empty string ("").
293 inline ::rtl::OUString SAL_CALL getPeerHost() const;
295 /** Binds the socket to the specified (local) interface.
296 @param LocalInterface Address of the Interface
297 @return True if bind was successful.
299 inline bool SAL_CALL bind(const SocketAddr& LocalInterface);
301 /** Checks if read operations will block.
303 You can specify a timeout-value in seconds/nanoseconds that denotes
304 how the operation will block if the Socket is not ready.
305 @return <code>true</code> if read operations (recv, recvFrom, accept) on the Socket
306 will NOT block; <code>false</code> if it would block or if an error occurred.
308 @param pTimeout if 0, the operation will block without a timeout. Otherwise
309 the specified amount of time.
311 inline bool SAL_CALL isRecvReady(const TimeValue *pTimeout = NULL) const;
313 /** Checks if send operations will block.
315 You can specify a timeout-value in seconds/nanoseconds that denotes
316 how the operation will block if the Socket is not ready.
317 @return <code>true</code> if send operations (send, sendTo) on the Socket
318 will NOT block; <code>false</code> if it would block or if an error occurred.
320 @param pTimeout if 0, the operation will block without a timeout. Otherwise
321 the specified amount of time.
323 inline bool SAL_CALL isSendReady(const TimeValue *pTimeout = NULL) const;
326 /** Checks if a request for out-of-band data will block.
328 You can specify a timeout-value in seconds/nanoseconds that denotes
329 how the operation will block if the Socket has no pending OOB data.
331 @return <code>true</code> if OOB-request operations (recv with appropriate flags)
332 on the Socket will NOT block; <code>false</code> if it would block or if
333 an error occurred.
335 @param pTimeout if 0, the operation will block without a timeout. Otherwise
336 the specified amount of time.
338 inline bool SAL_CALL isExceptionPending(const TimeValue *pTimeout = NULL) const;
341 /** Queries the socket for its type.
343 @retval osl_Socket_TypeStream
344 @retval osl_Socket_TypeDgram
345 @retval osl_Socket_TypeRaw
346 @retval osl_Socket_TypeRdm
347 @retval osl_Socket_TypeSeqPacket
348 @retval osl_invalid_SocketType if an error occurred
350 inline oslSocketType SAL_CALL getType() const;
352 /** Retrieves option-attributes associated with the socket.
353 @param Option The attribute to query.
354 Valid values (depending on the Level) are:
355 <ul>
356 <li> <code>osl_Socket_Option_Debug</code><br>
357 (sal_Bool) Socket debug flag 1 = enabled, 0 = disabled.
359 <li> <code>osl_Socket_OptionAcceptConn</code><br>
360 <li> <code>osl_Socket_OptionReuseAddr</code><br>
361 (sal_Bool) Allows the socket to be bound to an address that is
362 already in use.
363 1 = multiple bound allowed, 0 = no multiple bounds allowed
365 <li><code>osl_Socket_OptionKeepAlive</code><br>
366 (sal_Bool) Keepalive packets are sent by the underlying socket.
367 1 = enabled, 0 = disabled
369 <li><code>osl_Socket_OptionDontRoute</code><br>
370 (sal_Bool) Do not route: send directly to interface.
371 1 = do not route , 0 = routing possible
373 <li><code>osl_Socket_OptionBroadcast</code><br>
374 (sal_Bool) Transmission of broadcast messages are allowed on the socket.
375 1 = transmission allowed, 0 = transmission disallowed
377 <li><code>osl_Socket_OptionUseLoopback</code><br>
379 <li><code>osl_Socket_OptionLinger</code><br>
380 (linger) Linger on close if unsent data is present.
381 linger has two members: l_onoff, l_linger
382 l_onoff = 0 is off, l_onoff > 0 and l_linger= timeout in seconds.
384 <li><code>osl_Socket_OptionOOBinLine</code><br>
387 <li><code>osl_Socket_OptionSndBuf</code><br>
388 (sal_Int32) Size of the send buffer in bytes. Data is sent after
389 SndTimeo or when the buffer is full. This allows faster writing
390 to the socket.
392 <li><code>osl_Socket_OptionRcvBuf</code><br>
393 (sal_Int32) Size of the receive buffer in bytes. Data is sent after
394 SndTimeo or when the buffer is full. This allows faster writing
395 to the socket and larger packet sizes.
397 <li><code>osl_Socket_OptionSndLowat</code><br>
399 <li><code>osl_Socket_OptionRcvLowat</code><br>
401 <li><code>osl_Socket_OptionSndTimeo</code><br>
402 (sal_Int32) Data is sent after this timeout. This allows gathering
403 of data to send larger packages but increases latency times.
405 <li><code>osl_Socket_OptionRcvTimeo</code><br>
407 <li><code>osl_Socket_OptionError</code><br>
408 <li><code>osl_Socket_OptionType</code><br>
410 <li><code>osl_Socket_OptionTcpNoDelay</code><br>
411 Disables the Nagle algorithm for send coalescing. (Do not
412 collect data until a packet is full, instead send immediately.
413 This increases network traffic but might improve latency-times.)
414 1 = disables the algorithm, 0 = keeps it enabled.
415 </ul>
417 If not above mentioned otherwise, the options are only valid for
418 level <code>osl_Socket_LevelSocket</code>.
419 @param pBuffer The Buffer will be filled with the attribute.
421 @param BufferLen The size of pBuffer.
423 @param Level The option level.
425 Valid values are:
426 <ul>
427 <li><code>osl_Socket_LevelSocket</code> : Socket Level
428 <li><code>osl_Socket_LevelTcp</code> : Level of Transmission Control Protocol
429 </ul>
430 @return The size of the attribute copied into pBuffer or -1 if an error
431 occurred.
433 inline sal_Int32 SAL_CALL getOption(
434 oslSocketOption Option,
435 void* pBuffer,
436 sal_uInt32 BufferLen,
437 oslSocketOptionLevel Level= osl_Socket_LevelSocket) const;
439 /** Sets the sockets attributes.
441 @param Option denotes the option to modify.
442 Valid values (depending on the Level) are:
443 <ul>
444 <li> osl_Socket_Option_Debug
445 <li> osl_Socket_OptionAcceptConn
446 <li> osl_Socket_OptionReuseAddr
447 <li> osl_Socket_OptionKeepAlive
448 <li> osl_Socket_OptionDontRoute
449 <li> osl_Socket_OptionBroadcast
450 <li> osl_Socket_OptionUseLoopback
451 <li> osl_Socket_OptionLinger
452 <li> osl_Socket_OptionOOBinLine
453 <li> osl_Socket_OptionSndBuf
454 <li> osl_Socket_OptionRcvBuf
455 <li> osl_Socket_OptionSndLowat
456 <li> osl_Socket_OptionRcvLowat
457 <li> osl_Socket_OptionSndTimeo
458 <li> osl_Socket_OptionRcvTimeo
459 <li> osl_Socket_OptionError
460 <li> osl_Socket_OptionType
461 <li> osl_Socket_OptionTcpNoDelay
462 </ul>
464 If not above mentioned otherwise, the options are only valid for
465 level osl_Socket_LevelSocket.
467 @param pBuffer Pointer to a Buffer which contains the attribute-value.
469 @param BufferLen contains the length of the Buffer.
471 @param Level selects the level for which an option should be changed.
472 Valid values are:
473 <ul>
474 <li> osl_Socket_evel_Socket : Socket Level
475 <li> osl_Socket_Level_Tcp : Level of Transmission Control Protocol
476 </ul>
478 @return True if the option could be changed.
480 inline bool SAL_CALL setOption( oslSocketOption Option,
481 void* pBuffer,
482 sal_uInt32 BufferLen,
483 oslSocketOptionLevel Level= osl_Socket_LevelSocket ) const;
485 /** Convenience function for setting sal_Bool and sal_Int32 option values.
486 @see setOption()
488 inline bool setOption( oslSocketOption option, sal_Int32 nValue );
490 /** Convenience function for retrieving sal_Bool and sal_Int32 option values.
491 @see setOption()
493 inline sal_Int32 getOption( oslSocketOption option ) const;
495 /** Enables/disables non-blocking mode of the socket.
496 @param bNonBlockingMode If <code>true</code>, blocking mode will be switched off
497 If <code>false</code>, the socket will become a blocking
498 socket (which is the default behaviour of a socket).
499 @return <code>true</code> if mode could be set.
501 inline bool SAL_CALL enableNonBlockingMode( bool bNonBlockingMode);
503 /** Query blocking mode of the socket.
504 @return <code>true</code> if non-blocking mode is set.
506 inline bool SAL_CALL isNonBlockingMode() const;
509 /** clears the error status
511 inline void SAL_CALL clearError() const;
513 /** returns a constant describing the last error for the socket system.
515 @return osl_Socket_E_NONE if no error occurred, invalid_SocketError if
516 an unknown (unmapped) error occurred, otherwise an enum describing the
517 error.
518 @see osl_getLastSocketError()
520 inline oslSocketError getError() const;
522 /** Builds a string with the last error-message for the socket.
524 inline ::rtl::OUString getErrorAsString( ) const;
526 /** Returns the underlying handle unacquired (The caller must acquire it to keep it).
528 inline oslSocket getHandle() const;
532 class StreamSocket : public Socket
534 public:
535 /** Creates a socket.
536 @param Family the Family of the socket (Inet by default)
537 @param Protocol the Protocon of the socket (IP by default)
538 @param Type For some protocols it might be desirable to
539 use a different type than <code>osl_Socket_TypeStream</code>
540 (like <code>osl_Socket_TypeSeqPacket</code>).
541 Therefore this parameter is not hidden.
543 inline StreamSocket(oslAddrFamily Family = osl_Socket_FamilyInet,
544 oslProtocol Protocol = osl_Socket_ProtocolIp,
545 oslSocketType Type = osl_Socket_TypeStream);
547 inline StreamSocket( oslSocket Socket , __sal_NoAcquire noacquire );
549 inline StreamSocket( oslSocket Socket );
551 /** Retrieves n bytes from the stream and copies them into pBuffer.
552 The method avoids incomplete reads due to packet boundaries and is thus
553 blocking.
554 @param pBuffer receives the read data. pBuffer must be large enough
555 to hold n bytes.
556 @param n the number of bytes to read.
557 @return the number of read bytes. The number will only be smaller than
558 n if an exceptional condition (e.g. connection closed) occurs.
560 inline sal_Int32 SAL_CALL read(void* pBuffer, sal_uInt32 n);
562 /** Writes n bytes from pBuffer to the stream. The method avoids
563 incomplete writes due to packet boundaries and is thus blocking.
564 @param pBuffer contains the data to be written.
565 @param n the number of bytes to write.
566 @return the number of written bytes. The number will only be smaller than
567 n if an exceptional condition (e.g. connection closed) occurs.
569 inline sal_Int32 SAL_CALL write(const void* pBuffer, sal_uInt32 n);
572 /** Tries to receive BytesToRead data from the connected socket,
574 @param[out] pBuffer Points to a buffer that will be filled with the received
575 data. pBuffer must have at least have a size of BytesToRead.
576 @param[in] BytesToRead The number of bytes to read.
577 @param[in] flags Modifier for the call. Valid values are:
579 <ul>
580 <li><code>osl_Socket_MsgNormal</code>
581 <li><code>osl_Socket_MsgOOB</code>
582 <li><code>osl_Socket_MsgPeek</code>
583 <li><code>osl_Socket_MsgDontRoute</code>
584 <li><code>osl_Socket_MsgMaxIOVLen</code>
585 </ul>
586 @return the number of received bytes, which may be less than BytesToRead.
588 inline sal_Int32 SAL_CALL recv(void* pBuffer,
589 sal_uInt32 BytesToRead,
590 oslSocketMsgFlag flags= osl_Socket_MsgNormal);
592 /** Tries to send BytesToSend data to the connected socket.
594 @param pBuffer [in] Points to a buffer that contains the send-data.
595 @param BytesToSend [in] The number of bytes to send. pBuffer must have at least
596 this size.
597 @param Flag [in] Modifier for the call. Valid values are:
598 <ul>
599 <li><code>osl_Socket_MsgNormal</code>
600 <li><code>osl_Socket_MsgOOB</code>
601 <li><code>osl_Socket_MsgPeek</code>
602 <li><code>osl_Socket_MsgDontRoute</code>
603 <li><code>osl_Socket_MsgMaxIOVLen</code>
604 </ul>
606 @return the number of transferred bytes. It may be less than BytesToSend.
608 sal_Int32 SAL_CALL send(const void* pBuffer,
609 sal_uInt32 BytesToSend,
610 oslSocketMsgFlag= osl_Socket_MsgNormal);
613 class ConnectorSocket : public StreamSocket
615 public:
616 /** Creates a socket that can connect to a (remote) host.
617 @param Family the Family of the socket (Inet by default)
618 @param Protocol the Protocon of the socket (IP by default)
619 @param Type For some protocols it might be desirable to
620 use a different type than sock_stream <code>osl_Socket_TypeSeqPacket</code>
621 (like <code>osl_Socket_TypeSeqPacket</code>).
622 Therefore we do not hide this parameter here.
624 ConnectorSocket(oslAddrFamily Family = osl_Socket_FamilyInet,
625 oslProtocol Protocol = osl_Socket_ProtocolIp,
626 oslSocketType Type = osl_Socket_TypeStream);
629 /** Connects the socket to a (remote) host.
630 @param TargetHost The address of the target.
631 @param pTimeout The timeout for blocking. If 0, a default system dependent timeout
632 us used.
633 @return <code> osl_Socket_Ok</code> if connected successfully,
634 <code>osl_Socket_TimedOut</code> on timeout,
635 <code>osl_Socket_Interrupted</code> if unblocked forcefully (by osl::Socket::close()),
636 <code>osl_Socket_Error</code> if connect failed.
638 oslSocketResult SAL_CALL connect(const SocketAddr& TargetHost, const TimeValue* pTimeout = NULL);
641 /** Allows to accept socket connections.
643 class AcceptorSocket : public Socket
645 public:
646 inline AcceptorSocket(oslAddrFamily Family = osl_Socket_FamilyInet,
647 oslProtocol Protocol = osl_Socket_ProtocolIp,
648 oslSocketType Type = osl_Socket_TypeStream);
650 /** Prepare a socket for the accept-call. The socket must have been
651 bound before to the local address.
652 @param MaxPendingConnections The maximum number of pending
653 connections (waiting to be accepted) on this socket. If you use
654 -1, a system default value is used.
655 @return <code>true</code> if call was successful.
657 inline bool SAL_CALL listen(sal_Int32 MaxPendingConnections= -1);
659 /** Accepts incoming connections on the socket. You must
660 precede this call with osl::Socket::bind() and listen().
661 @param Connection receives the incoming connection.
662 @return <code>osl_Socket_Ok</code>, if a connection has been accepted,
663 <code>osl_Socket_TimedOut</code>, if m_RecvTimeout milliseconds passed without connect,
664 <code>osl_Socket_Error</code> on errors.
666 inline oslSocketResult SAL_CALL acceptConnection( StreamSocket& Connection);
668 /** Accepts incoming connections on the socket. You must
669 precede this call with osl::Socket::bind() and listen().
670 @param PeerAddr receives the address of the connecting entity
671 (your communication partner).
672 @param Connection receives the incoming connection.
673 @return <code>osl_Socket_Ok</code>, if a connection has been accepted,
674 <code>osl_Socket_TimedOut</code>, if m_RecvTimeout milliseconds passed without connect,
675 <code>osl_Socket_Error</code> on errors.
677 inline oslSocketResult SAL_CALL acceptConnection( StreamSocket& Connection, SocketAddr & PeerAddr);
681 /** A connectionless socket to send and receive datagrams.
683 class DatagramSocket : public Socket
685 public:
687 /** Creates a datagram socket.
688 @param Family the Family of the socket (Inet by default)
689 @param Protocol the Protocon of the socket (IP by default)
690 @param Type is sock_dgram by default.
692 inline DatagramSocket(oslAddrFamily Family= osl_Socket_FamilyInet,
693 oslProtocol Protocol= osl_Socket_ProtocolIp,
694 oslSocketType Type= osl_Socket_TypeDgram);
696 /** Tries to receives BufferSize data from the socket, if no error occurs.
698 @param pSenderAddr [out] You must provide pointer to a SocketAddr.
699 It will be filled with the address of the datagrams sender.
700 If pSenderAddr is 0, it is ignored.
701 @param pBuffer [out] Points to a buffer that will be filled with the received
702 datagram.
703 @param BufferSize [in] The size of pBuffer.
704 @param Flag [in] Modifier for the call. Valid values are:
705 <ul>
706 <li><code>osl_Socket_MsgNormal</code>
707 <li><code>osl_Socket_MsgOOB</code>
708 <li><code>osl_Socket_MsgPeek</code>
709 <li><code>osl_Socket_MsgDontRoute</code>
710 <li><code>osl_Socket_MsgMaxIOVLen</code>
711 </ul>
713 @return the number of received bytes.
715 inline sal_Int32 SAL_CALL recvFrom(void* pBuffer,
716 sal_uInt32 BufferSize,
717 SocketAddr* pSenderAddr= NULL,
718 oslSocketMsgFlag Flag= osl_Socket_MsgNormal);
720 /** Tries to send one datagram with BytesToSend size to the given ReceiverAddr.
721 Since there is only send one packet, the function doesn't care about
722 packet boundaries.
724 @param ReceiverAddr [in] A SocketAddr that contains
725 the destination address for this send.
727 @param pBuffer [in] Points to a buffer that contains the send-data.
728 @param BufferSize [in] The number of bytes to send. pBuffer must have at least
729 this size.
730 @param Flag [in] Modifier for the call. Valid values are:
732 <ul>
733 <li><code>osl_Socket_MsgNormal</code>
734 <li><code>osl_Socket_MsgOOB</code>
735 <li><code>osl_Socket_MsgPeek</code>
736 <li><code>osl_Socket_MsgDontRoute</code>
737 <li><code>osl_Socket_MsgMaxIOVLen</code>
738 </ul>
740 @return the number of transferred bytes.
742 inline sal_Int32 SAL_CALL sendTo( const SocketAddr& ReceiverAddr,
743 const void* pBuffer,
744 sal_uInt32 BufferSize,
745 oslSocketMsgFlag Flag= osl_Socket_MsgNormal);
750 #endif
752 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */