Re: Can NetworkStream.Write() block?

Tech-Archive recommends: Fix windows errors by optimizing your registry



Jesse Houwing wrote:
Hello GAZ,

myNetworkStream.Write(byte[], int offset, int size);

From the MSDN documentation:
"
Remarks:
The Write method starts at the specified offset and sends size bytes
from the contents of buffer to the network. The Write method blocks
until the requested number of bytes is sent or a SocketException is
thrown. If you receive a SocketException, use the
SocketException.ErrorCode property to obtain the specific error code,
and refer to the Windows Sockets version 2 API error code
documentation
in MSDN for a detailed description of the error.
"
It says the call blocks until the bytes are sent but aren't the bytes
just queued to the write buffer until the OS feels like sending them
over the wire? Therefore doesn't the call always return pretty much
immediately anyway?

My guess is that it'll block if the buffer is full.

--
Jesse Houwing
jesse.houwing at sogeti.nl



Thank you.

It seems this is better than using the non-blocking version myNetworkStream.BeginWrite(byte[] buffer, int offset, int size) since all that does (if the write buffer is full) is create a backlog of BeginWrite threads all waiting to complete. And what happens when /that/ buffer is full? another blockage?

Might as well use the blocking version and increase the buffer size if that is possible.
.



Relevant Pages

  • Can NetworkStream.Write() block?
    ... myNetworkStream.Write(byte, int offset, int size); ... From the MSDN documentation: ... If you receive a SocketException, use the SocketException.ErrorCode property to obtain the specific error code, and refer to the Windows Sockets version 2 API error code documentation in MSDN for a detailed description of the error. ... It says the call blocks until the bytes are sent but aren't the bytes just queued to the write buffer until the OS feels like sending them over the wire? ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Can NetworkStream.Write() block?
    ... From the MSDN documentation: ... from the contents of buffer to the network. ... until the requested number of bytes is sent or a SocketException is ... SocketException.ErrorCode property to obtain the specific error code, ...
    (microsoft.public.dotnet.languages.csharp)
  • Question about IntPtr
    ... I am having a problem while trying to use a buffer in a Function call. ... have ported the code from the MSDN documentation and it seems that the ... function expects a different type of input parameter than the one MSDN is ... ' I have to copy the values as my function returns an array of Doubles ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Possible optimization in GDI+
    ... But the msdn documentation says it will copy to internal buffer ... > when specifying reading mode. ...
    (microsoft.public.win32.programmer.gdi)
  • Re: stack around the variable corrupted
    ... Check the MSDN documentation for the term "Buffer Overrun". ... I invoked a routine in my ...
    (microsoft.public.vc.language)