Guiserver none-blocking question

Guiserver, GTK-server, OpenGL, PostScript,
HTML 5, MIDI, IDE
Locked
newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

Guiserver none-blocking question

Post by newdep »

Hi Lutz,

I seem to be unable to get my network functions work together with guiserver.

I use net-peek and/or net-select but its or the guiserver or the network
that is working, but never both...

My program is unable to and do copy from text area's
and listen handle network data... I expected this though but i did not expect
that i could not fix it.. :-)

Do i need to create my own gs:listen to get blocking network events working
together with guiserver?


PS: perhpas gs:listen could get a net-select inside its function?
so that other actions from the script can continue?


Norman.
-- (define? (Cornflakes))

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

Do i need to create my own gs:listen to get blocking network events working together with guiserver?
it depends on the circumstances. For closed transactions like http requests which are initiated and finished in an action handler, there should not be a problem, but if you have your own blocking net work stuff going then yes you have to prep up the gs:net-listen function.

Look at the definition of it inside guiserver.lsp inside the gs context:

Code: Select all

(define (listen flag)
    (while (net-receive in 'event 100240 "\n")
        (eval-string event))
    (println "server shut down")
    (if (not flag) (exit))
)
As you can see, its really simple. Build your own and as you say: use net-select to contsruct a loop where both the even-requests coming from guisever and your own network stuff is served.

Note that the (eval-string event) has to happen inside the gs context. When you run your own loop perhaps you define inside gs:

Code: Select all

(define (eval-event str)
	(eval-string str))
and then in your code in some other context you do:

Code: Select all

(while listening
	(if (net-select gs:in "read" 10000)
		(begin
			(net-receive gs:in 'event 100240 "\n")
			(eval-event event)
		)
	)
	(if (net-select myport "read" 10000)
		(do-my-thing))
)
perhaps we make a little API around this, something like:

Code: Select all

(while my-loop-is-running
	(gs:check-for-events)
	(if (net-select myport "read" 10000)
		(do-my-thing))
)
gs:check-for-events then will do the net-select for gs:in and read and fire the event if necessary.

I am open to suggestions ...

Lutz

newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

Post by newdep »

Yes oke..thanks...

I think we need indeed a kind of "insert" mechanism towards the gs:listen function.. to work around this...

perhpas gs:listen could accept a list which contains all functions that
should be used given with gs:listen... else return 'nil...


(gs:listen '( (function-one-blocking timeout) (function-two-blocking timeout) ) true|none )

Then put them all inside a net-select with the specific timeout defined..

I need to think this over ;-)
-- (define? (Cornflakes))

newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

Post by newdep »

addon: Unable to get a nice synchrone event ;-)
Its now working but I need 1 step extra interaction with the
gui-server to get the networking to receive data..hehehe..

ill do that tomorrow..

Norman.
-- (define? (Cornflakes))

Locked