Re: Non-blocking method for reading writing objects to sockets



Esmond Pitt wrote:
Joseph Dionne wrote:

One can read a socket non blocked, using a single method call, receiving either data, or no data.


or some data. There is a third state.

Only proxy like applications, providing connectivity between two end points, can truly read a socket STREAM without regard to message boundaries. At some point, even a socket read method requires a complete packet delivery.


As you may or may not know, not knowing the level of expertise you bring to this discussion, socket stream of non ASCII STREAMS, use two to four bytes preceding the data allowing the received to know the message size and prepare applications to receive the data. Prior to threading support, a relatively new feature, applications ip applications were just state engines, with socket I/O just one state, using select() or poll() to monitor state. These functions measured the leading edge event of a socket STREAM, data has arrived. If one did not read all the data received, select() (always), and poll() (most implementations) would not signal the socket handle ready until more data arrives. This is a common error in socket I/O applications.

My original point what that there exist no single socket interface method that removes the responsibility to manage the socket STREAMS like garbage collection has done for memory management. And, now we have learned, even garbage collectors do not completely remove the job of proper memory management, one can still obfuscate Object references in many ways that prevent Object memory reclamation.


But, one cannot code a single method call to write non blocked in a "fire and forget" manner. Even you acknowledge that write might fail to emit all the data one attempted to write. So, one always needs to put a loop around socket write methods, terminating only after all data has been emitted.


or when you have something better to do in non-blocking mode than wait for the client to empty his receive buffer. Also, at some point you want to decide that this is never going to happen and you prefer to give up.

That is why is said "technically". Conceptually, a non blocked socket read method is expected to do one of two things, return data, or indicate that no data is returned, while a socket write can have three states, all data written, some data written, no data written. Since "some data written" will a application error. I'm pretty sure no one desires half of the STREAM delivered to the remote client.


Nevertheless that is how both the non-blocking read and non-blocking write calls behave on a socket. There are three states in both, and technically your statement does not hold water.

and BTW what exactly is a socket MCB?

An MCB, or the memory control blocks defining the socket's mbufs within the ip stack application interface. It is a term I use, but is not part of any user level, or even stack level, data structures. I was incorrect to inject my nomenclature, but I have been working at low level IP for decades, developing many features for my old IPX used with such ease as Java's socket interfaces today.


Has that answered your question?
.



Relevant Pages

  • Re: Various Language Architecture Questions
    ... Simple,unportabe Network Data Transport: To transport a C struct, I just cast it to char* and then write sizeofbytes to the Socket. ... That is something you can supply for a record type, together with a socket stream, for example. ...
    (comp.lang.ada)
  • Re: closing ASyncSocket
    ... I reread the help for the ShutDown() call. ... not close the socket, and resources attached to the socket will not be freed ... What if I want to Closethe connection to return resources. ... receiving side after I received the last data. ...
    (microsoft.public.vc.mfc)
  • Re: BeginReceive return zero length buffer when run ,and work correctly when use step by step debug
    ... Your first read is receiving 0 bytes? ... Your async socket listens and receives 500 bytes (your total buffer size ... But the data remains on the socket, until such time as it IS ... With a stream-oriented socket (eg TCP), ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Handling multiple connections
    ... each time select says the socket has more data. ... All data being sent by clients are prepended with a header that indicates ... received and thus delays receiving on the other readable sockets. ... When the client closes the connection, ...
    (microsoft.public.win32.programmer.networks)
  • Re: Socket Communication with Laptop
    ... then keep receiving until that many bytes have arrived and then stop. ... The laptop seems to be sending at 1024 for a 1mb file. ... to determine if there is more data in the socket buffer to receive. ... SOCKET sockDest; ...
    (microsoft.public.windowsce.embedded.vc)