-
Notifications
You must be signed in to change notification settings - Fork 43
Open
Description
init
_connector = new AsyncSocketConnector();
_connector.FilterChain.AddLast("codec", new ProtocolCodecFilter(new TextLineCodecFactory(Encoding.UTF8)));
_connector.FilterChain.AddLast("logger", new Log4UnityFilter());
_connector.FilterChain.AddLast("json", new JsonFilter());
_connector.FilterChain.AddLast("error", new ErrorMessageFilter());
_connector.FilterChain.AddLast("identity", new IdentityFilter(deviceType));
_connector.Handler = new SyncSendReceiveHandler();
Filter
public class ErrorMessageFilter : IoFilterAdapter
{
public override void MessageReceived(INextFilter nextFilter, IoSession session, object message)
{
ResponseMessage response = message as ResponseMessage;
if (response == null)
nextFilter.ExceptionCaught(session, new Exception("Wrong Used"));
if(response.Error != null)
{
Exception cause = new Exception("[code]:" + response.Error.Code + " [message]:" + response.Error.Message);
throw cause; // HERE
nextFilter.ExceptionCaught(session, cause);
}
nextFilter.MessageReceived(session, message);
}
}
并没有执行Handler
当throw Exception时,进入到DefaultIoFilterChain中的
private void CallNext(IEntry<IoFilter, INextFilter> entry, Action<IoFilter, INextFilter> act, Action<Exception> error = null)
{
try
{
IoFilter filter = entry.Filter;
INextFilter nextFilter = entry.NextFilter;
act(filter, nextFilter);
}
catch (Exception ex)
{
if (error == null)
this.FireExceptionCaught(ex);
else
error(ex);
}
}
进入FireExceptionCaught(ex),但是之后过后,并没有进入Handler
Metadata
Metadata
Assignees
Labels
No labels