Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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