1. Attn: Robert (Non-Blocking Support Revisited)

Hello Robert,

As you know I have been pushing for non-blocking support to be added to EU for
quite sometime. I have tried some of the suggested alternatives with no avail.
Certain libraries/dlls I use do not work with the alternatives you and others
suggested. I can pretty much do everything I need with EU, but non-blocking
support is the only hurtle that I have yet to overcome. In the past I have been
able to find workarounds, but I am increasingly finding it more difficult to find
suitable alternatives. Is there any way I can persuade you to begin work on
officially adding non-blocking support to EU?

~C Bouzy

"If you do what you have always done, you will get what you always got."

new topic     » topic index » view message » categorize

2. Re: Attn: Robert (Non-Blocking Support Revisited)

I second the motion!!!!!

Chris, specifically what problems were you running into using TDLL or the like?

Jonas Temple
http://www.innovativesys.net

new topic     » goto parent     » topic index » view message » categorize

3. Re: Attn: Robert (Non-Blocking Support Revisited)

Hello Jonas,

One library in particular is bass. The function BASSStreamCreateURL will not
work with TDLL.

~Chris

"If you do what you have always done, you will get what you always got."

new topic     » goto parent     » topic index » view message » categorize

4. Re: Attn: Robert (Non-Blocking Support Revisited)

C Bouzy wrote:
> Hello Robert,
> 
> As you know I have been pushing for non-blocking support to be added to EU for
> quite sometime. I have tried some of the suggested alternatives with no avail.
> Certain libraries/dlls I use do not work with the alternatives you and others
> suggested. I can pretty much do everything I need with EU, but non-blocking
> support is the only hurtle that I have yet to overcome. In the past I have
> been
> able to find workarounds, but I am increasingly finding it more difficult to
> find suitable alternatives. Is there any way I can persuade you to begin work
> on officially adding non-blocking support to EU? 

I haven't started on this yet.
All I was hoping to do was somehow wrap the asynchronous I/O
capabilities of the WIN32 ReadFileEx and WriteFileEx routines,
and add a couple of easy-to-use Euphoria library routines 
(in an include file). Other people could also try to do this. 
I'm not sure if any Euphoria-internal C-code is needed.
It would complement Euphoria's cooperative multitasking
capabilities if there was a way for a task to start some I/O
and then poll periodically for completion, while other tasks 
are free to run. I would also try to implement the same
functionality on Linux/FreeBSD. Another possibility is for
a call-back to occur upon I/O completion, but somehow polling
seems to fit nicer with Euphoria's multitasking.

I haven't looked at Daniel's latest SDLL yet,
though I definitely should, before starting to work on this.

In general, I think we need some time to experiment
before trying to package this stuff officially.

> Hello Jonas,
>
> One library in particular is bass. The function BASSStreamCreateURL will not
> work with TDLL.

I have no idea if what I am planning would solve this problem
for you. Maybe you can experiment by trying to somehow wrap 
ReadFileEx/WriteFileEx by yourself. It actually looks a bit more 
complicated than I imagined at first.

Regards,
   Rob Craig
   Rapid Deployment Software
   http://www.RapidEuphoria.com

new topic     » goto parent     » topic index » view message » categorize

5. Re: Attn: Robert (Non-Blocking Support Revisited)

> One library in particular is bass. The function BASSStreamCreateURL will not
> work with TDLL.
> 

What does it "not" do?  Does your program bomb?  If you like, I could take a
look at the code.  I'm about to release an update to my FROG database utility
that uses the new task features in Eu and Daniel's TDLL and everything is working
just fine.

Jonas Temple
http://www.innovativesys.net

new topic     » goto parent     » topic index » view message » categorize

6. Re: Attn: Robert (Non-Blocking Support Revisited)

Hello Jonas,

The function just does not work with TDLL, you are free to download bass from
the EU archives and test the function. Actually there is an example included in
the download package called NetRadio.exw which would make things easier for you.

