private static void PipeConnectionPoolManagerCallback(Object state) { DBG.Info(null, "PipeConnectionPoolManagerCallback"); lock (_poolInstances) { foreach (DictionaryEntry entry in _poolInstances) { PipeConnectionPool pool = (PipeConnectionPool)entry.Value; lock (pool) { pool.CloseStaleConnections(); } } } // Requeue timer timer = new Timer(timerDelegate, null, timerDueTime, 0); }
public void Write(Stream str) { DBG.Info(null, _handle + "> Write stream " + str.Length); //int chunk = 4096; int chunk = 128; long len = chunk; byte[] buffer = new byte[chunk]; _writer.Write((int)(str.Length)); while (len != 0) { len = str.Read(buffer, 0, chunk); if (len > 0) { _writer.Write(buffer); } } }
//////////////////////////////////////////////////////////// public void CloseStaleConnections() { ArrayList _activeConnections = new ArrayList(); foreach (Object obj in _list) { PipeConnection _pipe = (PipeConnection)obj; if (_pipe.IsConnectionStale() == true) { DBG.Info(null, "Disposing of stale connection"); _pipe.Dispose(); _pipe = null; } else { _activeConnections.Add(_pipe); } } _list = _activeConnections; }
public PipeConnection SendWithRetry(IMessage msg, ITransportHeaders reqHead, Stream reqStm) { IMethodCallMessage mcm = (IMethodCallMessage)msg; String uri = mcm.Uri; PipeConnection _pipe = null; int tryCount = _defaultRetryCount; long reqStmPosition = -1; if (reqStm.CanSeek == false) { tryCount = 1; } else { reqStmPosition = reqStm.Position; } while (tryCount > 0) { try { if (_pipeConnectionPool != null) { DBG.Info(null, "Look in pipe connection in pool"); _pipe = (PipeConnection)_pipeConnectionPool.Obtain(); } // otherwise create a new connection if (_pipe == null) { _pipe = new PipeConnection(_pipeName, false, IntPtr.Zero); } //Send with Retry _pipe.BeginWriteMessage(); _pipe.WriteHeaders(uri, reqHead); _pipe.Write(reqStm); _pipe.EndWriteMessage(); tryCount = 0; } catch (PipeIOException pe) { pe = pe; if (_pipe != null) { _pipe.Dispose(); _pipe = null; } tryCount--; reqStm.Position = reqStmPosition; } } return(_pipe); }
private void ServerMain() { PipeConnection pipe = _pipe; _pipe = null; // Signal the guy to start waiting again... (w/ new event and endpoint) _event.Set(); try { //TODO close the connection on a timeout //TODO if no activity for Nnnn milliseconds while (true) { pipe.BeginReadMessage(); ITransportHeaders headers = pipe.ReadHeaders(); headers["__CustomErrorsEnabled"] = false; Stream request = pipe.ReadStream(); pipe.EndReadMessage(); ServerChannelSinkStack stack = new ServerChannelSinkStack(); stack.Push(_transportSink, null); IMessage responseMsg; ITransportHeaders responseHeaders; Stream responseStream; ServerProcessing processing = _transportSink.NextChannelSink.ProcessMessage(stack, null, headers, request, out responseMsg, out responseHeaders, out responseStream); // handle response switch (processing) { case ServerProcessing.Complete: // Send the response. Call completed synchronously. stack.Pop(_transportSink); WriteClientResponse(pipe, responseHeaders, responseStream); break; case ServerProcessing.OneWay: break; case ServerProcessing.Async: stack.StoreAndDispatch(_transportSink, null); break; } } } catch (Exception e) { DBG.Info(null, "Terminating client connection: " + e.Message); WriteExceptionResponse(pipe, e.ToString()); } finally { if (pipe != null) { pipe.Dispose(); } } }
public String ReadString() { DBG.Info(null, _handle + "> Reading string..."); return(_reader.ReadString()); }
public int ReadInt() { DBG.Info(null, _handle + "> Reading int..."); return(_reader.ReadInt32()); }
public ushort ReadUShort() { DBG.Info(null, _handle + "> Reading ushort..."); return(_reader.ReadUInt16()); }
public byte[] ReadBytes(int cb) { DBG.Info(null, _handle + "> Reading bytes len " + cb); return(_reader.ReadBytes(cb)); }
public void Write(int val) { DBG.Info(null, _handle + "> Write int " + val); _writer.Write(val); }
public void Write(ushort val) { DBG.Info(null, _handle + "> Write ushort " + val); _writer.Write(val); }