Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
kbengine committed Feb 27, 2015
1 parent 5eaf937 commit f4efa36
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
12 changes: 9 additions & 3 deletions KBEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ void installEvents()
Event.registerIn("createAccount", this, "createAccount");
Event.registerIn("login", this, "login");
Event.registerIn("relogin_baseapp", this, "relogin_baseapp");
Event.registerIn("_closeNetwork", this, "_closeNetwork");
}

public KBEngineArgs getInitArgs()
Expand Down Expand Up @@ -265,14 +266,14 @@ public static bool validEmail(string strEmail)
*/
public virtual void process()
{
// 处理网络
_networkInterface.process();

// 处理外层抛入的事件
Event.processInEvents();

// 向服务端发送心跳以及同步角色信息到服务端
sendTick();

// 处理网络
_networkInterface.process();
}

/*
Expand All @@ -287,6 +288,11 @@ public Entity player()
return null;
}

public void _closeNetwork(NetworkInterface networkInterface)
{
networkInterface.close();
}

/*
向服务端发送心跳以及同步角色信息到服务端
*/
Expand Down
5 changes: 2 additions & 3 deletions NetworkInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,8 @@ public bool send(byte[] datas)

public void process()
{
// 避免close后一些消息没有得到处理,将这里屏蔽
// if(!valid())
// return;
if(!valid())
return;

if(_packetReceiver != null)
_packetReceiver.process();
Expand Down
6 changes: 3 additions & 3 deletions PacketReceiver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public void startRecv()
catch (Exception e)
{
Dbg.ERROR_MSG("PacketReceiver::startRecv(): call ReceiveAsync() is err: " + e.ToString());
_networkInterface.close();
Event.fireIn("_closeNetwork", new object[]{_networkInterface});
}
}

Expand Down Expand Up @@ -151,7 +151,7 @@ private static void _onRecv(IAsyncResult ar)
if (bytesRead == 0)
{
Dbg.WARNING_MSG(string.Format("PacketReceiver::_processRecved(): disconnect!"));
state.networkInterface().close();
Event.fireIn("_closeNetwork", new object[]{state.networkInterface()});
return;
}
else
Expand All @@ -163,7 +163,7 @@ private static void _onRecv(IAsyncResult ar)
catch (Exception e)
{
Dbg.ERROR_MSG(string.Format("PacketReceiver::_processRecved(): is error({0})!", e.ToString()));
state.networkInterface().close();
Event.fireIn("_closeNetwork", new object[]{state.networkInterface()});
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions PacketSender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ void _startSend()
catch (Exception e)
{
Dbg.ERROR_MSG("PacketSender::startSend(): is err: " + e.ToString());
_networkInterface.close();
Event.fireIn("_closeNetwork", new object[]{_networkInterface});
}
}

Expand Down Expand Up @@ -155,7 +155,7 @@ private static void _onSent(IAsyncResult ar)
catch (Exception e)
{
Dbg.ERROR_MSG(string.Format("PacketSender::_processSent(): is error({0})!", e.ToString()));
state.networkInterface().close();
Event.fireIn("_closeNetwork", new object[]{state.networkInterface()});
Interlocked.Exchange(ref state._sending, 0);
}
}
Expand Down

0 comments on commit f4efa36

Please sign in to comment.