~Chris

"If you do what you have always done, you will get what you always got."

new topic     » goto parent     » topic index » view message » categorize

7. Re: Attn: Robert (Non-Blocking Support Revisited)

One of the main reasons for wanting non-blocking support is
so a program can access a URL and not get stuck waiting for the
download to occur (or time-out).

The Linux/FreeBSD distribution has this "news.exu" multitasking
demo, which also runs on Windows, provided you have wget.exe
in the current directory, or on your PATH.
In the next release I'll include it in the Windows installation as well.
This might be useful for some people, until we have something better.

-- news.exu: Search news pages

-- All this demo does is read several Web pages in parallel 
-- and report on the number of occurences of a word or phrase.
-- Each page is handled by a separate Euphoria task running
-- in parallel with several other tasks.

-- usage:
--    exw news.exu string
-- or:
--    exw news.exu "a multi-word phrase"
-- (case insensitive search)

-- On Linux/FreeBSD use exu instead of exw.

-- This demo uses Euphoria's new multitasking feature. It can run
-- on Linux, FreeBSD, or Windows, without change.
-- It creates multiple wget background processes, each retrieving one Web page.

-- You can get a version of wget for Windows from:
-- http://www.gnu.org/software/wget/wget.html
-- Linux and FreeBSD systems will probably already have it.

-- A Euphoria task is assigned to each instance of wget, searching the 
-- Web page text as it arrives. In this way, when a task is blocked due 
-- to a delayed response from a particular server, the program can easily 
-- switch to another task that is not blocked. The program quits after a 
-- period of 10-15 seconds with no progress made on any page.

include wildcard.e
include graphics.e

sequence cl
sequence search_phrase

cl = command_line()
if length(cl) >= 3 then
    search_phrase = cl[3]
else
    puts(1, "Usage:\n")
    puts(1, "       exw news search-phrase\n")
    if getc(0) then
    end if
    abort(1)
end if

-- news sources
sequence URLs
URLs = {
    "http://www.cbc.ca/news/",
    "http://www.juancole.com/",
    "http://www.abc.net.au/",
    "http://abcnews.go.com/",
    "http://english.aljazeera.net/HomePage",
    "http://news.bbc.co.uk/",
    "http://www.cbsnews.com/",
    "http://cnn.com/",
    "http://www.democracynow.org/index.pl",
    "http://www.foxnews.com/",
    "http://www.guardian.co.uk/",
    "http://www.msnbc.msn.com/",
    "http://www.reuters.com/",
    "http://www.whatreallyhappened.com/",
    "http://news.yahoo.com/"
}

sequence null_device, del_cmd

if platform() = LINUX then
    URLs = URLs[1..9] -- less room on screen
    null_device = "/dev/null"
    del_cmd = "rm"
else
    null_device = "NUL"
    del_cmd = "del"
end if

integer progress, quit

procedure search_url(sequence url, sequence string)
-- download a Web page and search it for a string   
    integer f, hits
    integer line_count
    object line
    sequence mytemp, ustring
    
    if task_self() > 20 or task_self() < 0 then
        printf(1, "\n1. my task id is rubbish: %g\n", task_self())
        if getc(0) then
        end if
        abort(0)
    end if
    
    position(task_self()*2+1, 1)
