Skip to content

Commit

Permalink
Merge cb7d4b5 into 45672e0
Browse files Browse the repository at this point in the history
  • Loading branch information
wild-coffee committed Nov 20, 2023
2 parents 45672e0 + cb7d4b5 commit 3234a50
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/Fleck/Interfaces/ISocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public interface ISocket

Task<ISocket> Accept(Action<ISocket> callback, Action<Exception> error);
Task Send(byte[] buffer, Action callback, Action<Exception> error);
Task Send(byte[] buffer, int offset, int length, Action callback, Action<Exception> error);
Task<int> Receive(byte[] buffer, Action<int> callback, Action<Exception> error, int offset = 0);
Task Authenticate(X509Certificate2 certificate, SslProtocols enabledSslProtocols, Action callback, Action<Exception> error);

Expand Down
10 changes: 7 additions & 3 deletions src/Fleck/SocketWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ namespace Fleck
{
public class SocketWrapper : ISocket
{

public const UInt32 KeepAliveInterval = 60000;
public const UInt32 RetryInterval = 10000;

private readonly Socket _socket;
private Stream _stream;
private CancellationTokenSource _tokenSource;
Expand Down Expand Up @@ -166,14 +166,18 @@ public int EndSend(IAsyncResult asyncResult)
}

public Task Send(byte[] buffer, Action callback, Action<Exception> error)
{
return Send(buffer, 0, buffer.Length, callback, error);
}
public Task Send(byte[] buffer, int offset, int length, Action callback, Action<Exception> error)
{
if (_tokenSource.IsCancellationRequested)
return null;

try
{
Func<AsyncCallback, object, IAsyncResult> begin =
(cb, s) => _stream.BeginWrite(buffer, 0, buffer.Length, cb, s);
(cb, s) => _stream.BeginWrite(buffer, offset, length, cb, s);

Task task = Task.Factory.FromAsync(begin, _stream.EndWrite, null);
task.ContinueWith(t => callback(), TaskContinuationOptions.NotOnFaulted)
Expand Down

0 comments on commit 3234a50

Please sign in to comment.