[android-developers] How to interrupt a blocking I/O operation?
I'm wondering what the currently suggested method is for interrupting a read operation of a socket input stream? I know that traditionally the read could be interrupted by closing the socket from another thread and catching an IOException, but I'm not quite sure how to get at the socket from the apache classes. Maybe I should use some sort of interruptible channel instead ... ? Any links or help is greatly appreciated. My code looks like this -- minus most of the error handling: org.apache.http.impl.client.DefaultHttpClient org.apache.http.client.methods.HttpGet org.apache.http.HttpResponse DefaultHttpClient client = new DefaultHttpClient(httpParameters); HttpGet request = new HttpGet(Uri); HttpResponse response = client.execute(request); InputStream entityStream = response.getEntity().getContent(); try { bytesRead = entityStream.read(data); } catch (IOException ex) { } -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] How to interrupt a blocking I/O operation?
You could try closing the input stream - that should propagate to the socket. 07.01.2011 20:07, ivan пишет: I'm wondering what the currently suggested method is for interrupting a read operation of a socket input stream? I know that traditionally the read could be interrupted by closing the socket from another thread and catching an IOException, but I'm not quite sure how to get at the socket from the apache classes. Maybe I should use some sort of interruptible channel instead ... ? Any links or help is greatly appreciated. My code looks like this -- minus most of the error handling: org.apache.http.impl.client.DefaultHttpClient org.apache.http.client.methods.HttpGet org.apache.http.HttpResponse DefaultHttpClient client = new DefaultHttpClient(httpParameters); HttpGet request = new HttpGet(Uri); HttpResponse response = client.execute(request); InputStream entityStream = response.getEntity().getContent(); try { bytesRead = entityStream.read(data); } catch (IOException ex) { } -- Kostya Vasilyev -- WiFi Manager + pretty widget -- http://kmansoft.wordpress.com -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] How to interrupt a blocking I/O operation?
Well, HttpClient doesn't use sockets directly, so you would not be able to close the corresponding sockets. The execute method is actually the method that is blocking for the first time. You can look at the underlying request classes like HttpPost and HttpGet. Both of them are subclasses of HttpRequestBase class which has an abort method. May that would help. Another way, might be to specify the timeout to a few seconds. :) Kumar Bibek http://techdroid.kbeanie.com http://www.kbeanie.com On Fri, Jan 7, 2011 at 10:37 PM, ivan istas...@gmail.com wrote: I'm wondering what the currently suggested method is for interrupting a read operation of a socket input stream? I know that traditionally the read could be interrupted by closing the socket from another thread and catching an IOException, but I'm not quite sure how to get at the socket from the apache classes. Maybe I should use some sort of interruptible channel instead ... ? Any links or help is greatly appreciated. My code looks like this -- minus most of the error handling: org.apache.http.impl.client.DefaultHttpClient org.apache.http.client.methods.HttpGet org.apache.http.HttpResponse DefaultHttpClient client = new DefaultHttpClient(httpParameters); HttpGet request = new HttpGet(Uri); HttpResponse response = client.execute(request); InputStream entityStream = response.getEntity().getContent(); try { bytesRead = entityStream.read(data); } catch (IOException ex) { } -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.comandroid-developers%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] How to interrupt a blocking I/O operation?
@Kostya: The execute method is blocked till the server sends a request. Closing the input stream will not help in this situation. Kumar Bibek http://techdroid.kbeanie.com http://www.kbeanie.com On Fri, Jan 7, 2011 at 10:44 PM, Kostya Vasilyev kmans...@gmail.com wrote: You could try closing the input stream - that should propagate to the socket. 07.01.2011 20:07, ivan пишет: I'm wondering what the currently suggested method is for interrupting a read operation of a socket input stream? I know that traditionally the read could be interrupted by closing the socket from another thread and catching an IOException, but I'm not quite sure how to get at the socket from the apache classes. Maybe I should use some sort of interruptible channel instead ... ? Any links or help is greatly appreciated. My code looks like this -- minus most of the error handling: org.apache.http.impl.client.DefaultHttpClient org.apache.http.client.methods.HttpGet org.apache.http.HttpResponse DefaultHttpClient client = new DefaultHttpClient(httpParameters); HttpGet request = new HttpGet(Uri); HttpResponse response = client.execute(request); InputStream entityStream = response.getEntity().getContent(); try { bytesRead = entityStream.read(data); } catch (IOException ex) { } -- Kostya Vasilyev -- WiFi Manager + pretty widget -- http://kmansoft.wordpress.com -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.comandroid-developers%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] How to interrupt a blocking I/O operation?
It was implied that close() would be called from another thread (like the OP said he could do with a Socket reference). But then, I haven't used this library much. 07.01.2011 20:16, Kumar Bibek пишет: @Kostya: The execute method is blocked till the server sends a request. Closing the input stream will not help in this situation. Kumar Bibek http://techdroid.kbeanie.com http://www.kbeanie.com On Fri, Jan 7, 2011 at 10:44 PM, Kostya Vasilyev kmans...@gmail.com mailto:kmans...@gmail.com wrote: You could try closing the input stream - that should propagate to the socket. 07.01.2011 20:07, ivan пишет: I'm wondering what the currently suggested method is for interrupting a read operation of a socket input stream? I know that traditionally the read could be interrupted by closing the socket from another thread and catching an IOException, but I'm not quite sure how to get at the socket from the apache classes. Maybe I should use some sort of interruptible channel instead ... ? Any links or help is greatly appreciated. My code looks like this -- minus most of the error handling: org.apache.http.impl.client.DefaultHttpClient org.apache.http.client.methods.HttpGet org.apache.http.HttpResponse DefaultHttpClient client = new DefaultHttpClient(httpParameters); HttpGet request = new HttpGet(Uri); HttpResponse response = client.execute(request); InputStream entityStream = response.getEntity().getContent(); try { bytesRead = entityStream.read(data); } catch (IOException ex) { } -- Kostya Vasilyev -- WiFi Manager + pretty widget -- http://kmansoft.wordpress.com -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com mailto:android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com mailto:android-developers%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -- Kostya Vasilyev -- WiFi Manager + pretty widget -- http://kmansoft.wordpress.com -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en