nidas  v1.2-1520
UDPSocketIODevice.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_UDPSOCKETIODEVICE_H
27 #define NIDAS_CORE_UDPSOCKETIODEVICE_H
28 
29 #include <nidas/util/Socket.h>
30 #include "SocketIODevice.h"
31 
32 #include <iostream>
33 
34 namespace nidas { namespace core {
35 
40 
41 public:
42 
48 
50 
56  void open(int flags)
58 
62  int getReadFd() const
63  {
64  if (_socket) return _socket->getFd();
65  return -1;
66  }
67 
71  int getWriteFd() const {
72  if (_socket) return _socket->getFd();
73  return -1;
74  }
75 
79  size_t read(void *buf, size_t len) throw(nidas::util::IOException)
80  {
81  return _socket->recv(buf,len);
82  }
83 
87  size_t read(void *buf, size_t len, int msecTimeout)
89 
93  size_t write(const void *buf, size_t len) throw(nidas::util::IOException)
94  {
95  return _socket->send(buf,len);
96  }
97 
101  void close() throw(nidas::util::IOException);
102 
103 protected:
104 
111  nidas::util::DatagramSocket* _socket;
112 
117 
121  UDPSocketIODevice& operator=(const UDPSocketIODevice&);
122 
123 };
124 
125 }} // namespace nidas namespace core
126 
127 #endif
void open(int flags)
Open the socket, which does a socket bind to the remote address which is parsed from the contents of ...
Definition: UDPSocketIODevice.cc:57
size_t recv(void *buf, size_t len, int flags=0)
Definition: Socket.h:1063
void send(const DatagramPacketBase &packet, int flags=0)
Definition: Socket.h:1058
UDPSocketIODevice()
Create a UDPSocketIODevice.
Definition: UDPSocketIODevice.cc:36
int getFd() const
Definition: Socket.h:1031
A IODevice providing support for UDP and TCP sockets.
Definition: SocketIODevice.h:40
int getReadFd() const
The file descriptor used when reading from this SocketIODevice.
Definition: UDPSocketIODevice.h:62
size_t write(const void *buf, size_t len)
Write to the device.
Definition: UDPSocketIODevice.h:93
void close()
close the device.
Definition: UDPSocketIODevice.cc:46
int getWriteFd() const
The file descriptor used when writing to this device.
Definition: UDPSocketIODevice.h:71
Implementation of an IOChannel, over a DatagramSocket.
Definition: DatagramSocket.h:44
int len
Definition: sing.cc:934
Definition: IOException.h:37
~UDPSocketIODevice()
Definition: UDPSocketIODevice.cc:41
nidas::util::DatagramSocket * _socket
The datagramsocket.
Definition: UDPSocketIODevice.h:111
size_t read(void *buf, size_t len)
Read from the device.
Definition: UDPSocketIODevice.h:79
An IODevice consisting of an UDP socket.
Definition: UDPSocketIODevice.h:39
Definition: InvalidParameterException.h:35