mirror of
https://github.com/esiur/esiur-dotnet.git
synced 2025-06-27 05:23:13 +00:00
1.2.7
This commit is contained in:
@ -34,7 +34,7 @@ using Esiur.Data;
|
||||
using Esiur.Misc;
|
||||
using System.Collections.Concurrent;
|
||||
using Esiur.Resource;
|
||||
using Esiur.Engine;
|
||||
using Esiur.Core;
|
||||
|
||||
namespace Esiur.Net.Sockets
|
||||
{
|
||||
@ -53,7 +53,7 @@ namespace Esiur.Net.Sockets
|
||||
void Send(byte[] message);
|
||||
void Send(byte[] message, int offset, int size);
|
||||
void Close();
|
||||
bool Connect(string hostname, ushort port);
|
||||
AsyncReply<bool> Connect(string hostname, ushort port);
|
||||
bool Begin();
|
||||
//ISocket Accept();
|
||||
AsyncReply<ISocket> Accept();
|
||||
|
@ -29,7 +29,7 @@ using System.Text;
|
||||
using System.Net.Sockets;
|
||||
using System.Net;
|
||||
using Esiur.Misc;
|
||||
using Esiur.Engine;
|
||||
using Esiur.Core;
|
||||
using System.Threading;
|
||||
using System.Net.Security;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
@ -77,20 +77,29 @@ namespace Esiur.Net.Sockets
|
||||
}
|
||||
}
|
||||
|
||||
public bool Connect(string hostname, ushort port)
|
||||
public AsyncReply<bool> Connect(string hostname, ushort port)
|
||||
{
|
||||
var rt = new AsyncReply<bool>();
|
||||
|
||||
try
|
||||
{
|
||||
this.hostname = hostname;
|
||||
server = false;
|
||||
state = SocketState.Connecting;
|
||||
sock.ConnectAsync(hostname, port).ContinueWith(Connected);
|
||||
return true;
|
||||
sock.ConnectAsync(hostname, port).ContinueWith((x) =>
|
||||
{
|
||||
if (x.IsFaulted)
|
||||
rt.TriggerError(x.Exception);
|
||||
else
|
||||
rt.Trigger(true);
|
||||
|
||||
Connected(x);
|
||||
});
|
||||
}
|
||||
catch
|
||||
catch (Exception ex)
|
||||
{
|
||||
return false;
|
||||
rt.TriggerError(ex);
|
||||
}
|
||||
|
||||
return rt;
|
||||
}
|
||||
|
||||
private void DataSent(Task task)
|
||||
|
@ -29,7 +29,7 @@ using System.Text;
|
||||
using System.Net.Sockets;
|
||||
using System.Net;
|
||||
using Esiur.Misc;
|
||||
using Esiur.Engine;
|
||||
using Esiur.Core;
|
||||
using System.Threading;
|
||||
using Esiur.Resource;
|
||||
using System.Threading.Tasks;
|
||||
@ -62,13 +62,6 @@ namespace Esiur.Net.Sockets
|
||||
|
||||
SocketAsyncEventArgs socketArgs = new SocketAsyncEventArgs();
|
||||
|
||||
private void Connected(Task t)
|
||||
{
|
||||
state = SocketState.Established;
|
||||
OnConnect?.Invoke();
|
||||
Begin();
|
||||
}
|
||||
|
||||
public bool Begin()
|
||||
{
|
||||
if (began)
|
||||
@ -86,18 +79,34 @@ namespace Esiur.Net.Sockets
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Connect(string hostname, ushort port)
|
||||
public AsyncReply<bool> Connect(string hostname, ushort port)
|
||||
{
|
||||
var rt = new AsyncReply<bool>();
|
||||
|
||||
try
|
||||
{
|
||||
state = SocketState.Connecting;
|
||||
sock.ConnectAsync(hostname, port).ContinueWith(Connected);
|
||||
return true;
|
||||
sock.ConnectAsync(hostname, port).ContinueWith((x) =>
|
||||
{
|
||||
|
||||
if (x.IsFaulted)
|
||||
rt.TriggerError(x.Exception);
|
||||
else
|
||||
{
|
||||
|
||||
state = SocketState.Established;
|
||||
OnConnect?.Invoke();
|
||||
Begin();
|
||||
rt.Trigger(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
catch
|
||||
catch (Exception ex)
|
||||
{
|
||||
return false;
|
||||
rt.TriggerError(ex);
|
||||
}
|
||||
|
||||
return rt;
|
||||
}
|
||||
|
||||
|
||||
@ -117,7 +126,7 @@ namespace Esiur.Net.Sockets
|
||||
}
|
||||
|
||||
//if (receiveNetworkBuffer.Protected)
|
||||
// Console.WriteLine();
|
||||
// Console.WriteLine();
|
||||
|
||||
//lock (receiveNetworkBuffer.SyncLock)
|
||||
receiveNetworkBuffer.Write(receiveBuffer, 0, (uint)task.Result);
|
||||
@ -128,7 +137,7 @@ namespace Esiur.Net.Sockets
|
||||
if (state == SocketState.Established)
|
||||
{
|
||||
sock.ReceiveAsync(receiveBufferSegment, SocketFlags.None).ContinueWith(DataReceived);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -149,7 +158,7 @@ namespace Esiur.Net.Sockets
|
||||
try
|
||||
{
|
||||
// SocketError err;
|
||||
|
||||
|
||||
if (state == SocketState.Closed || state == SocketState.Terminated)
|
||||
return;
|
||||
|
||||
@ -162,7 +171,7 @@ namespace Esiur.Net.Sockets
|
||||
//if (receiveNetworkBuffer.Protected)
|
||||
// Console.WriteLine();
|
||||
|
||||
|
||||
|
||||
//lock (receiveNetworkBuffer.SyncLock)
|
||||
receiveNetworkBuffer.Write(receiveBuffer, 0, (uint)e.BytesTransferred);
|
||||
|
||||
|
@ -31,7 +31,7 @@ using System.Net;
|
||||
using Esiur.Net.Packets;
|
||||
using Esiur.Misc;
|
||||
using System.IO;
|
||||
using Esiur.Engine;
|
||||
using Esiur.Core;
|
||||
using Esiur.Resource;
|
||||
using Esiur.Data;
|
||||
|
||||
@ -236,7 +236,7 @@ namespace Esiur.Net.Sockets
|
||||
sock.Close();
|
||||
}
|
||||
|
||||
public bool Connect(string hostname, ushort port)
|
||||
public AsyncReply<bool> Connect(string hostname, ushort port)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
Reference in New Issue
Block a user