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

No-wait

 [1/18] from: ptretter:charter at: 22-Feb-2004 13:49


What is the purpose of no-wait. Doesn't seem work for me. Isn't no wait supposed to return immediately. For example: Shouldn't a forever loop that has the following code always be printing instead of only once the port has received data? port: open/direct/no-wait tcp://:7000 x: 0 forever [ print x + 1 x: x + 1 data: first wait port ] I would like to see it continuously printing the value of x instead of only after it receives data on the port. So what does no-wait accomplish? Paul Tretter

 [2/18] from: maarten:vrijheid at: 22-Feb-2004 21:18


No-wait modifies the behaviour of 'copy, not 'wait. Copy doesn't block, but returns immediately with an empty string if there is no data. BTW: I found that it works best to have buffering on in TCP ports. --Maarten Paul Tretter wrote:

 [3/18] from: ptretter:charter at: 22-Feb-2004 15:42


Problem is that when I try copy I get: * Script Error: Cannot use copy on this type port ** Where: forever ** Near: data: copy port Paul Tretter

 [4/18] from: petr:krenzelok:trz:cz at: 22-Feb-2004 23:09


Maarten Koopmans wrote:
>No-wait modifies the behaviour of 'copy, not 'wait. >Copy doesn't block, but returns immediately with an empty string if >there is no data. > >BTW: I found that it works best to have buffering on in TCP ports. >
Could you explain, please? I would not expect it being so ... -pekr-

 [5/18] from: maarten:vrijheid at: 22-Feb-2004 23:12


That *is* strange. --Maarten Paul Tretter wrote:

 [6/18] from: rotenca:telvia:it at: 23-Feb-2004 0:01


listen port are always wait (afaik) you should use the awake port field for async code --- Ciao Romano

 [7/18] from: ptretter:charter at: 22-Feb-2004 17:05


Seems strange to me also. I even tried the latest 1.3 build of /view and tried it and got same results. I expected it to behave as you described. Anyone else have that problem? Paul Tretter

 [8/18] from: andreas:bolka:gmx at: 23-Feb-2004 1:41


Sunday, February 22, 2004, 10:42:06 PM, Paul wrote:
> Problem is that when I try copy I get: > ** Script Error: Cannot use copy on this type port > ** Where: forever > ** Near: data: copy port
Your example was: port: open/direct/no-wait tcp://:7000 x: 0 forever [ print x + 1 x: x + 1 data: first wait port ; HERE ] At the point I marked with HERE, you have a _server_ port bound to the word 'port and a _client_ port bound to 'data. Basically, data: first wait port _accepts_ a new client. After HERE you can do copy on 'data, e.g.: tmp: copy data and copy will behave here, as Maarten described. -- Best regards, Andreas

 [9/18] from: ptretter:charter at: 22-Feb-2004 21:31


Even that still blocks. Need a way of not waiting for the port data if nothing is there. A way to just continue processing the rest of the forever loop which should be continously print the current value of x. Maybe, I need to see an example of something that works. Paul Tretter

 [10/18] from: nitsch-lists:netcologne at: 23-Feb-2004 11:51


Am Sonntag, 22. Februar 2004 20:49 schrieben Sie:
> What is the purpose of no-wait. Doesn't seem work for me. Isn't no wait > supposed to return immediately.
<<quoted lines omitted: 10>>
> I would like to see it continuously printing the value of x instead of only > after it receives data on the port. So what does no-wait accomplish?
return what is currently in the buffer. You want to use [ wait [port 0] ]. this returns when there is data on the port, or after 0 seconds. If it returns the port, there is data. so either port = wait [port 0][print "hey data"][print "dumdidumdidum.."] 0 is the wait-value, with [ wait [port 0:0:0.1 ] ] you would print 10* a second. (maybe you need to redcue, not checked)
> Paul Tretter >
-Volker

 [11/18] from: g:santilli:tiscalinet:it at: 23-Feb-2004 12:14


Hi Paul, On Monday, February 23, 2004, 4:31:01 AM, you wrote: PT> Even that still blocks. Need a way of not waiting for the port data if PT> nothing is there. A way to just continue processing the rest of the forever PT> loop which should be continously print the current value of x. Maybe, I PT> need to see an example of something that works. listen: open/no-wait tcp://:7000 listen/awake: func [port /local conn] [ print "Got connection" conn: first port ; do something with conn false ] insert tail system/ports/wait-list listen x: 0 forever [ print x: x + 1 wait 0.2 ] Regards, Gabriele. -- Gabriele Santilli <[g--santilli--tiscalinet--it]> -- REBOL Programmer Amiga Group Italia sez. L'Aquila --- SOON: http://www.rebol.it/

 [12/18] from: ptretter:charter at: 23-Feb-2004 6:41


