public _RPCRetHandler(_NetRPCComponent rpcComponent , NetRPCCall message , long timeoutTime , Action <_NetRPCReturn, Exception> callback) { _netRPCComponent = rpcComponent; _CallMessage = message; _bIsDone = false; _timer = TimerMgr.AddTimer(); _timer.Handler(_onTimeout); _timer.Interval(timeoutTime).Start(); _OnCallback = callback; _error = null; }
public _RPCRetHandler Call(NetRPCCall callMessage , Action <_NetRPCReturn, Exception> callback , long timeout) { __rpcIndex = 1 + ((__rpcIndex + 1) % 65534); callMessage._SetRPCID(__rpcIndex); _RPCRetHandler rpcRetHandler = new _RPCRetHandler(this, callMessage , timeout, callback); _rpcRetHandlers.Add((ushort)__rpcIndex, rpcRetHandler); _connection.SendNetMessage(callMessage); return(rpcRetHandler); }
protected void _doNetCall(short type, object param, Action <_NetRPCReturn, Exception> callback) { ISerializableData data = null; if (param is ISerializableData) { data = (ISerializableData)param; } else { data = new PojoObject(param); } NetRPCCall netRPCCall = new NetRPCCall(type, data); if (_netRPCComponent == null) { _netRPCComponent = new _NetRPCComponent(this); } _netRPCComponent.Call(netRPCCall, callback, DEFAULT_RPC_TIMEOUT); }
///------------ protected void _onData(byte[] data) { try { ByteBuffer buffer = new ByteBuffer(data); NetMessage netMessage = null; /// Read the headerType first to determine which message class to use buffer.position = NetMessage.LEN_SIZE; short headerType = buffer.FReadByte(); buffer.position = 0; if (HeaderType.RPCCall == headerType) { netMessage = new NetRPCCall(); } else if (HeaderType.RPCReturn == headerType) { netMessage = new _NetRPCReturn(); } else if (HeaderType.Notify == headerType) { netMessage = new NetNotify(); } else { throw NetMessage.INVALID_HEADER_TYPE; } netMessage.Deserialize(buffer); bool needFurtherProcess = true; if (NetMessageFilter != null) { needFurtherProcess = NetMessageFilter(netMessage); } if (needFurtherProcess) { if (HeaderType.RPCCall == headerType) { Debugger.Assert(false, "Has not implement!"); } else if (HeaderType.RPCReturn == headerType) { _netRPCComponent._OnRPCReturn(netMessage as _NetRPCReturn); } else if (HeaderType.Notify == headerType) { int handlerCount = _messageDispatcher.DispatchEvent(netMessage); if (0 == handlerCount) { Debugger.LogWarning("No message handler for message type: " + netMessage.type); } } else { Debugger.Assert(false); } } } catch (Exception e) { _onFatalError(e); } }