printf(1, "task %2.0f: %s\n         waiting for wget...", {task_self(),
    url})
    
    ustring = upper(string)
    hits = 0
    
    -- run a copy of wget as a background process
    mytemp = sprintf("newstemp%.0f.html", task_self())
    system(sprintf("wget -q -b -O %s %s > %s", {mytemp, url, null_device}), 2)
    
    f = -1
    while f = -1 do
        -- wait until file exists
        if quit then
            return
        end if
        if task_self() > 20 or task_self() < 0 then
            printf(1, "\n2. my task id is rubbish: %.0f\n", task_self())
            if getc(0) then
            end if
            abort(0)
        end if
    
        task_schedule(task_self(), {1.0, 2.0})
        task_yield()
        f = open(mytemp, "rb")
    end while

    position(task_self()*2+2, 1)
    text_color(BRIGHT_RED)
    puts(1, "         waiting for data...")
    text_color(WHITE)
    
    line_count = 0
    while 1 do
        line = gets(f)
        if atom(line) then
            -- could be actual end-of-file, or maybe there's more coming
            task_schedule(task_self(), {1.0, 1.5})
            while 1 do
                line = gets(f)
                if sequence(line) then
                    exit -- more data came in
                end if
                if quit then
                    return -- we've been told to quit
                end if  
                task_yield()
            end while
        end if
        
        if match(ustring, upper(line)) then
            hits += 1
        end if
        
        line_count += 1
        position(task_self()*2+2, 1)
        text_color(BRIGHT_GREEN)
        printf(1, "         matched %d lines out of %d   ", {hits, line_count})
        text_color(WHITE)
        progress = 1
        -- this yield is not necessary, but it 
        -- lets you see the parallelism better
        task_schedule(task_self(), 1)
        task_yield()
    end while
end procedure

integer t

for i = 1 to length(URLs) do
    t = task_create(routine_id("search_url"), {URLs[i], search_phrase})
    task_schedule(t, 1)
end for

system(del_cmd & " newstemp*.html > " & null_device, 2)
clear_screen()
if text_rows(43) then
end if
puts(1, "Looking for lines containing \"" & search_phrase & "\"")

atom time_out
time_out = time() + 45
task_schedule(0, {2.5, 3.0}) -- check the time every 2.5 to 3.0 seconds

quit = 0
while 1 do
    progress = 0
    task_yield()
    if progress then
        -- quit 10 seconds after no more lines are read
        -- from any file by any task
        time_out = time() + 10
    else
        if time() > time_out then
            exit
        end if
    end if
end while

quit = 1 -- signal all tasks to report any final results and terminate

while length(task_list()) > 1 do
    task_yield()
end while

position(2*length(URLs)+3, 1)
puts(1, "\nAll Done.\n")

if getc(0) then
end if

system(del_cmd & " wget-log* > " & null_device, 2)


Regards,
   Rob Craig
   Rapid Deployment Software
   http://www.RapidEuphoria.com

new topic     » goto parent     » topic index » view message » categorize

8. Re: Attn: Robert (Non-Blocking Support Revisited)

I noticed there was still some old debug code in there.
Here's a cleaner version with a dozen lines of 
debug code stripped out ...

-- Search news pages

-- All this demo does is read several Web pages in parallel 
-- and report on the number of occurences of a word or phrase.
-- Each page is handled by a separate Euphoria task running
-- in parallel with several other tasks.

-- usage:
--    exw news.exu string
-- or:
--    exw news.exu "a multi-word phrase"
-- (case insensitive search)

-- On Linux/FreeBSD use exu instead of exw.

-- This demo uses Euphoria's new multitasking feature. It can run
-- on Linux, FreeBSD, or Windows, without change.
-- It creates multiple wget background processes, each retrieving one Web page.

-- You can get a version of wget for Windows from:
-- http://www.gnu.org/software/wget/wget.html
-- Linux and FreeBSD systems will probably already have it.

-- A Euphoria task is assigned to each instance of wget, searching the 
-- Web page text as it arrives. In this way, when a task is blocked due 
-- to a delayed response from a particular server, the program can easily 
-- switch to another task that is not blocked. The program quits after a 
-- period of 10-15 seconds with no progress made on any page.

include wildcard.e
include graphics.e

sequence cl
sequence search_phrase

cl = command_line()
if length(cl) >= 3 then
    search_phrase = cl[3]
else
    puts(1, "Usage:\n")
    puts(1, "       exw news.exu search-phrase\n")
    if getc(0) then
    end if
    abort(1)
end if

