void Dispatch(FramingData data) { if (data == null) { // FUTURE: Error handling return; } dataReceivedCallback(data); }
FramingData EndReceive(Socket listenSocket, IAsyncResult result) { // if we've started the shutdown process, then we've disposed // the socket and calls to socket.EndReceive will throw if (closed) { return(null); } byte[] buffer = ((SocketReceiveState)result.AsyncState).Buffer; Debug.Assert(buffer != null); FramingData data = null; try { int count = 0; lock (ThisLock) { // if we've started the shutdown process, socket is disposed // and calls to socket.EndReceive will throw if (!closed) { EndPoint dummy = CreateDummyEndPoint(listenSocket); count = listenSocket.EndReceiveFrom(result, ref dummy); } } if (count > 0) { data = FramingCodec.Decode(new ArraySegment <byte>(buffer, 0, count)); } } catch (Exception e) { Debug.WriteLine("Error in completing the async receive via EndReceiveFrom method."); Debug.WriteLine(e.ToString()); } finally { if (data == null) { this.bufferManager.ReturnBuffer(buffer); buffer = null; } } return(data); }
void OnDataReceived(FramingData data) { Uri uri = data.To; App app = appQueue.Lookup(uri); if (app == null) { // Not found return; } lock (ThisLock) { bool firstStart; app.EnsureStarted(out firstStart); if (firstStart) { WasHelper.OpenListenerChannelInstance(this.protocolHandle, app.AppPoolId, app.Instance.Id, app.Instance.Serialize()); } app.EnqueueAndDispatch(data); } }
void ContinueReceiving(IAsyncResult receiveResult, Socket listenSocket) { bool continueReceiving = true; while (continueReceiving) { FramingData data = null; if (receiveResult != null) { data = EndReceive(listenSocket, receiveResult); receiveResult = null; } lock (ThisLock) { if (!closed) { EndPoint dummy = CreateDummyEndPoint(listenSocket); byte[] buffer = this.bufferManager.TakeBuffer(maxMessageSize); receiveResult = listenSocket.BeginReceiveFrom(buffer, 0, buffer.Length, SocketFlags.None, ref dummy, this.onReceive, new SocketReceiveState(listenSocket, buffer)); } } if (receiveResult == null || !receiveResult.CompletedSynchronously) { continueReceiving = false; Dispatch(data); } else if (data != null) { ThreadPool.QueueUserWorkItem(new WaitCallback(DispatchCallback), data); } } }
public RequestContext(FramingData data) { this.data = data; this.contextDequeued = new ManualResetEvent(false); }
public void EnqueueAndDispatch(FramingData data) { // Schedule message dispatch RequestContext context = new RequestContext(data); messageQueue.EnqueueAndDispatch(context, context.OnContextDequeued, false); // Wait for the message to be dequeued. context.OnContextEnqueued(); }
public void Dispatch(FramingData data) { UdpChannelListener channelListener = channelListeners.Lookup(data.To); channelListener.OnRawMessageReceived(data.Payload); }
public void OnDataReceived(FramingData data) { base.Dispatch(data); }
public void Dispatch(FramingData data) { // Dispatch the message on a new thread ThreadPool.QueueUserWorkItem(new WaitCallback(OnDispatchMessage), data); }
public void OnDataReceived(FramingData data) { ServiceHostingEnvironment.EnsureServiceAvailable(data.To.LocalPath); base.Dispatch(data); }