mirror of
https://github.com/esiur/esiur-dotnet.git
synced 2025-06-27 05:23:13 +00:00
1.4
This commit is contained in:
@ -225,7 +225,6 @@ namespace Esyur.Net.HTTP
|
||||
}
|
||||
}
|
||||
|
||||
bool bb;
|
||||
|
||||
public void SendFile(string filename)
|
||||
{
|
||||
@ -299,7 +298,7 @@ namespace Esyur.Net.HTTP
|
||||
if (n <= 0)
|
||||
break;
|
||||
|
||||
|
||||
Thread.Sleep(50);
|
||||
base.Send(buffer, 0, n);
|
||||
|
||||
}
|
||||
|
@ -53,48 +53,48 @@ namespace Esyur.Net.HTTP
|
||||
}
|
||||
|
||||
[Storable]
|
||||
string ip
|
||||
public virtual string ip
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
[Storable]
|
||||
ushort port
|
||||
public virtual ushort port
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[Storable]
|
||||
uint timeout
|
||||
public virtual uint timeout
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[Storable]
|
||||
uint clock
|
||||
public virtual uint clock
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[Storable]
|
||||
uint maxPost
|
||||
public virtual uint maxPost
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[Storable]
|
||||
bool ssl
|
||||
public virtual bool ssl
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[Storable]
|
||||
string certificate
|
||||
public virtual string certificate
|
||||
{
|
||||
get;
|
||||
set;
|
||||
@ -380,6 +380,11 @@ namespace Esyur.Net.HTTP
|
||||
sender.SetParent(this);
|
||||
|
||||
//Console.WriteLine("IN: " + this.Connections.Count);
|
||||
if (filters == null)
|
||||
{
|
||||
sender.Close();
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var resource in filters)
|
||||
{
|
||||
|
@ -610,8 +610,10 @@ namespace Esyur.Net.IIP
|
||||
else
|
||||
{
|
||||
//Console.WriteLine("User not found");
|
||||
//SendParams((byte)0xc0, (byte)1, (ushort)14, DC.ToBytes("User not found"));
|
||||
SendParams().AddUInt8(0xc0).AddUInt8(1).AddUInt16(14).AddString("User not found").Done();
|
||||
SendParams().AddUInt8(0xc0)
|
||||
.AddUInt8((byte)ExceptionCode.UserNotFound)
|
||||
.AddUInt16(14)
|
||||
.AddString("User not found").Done();
|
||||
}
|
||||
});
|
||||
|
||||
@ -649,9 +651,11 @@ namespace Esyur.Net.IIP
|
||||
else
|
||||
{
|
||||
//Global.Log("auth", LogType.Warning, "U:" + RemoteUsername + " IP:" + Socket.RemoteEndPoint.Address.ToString() + " S:DENIED");
|
||||
//Console.WriteLine("Incorrect password");
|
||||
//SendParams((byte)0xc0, (byte)1, (ushort)5, DC.ToBytes("Error"));
|
||||
SendParams().AddUInt8(0xc0).AddUInt8(1).AddUInt16(5).AddString("Error").Done();
|
||||
SendParams().AddUInt8(0xc0)
|
||||
.AddUInt8((byte)ExceptionCode.AccessDenied)
|
||||
.AddUInt16(13)
|
||||
.AddString("Access Denied")
|
||||
.Done();
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -729,9 +733,9 @@ namespace Esyur.Net.IIP
|
||||
{
|
||||
SendParams()
|
||||
.AddUInt8(0xc0)
|
||||
.AddUInt8(1)
|
||||
.AddUInt16(5)
|
||||
.AddString("Error")
|
||||
.AddUInt8((byte)ExceptionCode.ChallengeFailed)
|
||||
.AddUInt16(16)
|
||||
.AddString("Challenge Failed")
|
||||
.Done();
|
||||
|
||||
//SendParams((byte)0xc0, 1, (ushort)5, DC.ToBytes("Error"));
|
||||
@ -789,7 +793,6 @@ namespace Esyur.Net.IIP
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex);
|
||||
Console.Beep();
|
||||
}
|
||||
finally
|
||||
{
|
||||
@ -830,7 +833,7 @@ namespace Esyur.Net.IIP
|
||||
var sock = new TCPSocket();
|
||||
|
||||
|
||||
sock.Connect(domain, port).Then((x)=> {
|
||||
sock.Connect(address, port).Then((x)=> {
|
||||
Assign(sock);
|
||||
//rt.trigger(true);
|
||||
}).Error((x) =>
|
||||
@ -849,7 +852,7 @@ namespace Esyur.Net.IIP
|
||||
/// </summary>
|
||||
/// <param name="resource">Resource.</param>
|
||||
/// <returns></returns>
|
||||
public bool Put(IResource resource)
|
||||
public async AsyncReply<bool> Put(IResource resource)
|
||||
{
|
||||
if (Codec.IsLocalResource(resource, this))
|
||||
resources.Add((resource as DistributedResource).Id, (DistributedResource)resource);
|
||||
|
@ -1097,6 +1097,10 @@ namespace Esyur.Net.IIP
|
||||
var ft = r.Instance.Template.GetFunctionTemplateByIndex(index);
|
||||
if (ft != null)
|
||||
{
|
||||
|
||||
// un hold the socket to send data immediately
|
||||
this.Socket.Unhold();
|
||||
|
||||
if (r is DistributedResource)
|
||||
{
|
||||
var rt = (r as DistributedResource)._InvokeByArrayArguments(index, arguments);
|
||||
@ -1163,7 +1167,8 @@ namespace Esyur.Net.IIP
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
SendError(ErrorType.Exception, callback, 0, ex.InnerException.ToString());
|
||||
SendError(ErrorType.Exception, callback, 0,
|
||||
ex.InnerException != null ? ex.InnerException.ToString() : ex.ToString());
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1171,12 +1176,18 @@ namespace Esyur.Net.IIP
|
||||
{
|
||||
var enu = rt as System.Collections.IEnumerable;
|
||||
|
||||
foreach (var v in enu)
|
||||
SendChunk(callback, v);
|
||||
|
||||
SendReply(IIPPacket.IIPPacketAction.InvokeFunctionArrayArguments, callback)
|
||||
.AddUInt8((byte)DataType.Void)
|
||||
.Done();
|
||||
try
|
||||
{
|
||||
foreach (var v in enu)
|
||||
SendChunk(callback, v);
|
||||
SendReply(IIPPacket.IIPPacketAction.InvokeFunctionArrayArguments, callback)
|
||||
.AddUInt8((byte)DataType.Void)
|
||||
.Done();
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
SendError(ErrorType.Exception, callback, 0, ex.ToString());
|
||||
}
|
||||
|
||||
}
|
||||
else if (rt is Task)
|
||||
@ -1254,6 +1265,9 @@ namespace Esyur.Net.IIP
|
||||
var ft = r.Instance.Template.GetFunctionTemplateByIndex(index);
|
||||
if (ft != null)
|
||||
{
|
||||
// un hold the socket to send data immediately
|
||||
this.Socket.Unhold();
|
||||
|
||||
if (r is DistributedResource)
|
||||
{
|
||||
var rt = (r as DistributedResource)._InvokeByNamedArguments(index, namedArgs);
|
||||
@ -1323,12 +1337,19 @@ namespace Esyur.Net.IIP
|
||||
{
|
||||
var enu = rt as System.Collections.IEnumerable;
|
||||
|
||||
foreach (var v in enu)
|
||||
SendChunk(callback, v);
|
||||
try
|
||||
{
|
||||
foreach (var v in enu)
|
||||
SendChunk(callback, v);
|
||||
|
||||
SendReply(IIPPacket.IIPPacketAction.InvokeFunctionNamedArguments, callback)
|
||||
.AddUInt8((byte)DataType.Void)
|
||||
.Done();
|
||||
SendReply(IIPPacket.IIPPacketAction.InvokeFunctionNamedArguments, callback)
|
||||
.AddUInt8((byte)DataType.Void)
|
||||
.Done();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
SendError(ErrorType.Exception, callback, 0, ex.ToString());
|
||||
}
|
||||
}
|
||||
else if (rt is Task)
|
||||
{
|
||||
|
@ -284,9 +284,9 @@ namespace Esyur.Net
|
||||
sock.Send(msg, offset, length);
|
||||
}
|
||||
}
|
||||
catch
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
Console.WriteLine(ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -50,6 +50,7 @@ namespace Esyur.Net.Sockets
|
||||
event ISocketConnectEvent OnConnect;
|
||||
event ISocketCloseEvent OnClose;
|
||||
|
||||
|
||||
void Send(byte[] message);
|
||||
void Send(byte[] message, int offset, int size);
|
||||
void Close();
|
||||
|
@ -48,11 +48,11 @@ namespace Esyur.Net.Sockets
|
||||
|
||||
NetworkBuffer receiveNetworkBuffer = new NetworkBuffer();
|
||||
|
||||
object sendLock = new object();
|
||||
readonly object sendLock = new object();
|
||||
|
||||
Queue<byte[]> sendBufferQueue = new Queue<byte[]>();
|
||||
|
||||
bool asyncSending;
|
||||
bool asyncSending;
|
||||
bool began = false;
|
||||
|
||||
|
||||
@ -176,7 +176,7 @@ namespace Esyur.Net.Sockets
|
||||
|
||||
|
||||
//lock (receiveNetworkBuffer.SyncLock)
|
||||
// Console.WriteLine(e. + " " + e.BytesTransferred);
|
||||
// Console.WriteLine(e. + " " + e.BytesTransferred);
|
||||
|
||||
receiveNetworkBuffer.Write(receiveBuffer, 0, (uint)e.BytesTransferred);
|
||||
|
||||
@ -238,39 +238,39 @@ namespace Esyur.Net.Sockets
|
||||
|
||||
}
|
||||
|
||||
private void DataSent(Task<int> task)
|
||||
{
|
||||
try
|
||||
{
|
||||
lock (sendLock)
|
||||
{
|
||||
//private void DataSent(Task<int> task)
|
||||
//{
|
||||
// try
|
||||
// {
|
||||
// lock (sendLock)
|
||||
// {
|
||||
|
||||
if (sendBufferQueue.Count > 0)
|
||||
{
|
||||
byte[] data = sendBufferQueue.Dequeue();
|
||||
//Console.WriteLine(Encoding.UTF8.GetString(data));
|
||||
sock.SendAsync(new ArraySegment<byte>(data), SocketFlags.None).ContinueWith(DataSent);
|
||||
}
|
||||
// if (sendBufferQueue.Count > 0)
|
||||
// {
|
||||
// byte[] data = sendBufferQueue.Dequeue();
|
||||
// //Console.WriteLine(Encoding.UTF8.GetString(data));
|
||||
// sock.SendAsync(new ArraySegment<byte>(data), SocketFlags.None).ContinueWith(DataSent);
|
||||
// }
|
||||
|
||||
else
|
||||
{
|
||||
asyncSending = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (state != SocketState.Closed && !sock.Connected)
|
||||
{
|
||||
state = SocketState.Terminated;
|
||||
Close();
|
||||
}
|
||||
// else
|
||||
// {
|
||||
// asyncSending = false;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// catch (Exception ex)
|
||||
// {
|
||||
// if (state != SocketState.Closed && !sock.Connected)
|
||||
// {
|
||||
// state = SocketState.Terminated;
|
||||
// Close();
|
||||
// }
|
||||
|
||||
asyncSending = false;
|
||||
// asyncSending = false;
|
||||
|
||||
Global.Log("TCPSocket", LogType.Error, ex.ToString());
|
||||
}
|
||||
}
|
||||
// Global.Log("TCPSocket", LogType.Error, ex.ToString());
|
||||
// }
|
||||
//}
|
||||
|
||||
public TCPSocket(IPEndPoint localEndPoint)
|
||||
{
|
||||
@ -348,42 +348,44 @@ namespace Esyur.Net.Sockets
|
||||
|
||||
public void Send(byte[] message, int offset, int size)
|
||||
{
|
||||
//sock.Blocking =
|
||||
//sock.Send(message, offset, size, SocketFlags.None);
|
||||
//return;
|
||||
if (sock.Connected)
|
||||
lock (sendLock)
|
||||
{
|
||||
|
||||
if (asyncSending || held)
|
||||
{
|
||||
sendBufferQueue.Enqueue(message.Clip((uint)offset, (uint)size));
|
||||
}
|
||||
else
|
||||
{
|
||||
asyncSending = true;
|
||||
sock.BeginSend(message, offset, size, SocketFlags.None, PacketSent, null);
|
||||
//sock.SendAsync(new ArraySegment<byte>(msg), SocketFlags.None).ContinueWith(DataSent);
|
||||
}
|
||||
var msg = message.Clip((uint)offset, (uint)size);
|
||||
|
||||
lock (sendLock)
|
||||
{
|
||||
if (!sock.Connected)
|
||||
return;
|
||||
|
||||
if (asyncSending || held)
|
||||
{
|
||||
sendBufferQueue.Enqueue(msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
asyncSending = true;
|
||||
sock.BeginSend(msg, 0, size, SocketFlags.None, PacketSent, null);
|
||||
//sock.SendAsync(new ArraySegment<byte>(msg), SocketFlags.None).ContinueWith(DataSent);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void PacketSent(IAsyncResult ar)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (sendBufferQueue.Count > 0)
|
||||
lock (sendLock)
|
||||
{
|
||||
lock (sendLock)
|
||||
if (sendBufferQueue.Count > 0)
|
||||
{
|
||||
byte[] data = sendBufferQueue.Dequeue();
|
||||
|
||||
sock.BeginSend(data, 0, data.Length, SocketFlags.None, PacketSent, null);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
asyncSending = false;
|
||||
else
|
||||
{
|
||||
asyncSending = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -447,12 +449,11 @@ namespace Esyur.Net.Sockets
|
||||
{
|
||||
try
|
||||
{
|
||||
DataSent(null);
|
||||
PacketSent(null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex);
|
||||
Console.Beep();
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
Reference in New Issue
Block a user