PTLib  Version 2.12.9
 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  * $Revision: 29415 $
30  * $Author: rjongbloed $
31  * $Date: 2013-04-03 08:41:13 +1100 (Wed, 03 Apr 2013) $
32  */
33 
34 #ifndef PTLIB_UDPSOCKET_H
35 #define PTLIB_UDPSOCKET_H
36 
37 #ifdef P_USE_PRAGMA
38 #pragma interface
39 #endif
40 
41 #include <ptlib/ipdsock.h>
42 
47 {
48  PCLASSINFO(PUDPSocket, PIPDatagramSocket);
49 
50  public:
56  PUDPSocket(
57  WORD port = 0,
58  int iAddressFamily = AF_INET
59  );
60  PUDPSocket(
61  const PString & service,
62  int iAddressFamily = AF_INET
63  );
64  PUDPSocket(
65  const PString & address,
66  WORD port
67  );
68  PUDPSocket(
69  const PString & address,
70  const PString & service
71  );
73 
78  PBoolean Read(
79  void * buf,
80  PINDEX len
81  );
82 
86  const void * buf,
87  PINDEX len
88  );
89 
93  const PString & address
94  );
96 
101  void SetSendAddress(
102  const Address & address,
103  WORD port
104  );
105  void SetSendAddress(
106  const PIPSocketAddressAndPort & addressAndPort
107  );
108 
111  void GetSendAddress(
112  Address & address,
113  WORD & port
114  ) const;
115  void GetSendAddress(
116  PIPSocketAddressAndPort & addressAndPort
117  ) const;
118  PString GetSendAddress() const;
119 
125  Address & address,
126  WORD & port
127  ) const;
129  PIPSocketAddressAndPort & addressAndPort
130  ) const;
132 
138  const Address & address,
139  WORD port
140  );
141 
148  virtual PBoolean DoPseudoRead(int & selectStatus);
150 
151  // Normally, one would expect these to be protected, but they are just so darn
152  // useful that it's just easier if they are public
153  virtual void InternalSetSendAddress(const PIPSocketAddressAndPort & addr);
154  virtual void InternalGetSendAddress(PIPSocketAddressAndPort & addr) const;
155  virtual void InternalSetLastReceiveAddress(const PIPSocketAddressAndPort & addr);
156  virtual void InternalGetLastReceiveAddress(PIPSocketAddressAndPort & addr) const;
157 
158  protected:
159  virtual PBoolean ConvertOSError(P_INT_PTR libcReturnValue, ErrorGroup group = LastGeneralError);
160 
161  // Open an IPv4 socket (for backward compatibility)
162  virtual PBoolean OpenSocket();
163 
164  // Open an IPv4 or IPv6 socket
165  virtual PBoolean OpenSocket(
166  int ipAdressFamily
167  );
168 
169  virtual bool InternalListen(const Address & bind, unsigned queueSize, WORD port, Reusability reuse);
170 
171  virtual const char * GetProtocolName() const;
172 
173 // Include platform dependent part of class
174 #ifdef _WIN32
175 #include "msos/ptlib/udpsock.h"
176 #else
177 #include "unix/ptlib/udpsock.h"
178 #endif
179 
180  private:
181  Address m_sendAddress;
182  WORD m_sendPort;
183 
184  Address m_lastReceiveAddress;
185  WORD m_lastReceivePort;
186 };
187 
188 
189 #endif // PTLIB_UDPSOCKET_H
190 
191 
192 // End Of File ///////////////////////////////////////////////////////////////