00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef _terimber_aiogate_factory_h_
00029 #define _terimber_aiogate_factory_h_
00030
00031 #include "log.h"
00032
00033
00034
00035
00036
00037
00038
00039
00040 class terimber_aiogate;
00041
00043 const ub4_t aiogate_accept_mask = 0x00000001;
00045 const ub4_t aiogate_connect_mask = 0x00000002;
00047 const ub4_t aiogate_send_mask = 0x00000004;
00049 const ub4_t aiogate_recv_mask = 0x00000008;
00051 const ub4_t aiogate_bind_mask = 0x00000010;
00052
00055 class terimber_aiogate_buffer
00056 {
00057 public:
00058 const void* buf;
00059 size_t len;
00060 };
00061
00065 class terimber_aiogate_pin
00066 {
00067 public:
00069 virtual ~terimber_aiogate_pin() {}
00070
00072 virtual
00073 void
00074 on_accept( const sockaddr_in& local,
00075 const sockaddr_in& remote,
00076 size_t ident,
00077 terimber_aiogate* callback
00078 ) = 0;
00079
00081 virtual
00082 void
00083 on_connect( const sockaddr_in& local,
00084 const sockaddr_in& remote,
00085 size_t ident,
00086 terimber_aiogate* callback
00087 ) = 0;
00088
00090 virtual
00091 void
00092 on_bind( const sockaddr_in& local,
00093 size_t ident,
00094 terimber_aiogate* callback
00095 ) = 0;
00096
00098
00099
00100 virtual
00101 bool
00102 on_recv( const void* buf,
00103 size_t len,
00104 const sockaddr_in& peeraddr,
00105 bool& expected_more
00106 ) = 0;
00107
00109 virtual
00110 void
00111 on_send( const sockaddr_in& peeraddr
00112 ) = 0;
00113
00115
00116 virtual
00117 void
00118 on_close( ub4_t mask
00119 ) = 0;
00120 };
00121
00122
00125
00126 class terimber_aiogate_pin_factory
00127 {
00128 public:
00130 virtual ~terimber_aiogate_pin_factory() {}
00131
00134 virtual
00135 terimber_aiogate_pin*
00136 create( void* arg
00137 ) = 0;
00138
00140 virtual
00141 void
00142 destroy( terimber_aiogate_pin* pin
00143 ) = 0;
00144 };
00145
00149 class terimber_aiogate : public terimber_log_helper
00150 {
00151 public:
00153 virtual ~terimber_aiogate() {}
00154
00162 virtual
00163 size_t
00164 listen( const char* address,
00165 unsigned short port,
00166 size_t max_connection,
00167 unsigned short buffered_acceptors,
00168 terimber_aiogate_pin_factory* factory,
00169 void* arg
00170
00171 ) = 0;
00172
00174 virtual
00175 void
00176 deaf( size_t ident
00177 ) = 0;
00178
00183 virtual
00184 size_t
00185 connect( const char* remote,
00186 unsigned short rport,
00187 const char* local,
00188 unsigned short lport,
00189 size_t timeout,
00190 terimber_aiogate_pin_factory* factory,
00191 void* arg
00192
00193 ) = 0;
00194
00195
00197 virtual
00198 size_t
00199 bind( const char* address,
00200 unsigned short port,
00201 terimber_aiogate_pin_factory* factory,
00202 void* arg
00203 ) = 0;
00204
00205
00209 virtual
00210 bool
00211 send( size_t ident,
00212 const void* buf,
00213 size_t len,
00214 const sockaddr_in* toaddr
00215 ) = 0;
00216
00218 virtual
00219 bool
00220 send_bulk( size_t ident,
00221 const terimber_aiogate_buffer* bulk,
00222 size_t count,
00223 const sockaddr_in* toaddr
00224 ) = 0;
00225
00229 virtual
00230 bool
00231 recv( size_t ident,
00232 bool expect_delivery,
00233 const sockaddr_in* toaddr
00234 ) = 0;
00236 virtual
00237 bool
00238 close( size_t ident
00239 ) = 0;
00241 virtual
00242 bool
00243 set_send_timeout(size_t ident,
00244 size_t timeout
00245 ) = 0;
00246
00248 virtual
00249 bool
00250 set_recv_timeout(size_t ident,
00251 size_t timeout
00252 ) = 0;
00253
00255 virtual
00256 void
00257 doxray() = 0;
00258 };
00259
00262 class terimber_aiogate_factory
00263 {
00264 public:
00266 terimber_aiogate_factory();
00267
00272 terimber_aiogate*
00273 get_terimber_aiogate(terimber_log* log,
00274 size_t addional_working_threads = 0,
00275 size_t max_mem_usage = 1024*1024*16
00276 );
00277 };
00278
00279 #endif // _terimber_aiogate_access_h_