Re: NIO



Remon van Vliet wrote:

Well, this is not how you're supposed to do it. Like you said, the socket is
non-blocking, which means that it will return from your .write() right away,
and after that calls the close(). The proper way to do this is this :

1) establish a connection using a non-blocking socket connect()
2) wait for finishConnect() to return true

This is generally pointless unless you want to timeout the connection and are already using select(); usually better to use blocking connect with a timeout


3) At this point you can send data, do so once the OP_WRITE key is selected
after a select() call

which will happen immediately the connection is complete, not much point selecting for it really


4) Write all data (in a secure way, meaning keep track of what you send and
make sure you send it all)

this part is correct, you do need to ensure no short or zero-length writes before you close


5) Once this is done you can close the connection

and this .



Relevant Pages

  • Re: Timeout strategy: terminal vs Telnet drivers
    ... Isn't this why you have the choice of blocking and non-blocking? ... you're sensible enough to use the $QIO interface then you have the benefit ... > goto loop if not timeout. ... > "sleep" when data stops coming. ...
    (comp.os.vms)
  • Re: System Calls Hang in Multi-Threaded Webcrawler
    ... You don't know for sure that it is non-blocking here, ... inline bool set_non_blocking ... Maybe something is wrong with my select routine. ... bool Select(int m_sock, int timeout) ...
    (comp.programming.threads)
  • Re: socket read behavior
    ... > implemented with non-blocking calls, ... either received the entire transaction or a timeout occurs. ... }// loop end ... receiving of the data. ...
    (comp.unix.programmer)
  • Re: Problem using sockets
    ... It depends on network latency, ... and the load on the remote host. ... thing a non-blocking connectis going to get you is more control ... connects and then sharing one timeout for both of them. ...
    (comp.unix.programmer)
  • Re: NIO
    ... >> non-blocking, which means that it will return from your .writeright ... >> 1) establish a connection using a non-blocking socket connect ... > This is generally pointless unless you want to timeout the connection ... > selecting for it really ...
    (comp.lang.java.programmer)