-- news sources
sequence URLs
URLs = {
    "http://www.cbc.ca/news/",
    "http://www.juancole.com/",
    "http://www.abc.net.au/",
    "http://abcnews.go.com/",
    "http://english.aljazeera.net/HomePage",
    "http://news.bbc.co.uk/",
    "http://www.cbsnews.com/",
    "http://cnn.com/",
    "http://www.democracynow.org/index.pl",
    "http://www.foxnews.com/",
    "http://www.guardian.co.uk/",
    "http://www.msnbc.msn.com/",
    "http://www.reuters.com/",
    "http://www.whatreallyhappened.com/",
    "http://news.yahoo.com/"
}

sequence null_device, del_cmd

if platform() = LINUX then
    URLs = URLs[1..9] -- less room on screen
    null_device = "/dev/null"
    del_cmd = "rm"
else
    null_device = "NUL"
    del_cmd = "del"
end if

integer progress, quit

procedure search_url(sequence url, sequence string)
-- download a Web page and search it for a string   
    integer f, hits
    integer line_count
    object line
    sequence mytemp, ustring
    
    position(task_self()*2+1, 1)
printf(1, "task %2.0f: %s\n         waiting for wget...", {task_self(),
    url})
    
    ustring = upper(string)
    hits = 0
    
    -- run a copy of wget as a background process
    mytemp = sprintf("newstemp%.0f.html", task_self())
    system(sprintf("wget -q -b -O %s %s > %s", {mytemp, url, null_device}), 2)
    
    f = -1
    while f = -1 do
        -- wait until file exists
        if quit then
            return
        end if
    
        task_schedule(task_self(), {1.0, 2.0})
        task_yield()
        f = open(mytemp, "rb")
    end while

    position(task_self()*2+2, 1)
    text_color(BRIGHT_RED)
    puts(1, "         waiting for data...")
    text_color(WHITE)
    
    line_count = 0
    while 1 do
        line = gets(f)
        if atom(line) then
            -- could be actual end-of-file, or maybe there's more coming
            task_schedule(task_self(), {1.0, 1.5})
            while 1 do
                line = gets(f)
                if sequence(line) then
                    exit -- more data came in
                end if
                if quit then
                    return -- we've been told to quit
                end if  
                task_yield()
            end while
        end if
        
        if match(ustring, upper(line)) then
            hits += 1
        end if
        
        line_count += 1
        position(task_self()*2+2, 1)
        text_color(BRIGHT_GREEN)
        printf(1, "         matched %d lines out of %d   ", {hits, line_count})
        text_color(WHITE)
        progress = 1
        -- this yield is not necessary, but it 
        -- lets you see the parallelism better
        task_schedule(task_self(), 1)
        task_yield()
    end while
end procedure

integer t

for i = 1 to length(URLs) do
    t = task_create(routine_id("search_url"), {URLs[i], search_phrase})
    task_schedule(t, 1)
end for

system(del_cmd & " newstemp*.html > " & null_device, 2)
clear_screen()
if text_rows(43) then
end if
puts(1, "Looking for lines containing \"" & search_phrase & "\"")

atom time_out
time_out = time() + 45
task_schedule(0, {2.5, 3.0}) -- check the time every 2.5 to 3.0 seconds

quit = 0
while 1 do
    progress = 0
    task_yield()
    if progress then
        -- quit 10 seconds after no more lines are read
        -- from any file by any task
        time_out = time() + 10
    else
        if time() > time_out then
            exit
        end if
    end if
end while

quit = 1 -- signal all tasks to report any final results and terminate

while length(task_list()) > 1 do
    task_yield()
end while

position(2*length(URLs)+3, 1)
puts(1, "\nAll Done.\n")

if getc(0) then
end if

system(del_cmd & " wget-log* > " & null_device, 2)


Regards,
   Rob Craig
   Rapid Deployment Software
   http://www.RapidEuphoria.com

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu