// 初始化 public NetSocket(ServerTask _serverTaskCtx = null) { serverTask = _serverTaskCtx; unPackCache.buf = null; unPackCache.len = 0; if (serverTask == null) { return; } Server server = serverTask.GetServer(); SetDePacketor(server.dePacketor); unPackHeadLen = dePacketor.GetPackHeadPreLength(); UniqueID uniqueID = UniqueID.GetInstance(); if (server.serverTaskCount > 1) { id = uniqueID.gen_multi(); } else { id = uniqueID.gen(); } }
void OnSendCallBack(IAsyncResult ar) { Packet packet = ar.AsyncState as Packet; packet.ar = ar; ServerTask serverTask = packet.serverTask; serverTask.PostSendedTask(packet); }
void OnReceiveCallBack(IAsyncResult ar) { Packet packet = ar.AsyncState as Packet; packet.ar = ar; ServerTask serverTask = packet.serverTask; serverTask.PostRecvedTask(packet); }
void OnConnectCallBack(IAsyncResult ar) { Packet packet = ar.AsyncState as Packet; packet.ar = ar; ServerTask serverTask = packet.serverTask; serverTask.PostConnectedServerTask(packet); }
public Timer CreateTimer(int serverTaskIdx, Timer.TimerCallBack timerCB, object param, int durationMS) { if (isStop) { return(null); } ServerTask serverTask = serverTaskMgr.GetServerTask(serverTaskIdx); TaskProcesser taskProcesser = serverTask.GetMainTaskProcesser(); Timer timer = new Timer(taskProcesser, durationMS, timerCB, param); return(timer); }
public ServerTaskMgr(Server _serverCtx) { server = _serverCtx; serverTaskCount = server.serverTaskCount; serverTaskList = new ServerTask[serverTaskCount]; serverTaskStateList = new ServerTaskState[serverTaskCount]; for (int i = 0; i < serverTaskCount; i++) { serverTaskList[i] = new ServerTask(this); } // taskProcesser = new CommonTaskProcesser(); }
public Packet(NetSocket _socketCtx, int _maxBufSize = 1024) { socketCtx = _socketCtx; serverTask = socketCtx.serverTask; socketID = socketCtx.GetID(); maxBufSize = _maxBufSize; if (_maxBufSize != 0) { buf = new byte[maxBufSize]; Array.Clear(buf, 0, buf.Length); } packBuf.buf = buf; packBuf.len = maxBufSize; }