/// <summary> /// Used for sending a message that gets a reply such as a query. /// </summary> /// <param name="msg"></param> /// <returns></returns> /// <exception cref="IOException">A reconnect will be issued but it is up to the caller to handle the error.</exception> public ReplyMessage SendTwoWayMessage(RequestMessage msg) { if (this.State != ConnectionState.Opened) { throw new MongoCommException("Operation cannot be performed on a closed connection.", this); } try{ ReplyMessage reply = new ReplyMessage(); lock (tcpclnt){ msg.Write(tcpclnt.GetStream()); reply.Read(tcpclnt.GetStream()); } return(reply); }catch (IOException) { this.Reconnect(); throw; } }
/// <summary> /// Sends the two way message core. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="message">The message.</param> /// <param name="readerSettings">The reader settings.</param> /// <returns></returns> internal ReplyMessage <T> SendTwoWayMessageCore <T>(IRequestMessage message, BsonReaderSettings readerSettings) where T : class { EnsureOpenConnection(); try { var reply = new ReplyMessage <T>(readerSettings); lock (_connection) { message.Write(_connection.GetStream()); reply.Read(_connection.GetStream()); } return(reply); } catch (IOException) { ReplaceInvalidConnection(); throw; } }