public Pair<ConnectionState,ConnectionState> SetStatus(StatusMessage sm) {
var res = _state.Update(delegate(ConnectionState old_state) {
if( old_state.Disconnected ) {
throw new Exception(String.Format("Connection: {0} is disconnected",this));
}
var new_state = new ConnectionState(old_state.Edge, sm, old_state.PeerLinkMessage, false);
return new_state;
});
ProtocolLog.WriteIf(ProtocolLog.Connections, String.Format(
"SetStatus called on {0}, old status: {1}, new status: {2}", this, res.First.StatusMessage, sm));
var ev = StateChangeEvent;
if( null != ev ) {
ev(this, res);
}
return res;
}