[UNIX][ALPHA][NET] When to tap the r/w sems?

Rob Withers slosher2 at home.com
Fri Jul 28 09:25:03 UTC 2000


Lex Spoon wrote:
> 
> It seems reasonable to me to tap when there is a *change* in the read or
> write flag.  In fact, if the image sockets code is modified to drain
> semaphores instead of just reading one signal at a time, then we could
> completely stop checking whether we think the image is watching or not,
> and just signal any events that someone in the image might be interested
> in.

Right on.  In that scenario, I think we would only have one Semaphore in
the platform socket code to serialize the interaction of the socket
commands (create, listen, accept, connect, close, shutdown, read, write)
and the async handlers.  If we link into Tims's event code and buffer in
the socket code (performance), then we could wait on an image semaphore
(for that socket), perhaps with a timeout, and upon a signal from the
arrival of an event, we would check socket state or read data.  There
could also be a write buffer in the platform socket code, so it should
be thread safe.

I am not sure I am following you on the change in flags.  In fact, if we
make the sockets eventful, then we would always send an event when
anything happens (connect, read, write, exception).

> In Unix, this would suggest that dataHandler and friends be given seven
> arguments:
> 
>         the fd
>         the current read, write, and exceptions flags
>         the previous read, write, and exceptions flags
> 
> The data handlers can then signal the relevant semaphore whenever read
> or write goes from 0 to 1.
 
> This approach *does* require some slight trickery in order to make the
> select() wait properly: do one select to wait for stuff to happen, and
> then do another select() to update all three flags for all open sockets.
>  (Note you can't ask select() to watch for a flag changing from 1 to 0).

I am confused about this.  The tapFlags in the current code are to
inform the async handlers of intent.  If the intent flags get set in the
sendDone or  dataAvailable primitives, then the client is going to wait
on the semaphore, so tap on it.  The scenario you painted with the read,
write, and excpetion flags sound like the FD flags for select.  I am not
entirely sure about the select() call but isn't it known when the select
occurs that whatever the current flags are set, is the event that
occurred.

Rob

> -Lex
> 
> Rob Withers <slosher2 at home.com> wrote:
> > Below are the code chunks.  The only time we are going to be waiting on
> > the semaphore is if we call one of the 'checking' methods
> > (SendDone/DataAvailable).  I am checking the readFlag in the async
> > handler, that was installed for data ops, and SETting the flag for
> > semaphore tap.  This means that I'm always tapping, but I thought I was
> > only to do it during an intent call.   Should I remove the SET_.. calls
> > in the async handler?
> >
> > thanks,
> > Rob
> >
> > The SET_... sets a flag that the tapSemaphores(pss) method checks for,
> > taps is set, then clears the flag.
> > Here are two chunks of code from the unix network code:
> >
> > /* async handler for data operation */
> > static void dataHandler(privateSocketStruct *pss, int errFlag, int
> > readFlag)
> > {
> >         aioSuspend(pss);
> >
> >         FPRINTF((stderr, "dataHandler(%d,%d,%d)\n", pss->s, errFlag,
> > readFlag));
> >         if (errFlag)
> >                 pss->sockState = OtherEndClosed;   /* error: almost
> > certainly "connection closed by peer" */
> >         if (readFlag) {
> >                 SET_TAPREADSEM(pss);
> >         } else {
> >                 SET_TAPWRITESEM(pss);
> >         }
> >         tapSemaphores(pss);
> > }
> >
> >
> > And the two primitives for checking for readAvailable and sendDone:
> >
> > /* answer whether the socket has data available for reading */
> > int sqSocketReceiveDataAvailable(SocketPtr s)
> > {
> >   if (!socketValid(s)) return -1;
> >   if (SOCKETSTATE(s) == Connected) {
> >     if (socketReadable(SOCKET(s))) return true;
> >     SET_TAPREADSEM(PSP(s));
> >     aioHandle(PSP(s), dataHandler, AIO_RW);
> >   }
> >   return false;
> > }
> >
> > /* answer whether the socket has space to receive more data */
> > int sqSocketSendDone(SocketPtr s)
> > {
> >   if (!socketValid(s)) return -1;
> >   if (SOCKETSTATE(s) == Connected) {
> >     if (socketWritable(SOCKET(s))) return true;
> >     SET_TAPWRITESEM(PSP(s));
> >     aioHandle(PSP(s), dataHandler, AIO_RW);
> >   }
> >   return false;
> > }
> >
> >
> > --
> > --------------------------------------------------
> > Smalltalking by choice.  Isn't it nice to have one!

-- 
--------------------------------------------------
Smalltalking by choice.  Isn't it nice to have one!





More information about the Squeak-dev mailing list