private void OnConnect() { try { if (this.Socket_Connect != null) { this.Socket_Connect(new EventData("connect")); } } catch (Exception ex) { ErrorRecorderHolder.recordError(ex); } }
private void OnError(Exception ex) { try { if (this.Socket_Error != null) { this.Socket_Error(new EventData("error", ex)); } } catch (Exception e) { ErrorRecorderHolder.recordError(e); } }
private void OnError(EventData evd) { try { if (this.Client_Error != null) { this.Client_Error(evd); } } catch (Exception ex) { ErrorRecorderHolder.recordError(ex); } }
private string GetString(byte[] bytes) { string str = null; try { str = System.Text.Encoding.UTF8.GetString(bytes, 0, bytes.Length); } catch (Exception ex) { ErrorRecorderHolder.recordError(ex); } return(str); }
public void RemoveListener(string type) { if (string.IsNullOrEmpty(type)) { ErrorRecorderHolder.recordError(new Exception("event type is null or empty")); return; } lock (self_locker) { this._listeners.Remove(type); } }
private void OnClose() { try { if (this.Socket_Close != null) { this.Socket_Close(new EventData("close")); } } catch (Exception ex) { ErrorRecorderHolder.recordError(ex); } this.Destroy(); }
public void OnSecond(long timestamp) { try { lock (self_locker) { if (this._processor != null) { this._processor.OnSecond(timestamp); } } } catch (Exception ex) { ErrorRecorderHolder.recordError(ex); } }
private void StopServiceThread() { lock (service_locker) { if (service_locker.Status == 1) { service_locker.Status = 0; try { this._serviceEvent.Set(); } catch (Exception ex) { ErrorRecorderHolder.recordError(ex); } } } }
private void CallService(ICollection <ServiceDelegate> list) { foreach (ServiceDelegate service in list) { try { if (service != null) { service(); } } catch (Exception ex) { ErrorRecorderHolder.recordError(ex); } } }
public void StopTaskTimer() { lock (task_locker) { task_locker.Status = 0; if (this._taskTimer != null) { try { this._taskTimer.Dispose(); this._taskTimer = null; } catch (Exception ex) { ErrorRecorderHolder.recordError(ex); } } } }
public void StopTimerThread() { lock (timer_locker) { timer_locker.Status = 0; if (this._threadTimer != null) { try { this._threadTimer.Dispose(); this._threadTimer = null; } catch (Exception ex) { ErrorRecorderHolder.recordError(ex); } } this._secondCalls.Clear(); } }
private void TryClose() { if (socket_locker.Status == SocketStatus.ScoketClosed) { return; } if (socket_locker.Count != 0) { return; } try { this.SocketClose(); } catch (Exception ex) { ErrorRecorderHolder.recordError(ex); } }
public void AddSecond(EventDelegate callback) { if (callback == null) { return; } lock (timer_locker) { if (this._secondCalls.Count >= 500) { ErrorRecorderHolder.recordError(new Exception("Second Calls Limit!")); return; } this._secondCalls.Add(callback); } this.StartTimerThread(); }
private void OnWrite(NetworkStream stream) { try { if (!this._sendEvent.SafeWaitHandle.IsClosed) { this._sendEvent.WaitOne(); } } catch (Exception ex) { ErrorRecorderHolder.recordError(ex); } byte[] buffer = new byte[0]; lock (self_locker) { buffer = this._sendQueue.ToArray(); this._sendQueue.Clear(); } this.WriteSocket(stream, buffer, OnWrite); }
public void ExecCallback(string key, Exception ex) { CallbackDelegate cb = null; if (this._cbMap.Contains(key)) { lock (this._cbMap) { cb = (CallbackDelegate)this._cbMap[key]; this._cbMap.Remove(key); } ThreadPool.Instance.Execute((state) => { try { cb(new CallbackData(ex)); } catch (Exception e) { ErrorRecorderHolder.recordError(e); } }); } }
public void StartTimerThread() { lock (timer_locker) { if (timer_locker.Status != 0) { return; } timer_locker.Status = 1; if (this._threadTimer == null) { try { this._threadTimer = new Timer(new TimerCallback(OnSecond), null, 1000, 1000); } catch (Exception ex) { ErrorRecorderHolder.recordError(ex); } } } }
private void StartTaskTimer() { lock (task_locker) { if (task_locker.Status != 0) { return; } task_locker.Status = 1; if (this._taskTimer == null) { try { this._taskTimer = new Timer(new TimerCallback(OnTask), null, Timeout.Infinite, Timeout.Infinite); } catch (Exception ex) { ErrorRecorderHolder.recordError(ex); } } } }
public void Close(Exception ex) { try { bool firstClose = false; lock (socket_locker) { if (socket_locker.Status == SocketStatus.Normal) { firstClose = true; socket_locker.Status = SocketStatus.SocketWillClosing; if (ex != null) { this.OnError(ex); } try { this._sendEvent.Set(); } catch (Exception e) { ErrorRecorderHolder.recordError(e); } if (this.IsConnecting()) { return; } } this.TryClose(); } if (firstClose) { FPManager.Instance.DelayTask(200, DelayClose, null); } } catch (Exception e) { ErrorRecorderHolder.recordError(e); } }
private void SocketClose() { if (this._stream != null) { this._stream.Close(); this._stream = null; } if (this._socket != null) { this._socket.Close(); this._socket = null; } try { this._sendEvent.Close(); } catch (Exception ex) { ErrorRecorderHolder.recordError(ex); } socket_locker.Status = SocketStatus.ScoketClosed; this.OnClose(); }
public void FireEvent(EventData evd) { if (evd == null) { ErrorRecorderHolder.recordError(new Exception("EventData is null")); return; } ArrayList queue = null; string type = evd.GetEventType(); if (string.IsNullOrEmpty(type)) { ErrorRecorderHolder.recordError(new Exception("event type is null or empty")); return; } lock (self_locker) { if (!this._listeners.Contains(type)) { return; } queue = ((ArrayList)this._listeners[type]); IEnumerator ie = queue.GetEnumerator(); while (ie.MoveNext()) { EventDelegate callback = (EventDelegate)ie.Current; if (callback != null) { FPManager.Instance.EventTask(callback, evd); } } } }
private void AddTimerTask(TimerTask task) { if (task == null) { return; } this.StartTaskTimer(); lock (task_locker) { if (this._timerTaskQueue.Count < 10000) { int index = this._timerTaskQueue.Count; for (int i = 0; i < this._timerTaskQueue.Count; i++) { if (task.timestamp < this._timerTaskQueue[i].timestamp) { index = i; break; } } this._timerTaskQueue.Insert(index, task); if (this._timerTaskQueue.Count == 9998) { ErrorRecorderHolder.recordError(new Exception("TimerTask Calls Limit!")); } if (index == 0) { this.TimerOneTask(); } } } }
private void OnClose(EventData evd) { this.Close(); lock (self_locker) { this._callback.RemoveCallback(); this._cry.Clear(); } lock (seq_locker) { this._seq = 0; } try { if (this.Client_Close != null) { this.Client_Close(new EventData("close")); } } catch (Exception ex) { ErrorRecorderHolder.recordError(ex); } this.Destroy(); }
private void StartServiceThread() { lock (service_locker) { if (service_locker.Status != 0) { return; } service_locker.Status = 1; try { this._serviceThread = new Thread(new ThreadStart(ServiceThread)); if (this._serviceThread.Name == null) { this._serviceThread.Name = "FPNN-SERVICE"; } this._serviceThread.Start(); } catch (Exception ex) { ErrorRecorderHolder.recordError(ex); } } }
private void WriteSocket(NetworkStream stream, byte[] buffer, Action <NetworkStream> calllback) { bool needTriggerDelayTask = false; lock (socket_locker) { if (this._socket == null) { return; } if (!this._socket.Connected) { this.Close(null); return; } if (_appleMobileDeviceInBackground) { if (_closeDelayForAppleMobileDeviceInBsckground == 0) { this.Close(null); return; } if (!_delayCloseTriggered) { needTriggerDelayTask = true; _delayCloseTriggered = true; } } if (socket_locker.Status == SocketStatus.Normal) { try { this._sendEvent.Reset(); } catch (Exception ex) { ErrorRecorderHolder.recordError(ex); } } socket_locker.Count++; } if (needTriggerDelayTask) { FPManager.Instance.DelayTask(_closeDelayForAppleMobileDeviceInBsckground, BackgroundDelayClose, null); } try { FPSocket self = this; stream.BeginWrite(buffer, 0, buffer.Length, (ar) => { try { try { stream.EndWrite(ar); } catch (Exception ex) { self.Close(ex); } lock (socket_locker) { socket_locker.Count--; } if (calllback != null) { calllback(stream); } } catch (Exception ex) { self.Close(ex); } }, null); } catch (Exception ex) { this.Close(ex); } }
public static void recordError(Exception ex) { ErrorRecorderHolder.getInstance().recordError(ex); }