public void Oneway(Command command) { lock (socketWriterLock) { try { if (closed.Value) { throw new Exception("Error writing to broker. Transport connection is closed."); } Wireformat.Marshal(command, socketWriter); //jdg socketWriter.Flush(); } catch (Exception ex) { if (command.ResponseRequired) { // Make sure that something higher up doesn't get blocked. // Respond with an exception. ExceptionResponse er = new ExceptionResponse(); BrokerError error = new BrokerError(); error.Message = "Transport connection error: " + ex.Message; error.ExceptionClass = ex.ToString(); er.Exception = error; er.CorrelationId = command.CommandId; commandHandler(this, er); } } } }
public void ReadLoop() { // This is the thread function for the reader thread. This runs continuously // performing a blokcing read on the socket and dispatching all commands // received. // // Exception Handling // ------------------ // If an Exception occurs during the reading/marshalling, then the connection // is effectively broken because position cannot be re-established to the next // message. This is reported to the app via the exceptionHandler and the socket // is closed to prevent further communication attempts. // // An exception in the command handler may not be fatal to the transport, so // these are simply reported to the exceptionHandler. // while (!closed.Value) { Command command = null; try { command = (Command)Wireformat.Unmarshal(socketReader); } catch (Exception ex) { if (!closed.Value) { this.exceptionHandler(this, ex); // Close the socket as there's little that can be done with this transport now. Close(); break; } } try { if (command != null) { this.commandHandler(this, command); } } catch (Exception e) { this.exceptionHandler(this, e); } } }
public void Oneway(Command command) { lock (myLock) { if (closed.Value) { throw new InvalidOperationException("Error writing to broker. Transport connection is closed."); } if (command is ShutdownInfo) { seenShutdown = true; } Wireformat.Marshal(command, socketWriter); } }
/// <summary> /// This is the thread function for the reader thread. This runs continuously performing a blocking read on the socket /// and dispatching all commands received. /// </summary> /// <remarks> /// Exception Handling /// ------------------ /// If an Exception occurs during the reading/marshaling, then the connection is effectively broken because position /// cannot be re-established to the next message. This is reported to the application via the exceptionHandler and the /// socket is closed to prevent further communication attempts. /// An exception in the command handler may not be fatal to the transport, so these are simply reported to the /// exceptionHandler. /// </remarks> private void ReadLoop() { while (!_closed.Value) { ICommand command; try { command = Wireformat.Unmarshal(_socketReader); } catch (Exception ex) { if (!_closed.Value) { // Close the socket as there's little that can be done with this transport now. Close(); if (!_seenShutdown) { Exception(this, ex); } } break; } try { if (command != null) { Command(this, command); } } catch (Exception ex) { Exception(this, ex); } } }
public void Oneway(Command command) { Wireformat.Marshal(command, socketWriter); socketWriter.Flush(); }