Notice (2018-05-24): bugzilla.xamarin.com is now in
Please join us on
Visual Studio Developer Community and in the
Mono organizations on
GitHub to continue tracking issues. Bugzilla will remain
available for reference in read-only mode. We will continue to work
on open Bugzilla bugs, copy them to the new locations
as needed for follow-up, and add the new items under Related
Our sincere thanks to everyone who has contributed on this bug
tracker over the years. Thanks also for your understanding as we
make these adjustments and improvements for the future.
Please create a new report on
Developer Community or GitHub with
your current version information, steps to reproduce, and relevant error
messages or log files if you are hitting an issue that looks similar to
this resolved bug and you do not yet see a matching new report.
Java's InputStream from BluetoothSocket is indirectly mapped into System.IO.Stream.
How then I can use java's is.available() to detect if there is any data in the stream?
There is no direct mapping for such a logic in the System.IO.Stream.
> We're wondering why you need polling access to the stream. InputStream.available() is documented as not being very useful:
I'm not sure why android's version of javadoc includes this passage. But from common sense - the available() method's efficiency depends etirely on the underlying implementation. And in case of network streams and bluetooth streams (which are BTW essentially the same nature) - data availability check is a common sence. Even .net's NetworkStream has its DataAvailable.
I mean yes, think I can workaround this by creating a separate thread and data queue (or using BeginRead), and essentially implementing my own buffering logic and available() check. But thats just another layer over the data stream abstraction - because network and bluetooth streams are for sure already contains internal queue/buffer.
> In particular, is there a reason you don't want to use Stream.BeginRead() or some other async mechanism? Why do you need polling?
We need polling because our current interaction model is based on polling.
> If there's a good need for polling, we're considering providing a `bool DataAvailable(this Stream stream)` extension method (thus translating the dubious `int` InputStream.available() return value into a `bool`, and this mechanism could also check for NetworkStream and return NetworkStream.DataAvailable), but before we provide this we'd like to know how useful it actually is.
Think thats logical to provide access to the information underlying stream already has. I was just surprised abit that no direct api mapping was done here. I understand InputStream and IO.Stream are different, but still.
Commit 765cf184 adds accessors to the underlying types to the relevant wrappers, e.g. there will be an Android.Runtime.InputStreamInvoker.BaseInputStream property of type Java.IO.InputStream.
Currently you'd still need to do a runtime check to see if the Stream is an InputStreamInvoker before calling invoker.BaseInputStream.Available(), but it'll be possible.
Commit 146fa7f6 adds a Stream.IsDataAvailable() extension method.
I renamed it from `DataAvailable` so that if the source type is a NetworkStream then DataAvailable and IsDataAvailable can be used independently, as DataAvailable is a property while IsDataAvailable() is a method.
I have checked this issue on following builds:
Xamarin Studio : 4.2.3 (build 60)
Xamarin.Android : 4.13.0 (Business Edition)
Now I am getting InputStream.Available() directly. Hence, I am closing this issue.