pull/1/head
Ogoun 5 years ago
parent 1d2e7fd80a
commit d348a3e163

@ -6,7 +6,7 @@ namespace ZeroLevel.Network
public interface IClient
: IDisposable
{
IPEndPoint EndPoint { get; }
IPEndPoint Endpoint { get; }
SocketClientStatus Status { get; }
IRouter Router { get; }
ISocketClient Socket { get; }

@ -8,7 +8,7 @@ namespace ZeroLevel.Network
: IClient, IDisposable
{
private readonly ISocketClient _client;
public IPEndPoint EndPoint => _client?.Endpoint;
public IPEndPoint Endpoint => _client?.Endpoint;
public SocketClientStatus Status => _client.Status;
public IRouter Router => _client.Router;
public ISocketClient Socket => _client;

@ -916,7 +916,7 @@ namespace ZeroLevel.Network
}
catch (Exception ex)
{
Log.SystemError(ex, $"[ExClientSet._RequestBroadcast] Error direct request to service '{client.EndPoint}' in broadcast request. Inbox '{inbox}'");
Log.SystemError(ex, $"[ExClientSet._RequestBroadcast] Error direct request to service '{client.Endpoint}' in broadcast request. Inbox '{inbox}'");
waiter.Signal();
}
});
@ -944,7 +944,7 @@ namespace ZeroLevel.Network
}
catch (Exception ex)
{
Log.SystemError(ex, $"[ExClientSet._RequestBroadcast] Error direct request to service '{client.EndPoint}' in broadcast request. Inbox '{inbox}'");
Log.SystemError(ex, $"[ExClientSet._RequestBroadcast] Error direct request to service '{client.Endpoint}' in broadcast request. Inbox '{inbox}'");
waiter.Signal();
}
});

@ -27,7 +27,7 @@ namespace ZeroLevel.Network
try
{
_connection_set_lock.EnterReadLock();
return _connections.Select(c => c.Value.EndPoint).ToList();
return _connections.Select(c => c.Value.Endpoint).ToList();
}
finally
{
@ -101,7 +101,7 @@ namespace ZeroLevel.Network
}
else
{
Log.Warning($"Server socket change state to: {Status}");
Log.Warning($"[ZSocketServer.BeginAcceptCallback] Server socket change state to: {Status}");
}
}

@ -220,25 +220,6 @@ namespace ZeroLevel.Network
}
}
public class Pack
: IBinarySerializable
{
public int Identity;
public long Timestamp;
public void Deserialize(IBinaryReader reader)
{
this.Identity = reader.ReadInt32();
this.Timestamp = reader.ReadLong();
}
public void Serialize(IBinaryWriter writer)
{
writer.WriteInt32(this.Identity);
writer.WriteLong(this.Timestamp);
}
}
public void HandleRequest(Frame frame, ISocketClient client, int identity, Action<int, byte[]> handler)
{
try

@ -11,28 +11,38 @@ namespace ZeroLevel.Utils
private BlockingCollection<T> _queue = new BlockingCollection<T>();
private List<Thread> _threads = new List<Thread>();
private bool _is_disposed = false;
private int _tasks_in_progress = 0;
public int Count => _queue.Count + _tasks_in_progress;
public Multiprocessor(Action<T> handler, int size, int stackSize = 1024 * 1024)
{
for (int i = 0; i < size; i++)
{
var t = new Thread(() =>
{
try
{
T item;
while (!_is_disposed && !_queue.IsCompleted)
while (!_is_disposed)
{
try
{
if (_queue.TryTake(out item, 500))
{
Interlocked.Increment(ref _tasks_in_progress);
try
{
handler(item);
}
finally
{
Interlocked.Decrement(ref _tasks_in_progress);
}
}
}
catch (Exception ex)
{
Log.Error(ex, "[Multiprocessor.HandleThread]");
}
}
}, stackSize);
t.IsBackground = true;
_threads.Add(t);
@ -53,7 +63,7 @@ namespace ZeroLevel.Utils
public void Dispose()
{
_queue.CompleteAdding();
while (_queue.Count > 0)
while (_queue.Count > 0 || _tasks_in_progress > 0)
{
Thread.Sleep(100);
}

Loading…
Cancel
Save

Powered by TurnKey Linux.