protected void HandleReply(ReqrepType rt, int idnum, MemBlock rest, ISender ret_path) {
RequestState reqs;
if( _req_state_table.TryGet(idnum, out reqs) ) {
IReplyHandler handler = null;
lock( _sync ) {
if (reqs.AddReplier(ret_path)) {
TimeSpan rtt = DateTime.UtcNow - reqs.ReqDate;
_to_mgr.AddReplySampleFor(reqs, ret_path, rtt);
handler = reqs.ReplyHandler;
}
}
/*
* Now handle this reply
*/
if( null != handler ) {
MemBlock payload;
PType pt = PType.Parse(rest, out payload);
Statistics statistics = new Statistics();
statistics.SendCount = reqs.SendCount;
#if REQREP_DEBUG
Console.Error.WriteLine("[ReqrepManager: {0}] Receiving reply on request id: {1}, from: {2}",
_info, idnum, ret_path);
#endif
//Don't hold the lock while calling the ReplyHandler:
bool continue_listening = handler.HandleReply(this, rt, idnum, pt, payload,
ret_path, statistics, reqs.UserState);
//the request has been served
if( !continue_listening ) {
StopRequest(idnum, handler);
}
}
}
else {
//We are ignoring this reply, it either makes no sense, or we have
//already handled it
}
}