PTLib  Version 2.18.8
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
udpsock.h
Go to the documentation of this file.
1 /*
2  * udpsock.h
3  *
4  * User Datagram Protocol socket I/O channel class.
5  *
6  * Portable Windows Library
7  *
8  * Copyright (c) 1993-1998 Equivalence Pty. Ltd.
9  *
10  * The contents of this file are subject to the Mozilla Public License
11  * Version 1.0 (the "License"); you may not use this file except in
12  * compliance with the License. You may obtain a copy of the License at
13  * http://www.mozilla.org/MPL/
14  *
15  * Software distributed under the License is distributed on an "AS IS"
16  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17  * the License for the specific language governing rights and limitations
18  * under the License.
19  *
20  * The Original Code is Portable Windows Library.
21  *
22  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
23  *
24  * Portions are Copyright (C) 1993 Free Software Foundation, Inc.
25  * All Rights Reserved.
26  *
27  * Contributor(s): ______________________________________.
28  */
29 
30 #ifndef PTLIB_UDPSOCKET_H
31 #define PTLIB_UDPSOCKET_H
32 
33 #ifdef P_USE_PRAGMA
34 #pragma interface
35 #endif
36 
37 #include <ptlib/ipdsock.h>
38 
43 {
44  PCLASSINFO(PUDPSocket, PIPDatagramSocket);
45 
46  public:
52  PUDPSocket(
53  WORD port = 0,
54  int iAddressFamily = AF_INET
55  );
56  PUDPSocket(
57  const PString & service,
58  int iAddressFamily = AF_INET
59  );
60  PUDPSocket(
61  const PString & address,
62  WORD port
63  );
64  PUDPSocket(
65  const PString & address,
66  const PString & service
67  );
69 
74  PBoolean Read(
75  void * buf,
76  PINDEX len
77  );
78 
82  const void * buf,
83  PINDEX len
84  );
85 
89  const PString & address
90  );
92 
101  bool SetSendAddress(
102  const Address & address,
103  WORD port,
104  int mtuDiscovery = -1
105  );
106  bool SetSendAddress(
107  const PIPSocketAddressAndPort & addressAndPort,
108  int mtuDiscovery = -1
109  );
110 
113  void GetSendAddress(
114  Address & address,
115  WORD & port
116  ) const;
117  void GetSendAddress(
118  PIPSocketAddressAndPort & addressAndPort
119  ) const;
120  PString GetSendAddress() const;
121 
127  Address & address,
128  WORD & port
129  ) const;
131  PIPSocketAddressAndPort & addressAndPort
132  ) const;
134 
138  int GetCurrentMTU();
140 
141  // Normally, one would expect these to be protected, but they are just so darn
142  // useful that it's just easier if they are public
143  virtual bool InternalReadFrom(Slice * slices, size_t sliceCount, PIPSocketAddressAndPort & ipAndPort);
144  virtual bool InternalSetSendAddress(const PIPSocketAddressAndPort & addr, int mtuDiscovery = -1);
145  virtual void InternalGetSendAddress(PIPSocketAddressAndPort & addr) const;
146  virtual void InternalSetLastReceiveAddress(const PIPSocketAddressAndPort & addr);
147  virtual void InternalGetLastReceiveAddress(PIPSocketAddressAndPort & addr) const;
148 
149  protected:
150  // Open an IPv4 socket (for backward compatibility)
151  virtual PBoolean OpenSocket();
152 
153  // Open an IPv4 or IPv6 socket
154  virtual PBoolean OpenSocket(
155  int ipAdressFamily
156  );
157 
158  virtual bool InternalListen(const Address & bind, unsigned queueSize, WORD port, Reusability reuse);
159 
160  virtual const char * GetProtocolName() const;
161 
162 // Include platform dependent part of class
163 #ifdef _WIN32
164 #include "msos/ptlib/udpsock.h"
165 #else
166 #include "unix/ptlib/udpsock.h"
167 #endif
168 
169  private:
170  AddressAndPort m_sendAddressAndPort;
171  AddressAndPort m_lastReceiveAddressAndPort;
172 };
173 
174 
175 #endif // PTLIB_UDPSOCKET_H
176 
177 
178 // End Of File ///////////////////////////////////////////////////////////////
bool SetSendAddress(const Address &address, WORD port, int mtuDiscovery=-1)
Set the address to use for connectionless Write() or Windows QoS.
virtual void InternalGetSendAddress(PIPSocketAddressAndPort &addr) const
A socket channel that uses the UDP transport on the Internet Protocol.
Definition: udpsock.h:42
virtual PBoolean OpenSocket()
PBoolean Connect(const PString &address)
Override of PSocket functions to allow connectionless writes.
A class describing an IP address and port number combination.
Definition: ipsock.h:278
PUDPSocket(WORD port=0, int iAddressFamily=AF_INET)
Create a UDP socket.
virtual bool InternalListen(const Address &bind, unsigned queueSize, WORD port, Reusability reuse)
virtual bool InternalReadFrom(Slice *slices, size_t sliceCount, PIPSocketAddressAndPort &ipAndPort)
PBoolean Read(void *buf, PINDEX len)
Override of PChannel functions to allow connectionless reads.
PBoolean Write(const void *buf, PINDEX len)
Override of PChannel functions to allow connectionless writes.
virtual void InternalSetLastReceiveAddress(const PIPSocketAddressAndPort &addr)
virtual void InternalGetLastReceiveAddress(PIPSocketAddressAndPort &addr) const
Structure that defines a &quot;slice&quot; of memory to be written to.
Definition: socket.h:434
int GetCurrentMTU()
Get the current MTU size.
bool PBoolean
Definition: object.h:174
virtual bool InternalSetSendAddress(const PIPSocketAddressAndPort &addr, int mtuDiscovery=-1)
PString GetSendAddress() const
The character string class.
Definition: pstring.h:108
A class describing an IP address.
Definition: ipsock.h:59
PString GetLastReceiveAddress() const
Internet Protocol Datagram Socket class.
Definition: ipdsock.h:41
virtual const char * GetProtocolName() const
This function returns the protocol name for the socket type.
Reusability
Flags to reuse of port numbers in Listen() function.
Definition: socket.h:85