I don't want "read from socket" to be blocking

Brian Yennie briany at qldlearning.com
Thu Jul 31 22:47:00 EDT 2003


I believe you are looking for something like this:

This breaks every single read and write into it's own non-blocking 
code. What effect that has on our client (or the server) if things end 
up getting sent out of order, is, well, the peril of non-blocking code. 
You might consider only making the large retrieve calls non-blocking, 
blocking the brief writes, etc.

But this is the idea, using "with message" syntax.

on handler theID, theData
   repeat with x = 1 to (the second word of theData)
     write ( "TOP" && x && "0" & crlf  ) to socket server & ":110" with 
message "fetchHeader"
   end repeat
end handler

on fetchHeader server
      read from socket server & ":110" until crlf & "." & crlf with 
message "checkHeader"
end fetchHeader

on checkHeader server, theHeader
    if theHeader contains "Reply-To: use-revolution at lists.runrev.com" 
then
       write ( "UIDL" && theData & crlf  ) to socket server & ":110" 
with message "processHeader"
    end if
end checkMessage

on processHeader server,theHeader
         read from socket server & ":110" until crlf with message 
"getHash"
end processHeader

on getHash server,theMessage
    put word 2 to -1 of theMessage into theHash
    if theHash is not among the items of the hashList of this stack then
       write ( "RETR" && theItem & crlf  ) to socket server & ":110" 
with message "processMessage"
    end if
end getHash

on processMessage server,fullMessage
         read from socket server & ":110" until crlf & "." & crlf with 
message "retrieved"
end processMessage

on retrieved server, theMessage
     answer "GOT IT::"&theMessage
end retrieved

> on handler theID theData
>   repeat with x = 1 to (the second word of theData) --number of 
> messages
>     write ( "TOP" && x && "0" & crlf  ) to socket server & ":110" 
> --TOP 0 =get only headers
>     read from socket server & ":110" until crlf & "." & crlf --should 
> be non-blocking but isn't
>     if theMessage contains "Reply-To: use-revolution at lists.runrev.com" 
> then
>       put x & "," after theList --gather all runrev messages
>     end if
>   end repeat
>   repeat for each item theItem in theList --all messages from runrev
>     write ( "UIDL" && theItem & crlf  ) to socket server & ":110" 
> --get hash of message
>     read from socket server & ":110" until crlf
>     put word 2 to -1 of it into theHash
>     if thehash is not among the items of the hashList of this stack 
> then --not previously downloaded
>       write ( "RETR" && theItem & crlf  ) to socket server & ":110" 
> --get the whole message
>       read from socket server & ":110" until crlf & "." & crlf with 
> message "retrieved" -- does this work?
>     end if
>   end repeat
> end handler




More information about the use-livecode mailing list