You have your FromAsync
defined incorrectly. Unfortunately, there isn't an overload of FromAsync which accepts 4 separate arguments (which would be required for BeginSend
), so you'll need to use a different overload:
public static Task<int> SendTaskAsync(this Socket socket, byte[] buffer, int offset, int size, SocketFlags flags)
{
AsyncCallback nullOp = (i) => {};
IAsyncResult result = socket.BeginSend(buffer, offset, size, flags, nullOp, socket);
// Use overload that takes an IAsyncResult directly
return Task.Factory.FromAsync(result, socket.EndSend);
}