PTLib  Version 2.14.3
 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: 32279 $
30  * $Author: rjongbloed $
31  * $Date: 2014-07-02 13:26:56 +1000 (Wed, 02 Jul 2014) $
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;
133 
134  // Normally, one would expect these to be protected, but they are just so darn
135  // useful that it's just easier if they are public
136  virtual bool InternalReadFrom(Slice * slices, size_t sliceCount, PIPSocketAddressAndPort & ipAndPort);
137  virtual void InternalSetSendAddress(const PIPSocketAddressAndPort & addr);
138  virtual void InternalGetSendAddress(PIPSocketAddressAndPort & addr) const;
139  virtual void InternalSetLastReceiveAddress(const PIPSocketAddressAndPort & addr);
140  virtual void InternalGetLastReceiveAddress(PIPSocketAddressAndPort & addr) const;
141 
142  protected:
143  // Open an IPv4 socket (for backward compatibility)
144  virtual PBoolean OpenSocket();
145 
146  // Open an IPv4 or IPv6 socket
147  virtual PBoolean OpenSocket(
148  int ipAdressFamily
149  );
150 
151  virtual bool InternalListen(const Address & bind, unsigned queueSize, WORD port, Reusability reuse);
152 
153  virtual const char * GetProtocolName() const;
154 
155 // Include platform dependent part of class
156 #ifdef _WIN32
157 #include "msos/ptlib/udpsock.h"
158 #else
159 #include "unix/ptlib/udpsock.h"
160 #endif
161 
162  private:
163  Address m_sendAddress;
164  WORD m_sendPort;
165 
166  Address m_lastReceiveAddress;
167  WORD m_lastReceivePort;
168 };
169 
170 
171 #endif // PTLIB_UDPSOCKET_H
172 
173 
174 // End Of File ///////////////////////////////////////////////////////////////