75 IoRecvCtx() : hadBytes(0), targetBytes(0), cnnAvail(false) { }
81 using OkFunction = std::function< void ( winux::SharedPointer<AsyncSocket> sock,
winux::uint64 costTimeMs,
bool cnnAvail ) >;
92 IoSendCtx() : hadBytes(0), costTimeMs(0), cnnAvail(false) { }
133 using IoMapMap = std::map< winux::SharedPointer<AsyncSocket>, std::map< IoType, winux::SharedPointer<IoCtx> > >;
134 using IoMap = IoMapMap::mapped_type;
140 IoService(
int threadCount = 4,
double serverWait = 0.002 );
146 bool init(
int threadCount = 4,
double serverWait = 0.002 );
149 void stop(
bool b =
true );
162 void getSockIoCount(
size_t * sockCount,
size_t * ioCount )
const;
182 winux::ThreadPool _pool;
184 winux::RecursiveMutex _mtx;
185 winux::Condition _cdt;
199 explicit AsyncSocket( IoService & ioServ,
int sock = -1,
bool isNewSock =
false ) : Socket( sock, isNewSock ), _ioServ(&ioServ), _data(nullptr)
201 this->setBlocking(
false);
207 this->setBlocking(
false);
232 template <
typename _Ty >
233 _Ty *
getDataPtr()
const {
return reinterpret_cast<_Ty*
>(_data); }
246 this->recvUntilSizeAsync( 0, cbOk,
timeoutMs, cbTimeout );
260 this->recvFromUntilSizeAsync( 0, cbOk,
timeoutMs, cbTimeout );
279 friend class IoService;
293 AsyncSocket( IoService & ioServ,
int sock,
bool isNewSock =
false ) : BaseClass( ioServ, sock, isNewSock ) { }
295 explicit AsyncSocket( IoService & ioServ ) : BaseClass( ioServ, BaseClass::afInet, BaseClass::sockStream, BaseClass::protoUnspec ) { }
320 AsyncSocket( IoService & ioServ,
int sock,
bool isNewSock =
false ) : BaseClass( ioServ, sock, isNewSock ) { }
322 explicit AsyncSocket( IoService & ioServ ) : BaseClass( ioServ, BaseClass::afInet, BaseClass::sockDatagram, BaseClass::protoUnspec ) { }
eiennet::AsyncSocket BaseClass
_Ty * getDataPtr() const
获取套接字关联数据
std::function< bool(winux::SharedPointer< AsyncSocket > servSock, winux::SharedPointer< AsyncSocket > clientSock, ip::EndPoint const &ep) > OkFunction
static winux::SharedPointer< AsyncSocket > New(IoService &ioServ, int sock=-1, bool isNewSock=false)
void setDataPtr(void *data)
设置套接字关联数据
winux::uint64 costTimeMs
总花费时间
void * getBuf() const
暴露缓冲区指针
TimeoutFunction cbTimeout
超时回调函数
TimeoutFunction cbTimeout
超时回调函数
ip::EndPoint epFrom
来自此EP的数据
winux::uint64 costTimeMs
总花费时间
winux::ThreadPool & getPool()
std::function< void(winux::SharedPointer< AsyncSocket > sock, winux::uint64 costTimeMs) > OkFunction
winux::uint64 timeoutMs
超时时间
void * getDataPtr() const
获取套接字关联数据
winux::uint64 costTimeMs
总花费时间
std::function< void(winux::SharedPointer< AsyncSocket > sock, IoConnectCtx *ctx) > TimeoutFunction
std::function< void(winux::SharedPointer< AsyncSocket > sock, IoSendCtx *ctx) > TimeoutFunction
static winux::SharedPointer< AsyncSocket > New(IoService &ioServ)
void sendAsync(winux::Buffer const &data, IoSendCtx::OkFunction cbOk, winux::uint64 timeoutMs=-1, IoSendCtx::TimeoutFunction cbTimeout=nullptr)
发送数据(异步)
TimeoutFunction cbTimeout
超时回调函数
std::function< void(winux::SharedPointer< AsyncSocket > sock, winux::Buffer &data, bool cnnAvail) > OkFunction
void recvAsync(IoRecvCtx::OkFunction cbOk, winux::uint64 timeoutMs=-1, IoRecvCtx::TimeoutFunction cbTimeout=nullptr)
接收数据(异步)
size_t getSize() const
获取数据大小
#define DISABLE_OBJECT_COPY(clsname)
static winux::SharedPointer< AsyncSocket > New(IoService &ioServ, int sock, bool isNewSock=false)
bool accept(int *sock, EndPoint *ep=NULL)
接受一个客户连接
std::function< void(winux::SharedPointer< AsyncSocket > sock, winux::uint64 costTimeMs, bool cnnAvail) > OkFunction
std::function< void(winux::SharedPointer< AsyncSocket > sock, IoRecvCtx *ctx) > TimeoutFunction
winux::GrowBuffer data
已接收的数据
std::function< bool(winux::SharedPointer< AsyncSocket > servSock, IoAcceptCtx *ctx) > TimeoutFunction
AsyncSocket(IoService &ioServ, int sock, bool isNewSock=false)
std::function< void(winux::SharedPointer< AsyncSocket > sock, winux::uint64 costTimeMs) > OkFunction
缓冲区,表示内存中一块二进制数据(利用malloc/realloc进行内存分配)
static winux::SharedPointer< AsyncSocket > New(IoService &ioServ)
eiennet::AsyncSocket BaseClass
winux::uint64 startTime
请求开启的时间
void recvFromAsync(IoRecvFromCtx::OkFunction cbOk, winux::uint64 timeoutMs=-1, IoRecvFromCtx::TimeoutFunction cbTimeout=nullptr)
无连接,接收数据(异步)
winux::SharedPointer< AsyncSocket > accept(EndPoint *ep=nullptr)
TimeoutFunction cbTimeout
超时回调函数
线程池,创建一组线程等待着从任务队列中获取任务执行
IoMapMap::mapped_type IoMap
uint64 GetUtcTimeMs(void)
获取UTC时间毫秒数,UTC秒数可以直接除以1000,或者调用CRT的time(NULL)
winux::GrowBuffer data
已接收的数据
std::function< void(winux::SharedPointer< AsyncSocket > sock, IoRecvFromCtx *ctx) > TimeoutFunction
#define DEFINE_CUSTOM_EVENT(evtname, paramtypes, calledparams)
AsyncSocket(IoService &ioServ)
static winux::SharedPointer< AsyncSocket > New(IoService &ioServ, int sock, bool isNewSock=false)
TimeoutFunction cbTimeout
超时回调函数
std::function< void(winux::SharedPointer< AsyncSocket > sock, IoSendToCtx *ctx) > TimeoutFunction
std::map< winux::SharedPointer< AsyncSocket >, std::map< IoType, winux::SharedPointer< IoCtx > > > IoMapMap
void sendToAsync(EndPoint const &ep, winux::Buffer const &data, IoSendToCtx::OkFunction cbOk, winux::uint64 timeoutMs=-1, IoSendToCtx::TimeoutFunction cbTimeout=nullptr)
无连接,发送数据(异步)
TimeoutFunction cbTimeout
超时回调函数
AsyncSocket(IoService &ioServ, AddrFamily af, SockType sockType, Protocol proto)
构造函数2
winux::SimplePointer< EndPoint > ep
std::function< void(winux::SharedPointer< AsyncSocket > sock, winux::Buffer &data, EndPoint const &ep) > OkFunction
winux::Mutex & getMutex()
static winux::SharedPointer< AsyncSocket > New(IoService &ioServ, AddrFamily af, SockType sockType, Protocol proto)
AsyncSocket(IoService &ioServ, int sock=-1, bool isNewSock=false)
构造函数1
IoService & getService() const
获取IO服务对象
AsyncSocket(IoService &ioServ, int sock, bool isNewSock=false)
AsyncSocket(IoService &ioServ)