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);
136 
140  static bool would_block(system::error_code const &e);
141 
142  protected:
146  bool dont_block(event_handler const &c);
150  bool dont_block(io_handler const &c);
151  private:
152 
153  struct data;
154  hold_ptr<data> d;
155  native_type fd_;
156  bool owner_;
157  bool nonblocking_was_set_;
158  io_service *srv_;
159  };
160 
161 
162 
163 } // aio
164 } // booster
165 
166 #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
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