Bombus - mobile Jabber client (J2ME)

Bombus - mobile Jabber client

Sources: http://bombus-im.org/wiki/bombus/svn

!!! ВНИМАНИЕ !!! Убедительная просьба перед занесением багрепорта ознакомиться с правилами. Правильно оформленный отчёт об ошибке - залог быстрого её исправления. Спасибо!

Задачи

FS#858 — Problematic InputStream.available() on some Samsung devices (patch)

Присоединено проекту — Bombus - mobile Jabber client (J2ME)
Открыто Krzysztof Kotlenga (pocek_) - Saturday, 09 August 2008, 10:51 GMT+1
Тип задачи Ошибка
Категория Основные функции
Статус Не подтверждено
Назначено Никто
ОС MIDP2.0 базовая
Важность Высокая
Приоритет Нормальный
Обнаружено в версии 0.7-devel
Ожидается в версии Не решено
Срок Не решено
Завершённость 0%
Голоса 1
Приватная задача Нет

Подробности

On some Samsung devices[1] connection hangs on “Opening stream”, sometimes it throws “java.io.InterruptedIOException: available was failed”, sometimes it just hangs. Problem relies in Utf8IOStream.read() where InputStream.available() is used.

According to InputStream.available() description this method always returns 0, so I don’t really understand how it’s supposed to work anyway (and apparently it does, at least on most devices). I see it could work when called on ZInputStream which simply returns bufsize (512), but it’s there only after Utf8IOStream.setStreamCompression() is called.

I have made a workaround by removing 512 bytes buffer and directly coupling reader with parser: bombus-direct-parsing.diff - there’s no need to call available() and it works.

[1]

Задача зависит от

Комментарий от Eugene (EvgS) - Saturday, 09 August 2008, 12:30 GMT+1

FYI, ZInputStream also polls InputStream.available() (see ZInputStream.java:95)

Actually, InputStream is absctract class and can’t be used directly to create InputStream object. Most phones that i tested has overriden available() method in InputStream object provided by StreamConnection.openInputStream() and works fine.

If ZLib compression (using available polling as said before) works fine with your patch, then problem may exists only when reading very first data from socket.

Комментарий от Eugene (EvgS) - Saturday, 09 August 2008, 12:41 GMT+1

I won’t remove polling socket because of two reasons:

  1. buffered parsing works much faster
  2. blocking reading hangs in some cases on Motorola phones

I suppose another way to fix this problem - disabling available() polling just for Samsung

Комментарий от Krzysztof Kotlenga (pocek_) - Monday, 11 August 2008, 14:08 GMT+1

Thanks for your explanation. With ZLib compression enabled I get “Exception in parser: com.jcraft.jzlib.ZStreamException: inflating: unknown compression method” on emulator, didn’t test on the phone. I was unable to track down why this happens; maybe it’s something with reading single byte in ZInputStream.read().

I did some tests using modified NetworkDemo and found that:

  • available() always throws an exception and doesn’t hang as I thought before (good news)
  • It’s not a problem with reading very first data - I’ve tried reading before calling available(), with and without available data in a stream and it always failed
  • Due to this, I guess ZInputStream also has to be modified to fall back to non-buffered approach
Комментарий от Krzysztof Kotlenga (pocek_) - Tuesday, 12 August 2008, 01:01 GMT+1

Better patch: bombus-blocking2.diff

  1. Buffered parsing stays untouched
  2. ZLib doesn’t work only* because of threading issues - first Utf8IOStream.setStreamCompression() is called, but before ZInputStream is in place JabberStream thread does its loop-read and passes compressed data to parser from “old” inpStream. I hope it’s easy to solve for someone who knows threads better
  3. This way it should be actually faster than current polling approach - no 100 ms delay
  4. It’s simple

* except available() being still there but I’d like to solve that threading issue first

Комментарий от Eugene (EvgS) - Saturday, 16 August 2008, 14:21 GMT+1

unfortunately blocking reading will break compatibility with motorola devices - read(byte[], int, int) sometimes hangs when bombus was backgrounded. so available() should still be used at least for motorola :(

Загрузка...