Re: Java NIO: calling selector.select() before socketChannel.write()

Avinash Lakshman <[email protected]> Wed, 16 Apr 2008 02:22:25 -0500
Newsgroups gmane.comp.windows.devel.java.advanced
Message-ID <[email protected]>
There is no reason to do a select() before a write(). However when you do p=
erform a write() you may not write the entire set of bytes you want to writ=
e. In that event you want to register for OP_WRITE interest with the select=
or and when notified by the selector (when the socket is writeable) push th=
e remaining bytes out.
=20
Cheers
A> Date: Tue, 15 Apr 2008 16:48:50 -0700> From: [email protected]> Subj=
ect: Re: [ADVANCED-JAVA] Java NIO: calling selector.select() before socketC=
hannel.write()> To: [email protected]> > I've never used Ja=
va's non-blocking I/O, but in POSIX non-blocking I/O, you> typically use on=
e select() for everything.> > Bob> > On Tue, Apr 15, 2008 at 4:27 PM, Serge=
y Marakhov <[email protected]>> wrote:> > > Hi all.> >> > I'm looki=
ng at ways to simplify our current implementation of socket> > communicatio=
ns between an agent and multiple clients. There is a client> > connection o=
bject created per connected client, client connection is> > passed through =
an "incoming" selector and each client connection opens its> > own outgoing=
 selector. So, question 1: do I need to create separate> > outgoing selecto=
rs, or is using a single selector for both in and out> > operations is the =
way to go?> >> > Next, before each invocation of socketChannel.write(=85) m=
ethod, we do> > outgoingSelector.select(). Is it necessary to do select() b=
efore write> > operations?> >> > Our knowledge of NIO is rather limited, he=
nce all this questions.> >> > Much appreciated=85> > Sergey> >> > =3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D> > This list is hosted by DevelopMentor(R) http://www=
.develop.com> >> > View archives and manage your subscription(s) at> > http=
://discuss.develop.com> >> > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D> This list is =
hosted by DevelopMentor=AE http://www.develop.com> > View archives and mana=
ge your subscription(s) at http://discuss.develop.com
_________________________________________________________________
Pack up or back up=96use SkyDrive to transfer files or keep extra copies. L=
earn how.
http://www.windowslive.com/skydrive/overview.html?ocid=3DTXT_TAGLM_WL_Refre=
sh_skydrive_packup_042008=

=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
This list is hosted by DevelopMentor=AE  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com