Hey that works! Thanks Gabriele. Always wondered what away was for. :-) So when I think I hit a brick wall, I found another undocumented feature does the trick. How did you find out about awake? and sub-port as you use in async protocol? Paul Tretter

 [13/18] from: ptretter:charter at: 23-Feb-2004 6:43


Yeah this was my current work around to use 0 as a timeout but I was a wondering why it was needed if there was no-wait. Paul

 [14/18] from: petr:krenzelok:trz:cz at: 23-Feb-2004 15:19


Paul Tretter napsal(a):
>Yeah this was my current work around to use 0 as a timeout but I was a >wondering why it was needed if there was no-wait. >
It was not imo. Your code was imo wrong for what you wanted to achieve: port: open/direct/no-wait tcp://:7000 x: 0 forever [ print x + 1 x: x + 1 data: first wait port ] Do you know what above code is basically doing? You opened so called listen socket - TCP "channel" assigned to you by OS. That kind of socket is able to accept new connections, nothing more. One there is new client asking for connection, it simply assigns it other type of socket, so called communication socket. Just look at 'probe of given port and look for 'local-port item - that is the port assigned to you by OS. So basically - what did you expect your above code will do? I think I can tell you :-) Your 'forever loop will hang on, untill there is new connection coming. Just open second console and type-in: client: open tcp://127.0.0.1:7000 and your 'x will counter will be raised by 1 - You created nothing more, than connection counter. For that, you choosed wrong name 'data. I would suggest: console1: --------- server: open/direct/no-wait tcp://:7000 conn: first wait server forever [ wait conn data: copy conn print mold data ] console2: --------- client: open tcp://127.0.0.1:7000 data: read %user.r forever [ insert client data wait 5 ] Just copy and paste and watch your simple client/server communication ..... you can put your console code in another loop, which will be able to accept several connection, wait on list of clients connected and voila, - you've got your tcp multiplexing engine running. Wouldn't above short description/example make it for short beginner's tutorial? :-) ... except the fact, that I am beginner too :-) Cheers, -pekr-

 [15/18] from: andreas:bolka:gmx at: 23-Feb-2004 18:43


Monday, February 23, 2004, 4:31:01 AM, Paul wrote:
> Even that still blocks. Need a way of not waiting for the port data > if nothing is there.
But here, only the "accept" (i.e. the wait on the listen port) blocks. You can overcome this by adding a "timeout": port: open/direct/no-wait tcp://:7000 x: 0 forever [ print x + 1 x: x + 1 if not none? tmp: wait reduce [ port 0.02 ] [ data: first tmp ; data is bound to a "client" port ] ] -- Best regards, Andreas

 [16/18] from: ptretter:charter at: 23-Feb-2004 14:47


Yeah Pekr, I was aware of what was returned by the port and was just using it as an example. I did write a small beginner tutorial for that covered here: http://www.rebol.net/cookbook/recipes/0034.html However, I was using the small reference of code to demonstrate the blocking aspect of the port despite no-wait. So I have a fix for my problem but not a good definition of what no-wait does. From /core docs: Nowait port will not wait for data However it seems that the port does sit and wait. Paul

 [17/18] from: andreas:bolka:gmx at: 23-Feb-2004 23:07


Monday, February 23, 2004, 9:47:33 PM, Paul wrote:
> However, I was using the small reference of code to demonstrate the > blocking aspect of the port despite no-wait. So I have a fix for my > problem but not a good definition of what no-wait does. From /core > docs: > Nowait port will not wait for data > However it seems that the port does sit and wait.
It does not. 'wait will not block on the client port, but only on the server port. Use 'wait on the server port with a timeout value (e.g. 0.02) if you don't want to block while waiting for a client to connect. -- Best regards, Andreas

 [18/18] from: ptretter:charter at: 23-Feb-2004 17:16


Excellent, Finally got the answer to it. I knew there had to be a purpose. I tried an example: fetch: open tcp://www.rebol.com:80 copy fetch fetch: open/no-wait tcp://www.rebol.com:80 copy fetch Good, now I know to only use no-wait for client ports. Thanks Andreas. Paul Tretter

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted