@@ -298,7 +298,7 @@ internal void Authenticate(bool isServer, string targetHost, X509Certificate cer
298298 certificate ,
299299 ca ,
300300 _useStoredDeviceCertificate ) ;
301-
301+
302302 SslNative . SecureAccept ( _sslContext , _socket ) ;
303303 }
304304 else
@@ -309,7 +309,7 @@ internal void Authenticate(bool isServer, string targetHost, X509Certificate cer
309309 certificate ,
310310 ca ,
311311 _useStoredDeviceCertificate ) ;
312-
312+
313313 SslNative . SecureConnect ( _sslContext , targetHost , _socket ) ;
314314 }
315315 }
@@ -394,13 +394,13 @@ protected override void Dispose(bool disposing)
394394 {
395395 _disposed = true ;
396396
397- if ( _socket . m_Handle != - 1 )
397+ if ( _socket . m_Handle != - 1 )
398398 {
399399 SslNative . SecureCloseSocket ( _socket ) ;
400400 _socket . m_Handle = - 1 ;
401401 }
402402
403- if ( _sslContext != - 1 )
403+ if ( _sslContext != - 1 )
404404 {
405405 SslNative . ExitSecureContext ( _sslContext ) ;
406406 _sslContext = - 1 ;
@@ -446,7 +446,30 @@ public override int Read(byte[] buffer, int offset, int size)
446446 /// <param name="buffer">An array that supplies the bytes written to the stream.</param>
447447 /// <param name="offset">he zero-based location in buffer at which to begin reading bytes to be written to the stream.</param>
448448 /// <param name="size">The number of bytes to read from buffer.</param>
449- public override void Write ( byte [ ] buffer , int offset , int size )
449+ /// <exception cref="ArgumentNullException"><paramref name="buffer"/> is <see langword="null"/>.</exception>
450+ /// <exception cref="ArgumentOutOfRangeException">
451+ /// <para>
452+ /// <paramref name="offset"/> or <paramref name="size"/> is less than zero
453+ /// </para>
454+ /// <para>
455+ /// -or-
456+ /// </para>
457+ /// <para>
458+ /// <paramref name="offset"/> is greater than the length of <paramref name="buffer"/>.
459+ /// </para>
460+ /// <para>
461+ /// -or-
462+ /// </para>
463+ /// <para>
464+ /// <paramref name="offset"/> + <paramref name="size"/> is greater than the length of <paramref name="buffer"/>.
465+ /// </para>
466+ /// </exception>
467+ /// <exception cref="ObjectDisposedException">The stream has been disposed.</exception>
468+ /// <exception cref="IOException">The write operation failed.</exception>
469+ public override void Write (
470+ byte [ ] buffer ,
471+ int offset ,
472+ int size )
450473 {
451474 if ( buffer == null )
452475 {
@@ -468,7 +491,12 @@ public override void Write(byte[] buffer, int offset, int size)
468491 throw new ArgumentOutOfRangeException ( ) ;
469492 }
470493
471- SslNative . SecureWrite ( _socket , buffer , offset , size , _socket . SendTimeout ) ;
494+ int written = SslNative . SecureWrite ( _socket , buffer , offset , size , _socket . SendTimeout ) ;
495+
496+ if ( written <= 0 && size > 0 )
497+ {
498+ throw new IOException ( ) ;
499+ }
472500 }
473501 }
474502}
0 commit comments