public void Execute() { _services.Trace.Event(TraceEventType.Start, TraceMessage.Connection); _baton = new Baton(_services.Memory); _fault = ex => { Debug.WriteLine(ex.Message); }; _receiveSocketEvent = _services.Memory.AllocSocketEvent(); _receiveSocketEvent.SetBuffer(_services.Memory.Empty, 0, 0); _frameConsumeCallback = frame => { try { Go(false, frame); } catch (Exception ex) { _fault(ex); } }; try { _socket.Blocking = false; _socket.NoDelay = true; Go(true, null); } catch (Exception ex) { _fault(ex); } }
public SocketSender(IFireflyService service, ISocket socket) { _service = service; _socket = socket; _state = State.Immediate; _socketEvent = _service.Memory.AllocSocketEvent(); }
public bool SendAsync(ISocketEvent socketEvent) { lock (_sendLock) { var buffers = socketEvent.BufferList ?? new[] {new ArraySegment<byte>(socketEvent.Buffer, socketEvent.Offset, socketEvent.Count)}; var byteTransfered = GiveOutput(new ArraySegment<byte>(socketEvent.Buffer, socketEvent.Offset, socketEvent.Count)); var errorCode = byteTransfered == 0 ? SocketError.IOPending : SocketError.Success; ((FakeSocketEvent)socketEvent).SocketError = errorCode; ((FakeSocketEvent)socketEvent).BytesTransferred = byteTransfered; return errorCode == SocketError.IOPending; } }
public bool ReceiveAsync(ISocketEvent socketEvent) { lock (_receiveLock) { if (ReceiveAsyncPaused) { throw new InvalidOperationException( "FakeSocket.Receive cannot be called when ReceiveCalled is true"); } ReceiveAsyncPaused = true; ReceiveAsyncArgs = socketEvent; return TryReceiveAsync() == null; } }
public void FreeSocketEvent(ISocketEvent socketEvent) { socketEvent.Dispose(); }
public void FreeSocketEvent(ISocketEvent socketEvent) { }
public bool SendAsync(ISocketEvent socketEvent) { return _socket.SendAsync(((SocketEventWrapper)socketEvent).SocketAsyncEventArgs); }
public bool ReceiveAsync(ISocketEvent socketEvent) { return _socket.ReceiveAsync(((SocketEventWrapper)socketEvent).SocketAsyncEventArgs); }
protected virtual void Dispose(bool disposing) { if (!_disposed) { if (_socketEvent != null) { _socketEvent.Dispose(); _socketEvent = null; } _disposed = true; } }