private void SendCurrent() { // Allows us to send everything before closing the connection. if (_currentOutboundMessage == CloseMessage) { try { _socket.Shutdown(SocketShutdown.Both); } catch (Exception e) { HandleDisconnect(SocketError.ConnectionReset, e); } _currentOutboundMessage = null; _closeEvent.Release(); return; } _encoder.Prepare(_currentOutboundMessage); _encoder.Send(_writeArgsWrapper); try { var isPending = _socket.SendAsync(_writeArgs); if (!isPending) { OnSendCompleted(this, _writeArgs); } } catch (Exception e) { HandleDisconnect(SocketError.ConnectionReset, e); } }
private void SendCurrent() { // Allows us to send everything before closing the connection. if (_currentOutboundMessage == CloseMessage) { try { _socket.Shutdown(SocketShutdown.Both); } catch (Exception e) { HandleDisconnect(e); } _currentOutboundMessage = null; _closeEvent.Release(); return; } _encoder.Prepare(_currentOutboundMessage); _encoder.Send(_writeBuffer); try { _stream.BeginWrite(_writeBuffer.Buffer, _writeBuffer.Offset, _writeBuffer.Count, OnSendCompleted, null); } catch (Exception e) { HandleDisconnect(e); } }
private void SendChannel(SocketChannel channel, object message) { //Logger.WriteDebug(this, "Pipeline => SendChannel"); try { Stream sendMessage = _encoder.Prepare(message); if (sendMessage.Length > 0) { SendCompleted(channel.Send(sendMessage)); } } catch (Exception ex) { SendFailure(channel, ex); } }
/// <summary> /// Send a new message /// </summary> /// <param name="message">Message to send</param> /// <remarks> /// <para> /// Outbound messages are enqueued and sent in order. /// </para> /// <para> /// You may enqueue <c>byte[]</c> arrays or <see cref="Stream" /> objects. They will not be serialized but /// MicroMessage framed directly. /// </para> /// </remarks> public void Send(object message) { if (_socket == null || !_socket.Connected) { throw new SocketException((int)SocketError.NotConnected); } _sendLock.Wait(); _messagePendingSendOperation = message; _encoder.Prepare(message); _encoder.Send(_writeArgsWrapper); var isPending = _socket.SendAsync(_writeArgs); if (!isPending) { OnSendCompleted(this, _writeArgs); } }