× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Scott,

Thanks for the reply.  I'm new to sockets programming, and without IBM's
samples and your tutorial, I wouldn't have gotten this far.  From all of us
learning this, thanks for your effort to make it easier and more
understandable for us beginners.  (Especially the conversion from 'C'
explanations.)

I have read all the material I have over a few times and I'm unclear on a
couple of points.

1) Once a read set is built or restored, is the program supposed to loop
thru it one time and go to sleep, or does it cycle thru for a period of time
before it sleeps?  I've played with the timeout value, and it doesn't appear
to work the way the documentation indicates it should.  Exactly how is that
supposed to work?

My program (partial code still below) seems to behave fairly reasonably when
the first message is processed.  It doesn't eat too much CPU and does go to
SELW after a minute or so.  The timeout value is 30 seconds.  But once I
send another message to process, it will run thru the code and take 90+ % of
the resourses if nothing much else is running.  It also doesn't appear to
sleep.

2) In your reply you recommended an FDZero each time thru the loop.  Would
that be placed at the top of the loop, right before the readset is restored?
  You also suggested dumping the contents of the FDes data somewhere and
manually checking that the correct descriptors are set before & after
calling the select.  What exactly should they look like?


I remember the second time I looked at your tutorial on-line, I saw that you
had made some changes to your tutorials, and had asked for feedback for
improvements.  Maybe a chapter on debugging problems like this, with some
detail on how the descriptors should be set before and after function calls
would be helpful.

Thanks again for your help.

Jim Whalen
PH 972 429-8238
jimw2001@hotmail.com


----Original Message Follows----
From: Scott Klement <klemscot@klements.com>
Reply-To: midrange-l@midrange.com
To: midrange-l@midrange.com
Subject: Re: Sockets server HELP! - repost
Date: Fri, 3 May 2002 11:31:18 -0500 (CDT)


Can I assume that FD_Set@ is a pointer that points to FDes?  And that
there isn't any code that could change that?

I'd also recommend doing an FDZero each time through the loop, and
then setting each descriptor explicitly to make sure they're all set
correctly.

If you're still having trouble after that, try (for debugging only)
hex dumping the contents of your FDes data somewhere that you can manually
check that the correct descriptors are set before & after calling select,
since that seems to be the likely source of a problem.

As an aside, I generally find it better to rely on the values returned
from FDIsSet rather than the return value from select(), other than for
detecting actual errors while select() is running, that is.


 > 0231.00  *   Clear readset array
 > 0232.00 C                CallP     FDZero(FDes)
 > 0233.00 C                Eval      SckFlags '0'
 > 0234.00
 > 0235.00  *   Set on the listening socket in readset and flag array
 > 0236.00 C                CallP     FDSet(SD: FDes)
 > 0237.00 C                Eval      SckFlags(SD + 1) = '1'
 > 0238.00 C                Eval      CurMax = SD
 > 0239.00
 > 0240.00  *  - - - - - - - - - -
 > 0241.00  *   Processing loop
 > 0242.00
 > 0243.00 C               DoW     0 = 0
 > 0244.00
 > 0245.00  *   .Restore readset using the flag array
 > 0246.00  *    Flag '1' sets on, flag '0' sets off
 > 0247.00 C     0         Do      CurMax        J
 > 0248.00 C               If      SckFlags(J + 1) = '1'
 > 0249.00 C               CallP   FDSet(J: FDes)
 > 0250.00 C               Else
 > 0251.00 C               CallP   FDClr(J: FDes)
 > 0252.00 C               EndIf
 > 0253.00 C               EndDo
 > 0254.00
 > 0255.00  *   .Select the sockets that connect or send data
 > 0256.00  *    (deselect other sockets)
 > 0257.00 C               Eval    RC = Select(CurMax + 1
 > 0258.00 C                       : FD_Set@: *NULL: *NULL
 > 0259.00 C                       : %Addr(WaitTime) )
 > 0264.00
 > 0265.00  *   .If Select timed out - Restore readset and reenter loop
 > 0266.00  *     (there is no incoming request waiting)
 > 0267.00 C               If      RC = 0
 > 0268.00 C               Iter
 > 0269.00 C               EndIf
 > 0270.00
 > 0271.00  *   .If Select was unsuccessful - End the server program
 > 0272.00  *     (a programming error)
 > 0273.00 C               If      RC < 0
 > 0274.00 C               CallP   SckClose(SD)
 > 0279.00 C               Eval    *InLR = *On
 > 0280.00 C               Return
 > 0281.00 C               EndIf
 > 0282.00
 > 0283.00  *   .Process all incoming requests if Select is successful
 > 0284.00 C               If      RC > 0
 > 0285.00
 > 0286.00  *   ..Inspection loop. Inspect all description bits in readset
 > 0287.00  *  up to the current maximum and process those which are set on
 > 0288.00 C     0         Do      CurMax        I
 > 0289.00
 > 0290.00  *   ...If a bit is set on - Process the incoming request
 > 0291.00 C               If      FDIsSet(I: FDes) > 0
 > 0292.00
 > 0293.00  *   ....If bit represents a listening socket - Accept a Connect
 > 0294.00 C               If      I = SD
 > 0295.00
 > 0296.00  *   .....Try to accept the first client in queue
 > 0297.00  *        and create a new client's socket - SD2
 > 0298.00 C               Eval      SD2 = Accept(SD: SockAddr: AddrLen)
 > 0303.00
 > 0304.00  *   .....Accept OK - Add the socket to readset
 > 0305.00 C               If        SD2 >= 0
 > 0306.00 C               CallP     FDSet (SD2: FDes)
 > 0307.00 C               Eval      SckFlags(SD2 + 1) = '1'
 > 0308.00
 > 0309.00  *   .....Set a new current maximum of used sockets
 > 0310.00 C            If        SD2 > CurMax
 > 0311.00 C            Eval      CurMax = SD2
 > 0312.00 C            EndIf
 > 0313.00
 > 0314.00  *   ....End of Accept
 > 0315.00 C            EndIf
 > 0316.00
 > 0317.00  *   ....Else (not a listening socket)-Receive and Process data
 > 0318.00 C            Else
 > 0318.01 C            Eval      SocketData = *Blanks
 > 0319.00
 > 0320.00  *   ....Receive first 8 bytes of header length
 > 0321.00 C            Eval      RC = Recv(I: SocketData@
 > 0322.00 C                             : 8: 0)
 > 0323.00  *  If no data received, then reset RC
 > 0324.00 C            Eval      SockDtaLen = %Len(%Trim(SocketData))
 > 0325.00 C            If        SockDtaLen = 0
 > 0326.00 C            Eval      RC = 0
 > 0326.01 C            Else
 > 0326.02  *   ....Use header length to receive request message
 > 0326.03 C            Eval      MsgLen = SocketData
 > 0326.04
 > 0326.05  *  Test for End of Server job
 > 0326.06 C            If        MsgLen = 'ENDSERVE'
 > 0326.08 C            CallP     SckClose(SD)
 > 0326.09 C            Eval      *INLR = *ON
 > 0326.10 C            Return
 > 0326.11 C                    EndIf
 > 0326.12
 > 0326.13  *   ....Convert socket data from ASCII to EBCDIC
 > 0326.15 C            CallP     Translate(8: MsgLen: 'EBCDIC')
 > 0326.17
(SNIP)





_________________________________________________________________
Join the world’s largest e-mail service with MSN Hotmail.
http://www.hotmail.com



As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.