CppCMS
stream_socket.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_STREAM_SOCKET_H
9 #define BOOSTER_AIO_STREAM_SOCKET_H
10 
11 #include <booster/aio/types.h>
12 #include <booster/callback.h>
13 #include <booster/hold_ptr.h>
14 #include <booster/noncopyable.h>
15 #include <booster/aio/endpoint.h>
16 #include <booster/aio/basic_io_device.h>
17 #include <booster/aio/basic_socket.h>
18 
19 namespace booster {
20 namespace aio {
21  class mutable_buffer;
22  class const_buffer;
23  class io_service;
24 
25 
26 
31  class BOOSTER_API stream_socket : public basic_socket {
32  public:
36  typedef enum {
37  shut_rd, //< Shutdown read operations
38  shut_wr, //< Shutdown write operations
39  shut_rdwr //< Shutdown both read and write operations
40  } how_type;
41 
45  stream_socket();
50  ~stream_socket();
51 
57  void open(family_type d);
63  void open(family_type d,system::error_code &e);
64 
70  void shutdown(how_type h);
76  void shutdown(how_type h,system::error_code &e);
77 
83  void connect(endpoint const &ep);
89  void connect(endpoint const &ep,system::error_code &e);
96  void async_connect(endpoint const &ep,event_handler const &h);
97 
103  size_t read_some(mutable_buffer const &buffer);
109  size_t read_some(mutable_buffer const &buffer,system::error_code &e);
110 
116  size_t write_some(const_buffer const &buffer);
122  size_t write_some(const_buffer const &buffer,system::error_code &e);
123 
130  size_t read(mutable_buffer const &buffer);
137  size_t write(const_buffer const &buffer);
138 
145  size_t read(mutable_buffer const &buffer,system::error_code &e);
152  size_t write(const_buffer const &buffer,system::error_code &e);
153 
163  void async_read_some(mutable_buffer const &buffer,io_handler const &h);
173  void async_write_some(const_buffer const &buffer,io_handler const &h);
174 
184  void async_read(mutable_buffer const &buffer,io_handler const &h);
194  void async_write(const_buffer const &buffer,io_handler const &h);
195 
200  size_t bytes_readable(booster::system::error_code &e);
201 
206  size_t bytes_readable();
207 
208  private:
209  int readv(mutable_buffer const &b);
210  int writev(const_buffer const &b);
211 
212  struct data;
213  hold_ptr<data> d;
214  };
215 
220  BOOSTER_API void socket_pair(stream_socket &s1,stream_socket &s2,system::error_code &e);
225  BOOSTER_API void socket_pair(stream_socket &s1,stream_socket &s2);
226 
227 
228 } // aio
229 } // booster
230 
231 #endif
this class represents the connection endpoint, that is generally sockaddr structure in Berkeley socke...
Definition: endpoint.h:26
This class represents a basic Socket object.
Definition: basic_socket.h:26
A mutable buffer - a buffer for read operations.
Definition: buffer.h:120
Definition: callback.h:18
The lightweight object that carries a error code information and its category.
Definition: system_error.h:83
An immutable buffer - buffer for write operations.
Definition: buffer.h:128
BOOSTER_API void socket_pair(stream_socket &s1, stream_socket &s2, system::error_code &e)
family_type
Definition: types.h:68
This object represents a stream socket: TCP/IP IPv4 or IPv6 or Unix domain stream socket...
Definition: stream_socket.h:31
Booster library namespace. The library that implements Boost Like API in ABI backward compatible way...
Definition: application.h:23
const_buffer buffer(void const *p, size_t n)
Definition: buffer.h:145
this is the central event loop that dispatches all requests.
Definition: io_service.h:37
how_type
Definition: stream_socket.h:36