× 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.



Sorry, I've been away from the list for awhile and forgot we don't have
attachments anymore.  Code is below....

0154.00  *   Obtain a listening socket descriptor
0155.00 C                       Eval            SD = Socket(AF_INET: 
SOCK_STREAM: 0)
0156.00 C     LogLvl            IfEQ      LogAll
0157.00 C                       Eval            EventID = 'ServerSocket'
0158.00 C                       CallP     EventLog (EventID)
0159.00 C                       EndIF
0160.00
0161.00  *   If Socket failed - End the server program
0162.00 C                       If              SD < 0
0163.00 C     LogLvl     IfNE      LogNone
0164.00 C                Eval           EventID = 'Socket Failed'
0165.00 C                CallP     EventLog (EventID)
0166.00 C                EndIF
0167.00 C                Eval      *InLR = *On
0168.00 C                Return
0169.00 C                EndIf
0170.00
0171.00  *   Allow the socket description to be reusable
0172.00 C                Eval      RC = SetSockOpt(SD: SOL_SOCKET
0173.00 C                                : SO_REUSEADDR
0174.00 C                                : %Addr(OptVal)
0175.00 C                                : %Size(OptVal))
0176.00 C     LogLvl     IfEQ      LogAll
0177.00 C                Eval      EventID = 'SvrSetSckOpt'
0178.00 C                CallP     EventLog (EventID)
0179.00 C                EndIf
0180.00
0181.00  *   If SetSockOpt failed - End the server program
0182.00 C                If        RC < 0
0183.00 C     LogLvl     IfNE      LogNone
0184.00 C                Eval      EventID = 'SetSockOpt Failed'
0185.00 C                CallP     EventLog (EventID)
0186.00 C                EndIF
0187.00 C                Eval      *InLR = *On
0188.00 C                Return
0189.00 C                EndIf
0190.00
0191.00
0192.00  *   Bind the socket to a local address
0193.00 C                Eval      SocketAddr = *LOVAL
0194.00 C                Eval      SinFamily  = AF_INET
0195.00 C                Eval      SinPort    = PortNumber
0196.00 C                Eval      SinAddr    = INADDR_ANY
0197.00 C                Eval      RC = Bind (SD: %ADDR(SocketAddr)
0198.00 C                                : %SIZE(SocketAddr))
0199.00 C     LogLvl     IfEQ      LogAll
0200.00 C                Eval      EventId ='ServerBind'
0201.00 C                CallP     EventLog(EventID)
0202.00 C                EndIf
0203.00
0204.00  *   If Bind failed - End the server program
0205.00 C                If        RC < 0
0206.00 C     LogLvl     IfNE      LogNone
0207.00 C                Eval      EventID = 'ServerBind Failed'
0208.00 C                CallP     EventLog (EventID)
0209.00 C                EndIF
0210.00 C                Eval      *InLR = *On
0211.00 C                Return
0212.00 C                EndIf
0213.00
0214.00  *   Listen to # of clients passed in MaxConnect
0215.00 C                Eval      RC = listen (SD : MaxConnect)
0216.00 C     LogLvl     IfEQ      LogAll
0217.00 C                Eval      EventID = 'ServerListen'
0218.00 C                CallP     EventLog (EventID)
0219.00 C                EndIf
0220.00
0221.00  *   If Listen failed - End the server program
0222.00 C                If     RC < 0
0223.00 C     LogLvl     IfNE   LogNone
0224.00 C                Eval   EventID = 'ServerListen Failed'
0225.00 C                CallP  EventLog (EventID)
0226.00 C                EndIF
0227.00 C                Eval   *InLR = *On
0228.00 C                Return
0229.00 C                EndIf
0230.00
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) )
0260.00 C     LogLvl    IfEQ    LogAll
0261.00 C               Eval    EventID = 'ServerSelect'
0262.00 C               CallP   EventLog (EventID)
0263.00 C               EndIf
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)
0275.00 C     LogLvl    IfNE    LogNone
0276.00 C               Eval    EventID = 'ServerSelect Failed'
0277.00 C               CallP   EventLog (EventID)
0278.00 C               EndIF
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)
0299.00 C     LogLvl    IfEQ      LogAll
0300.00 C               Eval      EventID = 'ServerAccept'
0301.00 C               CallP     EventLog (EventID)
0302.00 C               EndIf
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
0326.18 C               Move      MsgLen        MsgLenVar
0326.19  *   ....Receive from current socket up to header length
0326.20 C               Eval      RC = Recv(I: SocketData@
0326.21 C                                 : MsgLenVar: 0)
0326.22
0326.23 C     LogLvl    IfEQ      LogAll
0326.24 C               Eval      EventID = 'ServerRecv'
0326.25 C               CallP     EventLog (EventID)
0326.26 C               EndIf
0326.27
0326.28  *   .....If Recv failed - End the server program
0326.29 C               If        RC < 0
0326.30 C****           Eval      *InLR = *On
0326.31 C****           Return
0326.32 C     LogLvl    IfNE      LogNone
0326.33 C               Eval      EventID = 'Recv Ended'
0326.34 C               CallP     EventLog (EventID)
0326.35 C               EndIf
0326.36 C               Leave
0326.37 C               EndIf
0326.38
0326.39 C               Eval      SockDtaLen = %Len(%Trim(SocketData))
0326.40  *     If no data received, then reset RC
0326.41 C               If        SockDtaLen = 0
0326.42 C               Eval      RC = 0
0326.43 C               Eval      MsgLenVar = 0
0326.44 C               Else
0326.46  *     If header length equal data length received
0326.47 C               If        SockDtaLen = MsgLenVar
0326.48  *   .....Recv OK - Process data
0326.49 C               ExSr      ProcData
0326.50 C               Else
0326.51  *   .....Recv Not OK - Create and send an error message
0326.52 C               ExSr      MsgLenErr
0326.53 C               EndIf
0326.55 C               Endif
0326.56
0327.00 C               EndIf
0328.00
0348.00  *   ...End of Accept or Receive (current socket processing)
0349.00 C               EndIf
0350.00
0351.00  *   ..End of Process incoming request
0352.00 C               EndIf
0353.00
0354.00  *   ..End of Inspection loop
0355.00 C               EndDo
0356.00
0357.00  *   .End of Process all incoming requests
0358.00 C               EndIf
0359.00
0360.00  *   End of Processing loop
0361.00 C               EndDo
0362.00

----Original Message Follows------
Hi all,

I have a sockets application that I'm having a problem with, and wonder if
anyone can point me in the right direction.  The system is working, but it
is also eating up the machine.

When I run the server program in debug, I find that the return code from the
select() statement is always coming back with a value of '1'.  In this
particular case I sent one message from the client.  The server recognized
the activity on the socket and issued a read against it, and processed the
incomming message.  It then wrote the response back to the socket.  From
that point on, with every loop through the code, it continues to show a
return code of '1' for that socket, even though there are zero bytes read.
Because of this it appears the select is never sleeping as it should, and
the result is a fast running loop that is eating all the machine's
resources.

I've attached the main part of the code.  The select() is at 257.  I would
appreciate any pointers you might have.

Thanks in advance!


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




_________________________________________________________________
Send and receive Hotmail on your mobile device: http://mobile.msn.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.