nidas v1.2.3
ServerSocketIODevice.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 ** 2007, 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#ifndef NIDAS_CORE_SERVERSOCKETIODEVICE_H
27#define NIDAS_CORE_SERVERSOCKETIODEVICE_H
28
29#include "IODevice.h"
30#include <nidas/util/Socket.h>
32#include <nidas/util/auto_ptr.h>
33
34
35namespace nidas { namespace core {
36
47
48public:
49
55
56 virtual ~ServerSocketIODevice();
57
61 int getReadFd() const
62 {
63 if (_socket) return _socket->getFd();
64 return -1;
65 }
66
70 int getWriteFd() const {
71 if (_socket) return _socket->getFd();
72 return -1;
73 }
74
81 void open(int flags);
82
88 size_t read(void *buf, size_t len)
89 {
90 return _socket->recv(buf,len);
91 }
92
98 size_t read(void *buf, size_t len, int msecTimeout)
99 {
100 size_t l = 0;
101 try {
102 _socket->setTimeout(msecTimeout);
103 l = _socket->recv(buf,len,msecTimeout);
105 }
106 catch(const nidas::util::IOException& e) {
108 throw e;
109 }
110 return l;
111 }
112
118 size_t write(const void *buf, size_t len)
119 {
120 return _socket->send(buf,len);
121 }
122
129 void ioctl(int, void*, size_t)
130 {
132 "ioctl","not supported on SocketIODevice");
133 }
134
140 void close();
141
145 void setTcpNoDelay(bool val)
146 {
148 }
149
154 {
155 return _tcpNoDelay;
156 }
157
158protected:
159
163 void closeServerSocket();
164
165private:
166
171
175 std::string _unixPath;
176
181
185 nidas::util::auto_ptr<nidas::util::SocketAddress> _sockAddr;
186
194
196
198
201
204
205};
206
207}} // namespace nidas namespace core
208
209#endif
An interface to an IO device.
Definition IODevice.h:42
virtual const std::string & getName() const
Definition IODevice.h:57
An IODevice supporting a TCP or UNIX server socket.
Definition ServerSocketIODevice.h:46
nidas::util::Socket * _socket
Definition ServerSocketIODevice.h:195
std::string _unixPath
Path name of AF_UNIX socket.
Definition ServerSocketIODevice.h:175
ServerSocketIODevice(const ServerSocketIODevice &)
No copying.
int _sockPort
Port number that is parsed from sensor name.
Definition ServerSocketIODevice.h:180
virtual ~ServerSocketIODevice()
Definition ServerSocketIODevice.cc:44
int _addrtype
The type of the destination address, AF_INET or AF_UNIX.
Definition ServerSocketIODevice.h:170
nidas::util::ServerSocket * _serverSocket
The listen socket.
Definition ServerSocketIODevice.h:193
ServerSocketIODevice & operator=(const ServerSocketIODevice &)
No assignment.
void closeServerSocket()
Definition ServerSocketIODevice.cc:61
ServerSocketIODevice()
Create a SocketIODevice.
Definition ServerSocketIODevice.cc:37
int getReadFd() const
The file descriptor used when reading from this SocketIODevice.
Definition ServerSocketIODevice.h:61
nidas::util::auto_ptr< nidas::util::SocketAddress > _sockAddr
The destination socket address.
Definition ServerSocketIODevice.h:185
int getWriteFd() const
The file descriptor used when writing to this sensor.
Definition ServerSocketIODevice.h:70
void open(int flags)
Open the socket.
Definition ServerSocketIODevice.cc:69
size_t write(const void *buf, size_t len)
Write to the sensor.
Definition ServerSocketIODevice.h:118
bool getTcpNoDelay()
Definition ServerSocketIODevice.h:153
void close()
close the sensor (and any associated FIFOs).
Definition ServerSocketIODevice.cc:50
bool _tcpNoDelay
Definition ServerSocketIODevice.h:197
void ioctl(int, void *, size_t)
Perform an ioctl on the device.
Definition ServerSocketIODevice.h:129
size_t read(void *buf, size_t len)
Read from the sensor.
Definition ServerSocketIODevice.h:88
size_t read(void *buf, size_t len, int msecTimeout)
Read from the sensor with a timeout in milliseconds.
Definition ServerSocketIODevice.h:98
void setTcpNoDelay(bool val)
Definition ServerSocketIODevice.h:145
Definition IOException.h:37
A stream (TCP) socket that is used to listen for connections.
Definition Socket.h:981
A stream (TCP) socket.
Definition Socket.h:573
size_t recv(void *buf, size_t len, int flags=0)
Definition Socket.h:813
int getFd() const
Fetch the file descriptor associate with this socket.
Definition Socket.h:805
void setTimeout(int val)
Set the timeout for receive(), recv(), and recvfrom() methods.
Definition Socket.h:649
size_t send(const void *buf, size_t len, int flags=MSG_NOSIGNAL)
send data on socket, see man page for send system function.
Definition Socket.h:826
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
int len
Definition sing.cc:948