Hooks while File I/O?

BlitzMax Forums/BlitzMax Programming/Hooks while File I/O?

Garfield(Posted 2013) [#1]
I´m dealing with hooks since 2 days and have experiences with some Gadgetactions now. I´m using the eventhandler example they showed in many posts here.
It works with EVENT_TIMERTICK too.
But I can´t get a hook into a function while File I/O is in progress.
like this:
	While Not Eof(stream)
		WriteByte(file,ReadByte(stream))
		counter = counter+1
	Wend 


I´ve created a timer with 500 Hz. But no hook occurs to update my progress bar.

Inside my function EventHandler - tho hook: AddHook EmitEventHook,EventHandler
[code]
Case timer_progbar
Local zzz = 1/800*((filelength/800)/(filelength-counter))
Print "<--> "+zzz
UpdateProgBar statusbar,zzz
[/code)

Is there any chance to hook inside a standard File I/O?


col(Posted 2013) [#2]
One suggestion would be to use a method that allows the code to flow right through your whole main loop, maybe using a 'state' flag to signify your code to follow the 'loading path', which could look something like this pseudo code...

If STATE_LOADING
	If Not Eof(stream)
		WriteByte(file,ReadByte(stream))
		counter :+ 1
	Else
		STATE_LOADING = false
	EndIf
EndIf


ps If you just want to update the progress bar have you tried using updateprogbar inside your while...wend loop.


Garfield(Posted 2013) [#3]
Hi Dave,

update progbar won´t work inside this loop.
The problem isn´t the while wend, in "normal" while wend everything works fine. But with this "system-near" command like writebyte f.e., it seems the OS takes full control and blocked everything.
I´ve tried this since the GUI appears with BlitzPlus.
But now I had a little hope to deal this with a hook. Hooks are stuff I never tried before, because my programms wasn´t realtime sensitive, that wasn´t important for me.

The other way You suggest, maybe, but I´m inside a function that opens sockets and streams to get a file from a website. I´m not shure if this is a good idea to leave these flow. The writing into open streams to deal with the server at the other side, causes the same problems, the program seems to be "hanged". only a few prints to the output for control appears very slowly and shows that my prog is out of control while dealing with the server and getting the bytes.

Greetings from Berlin

Winfried


col(Posted 2013) [#4]
Hiya,

Have you tried putting a Delay 1 inside your while..wend. Its unlikely but worth a try just incase the readbyte and writebyte may be executing fast enough to block the cpu from other activities.


Brucey(Posted 2013) [#5]
Other possible options are :

* Run your stream stuff in a separate thread, so that blocking is not so problematic to the rest of your application.

* Use a third-party library such as libcurl which is designed for doing stuff with files over the internet. It supports non-blocking streaming, as well as progress hooks (via callback functions).


Garfield(Posted 2013) [#6]
Hi Brucey,

thanks. Oh my good, libcurl is what I need.
But how to understand?

almost only two lines doing ALL:

webdings.setOptString(CURLOPT_URL, "http://*****.****")

Local res:Int = webdings.perform()

is there a "simple" documentation out anywhere?
That reaches my horizon almost immediately .