bump product version to 6.3.0.0.beta1
[LibreOffice.git] / include / osl / socket_decl.hxx
blob3d2a0563434820b9aab49bc6fa1a699e2e2f45bf
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 .
20 #ifndef INCLUDED_OSL_SOCKET_DECL_HXX
21 #define INCLUDED_OSL_SOCKET_DECL_HXX
23 #include "sal/config.h"
25 #include <cstddef>
27 #include "osl/socket.h"
28 #include "rtl/ustring.hxx"
29 #include "rtl/byteseq.hxx"
31 namespace osl
33 enum __osl_socket_NoCopy { SAL_NO_COPY };
35 /** The class should be understood as a reference to a socket address handle (struct sockaddr).
37 The handle is mutable.
39 class SocketAddr
41 protected:
42 oslSocketAddr m_handle;
43 public:
45 /** Creates socket address of unknown type.
47 inline SocketAddr();
49 /** Copy constructor.
51 inline SocketAddr(const SocketAddr& Addr);
53 #if defined LIBO_INTERNAL_ONLY
54 inline SocketAddr(SocketAddr && other);
55 #endif
57 /** The SocketAddr takes over the responsibility of the handle (which means
58 that the handle gets destructed by the destructor of this reference)
60 @param Addr a handle
61 @param nocopy use SAL_NO_COPY
63 inline SocketAddr(const oslSocketAddr Addr, __osl_socket_NoCopy nocopy );
65 /** Copyconstructs the oslSocketAddr handle.
67 @param Addr a handle
69 inline SocketAddr(oslSocketAddr Addr);
71 /** TCP/IP-specific constructor.
73 @param strAddrOrHostName strAddrOrHostName hostname or dotted ip-number of the network
74 interface, the socket shall be created on.
75 @param nPort tcp-ip port number
77 inline SocketAddr(const ::rtl::OUString& strAddrOrHostName, sal_Int32 nPort);
79 /** destroys underlying oslSocketAddress
81 inline ~SocketAddr();
83 /** Checks if the SocketAddr was created successful.
85 @retval true if there is a valid underlying handle
86 @retval false no valid underlying handle
88 inline bool is() const;
90 /** Converts the address to a (human readable) domain-name.
92 @param[out] pResult value of 0 if you are not interested in errors,
93 otherwise *pResult contains an error code on failure
94 or osl_Socket_Ok on success
96 @return the hostname of this SocketAddr or an empty string on failure.
98 @see osl_getHostnameOfSocketAddr
100 inline ::rtl::OUString SAL_CALL getHostname(oslSocketResult *pResult = NULL) const;
102 /** Sets the IP address or hostname of the SocketAddress
104 @param[in] sDottedIpOrHostname IP address or hostname
106 @retval true success
107 @retval false failure
109 inline bool SAL_CALL setHostname(const ::rtl::OUString &sDottedIpOrHostname);
111 /** Returns the port number of the address.
113 @return the port in host-byte order or OSL_INVALID_PORT on errors.
115 inline sal_Int32 SAL_CALL getPort() const;
117 /** Sets the port number of the address.
119 @param[in] nPort port number
121 @retval true success
122 @retval false failure
124 inline bool SAL_CALL setPort(sal_Int32 nPort);
126 /** Sets the address of the underlying socket address struct in network byte order.
128 @retval true success
129 @retval false failure
131 inline bool SAL_CALL setAddr(const ::rtl::ByteSequence & address);
133 /** Returns the address of the underlying socket in network byte order
135 inline ::rtl::ByteSequence SAL_CALL getAddr(oslSocketResult *pResult = NULL) const;
137 /** assign the handle to this reference. The previous handle is released.
139 inline SocketAddr & SAL_CALL operator= (oslSocketAddr Addr);
141 inline SocketAddr & SAL_CALL operator= (const SocketAddr& Addr);
143 #if defined LIBO_INTERNAL_ONLY
144 inline SocketAddr & operator =(SocketAddr && other);
145 #endif
147 /** Assigns the socket addr without copyconstructing it.
148 @param Addr the socket address.
149 @param nocopy use SAL_NO_COPY
151 inline SocketAddr & SAL_CALL assign( oslSocketAddr Addr, __osl_socket_NoCopy nocopy );
153 /** Returns true if the underlying handle is identical to the Addr handle.
155 inline bool SAL_CALL operator== (oslSocketAddr Addr) const;
157 /** Returns true if the underlying handle is identical to the Addr handle.
159 inline bool SAL_CALL operator== (const SocketAddr & Addr) const;
161 /** Returns the underlying SocketAddr handle without copyconstructing it.
163 inline oslSocketAddr SAL_CALL getHandle() const;
165 /** Get the hostname for the local interface.
166 @param pResult after the call *pResult contains osl_Socket_Ok on success or
167 an error on failure.
168 @return the hostname
170 static inline ::rtl::OUString SAL_CALL getLocalHostname( oslSocketResult *pResult = NULL);
172 /** Tries to find an address for a host.
173 @see osl_resolveHostname()
174 @return A new created socket-address or 0 if the name could not be found.
176 static inline void SAL_CALL resolveHostname(
177 const ::rtl::OUString & strHostName , SocketAddr & Addr );
180 Tries to find the port associated with the given service/protocol-
181 pair (e.g. "ftp"/"tcp").
182 @return the port number in host-byte order or <code>OSL_INVALID_PORT</code>
183 if no service/protocol pair could be found.
185 static inline sal_Int32 SAL_CALL getServicePort(
186 const ::rtl::OUString& strServiceName,
187 const ::rtl::OUString & strProtocolName= ::rtl::OUString("tcp") );
191 class Socket
193 protected:
194 oslSocket m_handle;
195 protected:
196 /** Creates a socket. Note it's protected.
197 @param Type
198 @param Family
199 @param Protocol
201 inline Socket(oslSocketType Type,
202 oslAddrFamily Family = osl_Socket_FamilyInet,
203 oslProtocol Protocol = osl_Socket_ProtocolIp);
204 public:
205 inline Socket( );
207 inline Socket( const Socket & socket );
209 inline Socket( oslSocket socketHandle );
211 /** The instance takes over the handle's ownership without acquiring the
212 handle, but releases it within the dtor.
213 @param socketHandle the handle
214 @param noacquire use SAL_NO_ACQUIRE
216 inline Socket( oslSocket socketHandle, __sal_NoAcquire noacquire );
218 /** Destructor. Releases the underlying handle
220 inline ~Socket();
222 /** Assignment operator. If socket was already created, the old one will
223 be discarded.
225 inline Socket& SAL_CALL operator= ( oslSocket socketHandle);
227 /** Assignment operator. If socket was already created, the old one will
228 be discarded.
230 inline Socket& SAL_CALL operator= (const Socket& sock);
233 @return <code>true</code>, when the underlying handle of both
234 Socket instances are identical, <code>false</code> otherwise.
236 inline bool SAL_CALL operator==( const Socket& rSocket ) const ;
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 oslSocket socketHandle ) const;
244 /** Closes a definite or both directions of the bidirectional stream.
246 @param Direction
247 @see osl_shutdownSocket()
249 inline void SAL_CALL shutdown( oslSocketDirection Direction = osl_Socket_DirReadWrite );
251 /** Closes a socket.
252 Note that closing a socket is identical to shutdown( osl_Socket_DirReadWrite ),
253 as the operating system distinguish both cases, both functions or offered in this API.
254 @see osl_closeSocket()
256 inline void SAL_CALL close();
258 /** Retrieves the address of the local interface of this socket.
259 @param Addr [out] receives the address.
260 @see osl_getLocalAddrOfSocket()
262 inline void SAL_CALL getLocalAddr( SocketAddr &Addr ) const;
264 /** Get the local port of the socket. Usually used after bind().
265 @return the port number or OSL_INVALID_PORT on errors.
267 inline sal_Int32 SAL_CALL getLocalPort() const;
269 /** Get the hostname for the local interface.
270 @return the hostname or an empty string ("").
272 inline ::rtl::OUString SAL_CALL getLocalHost() const;
274 /** Retrieves the address of the remote host of this socket.
275 @param Addr [out] receives the address.
277 inline void SAL_CALL getPeerAddr( SocketAddr & Addr) const;
279 /** Get the remote port of the socket.
280 @return the port number or OSL_INVALID_PORT on errors.
282 inline sal_Int32 SAL_CALL getPeerPort() const;
284 /** Get the hostname for the remote interface.
285 @return the hostname or an empty string ("").
287 inline ::rtl::OUString SAL_CALL getPeerHost() const;
289 /** Binds the socket to the specified (local) interface.
290 @param LocalInterface Address of the Interface
291 @return True if bind was successful.
293 inline bool SAL_CALL bind(const SocketAddr& LocalInterface);
295 /** Checks if read operations will block.
297 You can specify a timeout-value in seconds/nanoseconds that denotes
298 how the operation will block if the Socket is not ready.
299 @return <code>true</code> if read operations (recv, recvFrom, accept) on the Socket
300 will NOT block; <code>false</code> if it would block or if an error occurred.
302 @param pTimeout if 0, the operation will block without a timeout. Otherwise
303 the specified amount of time.
305 inline bool SAL_CALL isRecvReady(const TimeValue *pTimeout = NULL) const;
307 /** Checks if send operations will block.
309 You can specify a timeout-value in seconds/nanoseconds that denotes
310 how the operation will block if the Socket is not ready.
311 @return <code>true</code> if send operations (send, sendTo) on the Socket
312 will NOT block; <code>false</code> if it would block or if an error occurred.
314 @param pTimeout if 0, the operation will block without a timeout. Otherwise
315 the specified amount of time.
317 inline bool SAL_CALL isSendReady(const TimeValue *pTimeout = NULL) const;
320 /** Checks if a request for out-of-band data will block.
322 You can specify a timeout-value in seconds/nanoseconds that denotes
323 how the operation will block if the Socket has no pending OOB data.
325 @return <code>true</code> if OOB-request operations (recv with appropriate flags)
326 on the Socket will NOT block; <code>false</code> if it would block or if
327 an error occurred.
329 @param pTimeout if 0, the operation will block without a timeout. Otherwise
330 the specified amount of time.
332 inline bool SAL_CALL isExceptionPending(const TimeValue *pTimeout = NULL) const;
335 /** Queries the socket for its type.
337 @retval osl_Socket_TypeStream
338 @retval osl_Socket_TypeDgram
339 @retval osl_Socket_TypeRaw
340 @retval osl_Socket_TypeRdm
341 @retval osl_Socket_TypeSeqPacket
342 @retval osl_invalid_SocketType if an error occurred
344 inline oslSocketType SAL_CALL getType() const;
346 /** Retrieves option-attributes associated with the socket.
347 @param Option The attribute to query.
348 Valid values (depending on the Level) are:
349 <ul>
350 <li> <code>osl_Socket_Option_Debug</code><br>
351 (sal_Bool) Socket debug flag 1 = enabled, 0 = disabled.
353 <li> <code>osl_Socket_OptionAcceptConn</code><br>
354 <li> <code>osl_Socket_OptionReuseAddr</code><br>
355 (sal_Bool) Allows the socket to be bound to an address that is
356 already in use.
357 1 = multiple bound allowed, 0 = no multiple bounds allowed
359 <li><code>osl_Socket_OptionKeepAlive</code><br>
360 (sal_Bool) Keepalive packets are sent by the underlying socket.
361 1 = enabled, 0 = disabled
363 <li><code>osl_Socket_OptionDontRoute</code><br>
364 (sal_Bool) Do not route: send directly to interface.
365 1 = do not route , 0 = routing possible
367 <li><code>osl_Socket_OptionBroadcast</code><br>
368 (sal_Bool) Transmission of broadcast messages are allowed on the socket.
369 1 = transmission allowed, 0 = transmission disallowed
371 <li><code>osl_Socket_OptionUseLoopback</code><br>
373 <li><code>osl_Socket_OptionLinger</code><br>
374 (linger) Linger on close if unsent data is present.
375 linger has two members: l_onoff, l_linger
376 l_onoff = 0 is off, l_onoff > 0 and l_linger= timeout in seconds.
378 <li><code>osl_Socket_OptionOOBinLine</code><br>
381 <li><code>osl_Socket_OptionSndBuf</code><br>
382 (sal_Int32) Size of the send buffer in bytes. Data is sent after
383 SndTimeo or when the buffer is full. This allows faster writing
384 to the socket.
386 <li><code>osl_Socket_OptionRcvBuf</code><br>
387 (sal_Int32) Size of the receive buffer in bytes. Data is sent after
388 SndTimeo or when the buffer is full. This allows faster writing
389 to the socket and larger packet sizes.
391 <li><code>osl_Socket_OptionSndLowat</code><br>
393 <li><code>osl_Socket_OptionRcvLowat</code><br>
395 <li><code>osl_Socket_OptionSndTimeo</code><br>
396 (sal_Int32) Data is sent after this timeout. This allows gathering
397 of data to send larger packages but increases latency times.
399 <li><code>osl_Socket_OptionRcvTimeo</code><br>
401 <li><code>osl_Socket_OptionError</code><br>
402 <li><code>osl_Socket_OptionType</code><br>
404 <li><code>osl_Socket_OptionTcpNoDelay</code><br>
405 Disables the Nagle algorithm for send coalescing. (Do not
406 collect data until a packet is full, instead send immediately.
407 This increases network traffic but might improve latency-times.)
408 1 = disables the algorithm, 0 = keeps it enabled.
409 </ul>
411 If not above mentioned otherwise, the options are only valid for
412 level <code>osl_Socket_LevelSocket</code>.
413 @param pBuffer The Buffer will be filled with the attribute.
415 @param BufferLen The size of pBuffer.
417 @param Level The option level.
419 Valid values are:
420 <ul>
421 <li><code>osl_Socket_LevelSocket</code> : Socket Level
422 <li><code>osl_Socket_LevelTcp</code> : Level of Transmission Control Protocol
423 </ul>
424 @return The size of the attribute copied into pBuffer or -1 if an error
425 occurred.
427 inline sal_Int32 SAL_CALL getOption(
428 oslSocketOption Option,
429 void* pBuffer,
430 sal_uInt32 BufferLen,
431 oslSocketOptionLevel Level= osl_Socket_LevelSocket) const;
433 /** Sets the sockets attributes.
435 @param Option denotes the option to modify.
436 Valid values (depending on the Level) are:
437 <ul>
438 <li> osl_Socket_Option_Debug
439 <li> osl_Socket_OptionAcceptConn
440 <li> osl_Socket_OptionReuseAddr
441 <li> osl_Socket_OptionKeepAlive
442 <li> osl_Socket_OptionDontRoute
443 <li> osl_Socket_OptionBroadcast
444 <li> osl_Socket_OptionUseLoopback
445 <li> osl_Socket_OptionLinger
446 <li> osl_Socket_OptionOOBinLine
447 <li> osl_Socket_OptionSndBuf
448 <li> osl_Socket_OptionRcvBuf
449 <li> osl_Socket_OptionSndLowat
450 <li> osl_Socket_OptionRcvLowat
451 <li> osl_Socket_OptionSndTimeo
452 <li> osl_Socket_OptionRcvTimeo
453 <li> osl_Socket_OptionError
454 <li> osl_Socket_OptionType
455 <li> osl_Socket_OptionTcpNoDelay
456 </ul>
458 If not above mentioned otherwise, the options are only valid for
459 level osl_Socket_LevelSocket.
461 @param pBuffer Pointer to a Buffer which contains the attribute-value.
463 @param BufferLen contains the length of the Buffer.
465 @param Level selects the level for which an option should be changed.
466 Valid values are:
467 <ul>
468 <li> osl_Socket_evel_Socket : Socket Level
469 <li> osl_Socket_Level_Tcp : Level of Transmission Control Protocol
470 </ul>
472 @return True if the option could be changed.
474 inline bool SAL_CALL setOption( oslSocketOption Option,
475 void* pBuffer,
476 sal_uInt32 BufferLen,
477 oslSocketOptionLevel Level= osl_Socket_LevelSocket ) const;
479 /** Convenience function for setting sal_Bool and sal_Int32 option values.
480 @see setOption()
482 inline bool setOption( oslSocketOption option, sal_Int32 nValue );
484 /** Convenience function for retrieving sal_Bool and sal_Int32 option values.
485 @see setOption()
487 inline sal_Int32 getOption( oslSocketOption option ) const;
489 /** Enables/disables non-blocking mode of the socket.
490 @param bNonBlockingMode If <code>true</code>, blocking mode will be switched off
491 If <code>false</code>, the socket will become a blocking
492 socket (which is the default behaviour of a socket).
493 @return <code>true</code> if mode could be set.
495 inline bool SAL_CALL enableNonBlockingMode( bool bNonBlockingMode);
497 /** Query blocking mode of the socket.
498 @return <code>true</code> if non-blocking mode is set.
500 inline bool SAL_CALL isNonBlockingMode() const;
503 /** clears the error status
505 inline void SAL_CALL clearError() const;
507 /** returns a constant describing the last error for the socket system.
509 @return osl_Socket_E_NONE if no error occurred, invalid_SocketError if
510 an unknown (unmapped) error occurred, otherwise an enum describing the
511 error.
512 @see osl_getLastSocketError()
514 inline oslSocketError getError() const;
516 /** Builds a string with the last error-message for the socket.
518 inline ::rtl::OUString getErrorAsString( ) const;
520 /** Returns the underlying handle unacquired (The caller must acquire it to keep it).
522 inline oslSocket getHandle() const;
526 class StreamSocket : public Socket
528 public:
529 /** Creates a socket.
530 @param Family the Family of the socket (Inet by default)
531 @param Protocol the Protocon of the socket (IP by default)
532 @param Type For some protocols it might be desirable to
533 use a different type than <code>osl_Socket_TypeStream</code>
534 (like <code>osl_Socket_TypeSeqPacket</code>).
535 Therefore this parameter is not hidden.
537 inline StreamSocket(oslAddrFamily Family = osl_Socket_FamilyInet,
538 oslProtocol Protocol = osl_Socket_ProtocolIp,
539 oslSocketType Type = osl_Socket_TypeStream);
541 inline StreamSocket( oslSocket Socket , __sal_NoAcquire noacquire );
543 inline StreamSocket( oslSocket Socket );
545 /** Retrieves n bytes from the stream and copies them into pBuffer.
546 The method avoids incomplete reads due to packet boundaries and is thus
547 blocking.
548 @param pBuffer receives the read data. pBuffer must be large enough
549 to hold n bytes.
550 @param n the number of bytes to read.
551 @return the number of read bytes. The number will only be smaller than
552 n if an exceptional condition (e.g. connection closed) occurs.
554 inline sal_Int32 SAL_CALL read(void* pBuffer, sal_uInt32 n);
556 /** Writes n bytes from pBuffer to the stream. The method avoids
557 incomplete writes due to packet boundaries and is thus blocking.
558 @param pBuffer contains the data to be written.
559 @param n the number of bytes to write.
560 @return the number of written bytes. The number will only be smaller than
561 n if an exceptional condition (e.g. connection closed) occurs.
563 inline sal_Int32 SAL_CALL write(const void* pBuffer, sal_uInt32 n);
566 /** Tries to receive BytesToRead data from the connected socket,
568 @param[out] pBuffer Points to a buffer that will be filled with the received
569 data. pBuffer must have at least have a size of BytesToRead.
570 @param[in] BytesToRead The number of bytes to read.
571 @param[in] flags 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 @return the number of received bytes, which may be less than BytesToRead.
582 inline sal_Int32 SAL_CALL recv(void* pBuffer,
583 sal_uInt32 BytesToRead,
584 oslSocketMsgFlag flags= osl_Socket_MsgNormal);
586 /** Tries to send BytesToSend data to the connected socket.
588 @param pBuffer [in] Points to a buffer that contains the send-data.
589 @param BytesToSend [in] The number of bytes to send. pBuffer must have at least
590 this size.
591 @param Flag [in] Modifier for the call. Valid values are:
592 <ul>
593 <li><code>osl_Socket_MsgNormal</code>
594 <li><code>osl_Socket_MsgOOB</code>
595 <li><code>osl_Socket_MsgPeek</code>
596 <li><code>osl_Socket_MsgDontRoute</code>
597 <li><code>osl_Socket_MsgMaxIOVLen</code>
598 </ul>
600 @return the number of transferred bytes. It may be less than BytesToSend.
602 sal_Int32 SAL_CALL send(const void* pBuffer,
603 sal_uInt32 BytesToSend,
604 oslSocketMsgFlag= osl_Socket_MsgNormal);
607 class ConnectorSocket : public StreamSocket
609 public:
610 /** Creates a socket that can connect to a (remote) host.
611 @param Family the Family of the socket (Inet by default)
612 @param Protocol the Protocon of the socket (IP by default)
613 @param Type For some protocols it might be desirable to
614 use a different type than sock_stream <code>osl_Socket_TypeSeqPacket</code>
615 (like <code>osl_Socket_TypeSeqPacket</code>).
616 Therefore we do not hide this parameter here.
618 ConnectorSocket(oslAddrFamily Family = osl_Socket_FamilyInet,
619 oslProtocol Protocol = osl_Socket_ProtocolIp,
620 oslSocketType Type = osl_Socket_TypeStream);
623 /** Connects the socket to a (remote) host.
624 @param TargetHost The address of the target.
625 @param pTimeout The timeout for blocking. If 0, a default system dependent timeout
626 us used.
627 @return <code> osl_Socket_Ok</code> if connected successfully,
628 <code>osl_Socket_TimedOut</code> on timeout,
629 <code>osl_Socket_Interrupted</code> if unblocked forcefully (by osl::Socket::close()),
630 <code>osl_Socket_Error</code> if connect failed.
632 oslSocketResult SAL_CALL connect(const SocketAddr& TargetHost, const TimeValue* pTimeout = NULL);
635 /** Allows to accept socket connections.
637 class AcceptorSocket : public Socket
639 public:
640 inline AcceptorSocket(oslAddrFamily Family = osl_Socket_FamilyInet,
641 oslProtocol Protocol = osl_Socket_ProtocolIp,
642 oslSocketType Type = osl_Socket_TypeStream);
644 /** Prepare a socket for the accept-call. The socket must have been
645 bound before to the local address.
646 @param MaxPendingConnections The maximum number of pending
647 connections (waiting to be accepted) on this socket. If you use
648 -1, a system default value is used.
649 @return <code>true</code> if call was successful.
651 inline bool SAL_CALL listen(sal_Int32 MaxPendingConnections= -1);
653 /** Accepts incoming connections on the socket. You must
654 precede this call with osl::Socket::bind() and listen().
655 @param Connection receives the incoming connection.
656 @return <code>osl_Socket_Ok</code>, if a connection has been accepted,
657 <code>osl_Socket_TimedOut</code>, if m_RecvTimeout milliseconds passed without connect,
658 <code>osl_Socket_Error</code> on errors.
660 inline oslSocketResult SAL_CALL acceptConnection( StreamSocket& Connection);
662 /** Accepts incoming connections on the socket. You must
663 precede this call with osl::Socket::bind() and listen().
664 @param PeerAddr receives the address of the connecting entity
665 (your communication partner).
666 @param Connection receives the incoming connection.
667 @return <code>osl_Socket_Ok</code>, if a connection has been accepted,
668 <code>osl_Socket_TimedOut</code>, if m_RecvTimeout milliseconds passed without connect,
669 <code>osl_Socket_Error</code> on errors.
671 inline oslSocketResult SAL_CALL acceptConnection( StreamSocket& Connection, SocketAddr & PeerAddr);
675 /** A connectionless socket to send and receive datagrams.
677 class DatagramSocket : public Socket
679 public:
681 /** Creates a datagram socket.
682 @param Family the Family of the socket (Inet by default)
683 @param Protocol the Protocon of the socket (IP by default)
684 @param Type is sock_dgram by default.
686 inline DatagramSocket(oslAddrFamily Family= osl_Socket_FamilyInet,
687 oslProtocol Protocol= osl_Socket_ProtocolIp,
688 oslSocketType Type= osl_Socket_TypeDgram);
690 /** Tries to receives BufferSize data from the socket, if no error occurs.
692 @param pSenderAddr [out] You must provide pointer to a SocketAddr.
693 It will be filled with the address of the datagrams sender.
694 If pSenderAddr is 0, it is ignored.
695 @param pBuffer [out] Points to a buffer that will be filled with the received
696 datagram.
697 @param BufferSize [in] The size of pBuffer.
698 @param Flag [in] Modifier for the call. Valid values are:
699 <ul>
700 <li><code>osl_Socket_MsgNormal</code>
701 <li><code>osl_Socket_MsgOOB</code>
702 <li><code>osl_Socket_MsgPeek</code>
703 <li><code>osl_Socket_MsgDontRoute</code>
704 <li><code>osl_Socket_MsgMaxIOVLen</code>
705 </ul>
707 @return the number of received bytes.
709 inline sal_Int32 SAL_CALL recvFrom(void* pBuffer,
710 sal_uInt32 BufferSize,
711 SocketAddr* pSenderAddr= NULL,
712 oslSocketMsgFlag Flag= osl_Socket_MsgNormal);
714 /** Tries to send one datagram with BytesToSend size to the given ReceiverAddr.
715 Since there is only send one packet, the function doesn't care about
716 packet boundaries.
718 @param ReceiverAddr [in] A SocketAddr that contains
719 the destination address for this send.
721 @param pBuffer [in] Points to a buffer that contains the send-data.
722 @param BufferSize [in] The number of bytes to send. pBuffer must have at least
723 this size.
724 @param Flag [in] Modifier for the call. Valid values are:
726 <ul>
727 <li><code>osl_Socket_MsgNormal</code>
728 <li><code>osl_Socket_MsgOOB</code>
729 <li><code>osl_Socket_MsgPeek</code>
730 <li><code>osl_Socket_MsgDontRoute</code>
731 <li><code>osl_Socket_MsgMaxIOVLen</code>
732 </ul>
734 @return the number of transferred bytes.
736 inline sal_Int32 SAL_CALL sendTo( const SocketAddr& ReceiverAddr,
737 const void* pBuffer,
738 sal_uInt32 BufferSize,
739 oslSocketMsgFlag Flag= osl_Socket_MsgNormal);
744 #endif
746 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */