Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

/core async example

 [1/12] from: warp::reboot::ch at: 4-Mar-2004 15:52


;copy-paste this in console and you'll see who is faster! ;thanks to Gabriele, Marteen, Romano and Carl 8) do http://www.rebol.it/giesse/async-protocol.r get-fast: func [hosts /local port][ foreach host hosts [ uri: host port: open rejoin [async:// host ":80"] port/awake: do compose/deep handler ] until [wait .1 empty? system/ports/wait-list] ] handler: [ func [port [port!] state [word! error!]] [ if error? :state [print mold disarm state return true] switch state [ connect [ insert port rejoin [ {GET / HTTP/1.0} crlf {Host: } (uri) crlf crlf] false ] read [false] write [false] close [ data: copy port ;close port clear system/ports/wait-list print (uri) ;print find data join crlf crlf ;data: find/tail data join crlf crlf true ] ] ] ] ;example urls: [ "www.rebol.com" "www.rebol.net" "www.rebol.org" "www.apple.com" "www.oracle.com" "www.microsoft.com" ] loop 10 [get-fast urls]

 [2/12] from: ammon:addept:ws at: 4-Mar-2004 8:42


From REBOL/Command 2.5.6.3.1 console...
>> loop 10 [get-fast urls]
www.microsoft.com www.microsoft.com www.microsoft.com www.microsoft.com www.rebol.net ** Access Error: Port none not open ** Where: get-fast ** Near: res: res or async/awake async From REBOL/Link 1.0.5.3.1 console...
>> loop 10 [get-fast urls]
www.rebol.net ** Access Error: Port none not open ** Where: get-fast ** Near: either error? err: try [read-io port data max-transfer] From REBOL/View 1.2.5.3.1 console...
>> loop 10 [get-fast urls]
www.rebol.net www.microsoft.com ** Access Error: Port none not open ** Where: get-fast ** Near: either error? err: try [read-io port data max-transfer] What's up with that? Enjoy!! ~~Ammon ;~>

 [3/12] from: warp:reboot:ch at: 4-Mar-2004 17:27


yeap, I did get those errors, but rarely. Must have something to do with: clear system/ports/wait-list but than I would appreciate Gabriele or Marteen opinion on why that should not be done, and what is the right way to do it. Thanks, Will On 4 mar 2004, at 16:42, Ammon Johnson wrote:

 [4/12] from: ammon:addept:ws at: 4-Mar-2004 9:53


Oh, and then you have to start with a clean console session cause it gives you this error if you try to run it again...
>> loop 10 [get-fast urls]
** User Error: Internal error: recursive call to on-data: should not happen! ** Near: make error! {Internal error: recursive call to on-data: should not happen!} Enjoy!! ~~Ammon ;~>

 [5/12] from: g:santilli:tiscalinet:it at: 4-Mar-2004 18:07


Hi Will, On Thursday, March 4, 2004, 5:27:04 PM, you wrote: WA> Must have something to do with: WA> clear system/ports/wait-list WA> but than I would appreciate Gabriele or Marteen opinion on WA> why that should not be done, and what is the right way to WA> do it. When you close the port, the sub-port is automatically removed from the wait-list. I'd recommend you not touching the wait-list directly... You just need to close all the async ports. Regards, Gabriele. -- Gabriele Santilli <[g--santilli--tiscalinet--it]> -- REBOL Programmer Amiga Group Italia sez. L'Aquila --- SOON: http://www.rebol.it/

 [6/12] from: rotenca:telvia:it at: 4-Mar-2004 21:01


Hi, Will I should write it in the following mode. Some notes: 1) you can set the awake function using make port! port: make port! [scheme: 'async host: hst port-id: 80 awake: :handl] you cannot use the words 'host or 'handler because the block is bound to the port before execution (like in an object!: a port is an object!) 2) you can insert a string BEFORE connection is done: you must not wait the 'connect event open port insert port rejoin [{GET / HTTP/1.0} crlf {Host: } port/host crlf crlf] 3) you should not clear the system/ports/wait-list, it can contain some others ports (like event port in View). Here i read the length? before the start and wait until it is returned the same, but it is not the best solution: --------- rebol [] do http://www.rebol.it/giesse/async-protocol.r get-fast: func [hosts /local port len][ len: length? system/ports/wait-list foreach hst hosts [ port: make port! [scheme: 'async host: hst port-id: 80 awake: :handl] open port insert port rejoin [{GET / HTTP/1.0} crlf {Host: } port/host crlf crlf] ] until [wait .1 len = length? system/ports/wait-list] ] handl: func [port [port!] state [word! error!]] [ if error? :state [print mold disarm state return true] switch state [ connect [false] read [false] write [false] close [ data: copy port close port print [port/host length? data] true ] ] ] ;example urls: [ www.rebol.com www.rebol.net www.rebol.org www.apple.com www.oracle.com www.microsoft.com ] loop 5 [get-fast urls] halt --- Ciao Romano

 [7/12] from: warp:reboot:ch at: 5-Mar-2004 8:21


Romano, Gabriele and Ammon, thank you for the feedback! I've done 2 variations of the original and put some comments. You can find them here: http://reboot.ch/space/get-fast Will

 [8/12] from: rotenca:telvia:it at: 5-Mar-2004 12:55


Hi Will, about the crash with not found address: they are not supported. The async:// protocol is simply "unfinished" as is stated in the Rebol header. Must be changed the protocol to make it work. Here it is a VERY FAST patch, to be tested: on-resolve: func [dnsport port] [ either port/host: scopy dnsport [ change wait-find dnsport port sclose dnsport port/awake port false ] [ wait-stop dnsport sclose dnsport port/user-data/awake port make error! "Host not found" true ] ] In Async code I added 3 functions also for users: wait-start wait-stop wait-find to handle insert/remove/find of ports in system/ports/ wait-list. perhaps i should call them wait-insert wait-remove wait-find ? --- Ciao Romano

 [9/12] from: maarten:vrijheid at: 5-Mar-2004 15:27


Hi Romano (and Gabriele),
>about the crash with not found address: they are not supported. >The async:// protocol is simply "unfinished" as is stated in the Rebol header. >
Don't you think it would be a good idea to post it to rebol.org, so everybody gets noticed of little bugfixes and enhancements? Surely async:// adds enough to REBOL to let people use it/enhance it. --Maarten

 [10/12] from: rotenca:telvia:it at: 5-Mar-2004 18:16


Hi Maarteen,
> Don't you think it would be a good idea to post it to rebol.org, so > everybody gets noticed of little bugfixes and enhancements? Surely > async:// adds enough to REBOL to let people use it/enhance it.
That was a fast patch, here it is a correction. The dns://async port seems to have some strange problems, this this a workaround: on-resolve: func [dnsport port] [ either port/host: scopy dnsport [ change wait-find dnsport port sclose dnsport port/awake port false ] [ wait-stop dnsport port/user-data/awake port make error! "Host not found" true ] ] About rebol.org. I have another version of async deeply changed. But it is not ready for a release. --- Ciao Romano

 [11/12] from: maarten:vrijheid at: 5-Mar-2004 18:47


>About rebol.org. I have another version of async deeply changed. But it is not >ready for a release. >
I know that :-) The thing is that this is one of the most wanted features with the Plugin from the last 2-3 years. So when you *do* feel it is ready for release..... That's why I wrote the tutorial based on the currently published version: it adds so much value for some of us in some situations. And we still need to wipe out .NET ;-) --Maarten

 [12/12] from: rotenca:telvia:it at: 5-Mar-2004 22:00


> That was a fast patch, here it is a correction. The dns://async port seems
to
> have some strange problems, this this a workaround:
The workaround does not work perfectly. I am not able until now to understand when/where the bug happens. It seems to me that under some conditions (dns:///async failure) the port event system starts to be instable. --- Ciao Romano