nidas  v1.2-1520
MultipleUDPSockets.h
Go to the documentation of this file.
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 4; tab-width: 4; -*-
2 // vim: set shiftwidth=4 softtabstop=4 expandtab:
3 /*
4  ********************************************************************
5  ** NIDAS: NCAR In-situ Data Acquistion Software
6  **
7  ** 2009, Copyright University Corporation for Atmospheric Research
8  **
9  ** This program is free software; you can redistribute it and/or modify
10  ** it under the terms of the GNU General Public License as published by
11  ** the Free Software Foundation; either version 2 of the License, or
12  ** (at your option) any later version.
13  **
14  ** This program is distributed in the hope that it will be useful,
15  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  ** GNU General Public License for more details.
18  **
19  ** The LICENSE.txt file accompanying this software contains
20  ** a copy of the GNU General Public License. If it is not found,
21  ** write to the Free Software Foundation, Inc.,
22  ** 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23  **
24  ********************************************************************
25 */
26 
27 #ifndef NIDAS_CORE_MULTIPLESOCKETUDP_H
28 #define NIDAS_CORE_MULTIPLESOCKETUDP_H
29 
30 #include "McSocketUDP.h"
31 
32 #include <string>
33 #include <iostream>
34 
35 namespace nidas { namespace core {
36 
38 {
39 public:
41 
43 
44  MultipleUDPSockets* clone() const;
45 
47 
49  const nidas::util::Inet4PacketInfoX& pktinfo) throw();
50 
51  size_t getBufferSize() const throw();
52 
53  size_t read(void*, size_t) throw(nidas::util::IOException)
54  {
55  assert(false);
56  return 0;
57  }
58 
59  size_t write(const void* buf, size_t len)
61 
62  size_t write(const struct iovec* iov, int iovcnt)
64 
65  void close() throw(nidas::util::IOException);
66 
67  int getFd() const;
68 
69  void fromDOMElement(const xercesc::DOMElement*)
70  throw(nidas::util::InvalidParameterException);
71 
82  void addClient(const ConnectionInfo& info);
83 
84  void removeClient(const nidas::util::Inet4SocketAddress& remoteSAddr);
85 
86  void removeClient(nidas::util::DatagramSocket*);
87 
88  void setDataPort(unsigned short val)
89  {
90  _dataPortNumber = htons(val);
91  }
92 
93  unsigned short getDataPort() const
94  {
95  return ntohs(_dataPortNumber);
96  }
97 
98 private:
99 
100  void handleChangedSockets();
101 
103 
104  std::list<std::pair<nidas::util::DatagramSocket*,nidas::util::Inet4SocketAddress> > _sockets;
105 
106  std::list<std::pair<nidas::util::DatagramSocket*,nidas::util::Inet4SocketAddress> > _pendingSockets;
107 
108  std::list<nidas::util::DatagramSocket*> _pendingRemoveSockets;
109 
113  std::map<nidas::util::Inet4SocketAddress,nidas::util::Inet4Address>
115 
119  std::map<nidas::util::Inet4Address,std::set<nidas::util::Inet4SocketAddress> >
121 
125  std::map<nidas::util::Inet4Address,nidas::util::DatagramSocket*>
127 
131  std::map<nidas::util::Inet4SocketAddress,nidas::util::DatagramSocket*>
133 
135 
136  unsigned short _dataPortNumber;
137 };
138 
139 
140 }} // namespace nidas namespace core
141 
142 #endif
Implementation of an IOChannel, using nidas::util::McSocket&lt;nidas::util::DatagramSocket&gt; to establish...
Definition: McSocketUDP.h:46
void connected(nidas::util::DatagramSocket *sock, const nidas::util::Inet4PacketInfoX &pktinfo)
Definition: MultipleUDPSockets.cc:82
size_t getBufferSize() const
Return suggested buffer length.
Definition: MultipleUDPSockets.cc:257
void fromDOMElement(const xercesc::DOMElement *)
Initialize myself from a xercesc::DOMElement.
Definition: MultipleUDPSockets.cc:367
A socket for sending or receiving datagrams, either unicast, broadcast or multicast.
Definition: Socket.h:912
std::map< nidas::util::Inet4Address, nidas::util::DatagramSocket * > _multicastSockets
Socket of each multicast interface.
Definition: MultipleUDPSockets.h:126
void close()
Definition: MultipleUDPSockets.cc:341
bool _socketsChanged
Definition: MultipleUDPSockets.h:134
void addClient(const ConnectionInfo &info)
From the Inet4PacketInfoX associated with the received request, determine if we need to create a new ...
Definition: MultipleUDPSockets.cc:99
Extra information associated with an IOChannel concerning the connection.
Definition: ConnectionInfo.h:38
Definition: Inet4PacketInfo.h:92
MultipleUDPSockets * clone() const
Derived classes must provide clone.
Definition: MultipleUDPSockets.cc:59
std::list< std::pair< nidas::util::DatagramSocket *, nidas::util::Inet4SocketAddress > > _pendingSockets
Definition: MultipleUDPSockets.h:106
std::list< nidas::util::DatagramSocket * > _pendingRemoveSockets
Definition: MultipleUDPSockets.h:108
size_t write(const void *buf, size_t len)
A McSocketUDP shouldn&#39;t be used to do any actual reads or writes, it just sets up the connection...
Definition: MultipleUDPSockets.cc:297
A channel for Input or Output of data.
Definition: IOChannel.h:64
Definition: MultipleUDPSockets.h:37
size_t read(void *, size_t)
A McSocketUDP shouldn&#39;t be used to do any actual reads or writes, it just sets up the connection...
Definition: MultipleUDPSockets.h:53
Implementation of an IOChannel, over a DatagramSocket.
Definition: DatagramSocket.h:44
int getFd() const
Definition: MultipleUDPSockets.cc:357
nidas::util::Mutex _socketMutex
Definition: MultipleUDPSockets.h:102
unsigned short _dataPortNumber
Definition: MultipleUDPSockets.h:136
std::list< std::pair< nidas::util::DatagramSocket *, nidas::util::Inet4SocketAddress > > _sockets
Definition: MultipleUDPSockets.h:104
int len
Definition: sing.cc:934
void removeClient(const nidas::util::Inet4SocketAddress &remoteSAddr)
Definition: MultipleUDPSockets.cc:168
Definition: IOException.h:37
void setDataPort(unsigned short val)
Definition: MultipleUDPSockets.h:88
std::map< nidas::util::Inet4SocketAddress, nidas::util::DatagramSocket * > _unicastSockets
Unicast Sockets for each destination.
Definition: MultipleUDPSockets.h:132
void handleChangedSockets()
Definition: MultipleUDPSockets.cc:272
IOChannel * connect()
Establish a connection.
Definition: MultipleUDPSockets.cc:64
unsigned short getDataPort() const
Definition: MultipleUDPSockets.h:93
A C++ wrapper for a POSIX mutex.
Definition: ThreadSupport.h:154
MultipleUDPSockets()
Definition: MultipleUDPSockets.cc:36
std::map< nidas::util::Inet4SocketAddress, nidas::util::Inet4Address > _multicastInterfaces
The local multicast interface of each remote client.
Definition: MultipleUDPSockets.h:114
std::map< nidas::util::Inet4Address, std::set< nidas::util::Inet4SocketAddress > > _multicastClients
Remote clients of each multicast interface.
Definition: MultipleUDPSockets.h:120