nidas  v1.2-1520
TCPSocketIODevice.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  ** 2008, 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_TCPSOCKETIODEVICE_H
27 #define NIDAS_CORE_TCPSOCKETIODEVICE_H
28 
29 #include "SocketIODevice.h"
30 
31 namespace nidas { namespace core {
32 
37 
38 public:
39 
45 
47 
53  void open(int flags)
55 
59  int getReadFd() const
60  {
61  if (_socket) return _socket->getFd();
62  return -1;
63  }
64 
68  int getWriteFd() const {
69  if (_socket) return _socket->getFd();
70  return -1;
71  }
72 
76  size_t read(void *buf, size_t len) throw(nidas::util::IOException)
77  {
78  return _socket->recv(buf,len);
79  }
80 
84  size_t read(void *buf, size_t len, int msecTimeout)
86 
90  size_t write(const void *buf, size_t len) throw(nidas::util::IOException)
91  {
92  return _socket->send(buf,len);
93  }
94 
98  void close() throw(nidas::util::IOException);
99 
100  void setTcpNoDelay(bool val) throw(nidas::util::IOException)
101  {
102  _tcpNoDelay = val;
103  }
104 
105  bool getTcpNoDelay() throw(nidas::util::IOException)
106  {
107  return _tcpNoDelay;
108  }
109 
111  {
112  _keepAliveIdleSecs = val;
113  }
114 
115  int getKeepAliveIdleSecs() const throw(nidas::util::IOException)
116  {
117  return _keepAliveIdleSecs;
118  }
119 
120 protected:
121 
129 
131 
133 
138 
143 
144 };
145 
146 }} // namespace nidas namespace core
147 
148 #endif
TCPSocketIODevice()
Create a TCPSocketIODevice.
Definition: TCPSocketIODevice.cc:36
TCPSocketIODevice & operator=(const TCPSocketIODevice &)
No assignment.
size_t read(void *buf, size_t len)
Read from the device.
Definition: TCPSocketIODevice.h:76
~TCPSocketIODevice()
Definition: TCPSocketIODevice.cc:42
A IODevice providing support for UDP and TCP sockets.
Definition: SocketIODevice.h:40
void open(int flags)
Open the socket, which does a socket connect to the remote address which is parsed from the contents ...
Definition: TCPSocketIODevice.cc:58
An IODevice consisting of a TCP socket.
Definition: TCPSocketIODevice.h:36
int getFd() const
Fetch the file descriptor associate with this socket.
Definition: Socket.h:617
int getKeepAliveIdleSecs() const
Definition: TCPSocketIODevice.h:115
void setTcpNoDelay(bool val)
Definition: TCPSocketIODevice.h:100
int getWriteFd() const
The file descriptor used when writing to this device.
Definition: TCPSocketIODevice.h:68
bool _tcpNoDelay
Definition: TCPSocketIODevice.h:130
int len
Definition: sing.cc:934
int _keepAliveIdleSecs
Definition: TCPSocketIODevice.h:132
Definition: IOException.h:37
int getReadFd() const
The file descriptor used when reading from this SocketIODevice.
Definition: TCPSocketIODevice.h:59
void close()
close the device.
Definition: TCPSocketIODevice.cc:47
nidas::util::Socket * _socket
The socket.
Definition: TCPSocketIODevice.h:128
A stream (TCP) socket.
Definition: Socket.h:430
size_t recv(void *buf, size_t len, int flags=0)
Definition: Socket.h:619
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:630
size_t write(const void *buf, size_t len)
Write to the device.
Definition: TCPSocketIODevice.h:90
bool getTcpNoDelay()
Definition: TCPSocketIODevice.h:105
void setKeepAliveIdleSecs(int val)
Definition: TCPSocketIODevice.h:110
Definition: InvalidParameterException.h:35