Request: ReadAvail

BlitzMax Forums/BlitzMax Programming/Request: ReadAvail

rdodson41(Posted 2007) [#1]
Could a ReadAvail method be added to the TStream class that returns the number of bytes of input that can be read without blocking? I think this would be useful for various things including networking and stuff.


FlameDuck(Posted 2007) [#2]
You cannot read anything "without blocking". When you make an IO request, your current thread switches state from "Running" to "IO". The only way to do non-blocking IO is using multithreading, where you main thread remains in the running state, and the IO is handled by worker threads, with either a callback (ideally) to the main thread (.Net style) or by using messages (Java style).

Anyway to get back on track, I don't think Streams are buffered by default, so a ReadAvail wouldn't make much sense. Sockets are tho' IIRC.


rdodson41(Posted 2007) [#3]
Okay thanks, but I know there was a ReadAvail() function in BlitzPlus for streams that did this, how did that work then?


FlameDuck(Posted 2007) [#4]
I wouldn't know as I don't have the source code for BlitzPlus. If I were a gambling man I would say that BlitzPlus streams are buffered.


Koriolis(Posted 2007) [#5]
I second the request for a ReadAvail method.