public void SendAsync(byte[] data, int offset, int count) { BufferValidator.ValidateBuffer(data, offset, count, "data"); if (!Connected) { throw new InvalidProgramException("This client has not connected to server."); } try { if (_stream.CanWrite) { var frame = _configuration.FrameBuilder.EncodeFrame(data, offset, count); _stream.BeginWrite(frame, 0, frame.Length, HandleDataWritten, _tcpClient); } } catch (Exception ex) { if (ex is IOException && ex.InnerException != null && ex.InnerException is SocketException && (ex.InnerException as SocketException).SocketErrorCode == SocketError.TimedOut) { _log.Error(ex.Message, ex); } else { if (!CloseIfShould(ex)) { throw; } } } }
public async Task SendAsync(byte[] data, int offset, int count) { BufferValidator.ValidateBuffer(data, offset, count, "data"); if (State != TcpSocketConnectionState.Connected) { throw new InvalidOperationException("This session has not connected."); } try { if (_stream.CanWrite) { byte[] frameBuffer; int frameBufferOffset; int frameBufferLength; _configuration.FrameBuilder.Encoder.EncodeFrame(data, offset, count, out frameBuffer, out frameBufferOffset, out frameBufferLength); await _stream.WriteAsync(frameBuffer, frameBufferOffset, frameBufferLength); } } catch (Exception ex) when(!ShouldThrow(ex)) { } }
public async Task SendAsync(byte[] data, int offset, int count) { BufferValidator.ValidateBuffer(data, offset, count, "data"); if (State != TcpSocketConnectionState.Connected) { throw new InvalidOperationException("This client has not connected to server."); } try { byte[] frameBuffer; int frameBufferOffset; int frameBufferLength; _configuration.FrameBuilder.Encoder.EncodeFrame(data, offset, count, out frameBuffer, out frameBufferOffset, out frameBufferLength); var saea = _saeaPool.Take(); saea.Saea.SetBuffer(frameBuffer, frameBufferOffset, frameBufferLength); await _socket.SendAsync(saea); _saeaPool.Return(saea); } catch (Exception ex) when(!ShouldThrow(ex)) { } }
public IAsyncResult BeginSend(byte[] data, int offset, int count, AsyncCallback callback, object state) { BufferValidator.ValidateBuffer(data, offset, count, "data"); if (this.State != TcpSocketConnectionState.Connected) { throw new InvalidProgramException("This client has not connected to server."); } try { byte[] frameBuffer; int frameBufferOffset; int frameBufferLength; _configuration.FrameBuilder.Encoder.EncodeFrame(data, offset, count, out frameBuffer, out frameBufferOffset, out frameBufferLength); return(_stream.BeginWrite(frameBuffer, frameBufferOffset, frameBufferLength, callback, state)); } catch (Exception ex) { if (IsSocketTimeOut(ex)) { _log.Error(ex.Message, ex); } else { if (!CloseIfShould(ex)) { throw; } } throw; } }
public void Send(byte[] data, int offset, int count) { BufferValidator.ValidateBuffer(data, offset, count, "data"); if (!Active) { throw new InvalidProgramException("This session has been closed."); } try { if (_stream.CanWrite) { var frame = _configuration.FrameBuilder.EncodeFrame(data, offset, count); _stream.Write(frame, 0, frame.Length); } } catch (Exception ex) { if (ex is IOException && ex.InnerException != null && ex.InnerException is SocketException && (ex.InnerException as SocketException).SocketErrorCode == SocketError.TimedOut) { _log.Error(ex.Message, ex); } else { if (!CloseIfShould(ex)) { throw; } } } }
public void BeginSend(byte[] data, int offset, int count) { BufferValidator.ValidateBuffer(data, offset, count, "data"); if (this.State != TcpSocketConnectionState.Connected) { throw new InvalidProgramException("This client has not connected to server."); } try { byte[] frameBuffer; int frameBufferOffset; int frameBufferLength; _configuration.FrameBuilder.Encoder.EncodeFrame(data, offset, count, out frameBuffer, out frameBufferOffset, out frameBufferLength); _stream.BeginWrite(frameBuffer, frameBufferOffset, frameBufferLength, HandleDataWritten, _stream); } catch (Exception ex) { if (IsSocketTimeOut(ex)) { _log.Error(ex.Message, ex); } else { if (!CloseIfShould(ex)) { throw; } } } }
public void Send(byte[] data, int offset, int count) { BufferValidator.ValidateBuffer(data, offset, count, "data"); if (State != TcpSocketConnectionState.Connected) { throw new InvalidProgramException("This session has been closed."); } try { byte[] frameBuffer; int frameBufferOffset; int frameBufferLength; _configuration.FrameBuilder.Encoder.EncodeFrame(data, offset, count, out frameBuffer, out frameBufferOffset, out frameBufferLength); _stream.Write(frameBuffer, frameBufferOffset, frameBufferLength); } catch (Exception ex) { if (IsSocketTimeOut(ex)) { Loger.Error(ex.Message, ex); } else { if (!CloseIfShould(ex)) { throw; } } } }
public void SendAsync(byte[] data, int offset, int count) { BufferValidator.ValidateBuffer(data, offset, count, "data"); if (!Active) { throw new InvalidProgramException("This session has been closed."); } try { byte[] frameBuffer; int frameBufferOffset; int frameBufferLength; _configuration.FrameBuilder.Encoder.EncodeFrame(data, offset, count, out frameBuffer, out frameBufferOffset, out frameBufferLength); _stream.BeginWrite(frameBuffer, frameBufferOffset, frameBufferLength, HandleDataWritten, _stream); } catch (Exception ex) { if (IsSocketTimeOut(ex)) { _log.Error(ex.Message, ex); } else { if (!CloseIfShould(ex)) { throw; } } } }
public async Task SendAsync(byte[] data, int offset, int count) { BufferValidator.ValidateBuffer(data, offset, count, "data"); if (State != TcpSocketConnectionState.Connected) { throw new InvalidOperationException("This client has not connected to server."); } try { if (_stream.CanWrite) { var frame = _configuration.FrameBuilder.EncodeFrame(data, offset, count); await _stream.WriteAsync(frame, 0, frame.Length); } } catch (Exception ex) when(!ShouldThrow(ex)) { } }
public void Send(byte[] data, int offset, int count) { BufferValidator.ValidateBuffer(data, offset, count, "data"); if (!Connected) { throw new InvalidProgramException("This client has not connected to server."); } try { if (_stream.CanWrite) { byte[] frameBuffer; int frameBufferOffset; int frameBufferLength; _configuration.FrameBuilder.Encoder.EncodeFrame(data, offset, count, out frameBuffer, out frameBufferOffset, out frameBufferLength); _stream.Write(frameBuffer, frameBufferOffset, frameBufferLength); } } catch (Exception ex) { if (ex is IOException && ex.InnerException != null && ex.InnerException is SocketException && (ex.InnerException as SocketException).SocketErrorCode == SocketError.TimedOut) { _log.Error(ex.Message, ex); } else { if (!CloseIfShould(ex)) { throw; } } } }
public void SendAsync(byte[] data, int offset, int count) { BufferValidator.ValidateBuffer(data, offset, count, "data"); if (!Active) { throw new InvalidProgramException("This session has been closed."); } try { if (_stream.CanWrite) { byte[] frameBuffer; int frameBufferOffset; int frameBufferLength; _configuration.FrameBuilder.Encoder.EncodeFrame(data, offset, count, out frameBuffer, out frameBufferOffset, out frameBufferLength); _stream.BeginWrite(frameBuffer, frameBufferOffset, frameBufferLength, HandleDataWritten, _tcpClient); } } catch (Exception ex) { if (ex is IOException && ex.InnerException != null && ex.InnerException is SocketException && (ex.InnerException as SocketException).SocketErrorCode == SocketError.TimedOut) { _log.Error(ex.Message, ex); } else { if (!CloseIfShould(ex)) { throw; } } } }
public async Task SendAsync(byte[] data, int offset, int count) { BufferValidator.ValidateBuffer(data, offset, count, "data"); if (State != TcpSocketConnectionState.Connected) { throw new InvalidOperationException("This client has not connected to server."); } try { byte[] frameBuffer; int frameBufferOffset; int frameBufferLength; _configuration.FrameBuilder.Encoder.EncodeFrame(data, offset, count, out frameBuffer, out frameBufferOffset, out frameBufferLength); await _stream.WriteAsync(frameBuffer, frameBufferOffset, frameBufferLength); } catch (Exception ex) { await HandleSendOperationException(ex); } }
public IAsyncResult BeginSend(byte[] data, int offset, int count, AsyncCallback callback, object state) { BufferValidator.ValidateBuffer(data, offset, count, "data"); if (this.State != TcpSocketConnectionState.Connected) { throw new InvalidProgramException("This client has not connected to server."); } try { byte[] frameBuffer; int frameBufferOffset; int frameBufferLength; _configuration.FrameBuilder.Encoder.EncodeFrame(data, offset, count, out frameBuffer, out frameBufferOffset, out frameBufferLength); return(_stream.BeginWrite(frameBuffer, frameBufferOffset, frameBufferLength, callback, state)); } catch (Exception ex) // catch exceptions then log then re-throw { HandleSendOperationException(ex); throw; } }
public void BeginSend(byte[] data, int offset, int count) { BufferValidator.ValidateBuffer(data, offset, count, "data"); if (State != TcpSocketConnectionState.Connected) { throw new InvalidProgramException("This session has been closed."); } try { byte[] frameBuffer; int frameBufferOffset; int frameBufferLength; _configuration.FrameBuilder.Encoder.EncodeFrame(data, offset, count, out frameBuffer, out frameBufferOffset, out frameBufferLength); _stream.BeginWrite(frameBuffer, frameBufferOffset, frameBufferLength, HandleDataWritten, _stream); } catch (Exception ex) // catch exceptions then log then re-throw { HandleSendOperationException(ex); throw; } }