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_aiosock_factory_h_
00029 #define _terimber_aiosock_factory_h_
00030
00031 #include "log.h"
00032
00035 enum aiosock_type
00036 {
00037 AIOSOCK_CONNECT,
00038 AIOSOCK_ACCEPT,
00039 AIOSOCK_SEND,
00040 AIOSOCK_RECV,
00041 };
00042
00045 class terimber_aiosock_callback
00046 {
00047 public:
00049 virtual
00050 ~terimber_aiosock_callback() {}
00051
00053 virtual
00054 void
00055 v_on_error( size_t handle,
00056 int err,
00057 aiosock_type mask,
00058 void* userdata
00059 ) = 0;
00061 virtual
00062 void
00063 v_on_connect( size_t handle,
00064 const sockaddr_in& peeraddr,
00065 void* userdata
00066 ) = 0;
00068 virtual
00069 void
00070 v_on_send( size_t handle,
00071 void* buf,
00072 size_t requested,
00073 size_t processed,
00074 const sockaddr_in& peeraddr,
00075 void* userdata
00076 ) = 0;
00078 virtual
00079 void
00080 v_on_receive( size_t handle,
00081 void* buf,
00082 size_t requested,
00083 size_t processed,
00084 const sockaddr_in& peeraddr,
00085 void* userdata
00086 ) = 0;
00089 virtual
00090 void
00091 v_on_accept( size_t handle,
00092 size_t handle_accepted,
00093 terimber_aiosock_callback*& callback,
00094 const sockaddr_in& peeraddr,
00095 void* userdata
00096 ) = 0;
00097 };
00098
00101 class terimber_aiosock : public terimber_log_helper
00102 {
00103 public:
00105 virtual ~terimber_aiosock() {}
00107 virtual
00108 size_t
00109 create( terimber_aiosock_callback* callback,
00110 bool tcp_udp
00111 ) = 0;
00113 virtual
00114 void
00115 close( size_t handle
00116 ) = 0;
00118 virtual
00119 int
00120 send( size_t handle,
00121 const void* buf,
00122 size_t len,
00123 size_t timeout,
00124 const sockaddr_in* toaddr,
00125 void* userdata
00126 ) = 0;
00128 virtual
00129 int
00130 receive(size_t handle,
00131 void* buf,
00132 size_t len,
00133 size_t timeout,
00134 const sockaddr_in* fromaddr,
00135 void* userdata
00136 ) = 0;
00137
00138
00140 virtual
00141 int
00142 connect(size_t handle,
00143 const char* address,
00144 unsigned short port,
00145 size_t timeout,
00146 void* userdata
00147 ) = 0;
00150 virtual
00151 int
00152 listen( size_t handle,
00153 unsigned short port,
00154 size_t max_connection,
00155 const char* address,
00156 unsigned short accept_pool,
00157 void* userdata
00158 ) = 0;
00160 virtual
00161 int
00162 getpeeraddr( size_t handle,
00163 sockaddr_in& addr
00164 ) = 0;
00165
00166
00167
00169 virtual
00170 int
00171 bind( size_t handle,
00172 const char* address,
00173 unsigned short port
00174 ) = 0;
00175
00176
00178 virtual
00179 int
00180 getsockaddr( size_t handle,
00181 sockaddr_in& addr
00182 ) = 0;
00183
00185 virtual
00186 bool
00187 get_error_description(
00188 int err,
00189 char* buf,
00190 size_t len
00191 ) const = 0;
00192
00194 virtual
00195 void
00196 doxray() = 0;
00197 };
00198
00201 class terimber_aiosock_factory
00202 {
00203 public:
00205 terimber_aiosock_factory();
00207 ~terimber_aiosock_factory();
00208
00211 terimber_aiosock*
00212 get_aiosock( terimber_log* log,
00213 size_t capacity = 3,
00214 size_t deactivate_time_msec = 60000
00215 );
00216 };
00217
00218 #endif // _terimber_socket_port_access_h_