internal void DoWorkNow() { try { ActuallyStarted = true; #if USE_HTTPSERVER_DLL Server.BlockingHandler(Context, Request, Response); #endif } catch (ThreadAbortException e) { WriteLine("ABORT: " + e); if (WorkerThread == Thread.CurrentThread) { Thread.ResetAbort(); } else { WriteLine("WRONG THREAD: " + WorkerThread); throw; } } catch (Exception e) { WriteLine("ERROR: " + e); Error = e; } finally { EndTimeOrDateTimeMax = DateTime.Now; TimeSpan usedTime = EndTimeOrDateTimeMax - StarTime; WriteLine("Finished in " + usedTime); Server.JobFinished(this); } }
private void _Worker() { #if LOG4NET Logger.Socket.Debug("ReadThread started"); #endif try { string data = ""; try { while (_Connection.IsConnected && ((data = _Connection._Reader.ReadLine()) != null)) { _Queue.Enqueue(data); #if LOG4NET Logger.Socket.Debug("received: \"" + data + "\""); #endif } } catch (IOException e) { #if LOG4NET Logger.Socket.Warn("IOException: " + e.Message); #endif } finally { #if LOG4NET Logger.Socket.Warn("connection lost"); #endif // only flag this as connection error if we are not // cleanly disconnecting if (!_Connection.IsDisconnecting) { _Connection.IsConnectionError = true; } } } catch (ThreadAbortException) { Thread.ResetAbort(); #if LOG4NET Logger.Socket.Debug("ReadThread aborted"); #endif } catch (Exception ex) { #if LOG4NET Logger.Socket.Error(ex); #endif } }
private void _Worker() { #if LOG4NET Logger.Socket.Debug("WriteThread started"); #endif try { try { while (_Connection.IsConnected) { _CheckBuffer(); Thread.Sleep(_Connection._SendDelay); } } catch (IOException e) { #if LOG4NET Logger.Socket.Warn("IOException: " + e.Message); #endif } finally { #if LOG4NET Logger.Socket.Warn("connection lost"); #endif // only flag this as connection error if we are not // cleanly disconnecting if (!_Connection.IsDisconnecting) { _Connection.IsConnectionError = true; } } } catch (ThreadAbortException) { Thread.ResetAbort(); #if LOG4NET Logger.Socket.Debug("WriteThread aborted"); #endif } catch (Exception ex) { #if LOG4NET Logger.Socket.Error(ex); #endif } }
private void _Worker() { #if LOG4NET Logger.Socket.Debug("IdleWorkerThread started"); #endif try { while (_Connection.IsConnected) { Thread.Sleep(_Connection._IdleWorkerInterval); // only send active pings if we are registered if (!_Connection.IsRegistered) { continue; } DateTime now = DateTime.Now; int last_ping_sent = (int)(now - _Connection._LastPingSent).TotalSeconds; int last_pong_rcvd = (int)(now - _Connection._LastPongReceived).TotalSeconds; // determins if the resoponse time is ok if (last_ping_sent < _Connection._PingTimeout) { if (_Connection._LastPingSent > _Connection._LastPongReceived) { // there is a pending ping request, we have to wait continue; } // determines if it need to send another ping yet if (last_pong_rcvd > _Connection._PingInterval) { _Connection.WriteLine(Rfc2812.Ping(_Connection.Address), Priority.Critical); _Connection._LastPingSent = now; //_Connection._LastPongReceived = now; } // else connection is fine, just continue } else { if (_Connection.IsDisconnecting) { break; } #if LOG4NET Logger.Socket.Warn("ping timeout, connection lost"); #endif // only flag this as connection error if we are not // cleanly disconnecting _Connection.IsConnectionError = true; break; } } } catch (ThreadAbortException) { Thread.ResetAbort(); #if LOG4NET Logger.Socket.Debug("IdleWorkerThread aborted"); #endif } catch (Exception ex) { #if LOG4NET Logger.Socket.Error(ex); #endif } }