public void HandleClose() { if (m_nStatus == 0) { return; } m_nStatus = 0; FFNet.GetTaskQueue().Post(() => { if (m_oSocket == null) { return; } try { m_oSocket.Close(); m_oSocket = null; m_oBuffSending.Clear(); m_oSocketCtrl.HandleBroken(this); } catch (Exception ex) { FFLog.Trace("scoket: HandleClose Error " + ex.Message); } }); }
public void Close() { FFNet.GetTaskQueue().Post(() => { HandleClose(); }); }
private void handleSendEnd(IAsyncResult ar) { try { var socket = ar.AsyncState as Socket; socket.EndSend(ar); } catch (SocketException ex) { FFLog.Trace("scoket: send Error " + ex.Message); HandleClose(); return; } FFNet.GetTaskQueue().Post(() => { if (m_oBuffSending.Count > 0) { m_oBuffSending.RemoveAt(0); } try { if (m_oBuffSending.Count > 0 && m_oSocket != null) { byte[] data = m_oBuffSending[0]; m_oSocket.BeginSend(data, 0, data.Length, 0, new AsyncCallback(handleSendEnd), m_oSocket); } } catch (SocketException ex) { FFLog.Trace("scoket: send Error " + ex.Message); HandleClose(); } }); }
public void AddPerf(string nameMod, Int64 us) { FFNet.GetTaskQueue().PostOrRunIfInSameThread(() => { if (!bInit) { Init(); } if (us < 1) { us = 1; } PerfData data = null; if (m_name2data.ContainsKey(nameMod)) { data = m_name2data[nameMod]; } else { data = new PerfData() { }; m_name2data[nameMod] = data; } data.total += us; data.times += 1; if (us > data.max) { data.max = us; } if (us < data.min) { data.min = us; } }); }
public void HandleRecv(IAsyncResult ar) { if (m_nStatus == 0) { FFLog.Trace("scoket: HandleRecv has closed"); return; } var length = 0; try { Socket socket = (Socket)ar.AsyncState; if (socket == null || m_oSocket == null) { return; } length = socket.EndReceive(ar); } catch (Exception ex) { FFLog.Warning("scoket: recv Error1 " + ex.Message); HandleClose(); return; } //FFLog.Trace(string.Format("scoket: recv 1111 {0}", length)); if (length == 0) { FFLog.Warning("HandleRecv: recv end ok file "); HandleClose(); return; } FFNet.GetTaskQueue().Post(() => { try { byte[] message = new byte[length]; Array.Copy(m_oBuffer, 0, message, 0, length); PostMsg(message); //接收下一个消息 if (m_oSocket != null) { m_oSocket.BeginReceive(m_oBuffer, 0, m_oBuffer.Length, SocketFlags.None, new AsyncCallback(HandleRecv), m_oSocket); } } catch (Exception ex) { FFLog.Error("scoket: recv Error2 " + ex.Message); HandleClose(); } }); }
public void AsyncSend(byte[] strData) { FFNet.GetTaskQueue().Post(() => { if (strData.Length == 0 || m_oSocket == null) { return; } m_oBuffSending.Add(strData); if (m_oBuffSending.Count == 1) { m_oSocket.BeginSend(strData, 0, strData.Length, 0, new AsyncCallback(handleSendEnd), m_oSocket); } }); }
public void HandleClose() { if (m_nStatus == 0) { return; } m_nStatus = 0; FFNet.GetTaskQueue().Post(() => { if (m_oSocket == null) { return; } m_oSocket.Close(); m_oSocket = null; m_oBuffSending.Clear(); m_funcBroken(this); }); }
public void AsyncSend(byte[] strData, bool bCheckSend = true) { FFNet.GetTaskQueue().Post(() => { if (strData.Length == 0 || m_oSocket == null) { return; } if (bCheckSend == true && m_funcPreSendCheck != null) { strData = m_funcPreSendCheck(strData); } m_oBuffSending.Add(strData); if (m_oBuffSending.Count == 1) { m_oSocket.BeginSend(strData, 0, strData.Length, 0, new AsyncCallback(handleSendEnd), m_oSocket); } }); }
public TaskQueue GetTaskQueue() { return(FFNet.GetTaskQueue()); }