Related: tdf#145722 need to clone userdata if we copy a module/dialog
[LibreOffice.git] / include / osl / socket_decl.hxx
blobde6442b273b2984de9a5152928005c65eddf5b0b
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.
177 @see osl_resolveHostname()
178 @return A new created socket-address or 0 if the name could not be found.
180 static inline void SAL_CALL resolveHostname(
181 const ::rtl::OUString & strHostName , SocketAddr & Addr );
184 Tries to find the port associated with the given service/protocol-
185 pair (e.g. "ftp"/"tcp").
186 @return the port number in host-byte order or <code>OSL_INVALID_PORT</code>
187 if no service/protocol pair could be found.
189 static inline sal_Int32 SAL_CALL getServicePort(
190 const ::rtl::OUString& strServiceName,
191 const ::rtl::OUString & strProtocolName= ::rtl::OUString("tcp") );
195 class Socket
197 protected:
198 oslSocket m_handle;
199 protected:
200 /** Creates a socket. Note it's protected.
201 @param Type
202 @param Family
203 @param Protocol
205 inline Socket(oslSocketType Type,
206 oslAddrFamily Family = osl_Socket_FamilyInet,
207 oslProtocol Protocol = osl_Socket_ProtocolIp);
208 public:
209 inline Socket( );
211 inline Socket( const Socket & socket );
213 inline Socket( oslSocket socketHandle );
215 /** The instance takes over the handle's ownership without acquiring the
216 handle, but releases it within the dtor.
217 @param socketHandle the handle
218 @param noacquire use SAL_NO_ACQUIRE
220 inline Socket( oslSocket socketHandle, __sal_NoAcquire noacquire );
222 /** Destructor. Releases the underlying handle
224 inline ~Socket();
226 /** Assignment operator. If socket was already created, the old one will
227 be discarded.
229 inline Socket& SAL_CALL operator= ( oslSocket socketHandle);
231 /** Assignment operator. If socket was already created, the old one will
232 be discarded.
234 inline Socket& SAL_CALL operator= (const Socket& sock);
237 @return <code>true</code>, when the underlying handle of both
238 Socket instances are identical, <code>false</code> otherwise.
240 inline bool SAL_CALL operator==( const Socket& rSocket ) const ;
243 @return <code>true</code>, when the underlying handle of both
244 Socket instances are identical, <code>false</code> otherwise.
246 inline bool SAL_CALL operator==( const oslSocket socketHandle ) const;
248 /** Closes a definite or both directions of the bidirectional stream.
250 @param Direction
251 @see osl_shutdownSocket()
253 inline void SAL_CALL shutdown( oslSocketDirection Direction = osl_Socket_DirReadWrite );
255 /** Closes a socket.
256 Note that closing a socket is identical to shutdown( osl_Socket_DirReadWrite ),
257 as the operating system distinguish both cases, both functions or offered in this API.
258 @see osl_closeSocket()
260 inline void SAL_CALL close();
262 /** Retrieves the address of the local interface of this socket.
263 @param Addr [out] receives the address.
264 @see osl_getLocalAddrOfSocket()
266 inline void SAL_CALL getLocalAddr( SocketAddr &Addr ) const;
268 /** Get the local port of the socket. Usually used after bind().
269 @return the port number or OSL_INVALID_PORT on errors.
271 inline sal_Int32 SAL_CALL getLocalPort() const;
273 /** Get the hostname for the local interface.
274 @return the hostname or an empty string ("").
276 inline ::rtl::OUString SAL_CALL getLocalHost() const;
278 /** Retrieves the address of the remote host of this socket.
279 @param Addr [out] receives the address.
281 inline void SAL_CALL getPeerAddr( SocketAddr & Addr) const;
283 /** Get the remote port of the socket.
284 @return the port number or OSL_INVALID_PORT on errors.
286 inline sal_Int32 SAL_CALL getPeerPort() const;
288 /** Get the hostname for the remote interface.
289 @return the hostname or an empty string ("").
291 inline ::rtl::OUString SAL_CALL getPeerHost() const;
293 /** Binds the socket to the specified (local) interface.
294 @param LocalInterface Address of the Interface
295 @return True if bind was successful.
297 inline bool SAL_CALL bind(const SocketAddr& LocalInterface);
299 /** Checks if read operations will block.
301 You can specify a timeout-value in seconds/nanoseconds that denotes
302 how the operation will block if the Socket is not ready.
303 @return <code>true</code> if read operations (recv, recvFrom, accept) on the Socket
304 will NOT block; <code>false</code> if it would block or if an error occurred.
306 @param pTimeout if 0, the operation will block without a timeout. Otherwise
307 the specified amount of time.
309 inline bool SAL_CALL isRecvReady(const TimeValue *pTimeout = NULL) const;
311 /** Checks if send operations will block.
313 You can specify a timeout-value in seconds/nanoseconds that denotes
314 how the operation will block if the Socket is not ready.
315 @return <code>true</code> if send operations (send, sendTo) on the Socket
316 will NOT block; <code>false</code> if it would block or if an error occurred.
318 @param pTimeout if 0, the operation will block without a timeout. Otherwise
319 the specified amount of time.
321 inline bool SAL_CALL isSendReady(const TimeValue *pTimeout = NULL) const;
324 /** Checks if a request for out-of-band data will block.
326 You can specify a timeout-value in seconds/nanoseconds that denotes
327 how the operation will block if the Socket has no pending OOB data.
329 @return <code>true</code> if OOB-request operations (recv with appropriate flags)
330 on the Socket will NOT block; <code>false</code> if it would block or if
331 an error occurred.
333 @param pTimeout if 0, the operation will block without a timeout. Otherwise
334 the specified amount of time.
336 inline bool SAL_CALL isExceptionPending(const TimeValue *pTimeout = NULL) const;
339 /** Queries the socket for its type.
341 @retval osl_Socket_TypeStream
342 @retval osl_Socket_TypeDgram
343 @retval osl_Socket_TypeRaw
344 @retval osl_Socket_TypeRdm
345 @retval osl_Socket_TypeSeqPacket
346 @retval osl_invalid_SocketType if an error occurred
348 inline oslSocketType SAL_CALL getType() const;
350 /** Retrieves option-attributes associated with the socket.
351 @param Option The attribute to query.
352 Valid values (depending on the Level) are:
353 <ul>
354 <li> <code>osl_Socket_Option_Debug</code><br>
355 (sal_Bool) Socket debug flag 1 = enabled, 0 = disabled.
357 <li> <code>osl_Socket_OptionAcceptConn</code><br>
358 <li> <code>osl_Socket_OptionReuseAddr</code><br>
359 (sal_Bool) Allows the socket to be bound to an address that is
360 already in use.
361 1 = multiple bound allowed, 0 = no multiple bounds allowed
363 <li><code>osl_Socket_OptionKeepAlive</code><br>
364 (sal_Bool) Keepalive packets are sent by the underlying socket.
365 1 = enabled, 0 = disabled
367 <li><code>osl_Socket_OptionDontRoute</code><br>
368 (sal_Bool) Do not route: send directly to interface.
369 1 = do not route , 0 = routing possible
371 <li><code>osl_Socket_OptionBroadcast</code><br>
372 (sal_Bool) Transmission of broadcast messages are allowed on the socket.
373 1 = transmission allowed, 0 = transmission disallowed
375 <li><code>osl_Socket_OptionUseLoopback</code><br>
377 <li><code>osl_Socket_OptionLinger</code><br>
378 (linger) Linger on close if unsent data is present.
379 linger has two members: l_onoff, l_linger
380 l_onoff = 0 is off, l_onoff > 0 and l_linger= timeout in seconds.
382 <li><code>osl_Socket_OptionOOBinLine</code><br>
385 <li><code>osl_Socket_OptionSndBuf</code><br>
386 (sal_Int32) Size of the send buffer in bytes. Data is sent after
387 SndTimeo or when the buffer is full. This allows faster writing
388 to the socket.
390 <li><code>osl_Socket_OptionRcvBuf</code><br>
391 (sal_Int32) Size of the receive buffer in bytes. Data is sent after
392 SndTimeo or when the buffer is full. This allows faster writing
393 to the socket and larger packet sizes.
395 <li><code>osl_Socket_OptionSndLowat</code><br>
397 <li><code>osl_Socket_OptionRcvLowat</code><br>
399 <li><code>osl_Socket_OptionSndTimeo</code><br>
400 (sal_Int32) Data is sent after this timeout. This allows gathering
401 of data to send larger packages but increases latency times.
403 <li><code>osl_Socket_OptionRcvTimeo</code><br>
405 <li><code>osl_Socket_OptionError</code><br>
406 <li><code>osl_Socket_OptionType</code><br>
408 <li><code>osl_Socket_OptionTcpNoDelay</code><br>
409 Disables the Nagle algorithm for send coalescing. (Do not
410 collect data until a packet is full, instead send immediately.
411 This increases network traffic but might improve latency-times.)
412 1 = disables the algorithm, 0 = keeps it enabled.
413 </ul>
415 If not above mentioned otherwise, the options are only valid for
416 level <code>osl_Socket_LevelSocket</code>.
417 @param pBuffer The Buffer will be filled with the attribute.
419 @param BufferLen The size of pBuffer.
421 @param Level The option level.
423 Valid values are:
424 <ul>
425 <li><code>osl_Socket_LevelSocket</code> : Socket Level
426 <li><code>osl_Socket_LevelTcp</code> : Level of Transmission Control Protocol
427 </ul>
428 @return The size of the attribute copied into pBuffer or -1 if an error
429 occurred.
431 inline sal_Int32 SAL_CALL getOption(
432 oslSocketOption Option,
433 void* pBuffer,
434 sal_uInt32 BufferLen,
435 oslSocketOptionLevel Level= osl_Socket_LevelSocket) const;
437 /** Sets the sockets attributes.
439 @param Option denotes the option to modify.
440 Valid values (depending on the Level) are:
441 <ul>
442 <li> osl_Socket_Option_Debug
443 <li> osl_Socket_OptionAcceptConn
444 <li> osl_Socket_OptionReuseAddr
445 <li> osl_Socket_OptionKeepAlive
446 <li> osl_Socket_OptionDontRoute
447 <li> osl_Socket_OptionBroadcast
448 <li> osl_Socket_OptionUseLoopback
449 <li> osl_Socket_OptionLinger
450 <li> osl_Socket_OptionOOBinLine
451 <li> osl_Socket_OptionSndBuf
452 <li> osl_Socket_OptionRcvBuf
453 <li> osl_Socket_OptionSndLowat
454 <li> osl_Socket_OptionRcvLowat
455 <li> osl_Socket_OptionSndTimeo
456 <li> osl_Socket_OptionRcvTimeo
457 <li> osl_Socket_OptionError
458 <li> osl_Socket_OptionType
459 <li> osl_Socket_OptionTcpNoDelay
460 </ul>
462 If not above mentioned otherwise, the options are only valid for
463 level osl_Socket_LevelSocket.
465 @param pBuffer Pointer to a Buffer which contains the attribute-value.
467 @param BufferLen contains the length of the Buffer.
469 @param Level selects the level for which an option should be changed.
470 Valid values are:
471 <ul>
472 <li> osl_Socket_evel_Socket : Socket Level
473 <li> osl_Socket_Level_Tcp : Level of Transmission Control Protocol
474 </ul>
476 @return True if the option could be changed.
478 inline bool SAL_CALL setOption( oslSocketOption Option,
479 void* pBuffer,
480 sal_uInt32 BufferLen,
481 oslSocketOptionLevel Level= osl_Socket_LevelSocket ) const;
483 /** Convenience function for setting sal_Bool and sal_Int32 option values.
484 @see setOption()
486 inline bool setOption( oslSocketOption option, sal_Int32 nValue );
488 /** Convenience function for retrieving sal_Bool and sal_Int32 option values.
489 @see setOption()
491 inline sal_Int32 getOption( oslSocketOption option ) const;
493 /** Enables/disables non-blocking mode of the socket.
494 @param bNonBlockingMode If <code>true</code>, blocking mode will be switched off
495 If <code>false</code>, the socket will become a blocking
496 socket (which is the default behaviour of a socket).
497 @return <code>true</code> if mode could be set.
499 inline bool SAL_CALL enableNonBlockingMode( bool bNonBlockingMode);
501 /** Query blocking mode of the socket.
502 @return <code>true</code> if non-blocking mode is set.
504 inline bool SAL_CALL isNonBlockingMode() const;
507 /** clears the error status
509 inline void SAL_CALL clearError() const;
511 /** returns a constant describing the last error for the socket system.
513 @return osl_Socket_E_NONE if no error occurred, invalid_SocketError if
514 an unknown (unmapped) error occurred, otherwise an enum describing the
515 error.
516 @see osl_getLastSocketError()
518 inline oslSocketError getError() const;
520 /** Builds a string with the last error-message for the socket.
522 inline ::rtl::OUString getErrorAsString( ) const;
524 /** Returns the underlying handle unacquired (The caller must acquire it to keep it).
526 inline oslSocket getHandle() const;
530 class StreamSocket : public Socket
532 public:
533 /** Creates a socket.
534 @param Family the Family of the socket (Inet by default)
535 @param Protocol the Protocon of the socket (IP by default)
536 @param Type For some protocols it might be desirable to
537 use a different type than <code>osl_Socket_TypeStream</code>
538 (like <code>osl_Socket_TypeSeqPacket</code>).
539 Therefore this parameter is not hidden.
541 inline StreamSocket(oslAddrFamily Family = osl_Socket_FamilyInet,
542 oslProtocol Protocol = osl_Socket_ProtocolIp,
543 oslSocketType Type = osl_Socket_TypeStream);
545 inline StreamSocket( oslSocket Socket , __sal_NoAcquire noacquire );
547 inline StreamSocket( oslSocket Socket );
549 /** Retrieves n bytes from the stream and copies them into pBuffer.
550 The method avoids incomplete reads due to packet boundaries and is thus
551 blocking.
552 @param pBuffer receives the read data. pBuffer must be large enough
553 to hold n bytes.
554 @param n the number of bytes to read.
555 @return the number of read bytes. The number will only be smaller than
556 n if an exceptional condition (e.g. connection closed) occurs.
558 inline sal_Int32 SAL_CALL read(void* pBuffer, sal_uInt32 n);
560 /** Writes n bytes from pBuffer to the stream. The method avoids
561 incomplete writes due to packet boundaries and is thus blocking.
562 @param pBuffer contains the data to be written.
563 @param n the number of bytes to write.
564 @return the number of written bytes. The number will only be smaller than
565 n if an exceptional condition (e.g. connection closed) occurs.
567 inline sal_Int32 SAL_CALL write(const void* pBuffer, sal_uInt32 n);
570 /** Tries to receive BytesToRead data from the connected socket,
572 @param[out] pBuffer Points to a buffer that will be filled with the received
573 data. pBuffer must have at least have a size of BytesToRead.
574 @param[in] BytesToRead The number of bytes to read.
575 @param[in] flags Modifier for the call. Valid values are:
577 <ul>
578 <li><code>osl_Socket_MsgNormal</code>
579 <li><code>osl_Socket_MsgOOB</code>
580 <li><code>osl_Socket_MsgPeek</code>
581 <li><code>osl_Socket_MsgDontRoute</code>
582 <li><code>osl_Socket_MsgMaxIOVLen</code>
583 </ul>
584 @return the number of received bytes, which may be less than BytesToRead.
586 inline sal_Int32 SAL_CALL recv(void* pBuffer,
587 sal_uInt32 BytesToRead,
588 oslSocketMsgFlag flags= osl_Socket_MsgNormal);
590 /** Tries to send BytesToSend data to the connected socket.
592 @param pBuffer [in] Points to a buffer that contains the send-data.
593 @param BytesToSend [in] The number of bytes to send. pBuffer must have at least
594 this size.
595 @param Flag [in] Modifier for the call. Valid values are:
596 <ul>
597 <li><code>osl_Socket_MsgNormal</code>
598 <li><code>osl_Socket_MsgOOB</code>
599 <li><code>osl_Socket_MsgPeek</code>
600 <li><code>osl_Socket_MsgDontRoute</code>
601 <li><code>osl_Socket_MsgMaxIOVLen</code>
602 </ul>
604 @return the number of transferred bytes. It may be less than BytesToSend.
606 sal_Int32 SAL_CALL send(const void* pBuffer,
607 sal_uInt32 BytesToSend,
608 oslSocketMsgFlag= osl_Socket_MsgNormal);
611 class ConnectorSocket : public StreamSocket
613 public:
614 /** Creates a socket that can connect to a (remote) host.
615 @param Family the Family of the socket (Inet by default)
616 @param Protocol the Protocon of the socket (IP by default)
617 @param Type For some protocols it might be desirable to
618 use a different type than sock_stream <code>osl_Socket_TypeSeqPacket</code>
619 (like <code>osl_Socket_TypeSeqPacket</code>).
620 Therefore we do not hide this parameter here.
622 ConnectorSocket(oslAddrFamily Family = osl_Socket_FamilyInet,
623 oslProtocol Protocol = osl_Socket_ProtocolIp,
624 oslSocketType Type = osl_Socket_TypeStream);
627 /** Connects the socket to a (remote) host.
628 @param TargetHost The address of the target.
629 @param pTimeout The timeout for blocking. If 0, a default system dependent timeout
630 us used.
631 @return <code> osl_Socket_Ok</code> if connected successfully,
632 <code>osl_Socket_TimedOut</code> on timeout,
633 <code>osl_Socket_Interrupted</code> if unblocked forcefully (by osl::Socket::close()),
634 <code>osl_Socket_Error</code> if connect failed.
636 oslSocketResult SAL_CALL connect(const SocketAddr& TargetHost, const TimeValue* pTimeout = NULL);
639 /** Allows to accept socket connections.
641 class AcceptorSocket : public Socket
643 public:
644 inline AcceptorSocket(oslAddrFamily Family = osl_Socket_FamilyInet,
645 oslProtocol Protocol = osl_Socket_ProtocolIp,
646 oslSocketType Type = osl_Socket_TypeStream);
648 /** Prepare a socket for the accept-call. The socket must have been
649 bound before to the local address.
650 @param MaxPendingConnections The maximum number of pending
651 connections (waiting to be accepted) on this socket. If you use
652 -1, a system default value is used.
653 @return <code>true</code> if call was successful.
655 inline bool SAL_CALL listen(sal_Int32 MaxPendingConnections= -1);
657 /** Accepts incoming connections on the socket. You must
658 precede this call with osl::Socket::bind() and listen().
659 @param Connection receives the incoming connection.
660 @return <code>osl_Socket_Ok</code>, if a connection has been accepted,
661 <code>osl_Socket_TimedOut</code>, if m_RecvTimeout milliseconds passed without connect,
662 <code>osl_Socket_Error</code> on errors.
664 inline oslSocketResult SAL_CALL acceptConnection( StreamSocket& Connection);
666 /** Accepts incoming connections on the socket. You must
667 precede this call with osl::Socket::bind() and listen().
668 @param PeerAddr receives the address of the connecting entity
669 (your communication partner).
670 @param Connection receives the incoming connection.
671 @return <code>osl_Socket_Ok</code>, if a connection has been accepted,
672 <code>osl_Socket_TimedOut</code>, if m_RecvTimeout milliseconds passed without connect,
673 <code>osl_Socket_Error</code> on errors.
675 inline oslSocketResult SAL_CALL acceptConnection( StreamSocket& Connection, SocketAddr & PeerAddr);
679 /** A connectionless socket to send and receive datagrams.
681 class DatagramSocket : public Socket
683 public:
685 /** Creates a datagram socket.
686 @param Family the Family of the socket (Inet by default)
687 @param Protocol the Protocon of the socket (IP by default)
688 @param Type is sock_dgram by default.
690 inline DatagramSocket(oslAddrFamily Family= osl_Socket_FamilyInet,
691 oslProtocol Protocol= osl_Socket_ProtocolIp,
692 oslSocketType Type= osl_Socket_TypeDgram);
694 /** Tries to receives BufferSize data from the socket, if no error occurs.
696 @param pSenderAddr [out] You must provide pointer to a SocketAddr.
697 It will be filled with the address of the datagrams sender.
698 If pSenderAddr is 0, it is ignored.
699 @param pBuffer [out] Points to a buffer that will be filled with the received
700 datagram.
701 @param BufferSize [in] The size of pBuffer.
702 @param Flag [in] Modifier for the call. Valid values are:
703 <ul>
704 <li><code>osl_Socket_MsgNormal</code>
705 <li><code>osl_Socket_MsgOOB</code>
706 <li><code>osl_Socket_MsgPeek</code>
707 <li><code>osl_Socket_MsgDontRoute</code>
708 <li><code>osl_Socket_MsgMaxIOVLen</code>
709 </ul>
711 @return the number of received bytes.
713 inline sal_Int32 SAL_CALL recvFrom(void* pBuffer,
714 sal_uInt32 BufferSize,
715 SocketAddr* pSenderAddr= NULL,
716 oslSocketMsgFlag Flag= osl_Socket_MsgNormal);
718 /** Tries to send one datagram with BytesToSend size to the given ReceiverAddr.
719 Since there is only send one packet, the function doesn't care about
720 packet boundaries.
722 @param ReceiverAddr [in] A SocketAddr that contains
723 the destination address for this send.
725 @param pBuffer [in] Points to a buffer that contains the send-data.
726 @param BufferSize [in] The number of bytes to send. pBuffer must have at least
727 this size.
728 @param Flag [in] Modifier for the call. Valid values are:
730 <ul>
731 <li><code>osl_Socket_MsgNormal</code>
732 <li><code>osl_Socket_MsgOOB</code>
733 <li><code>osl_Socket_MsgPeek</code>
734 <li><code>osl_Socket_MsgDontRoute</code>
735 <li><code>osl_Socket_MsgMaxIOVLen</code>
736 </ul>
738 @return the number of transferred bytes.
740 inline sal_Int32 SAL_CALL sendTo( const SocketAddr& ReceiverAddr,
741 const void* pBuffer,
742 sal_uInt32 BufferSize,
743 oslSocketMsgFlag Flag= osl_Socket_MsgNormal);
748 #endif
750 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */