Skip to content

Commit

Permalink
update bug
Browse files Browse the repository at this point in the history
  • Loading branch information
ScutGame committed Jun 26, 2015
1 parent 66232f4 commit b011c85
Show file tree
Hide file tree
Showing 15 changed files with 180 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,9 @@ public static IConfigger Configger
///
/// </summary>
/// <param name="sectionName"></param>
/// <exception cref="ArgumentException"></exception>
/// <exception cref="Exception"></exception>
/// <returns></returns>
public static void Intialize(string sectionName)
public static bool Intialize(string sectionName)
{
lock (syncRoot)
{
Expand All @@ -105,11 +104,9 @@ public static void Intialize(string sectionName)
instance.Install();
_configgerSet.Add(instance);
_configger = instance;
return true;
}
else
{
throw new ArgumentException("Not found section node.", "sectionName");
}
return false;
}
}

Expand Down
18 changes: 17 additions & 1 deletion Source/Framework/ZyGames.Framework/Cache/Generic/CacheItemSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -303,23 +303,39 @@ public void Dispose()
}


internal void ProcessExpired(string key)
/// <summary>
/// 是否能处理过期
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
internal bool TryProcessExpired(string key)
{
if (_itemData is AbstractEntity)
{
var t = ((AbstractEntity)_itemData);
if (t.HasChanged) return false;

t.IsInCache = false;
t.IsExpired = true;
}
else if (_itemData is BaseCollection)
{
bool hasChanged = false;
((BaseCollection)_itemData).Foreach<AbstractEntity>((k, t) =>
{
if (t.HasChanged)
{
hasChanged = t.HasChanged;
return false;
}
t.IsInCache = false;
t.IsExpired = true;
return true;
});

if (hasChanged) return false;
}
return true;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ public int PeriodTime
/// </summary>
public bool IsPeriod
{

get { return !IsPersistence && MathUtils.DiffDate(_preAccessTime).TotalSeconds > PeriodTime; }
get { return !IsPersistence && MathUtils.DiffDate(_accessTime).TotalSeconds > PeriodTime; }
}

/// <summary>
Expand Down Expand Up @@ -117,7 +116,6 @@ public void ResetCounter()
/// </summary>
public void RefreshAccessTime()
{

_preAccessTime = _accessTime;
_accessTime = DateTime.Now;
_preAccessCounter = _accessCounter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -465,8 +465,11 @@ public virtual void DisposeCache()
itemSet.RemoveExpired(itemPair.Key);
continue;
}
if (!itemSet.TryProcessExpired(itemPair.Key))
{
continue;
}
TraceLog.ReleaseWrite("Cache item:{0} key:{1} expired has been removed.", containerPair.Key, itemPair.Key);
itemSet.ProcessExpired(itemPair.Key);
object temp;
if (containerPair.Value.Collection.TryRemove(itemPair.Key, out temp))
{
Expand Down
24 changes: 24 additions & 0 deletions Source/Framework/ZyGames.Framework/RPC/IO/BufferUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,30 @@ static public Byte[] MergeBytes(params Byte[][] args)

}

/// <summary>
///
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
public static Byte[] GetBytes(byte[] data)
{
return GetBytes(data, 0, data.Length);
}

/// <summary>
///
/// </summary>
/// <param name="data"></param>
/// <param name="pos"></param>
/// <param name="count"></param>
/// <returns></returns>
static public Byte[] GetBytes(byte[] data, int pos, int count)
{
var buffer = new byte[count];
Buffer.BlockCopy(data, pos, buffer, 0, count);
return buffer;
}

/// <summary>
///
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,15 @@ public override bool TryReadMeaage(DataToken dataToken, byte[] buffer, out List<
remainingBytesToProcess = HandlePrefix(buffer, dataToken.bufferSkip, dataToken, remainingBytesToProcess);
if (dataToken.prefixBytesDone == 4 && (dataToken.messageLength > 10 * 1024 * 1024 || dataToken.messageLength <= 0))
{
byte[] bufferBytes = BufferUtils.MergeBytes(dataToken.byteArrayForPrefix, dataToken.byteArrayForMessage);
byte[] bufferBytes = dataToken.byteArrayForMessage == null ?
BufferUtils.MergeBytes(dataToken.byteArrayForPrefix, BufferUtils.GetBytes(buffer, dataToken.bufferSkip, buffer.Length - dataToken.bufferSkip)) :
BufferUtils.MergeBytes(dataToken.byteArrayForPrefix, dataToken.byteArrayForMessage, buffer);
string data = Encoding.UTF8.GetString(bufferBytes);
//消息头已接收完毕,并且接收到的消息长度大于10M,socket传输的数据已紊乱,关闭掉
TraceLog.ReleaseWriteDebug("Receive Ip {1} message length error:{0}\r\nData:{2}", dataToken.messageLength, (dataToken != null ? dataToken.Socket.RemoteEndPoint.ToNotNullString() : ""), data);
TraceLog.Write("The host[{0}] request parser head byte error, byte len={1}\r\ndata:{2}",
dataToken.Socket.RemoteEndPoint.ToNotNullString(),
dataToken.messageLength,
data);
needPostAnother = false;
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,10 @@ private void ProcessReceive(SocketAsyncEventArgs ioEventArgs)

if (ioEventArgs.SocketError != SocketError.Success)
{//Socket错误
TraceLog.Write("IP {0} ProcessReceive:{1}", (dataToken != null ? dataToken.Socket.RemoteEndPoint.ToNotNullString() : ""), ioEventArgs.SocketError);
TraceLog.Write("ProcessReceive IP {0} SocketError:{1}, bytes len:{2}",
(dataToken != null ? dataToken.Socket.RemoteEndPoint.ToNotNullString() : ""),
ioEventArgs.SocketError.ToString(),
ioEventArgs.BytesTransferred);
Closing(ioEventArgs);
return;
}
Expand Down
14 changes: 8 additions & 6 deletions Source/Middleware/AccountServer/AccountServer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,6 @@
<Reference Include="System.Configuration" />
<Reference Include="System.Web.Services" />
<Reference Include="System.EnterpriseServices" />
<Reference Include="ZyGames.Framework">
<HintPath>..\..\Framework\ZyGames.Framework\bin\Release\ZyGames.Framework.dll</HintPath>
</Reference>
<Reference Include="ZyGames.Framework.Common">
<HintPath>..\..\Framework\ZyGames.Framework\bin\Release\ZyGames.Framework.Common.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Content Include="Default.ashx" />
Expand Down Expand Up @@ -108,6 +102,14 @@
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Framework\ZyGames.Framework.Common\ZyGames.Framework.Common4.5.csproj">
<Project>{e87a5049-85a1-436b-a5ed-2bc0a4e45bdb}</Project>
<Name>ZyGames.Framework.Common4.5</Name>
</ProjectReference>
<ProjectReference Include="..\..\Framework\ZyGames.Framework\ZyGames.Framework4.5.csproj">
<Project>{416e2e00-4064-4d7a-87a2-a649ff120274}</Project>
<Name>ZyGames.Framework4.5</Name>
</ProjectReference>
<ProjectReference Include="..\ZyGames.Framework.Game\ZyGames.Framework.Game4.5.csproj">
<Project>{de7024b7-7168-4262-a250-6a21b932ec3b}</Project>
<Name>ZyGames.Framework.Game4.5</Name>
Expand Down
16 changes: 9 additions & 7 deletions Source/Middleware/GameServer/GameServer4.5.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,6 @@
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="ZyGames.Framework">
<HintPath>..\..\Framework\ZyGames.Framework\bin\Release\ZyGames.Framework.dll</HintPath>
</Reference>
<Reference Include="ZyGames.Framework.Common">
<HintPath>..\..\Framework\ZyGames.Framework\bin\Release\ZyGames.Framework.Common.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="..\Solution Items\GlobalAssemblyInfo.cs">
Expand Down Expand Up @@ -107,9 +101,17 @@
</None>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Framework\ZyGames.Framework.Common\ZyGames.Framework.Common4.5.csproj">
<Project>{e87a5049-85a1-436b-a5ed-2bc0a4e45bdb}</Project>
<Name>ZyGames.Framework.Common4.5</Name>
</ProjectReference>
<ProjectReference Include="..\..\Framework\ZyGames.Framework\ZyGames.Framework4.5.csproj">
<Project>{416e2e00-4064-4d7a-87a2-a649ff120274}</Project>
<Name>ZyGames.Framework4.5</Name>
</ProjectReference>
<ProjectReference Include="..\ZyGames.Framework.Game\ZyGames.Framework.Game4.5.csproj">
<Project>{DE7024B7-7168-4262-A250-6A21B932EC3B}</Project>
<Name>ZyGames.Framework.Game</Name>
<Name>ZyGames.Framework.Game4.5</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -523,15 +523,23 @@ private void DoHeartbeatTimeout()
/// </summary>
public bool EnterLock(int actionId, object agr1, out object arg2)
{
#if LOCK_TEST
arg2 = null;
return true;
#else
return _monitorLock.TryEnter(actionId, RequestTimeout, agr1, out arg2);
#endif
}
/// <summary>
///
/// </summary>
/// <param name="actionId"></param>
public void ExitLock(int actionId)
{
#if LOCK_TEST
#else
_monitorLock.Exit(actionId);
#endif
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ public RemotePackage()
/// 服务器间内部通讯通道
/// </summary>
public string RouteName { get; set; }
/// <summary>
///
/// </summary>
public int ErrorCode { get; set; }
/// <summary>
///
/// </summary>
public string ErrorInfo { get; set; }

/// <summary>
/// Message of custom
Expand Down
56 changes: 40 additions & 16 deletions Source/Middleware/ZyGames.Framework.Game/Contract/RemoteService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,27 +98,30 @@ private static void OnNetTcpCallback(object sender, RemoteEventArgs e)
{
return;
}
try
using (var ms = new MessageStructure(e.Data))
{
using (var ms = new MessageStructure(e.Data))
var head = ms.ReadHeadGzip();
if (head != null)
{
var head = ms.ReadHeadGzip();
if (head != null)
var package = proxy.Find(head.MsgId);
if (package != null)
{
var package = proxy.Find(head.MsgId);
if (package != null)
{
package.Message = ms.ReadBuffer();
proxy.Remove(head.MsgId);
package.OnCallback();
return;
}
package.ErrorCode = head.ErrorCode;
package.ErrorInfo = head.ErrorInfo;
package.Message = ms.ReadBuffer();
proxy.Remove(head.MsgId);
package.OnCallback();
}
else
{
proxy.OnPushedHandle(e);
}
}
else
{
proxy.OnErrorHandle(e);
}
}
catch (Exception)
{ }
proxy.OnPushedHandle(e);
}
catch (Exception ex)
{
Expand All @@ -143,10 +146,20 @@ private static void OnNetHttpCallback(object sender, RemoteEventArgs e)
var package = proxy.Find(head.MsgId);
if (package != null)
{
package.ErrorCode = head.ErrorCode;
package.ErrorInfo = head.ErrorInfo;
package.Message = ms.ReadBuffer();
proxy.Remove(head.MsgId);
package.OnCallback();
}
else
{
proxy.OnPushedHandle(e);
}
}
else
{
proxy.OnErrorHandle(e);
}
}
}
Expand All @@ -164,10 +177,21 @@ private static void OnNetHttpCallback(object sender, RemoteEventArgs e)
private string _proxySessionId = "";
private DictionaryExtend<int, RemotePackage> _packagePools;
/// <summary>
///
/// Server push to data callback
/// </summary>
public event RemoteCallback PushedHandle;

/// <summary>
///
/// </summary>
public event RemoteCallback ErrorHandle;

private void OnErrorHandle(RemoteEventArgs e)
{
RemoteCallback handler = ErrorHandle;
if (handler != null) handler(this, e);
}

private void OnPushedHandle(RemoteEventArgs e)
{
RemoteCallback handler = PushedHandle;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,16 @@ public class EnvironmentSetting

static EnvironmentSetting()
{
bool result;
try
{
ConfigManager.Intialize("appServerConfigger");
result = ConfigManager.Intialize("appServerConfigger");
}
catch (Exception)
{
result = false;
}
if (!result)
{
try
{
Expand Down Expand Up @@ -178,7 +183,7 @@ public string RedisHost
{
get
{
var section =ConfigManager.Configger.GetFirstOrAddConfig<RedisSection>();
var section = ConfigManager.Configger.GetFirstOrAddConfig<RedisSection>();
return section.Host;
}
}
Expand Down
Loading

0 comments on commit b011c85

Please sign in to comment.