Skip to content
Merged
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
32 changes: 16 additions & 16 deletions nanoFramework.System.Net/Security/SslStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -325,27 +325,27 @@ internal void Authenticate(bool isServer, string targetHost, X509Certificate cer
public bool IsServer { get { return _isServer; } }

/// <summary>
/// Gets the length of the stream. (Overrides NetworkStream. . :: . .Length.)
/// Gets the number of bytes of decrypted data available to be read from the stream.
/// </summary>
public override long Length
{
get
{
if (_disposed == true) throw new ObjectDisposedException();
if (_disposed) throw new ObjectDisposedException();
if (_socket == null) throw new IOException();

return SslNative.DataAvailable(_socket);
}
}

/// <summary>
/// Gets a value the indicates whether data is available in the stream. (Overrides NetworkStream. . :: . .DataAvailable.)
/// Gets a value that indicates whether decrypted data is available on the stream to be read.
/// </summary>
public override bool DataAvailable
{
get
{
if (_disposed == true) throw new ObjectDisposedException();
if (_disposed) throw new ObjectDisposedException();
if (_socket == null) throw new IOException();

return (SslNative.DataAvailable(_socket) > 0);
Expand Down Expand Up @@ -393,9 +393,9 @@ protected override void Dispose(bool disposing)
/// </summary>
/// <param name="buffer">An array that receives the bytes read from this stream.</param>
/// <param name="offset">An integer that contains the zero-based location in buffer at which to begin storing the data read from this stream.</param>
/// <param name="size">The maximum number of bytes to read from this stream.</param>
/// <param name="count">The maximum number of bytes to read from this stream.</param>
/// <returns></returns>
public override int Read(byte[] buffer, int offset, int size)
public override int Read(byte[] buffer, int offset, int count)
{
if (buffer == null)
{
Expand All @@ -412,24 +412,24 @@ public override int Read(byte[] buffer, int offset, int size)
throw new ArgumentOutOfRangeException();
}

if (size < 0 || size > buffer.Length - offset)
if (count < 0 || count > buffer.Length - offset)
{
throw new ArgumentOutOfRangeException();
}

return SslNative.SecureRead(_socket, buffer, offset, size, _socket.ReceiveTimeout);
return SslNative.SecureRead(_socket, buffer, offset, count, _socket.ReceiveTimeout);
}

/// <summary>
/// Write the specified number of bytes to the underlying stream using the specified buffer and offset.
/// </summary>
/// <param name="buffer">An array that supplies the bytes written to the stream.</param>
/// <param name="offset">he zero-based location in buffer at which to begin reading bytes to be written to the stream.</param>
/// <param name="size">The number of bytes to read from buffer.</param>
/// <param name="offset">The zero-based location in buffer at which to begin reading bytes to be written to the stream.</param>
/// <param name="count">The number of bytes to read from buffer.</param>
/// <exception cref="ArgumentNullException"><paramref name="buffer"/> is <see langword="null"/>.</exception>
/// <exception cref="ArgumentOutOfRangeException">
/// <para>
/// <paramref name="offset"/> or <paramref name="size"/> is less than zero
/// <paramref name="offset"/> or <paramref name="count"/> is less than zero
/// </para>
/// <para>
/// -or-
Expand All @@ -441,15 +441,15 @@ public override int Read(byte[] buffer, int offset, int size)
/// -or-
/// </para>
/// <para>
/// <paramref name="offset"/> + <paramref name="size"/> is greater than the length of <paramref name="buffer"/>.
/// <paramref name="offset"/> + <paramref name="count"/> is greater than the length of <paramref name="buffer"/>.
/// </para>
/// </exception>
/// <exception cref="ObjectDisposedException">The stream has been disposed.</exception>
/// <exception cref="IOException">The write operation failed.</exception>
public override void Write(
byte[] buffer,
int offset,
int size)
int count)
{
if (buffer == null)
{
Expand All @@ -466,14 +466,14 @@ public override void Write(
throw new ArgumentOutOfRangeException();
}

if (size < 0 || size > buffer.Length - offset)
if (count < 0 || count > buffer.Length - offset)
{
throw new ArgumentOutOfRangeException();
}

int written = SslNative.SecureWrite(_socket, buffer, offset, size, _socket.SendTimeout);
int written = SslNative.SecureWrite(_socket, buffer, offset, count, _socket.SendTimeout);

if (written <= 0 && size > 0)
if (written <= 0 && count > 0)
{
throw new IOException();
}
Expand Down
29 changes: 7 additions & 22 deletions nanoFramework.System.Net/Sockets/Socket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public EndPoint RemoteEndPoint
}

/// <summary>
/// Gets a value that indicates whether a <see cref="Socket"/> is connected to a remote host as of the last <see cref="Send"/> or <see cref="Receive"/> operation.
/// Gets a value that indicates whether a <see cref="Socket"/> is connected to a remote host as of the last <see cref="Send(byte[])"/> or <see cref="Receive(byte[])"/> operation.
/// </summary>
/// <value>
/// <see langword="true"/> if the <see cref="Socket"/> was connected to a remote resource as of the most recent operation; otherwise, <see langword="false"/>.
Expand Down Expand Up @@ -766,30 +766,12 @@ public int ReceiveFrom(byte[] buffer, int offset, int size, SocketFlags socketFl

if (_rightEndPoint == null)
{
// socket must have connection established or previously accepted a connection
// socket must be bound (by Bind, Connect or SendTo)
throw new SocketException(SocketError.NotConnected);
}

EndPoint endPointSnapshot = remoteEP;
Snapshot(ref endPointSnapshot);

int bytesTransferred = 0;

bytesTransferred = NativeSocket.recvfrom(this, buffer, offset, size, (int)socketFlags, m_recvTimeout, ref remoteEP);

if (!remoteEP.Equals(endPointSnapshot))
{
// no need to create a new EndPoint here if it's different from the orignal
// because the interpreter has already created a new instance of an IPEndPoint

if (_rightEndPoint == null)
{
// save a copy of the EndPoint
_rightEndPoint = remoteEP;
}
}

return bytesTransferred;
// recvfrom always replaces remoteEP with a new IPEndPoint holding the sender's address; the caller's instance is never modified
return NativeSocket.recvfrom(this, buffer, offset, size, (int)socketFlags, m_recvTimeout, ref remoteEP);
}

/// <summary>
Expand Down Expand Up @@ -1091,6 +1073,9 @@ void IDisposable.Dispose()
GC.SuppressFinalize(this);
}

/// <summary>
/// Releases unmanaged resources used by the <see cref="Socket"/> before it is reclaimed by garbage collection.
/// </summary>
~Socket()
{
Dispose(false);
Expand Down
Loading