libtasks Documentation  1.6
net_io_task.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013-2014 ADTECH GmbH
3  * Licensed under MIT (https://github.com/adtechlabs/libtasks/blob/master/COPYING)
4  *
5  * Author: Andreas Pohl
6  */
7 
8 #ifndef _TASKS_NET_IO_TASK_H_
9 #define _TASKS_NET_IO_TASK_H_
10 
11 #include <tasks/io_task_base.h>
12 #include <tasks/net/socket.h>
13 
14 namespace tasks {
15 
16 class worker;
17 
21 class net_io_task : public io_task_base {
22  public:
23  net_io_task(int events) : io_task_base(events) {}
25  virtual ~net_io_task();
26 
28  inline std::string get_string() const {
29  std::ostringstream os;
30  os << "net_io_task(" << this << "," << iob().fd() << ":" << events() << ")";
31  return os.str();
32  }
33 
35  inline net::socket& socket() {
36  return m_socket;
37  }
39  inline const net::socket& socket() const {
40  return m_socket;
41  }
42 
47  static void add_task(net_io_task* task);
48 
49  protected:
51 
53  io_base& iob() {
54  return m_socket;
55  }
57  const io_base& iob() const {
58  return m_socket;
59  }
62  m_auto_close = false;
63  }
64 
65  private:
67  bool m_auto_close = true;
68 };
69 
70 } // tasks
71 
72 #endif // _TASKS_NET_IO_TASK_H_
void disable_auto_close()
Disable automatic closing of the socket in the desctructor.
Definition: net_io_task.h:61
The base class for any task.
Definition: task.h:19
const io_base & iob() const
Grant const socket access to the io_task_base.
Definition: net_io_task.h:57
static void add_task(net_io_task *task)
Definition: net_io_task.cpp:40
The net_io_task implements the base for socket based network tasks.
Definition: net_io_task.h:21
int events() const
Return the monitored events.
Definition: io_task_base.h:38
int fd() const
Definition: io_base.h:22
The socket class.
Definition: socket.h:35
net::socket m_socket
Definition: net_io_task.h:66
This is the base class for io event tasks. It controls an ev_io watcher that monitors io events on fi...
Definition: io_task_base.h:26
std::string get_string() const
A debug helper.
Definition: net_io_task.h:28
Base class for socket and term.
Definition: io_base.h:16
net_io_task(int events)
Definition: net_io_task.h:23
io_base & iob()
Grant socket access to the io_task_base.
Definition: net_io_task.h:53
net::socket & socket()
Provide access to the underlying socket object.
Definition: net_io_task.h:35
const net::socket & socket() const
Provide const access to the underlying socket object.
Definition: net_io_task.h:39
virtual ~net_io_task()
Definition: net_io_task.cpp:22