nidas v1.2.3
DatagramSocket.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_DATAGRAMSOCKET_H
28#define NIDAS_CORE_DATAGRAMSOCKET_H
29
30#include "IOChannel.h"
31#include "DOMable.h"
32#include <nidas/util/Socket.h>
33#include <nidas/util/auto_ptr.h>
34
35#include <string>
36#include <iostream>
37
38namespace nidas { namespace core {
39
45
46public:
47
52
57
59
61
63
64 DatagramSocket* clone() const;
65
70
75
76 bool isNewInput() const { return false; }
77
78 bool writeNidasHeader() const { return false; }
79
83 std::list<nidas::util::Inet4NetworkInterface> getInterfaces() const
84 {
85 if (_nusocket) return _nusocket->getInterfaces();
86 return std::list<nidas::util::Inet4NetworkInterface>();
87 }
88
94 void setNonBlocking(bool val)
95 {
98 }
99
105 bool isNonBlocking() const
106 {
107 if (_nusocket) return _nusocket->isNonBlocking();
108 return _nonBlocking;
109 }
110
111 size_t getBufferSize() const throw();
112
118 size_t read(void* buf, size_t len)
119 {
120 return _nusocket->recv(buf,len);
121 }
122
128 size_t write(const void* buf, size_t len)
129 {
130 return _nusocket->send(buf,len,0);
131 }
132
138 size_t write(const struct iovec* iov, int iovcnt)
139 {
140 return _nusocket->send(iov,iovcnt,0);
141 }
142
146 void close()
147 {
148 if (_nusocket) _nusocket->close();
149 }
150
151
152 int getFd() const
153 {
154 if (_nusocket) return _nusocket->getFd();
155 return -1;
156 }
157
158 const std::string& getName() const { return _name; }
159
160 void setName(const std::string& val) { _name = val; }
161
165 const std::string& getUnixPath() const
166 {
167 return _unixPath;
168 }
169
173 void setUnixPath(const std::string& unixPath);
174
183
188
194 void setHostPort(const std::string& host,unsigned short port);
195
199 void setPort(unsigned short port);
200
204 const std::string& getHost() const
205 {
206 return _host;
207 }
208
209 unsigned short getPort() const
210 {
211 return _port;
212 }
213
217 void fromDOMElement(const xercesc::DOMElement*);
218
219private:
220
221 nidas::util::auto_ptr<nidas::util::SocketAddress> _sockAddr;
222
223 std::string _host;
224
225 unsigned short _port;
226
227 std::string _unixPath;
228
230
231 std::string _name;
232
234
236
237};
238
239}} // namespace nidas namespace core
240
241#endif
Implementation of an IOChannel, over a DatagramSocket.
Definition DatagramSocket.h:44
std::string _name
Definition DatagramSocket.h:231
void setUnixPath(const std::string &unixPath)
Set the pathname for the unix socket connection.
Definition DatagramSocket.cc:132
void close()
Definition DatagramSocket.h:146
DatagramSocket * clone() const
Derived classes must provide clone.
Definition DatagramSocket.cc:99
void setName(const std::string &val)
Definition DatagramSocket.h:160
std::list< nidas::util::Inet4NetworkInterface > getInterfaces() const
Definition DatagramSocket.h:83
const std::string & getUnixPath() const
Get the unix path name.
Definition DatagramSocket.h:165
IOChannelRequester * _iochanRequester
Definition DatagramSocket.h:233
void setSocketAddress(const nidas::util::SocketAddress &val)
Set address for this socket.
Definition DatagramSocket.cc:119
const std::string & getHost() const
Get the name of the remote host.
Definition DatagramSocket.h:204
int getFd() const
Definition DatagramSocket.h:152
nidas::util::DatagramSocket * _nusocket
Definition DatagramSocket.h:229
DatagramSocket & operator=(const DatagramSocket &rhs)
Definition DatagramSocket.cc:63
IOChannel * connect()
Definition DatagramSocket.cc:160
nidas::util::auto_ptr< nidas::util::SocketAddress > _sockAddr
Definition DatagramSocket.h:221
size_t write(const struct iovec *iov, int iovcnt)
Do the actual hardware write.
Definition DatagramSocket.h:138
unsigned short getPort() const
Definition DatagramSocket.h:209
void setPort(unsigned short port)
Set the the local port number.
~DatagramSocket()
Definition DatagramSocket.cc:88
size_t getBufferSize() const
Return suggested buffer length.
Definition DatagramSocket.cc:104
bool isNewInput() const
Some IOChannels, namely FileSet, which opens successive files, need to indicate when a read is from t...
Definition DatagramSocket.h:76
bool writeNidasHeader() const
Should the NIDAS header be written to this IOChannel? NIDAS headers are not written to DatagramSocket...
Definition DatagramSocket.h:78
bool _nonBlocking
Definition DatagramSocket.h:235
void setHostPort(const std::string &host, unsigned short port)
Set the hostname and port of the remote connection.
Definition DatagramSocket.cc:125
std::string _unixPath
Definition DatagramSocket.h:227
bool isNonBlocking() const
Return isNonBlocking() of underlying socket.
Definition DatagramSocket.h:105
void setNonBlocking(bool val)
Do setNonBlocking(val) on underlying socket.
Definition DatagramSocket.h:94
unsigned short _port
Definition DatagramSocket.h:225
size_t read(void *buf, size_t len)
Do the actual hardware read.
Definition DatagramSocket.h:118
const std::string & getName() const
Definition DatagramSocket.h:158
DatagramSocket()
Constructor.
Definition DatagramSocket.cc:37
void requestConnection(IOChannelRequester *service)
Definition DatagramSocket.cc:193
void fromDOMElement(const xercesc::DOMElement *)
Definition DatagramSocket.cc:200
size_t write(const void *buf, size_t len)
Do the actual hardware write.
Definition DatagramSocket.h:128
const nidas::util::SocketAddress & getSocketAddress()
Definition DatagramSocket.cc:137
std::string _host
Definition DatagramSocket.h:223
Interface for an object that requests connections to Inputs or Outputs.
Definition IOChannel.h:56
A channel for Input or Output of data.
Definition IOChannel.h:65
A socket for sending or receiving datagrams, either unicast, broadcast or multicast.
Definition Socket.h:1178
size_t recv(void *buf, size_t len, int flags=0)
Definition Socket.h:1356
void close()
Definition Socket.h:1233
bool isNonBlocking() const
Definition Socket.h:1438
std::list< Inet4NetworkInterface > getInterfaces() const
Definition Socket.h:1478
int getFd() const
Definition Socket.h:1312
void setNonBlocking(bool val)
Do fcntl system call to set O_NONBLOCK file descriptor flag on the socket.
Definition Socket.h:1430
void send(const DatagramPacketBase &packet, int flags=0)
Definition Socket.h:1348
An interface for a socket address.
Definition SocketAddress.h:36
Sample * getSample(sampleType type, unsigned int len)
A convienence method for getting a sample of an enumerated type from a pool.
Definition Sample.cc:70
Root namespace for the NCAR In-Situ Data Acquisition Software.
Definition A2DConverter.h:31
static n_u::SerialPort port
Definition sing.cc:68
int len
Definition sing.cc:948