CppCMS
basic_io_device.h
1 //
2 // Copyright (C) 2009-2012 Artyom Beilis (Tonkikh)
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See
5 // accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
7 //
8 #ifndef BOOSTER_AIO_BASIC_IO_DEVICE_H
9 #define BOOSTER_AIO_BASIC_IO_DEVICE_H
10 
11 #include <booster/aio/types.h>
12 #include <booster/hold_ptr.h>
13 #include <booster/callback.h>
14 #include <booster/noncopyable.h>
15 
16 namespace booster {
17 namespace aio {
18  class io_service;
19  class endpoint;
20 
36  class BOOSTER_API basic_io_device : public noncopyable {
37  public:
49  virtual ~basic_io_device();
50 
54  bool has_io_service();
58  io_service &get_io_service();
62  void set_io_service(io_service &srv);
66  void reset_io_service();
67 
73  void attach(native_type fd);
77  void assign(native_type fd);
83  native_type release();
87  native_type native();
88 
94  void close();
100  void close(system::error_code &e);
101 
107  void on_readable(event_handler const &r);
113  void on_writeable(event_handler const &r);
117  void cancel();
118 
122  basic_io_device &lowest_layer();
123 
129  void set_non_blocking(bool nonblocking);
135  void set_non_blocking(bool nonblocking,system::error_code &e);
143  void set_non_blocking_if_needed(bool nonblocking);
151  void set_non_blocking_if_needed(bool nonblocking,system::error_code &e);
152 
156  static bool would_block(system::error_code const &e);
157 
158  protected:
162  bool dont_block(event_handler const &c);
166  bool dont_block(io_handler const &c);
167  private:
168 
169  struct data;
170  hold_ptr<data> d;
171  native_type fd_;
172  bool owner_;
173  bool nonblocking_was_set_;
174  io_service *srv_;
175  };
176 
177 
178 
179 } // aio
180 } // booster
181 
182 #endif
This is a basic object that allows execution of asynchronous operations.
Definition: basic_io_device.h:36
Definition: callback.h:18
The lightweight object that carries a error code information and its category.
Definition: system_error.h:83
unspecified native_type
Definition: types.h:29
Booster library namespace. The library that implements Boost Like API in ABI backward compatible way...
Definition: application.h:23
this is the central event loop that dispatches all requests.
Definition: io_service.h:37
This class makes impossible to copy any class derived from this one.
Definition: noncopyable.h:15