Re: NIO




"Esmond Pitt" <esmond.nospam.pitt@xxxxxxxxxxxxxxxxxx> wrote in message
news:MIese.18710$F7.16808@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> 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

True, but if you want full non-blocking connects, this is how to do it. Call
finishConnect as soon as OP_CONNECT has been selected.
>
> > 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
It's good practice to do writing once OP_WRITE is selected, that it happens
immediately is true, but doesnt change the fact that it's bad style to
assume it. But fair enough, it will work.
>
> > 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: NIO
    ... |> selecting for it really ... but doesnt change the fact that it's ... determine if the socket is writable, ... OS can accept more data on that connection, ...
    (comp.lang.java.programmer)
  • Re: on the semantics of connect(): EINTR, EALREADY, EINPROGRESS
    ... assume fd is a file descriptor referring to a blocking, ... If the connection cannot be established ... the socket, connectshall block for up to an unspecified timeout ... Since it's then essentially a non-blocking connect, ...
    (comp.unix.programmer)
  • Re: Socket Server... Why two?
    ... I hope you meant non-blocking way ... The accept just accepts a connection and returns as soon ... It is just an information to the application that now one more socket ... nothing to do without that data, you can do a blocking recv(). ...
    (comp.unix.programmer)
  • Re: Socket Server... Why two?
    ... I hope you meant non-blocking way ... The accept just accepts a connection and returns as soon ... It is just an information to the application that now one more socket ... nothing to do without that data, you can do a blocking recv(). ...
    (comp.unix.programmer)
  • Connected Status on Sockets
    ... I have created a socket application in C++.NET that connects in non-blocking ... All my previous apps of this kind have used blocking mode at the ... non-blocking mode even after the connection is completed. ...
    (microsoft.public.dotnet.framework)