@@ -46,7 +46,7 @@ public NetworkStream(Socket socket, FileAccess access, bool ownsSocket)
4646 {
4747 ArgumentNullException . ThrowIfNull ( socket ) ;
4848
49- if ( ! socket . Blocking )
49+ if ( ! OperatingSystem . IsWasi ( ) && ! socket . Blocking )
5050 {
5151 // Stream.Read*/Write* are incompatible with the semantics of non-blocking sockets, and
5252 // allowing non-blocking sockets could result in non-deterministic failures from those
@@ -118,6 +118,8 @@ public override int ReadTimeout
118118 {
119119 get
120120 {
121+ if ( OperatingSystem . IsWasi ( ) ) throw new PlatformNotSupportedException ( ) ; // https://github.com/dotnet/runtime/issues/108151
122+
121123 int timeout = ( int ) _streamSocket . GetSocketOption ( SocketOptionLevel . Socket , SocketOptionName . ReceiveTimeout ) ! ;
122124 if ( timeout == 0 )
123125 {
@@ -127,6 +129,8 @@ public override int ReadTimeout
127129 }
128130 set
129131 {
132+ if ( OperatingSystem . IsWasi ( ) ) throw new PlatformNotSupportedException ( ) ; // https://github.com/dotnet/runtime/issues/108151
133+
130134 if ( value <= 0 && value != System . Threading . Timeout . Infinite )
131135 {
132136 throw new ArgumentOutOfRangeException ( nameof ( value ) , SR . net_io_timeout_use_gt_zero ) ;
@@ -141,6 +145,8 @@ public override int WriteTimeout
141145 {
142146 get
143147 {
148+ if ( OperatingSystem . IsWasi ( ) ) throw new PlatformNotSupportedException ( ) ; // https://github.com/dotnet/runtime/issues/108151
149+
144150 int timeout = ( int ) _streamSocket . GetSocketOption ( SocketOptionLevel . Socket , SocketOptionName . SendTimeout ) ! ;
145151 if ( timeout == 0 )
146152 {
@@ -150,6 +156,8 @@ public override int WriteTimeout
150156 }
151157 set
152158 {
159+ if ( OperatingSystem . IsWasi ( ) ) throw new PlatformNotSupportedException ( ) ; // https://github.com/dotnet/runtime/issues/108151
160+
153161 if ( value <= 0 && value != System . Threading . Timeout . Infinite )
154162 {
155163 throw new ArgumentOutOfRangeException ( nameof ( value ) , SR . net_io_timeout_use_gt_zero ) ;
@@ -218,6 +226,8 @@ public override long Seek(long offset, SeekOrigin origin)
218226 // Number of bytes we read, or 0 if the socket is closed.
219227 public override int Read ( byte [ ] buffer , int offset , int count )
220228 {
229+ if ( ! Socket . OSSupportsThreads ) throw new PlatformNotSupportedException ( ) ; // TODO remove with https://github.com/dotnet/runtime/pull/107185
230+
221231 ValidateBufferArguments ( buffer , offset , count ) ;
222232 ThrowIfDisposed ( ) ;
223233 if ( ! CanRead )
@@ -237,6 +247,8 @@ public override int Read(byte[] buffer, int offset, int count)
237247
238248 public override int Read ( Span < byte > buffer )
239249 {
250+ if ( ! Socket . OSSupportsThreads ) throw new PlatformNotSupportedException ( ) ; // TODO remove with https://github.com/dotnet/runtime/pull/107185
251+
240252 if ( GetType ( ) != typeof ( NetworkStream ) )
241253 {
242254 // NetworkStream is not sealed, and a derived type may have overridden Read(byte[], int, int) prior
@@ -260,6 +272,8 @@ public override int Read(Span<byte> buffer)
260272
261273 public override unsafe int ReadByte ( )
262274 {
275+ if ( ! Socket . OSSupportsThreads ) throw new PlatformNotSupportedException ( ) ; // TODO remove with https://github.com/dotnet/runtime/pull/107185
276+
263277 byte b ;
264278 return Read ( new Span < byte > ( & b , 1 ) ) == 0 ? - 1 : b ;
265279 }
@@ -282,6 +296,8 @@ public override unsafe int ReadByte()
282296 // way to indicate an error.
283297 public override void Write ( byte [ ] buffer , int offset , int count )
284298 {
299+ if ( ! Socket . OSSupportsThreads ) throw new PlatformNotSupportedException ( ) ; // TODO remove with https://github.com/dotnet/runtime/pull/107185
300+
285301 ValidateBufferArguments ( buffer , offset , count ) ;
286302 ThrowIfDisposed ( ) ;
287303 if ( ! CanWrite )
@@ -303,6 +319,8 @@ public override void Write(byte[] buffer, int offset, int count)
303319
304320 public override void Write ( ReadOnlySpan < byte > buffer )
305321 {
322+ if ( ! Socket . OSSupportsThreads ) throw new PlatformNotSupportedException ( ) ; // TODO remove with https://github.com/dotnet/runtime/pull/107185
323+
306324 if ( GetType ( ) != typeof ( NetworkStream ) )
307325 {
308326 // NetworkStream is not sealed, and a derived type may have overridden Write(byte[], int, int) prior
@@ -414,6 +432,8 @@ protected override void Dispose(bool disposing)
414432 // An IASyncResult, representing the read.
415433 public override IAsyncResult BeginRead ( byte [ ] buffer , int offset , int count , AsyncCallback ? callback , object ? state )
416434 {
435+ if ( ! Socket . OSSupportsThreads ) throw new PlatformNotSupportedException ( ) ; // TODO remove with https://github.com/dotnet/runtime/pull/107185
436+
417437 ValidateBufferArguments ( buffer , offset , count ) ;
418438 ThrowIfDisposed ( ) ;
419439 if ( ! CanRead )
@@ -447,6 +467,8 @@ public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, Asy
447467 // The number of bytes read. May throw an exception.
448468 public override int EndRead ( IAsyncResult asyncResult )
449469 {
470+ if ( ! Socket . OSSupportsThreads ) throw new PlatformNotSupportedException ( ) ; // TODO remove with https://github.com/dotnet/runtime/pull/107185
471+
450472 ThrowIfDisposed ( ) ;
451473 ArgumentNullException . ThrowIfNull ( asyncResult ) ;
452474
@@ -476,6 +498,8 @@ public override int EndRead(IAsyncResult asyncResult)
476498 // An IASyncResult, representing the write.
477499 public override IAsyncResult BeginWrite ( byte [ ] buffer , int offset , int count , AsyncCallback ? callback , object ? state )
478500 {
501+ if ( ! Socket . OSSupportsThreads ) throw new PlatformNotSupportedException ( ) ; // TODO remove with https://github.com/dotnet/runtime/pull/107185
502+
479503 ValidateBufferArguments ( buffer , offset , count ) ;
480504 ThrowIfDisposed ( ) ;
481505 if ( ! CanWrite )
@@ -506,6 +530,8 @@ public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, As
506530 // Returns: The number of bytes read. May throw an exception.
507531 public override void EndWrite ( IAsyncResult asyncResult )
508532 {
533+ if ( ! Socket . OSSupportsThreads ) throw new PlatformNotSupportedException ( ) ; // TODO remove with https://github.com/dotnet/runtime/pull/107185
534+
509535 ThrowIfDisposed ( ) ;
510536 ArgumentNullException . ThrowIfNull ( asyncResult ) ;
511537
@@ -659,6 +685,8 @@ public override void SetLength(long value)
659685 private int _currentWriteTimeout = - 1 ;
660686 internal void SetSocketTimeoutOption ( SocketShutdown mode , int timeout , bool silent )
661687 {
688+ if ( OperatingSystem . IsWasi ( ) ) throw new PlatformNotSupportedException ( ) ; // https://github.com/dotnet/runtime/issues/108151
689+
662690 if ( timeout < 0 )
663691 {
664692 timeout = 0 ; // -1 becomes 0 for the winsock stack
0 commit comments