0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
IOHandlerDatagram.h
Go to the documentation of this file.
1 /* -*- c++ -*-
2  * Copyright (C) 2007-2015 Hypertable, Inc.
3  *
4  * This file is part of Hypertable.
5  *
6  * Hypertable is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 3
9  * of the License, or any later version.
10  *
11  * Hypertable is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  * 02110-1301, USA.
20  */
21 
28 #ifndef AsyncComm_IOHandlerDatagram_h
29 #define AsyncComm_IOHandlerDatagram_h
30 
31 #include "CommBuf.h"
32 #include "IOHandler.h"
33 
34 #include <list>
35 #include <utility>
36 
37 extern "C" {
38 #include <netdb.h>
39 #include <string.h>
40 }
41 
42 namespace Hypertable {
43 
50  class IOHandlerDatagram : public IOHandler {
51 
52  public:
53 
60  Reactor::Priority rp) : IOHandler(sd, dhp, rp) {
61  m_message = new uint8_t [65536];
62  memcpy(&m_addr, &m_local_addr, sizeof(InetAddr));
63  }
64 
66  virtual ~IOHandlerDatagram() { delete [] m_message; }
67 
76  int send_message(const InetAddr &addr, CommBufPtr &cbp);
77 
86  int flush_send_queue();
87 
108  bool handle_event(struct pollfd *event,
109  ClockT::time_point arrival_time) override;
110 
111 #if defined(__APPLE__) || defined(__FreeBSD__)
112 
132  bool handle_event(struct kevent *event,
133  ClockT::time_point arrival_time) override;
134 #elif defined(__linux__)
135 
155  bool handle_event(struct epoll_event *event,
156  ClockT::time_point arrival_time) override;
157 #elif defined(__sun__)
158 
180  bool handle_event(port_event_t *event,
181  ClockT::time_point arrival_time) override;
182 #else
184 #endif
185 
193 
194  private:
195 
197  typedef std::pair<struct sockaddr_in, CommBufPtr> SendRec;
198 
200  uint8_t *m_message;
201 
203  std::list<SendRec> m_send_queue;
204  };
206 }
207 
208 #endif // AsyncComm_IOHandlerDatagram_h
int handle_write_readiness()
Handles write readiness.
int send_message(const InetAddr &addr, CommBufPtr &cbp)
Sends a message.
I/O handler for datagram (UDP) sockets.
chrono::time_point< fast_clock > time_point
Definition: fast_clock.h:42
int flush_send_queue()
Flushes send queue.
uint8_t * m_message
Message receive buffer.
virtual ~IOHandlerDatagram()
Destructor.
IOHandlerDatagram(int sd, const DispatchHandlerPtr &dhp, Reactor::Priority rp)
Constructor.
Encapsulate an internet address.
Definition: InetAddr.h:66
std::shared_ptr< CommBuf > CommBufPtr
Smart pointer to CommBuf.
Definition: CommBuf.h:305
Base class for socket descriptor I/O handlers.
Definition: IOHandler.h:76
std::list< SendRec > m_send_queue
Send queue.
Hypertable definitions
Declarations for CommBuf.
Priority
Enumeration for reactor priority.
Definition: Reactor.h:73
std::shared_ptr< DispatchHandler > DispatchHandlerPtr
Smart pointer to DispatchHandler.
std::pair< struct sockaddr_in, CommBufPtr > SendRec
Send queue message record.
bool handle_event(struct pollfd *event, ClockT::time_point arrival_time) override
Handle poll() interface events.
InetAddr m_addr
Handler socket address.
Definition: IOHandler.h:457
Declarations for IOHandler.
InetAddr m_local_addr
Local address of connection.
Definition: IOHandler.h:460