diff options
author | Scott Jackson <daneren2005@gmail.com> | 2013-03-13 20:41:21 -0700 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2013-03-13 20:41:21 -0700 |
commit | 486364133ef35fafe12854ca4968fa56d4d35a2a (patch) | |
tree | 2dbbe08d8a776d15a590e1883b3a85be01e802bf /subsonic-android | |
parent | 22eef7d99ae73c8a811d55aa37468abdca5cfc19 (diff) | |
download | dsub-486364133ef35fafe12854ca4968fa56d4d35a2a.tar.gz dsub-486364133ef35fafe12854ca4968fa56d4d35a2a.tar.bz2 dsub-486364133ef35fafe12854ca4968fa56d4d35a2a.zip |
Fix for devices sending repeated requests for more data after already having sent everything
Diffstat (limited to 'subsonic-android')
-rw-r--r-- | subsonic-android/src/github/daneren2005/dsub/service/StreamProxy.java | 81 |
1 files changed, 42 insertions, 39 deletions
diff --git a/subsonic-android/src/github/daneren2005/dsub/service/StreamProxy.java b/subsonic-android/src/github/daneren2005/dsub/service/StreamProxy.java index b3c05a66..88815706 100644 --- a/subsonic-android/src/github/daneren2005/dsub/service/StreamProxy.java +++ b/subsonic-android/src/github/daneren2005/dsub/service/StreamProxy.java @@ -126,9 +126,8 @@ public class StreamProxy implements Runnable { StringTokenizer st = new StringTokenizer(firstLine);
String method = st.nextToken();
String uri = st.nextToken();
- Log.d(TAG, uri);
String realUri = uri.substring(1);
- Log.d(TAG, realUri);
+ Log.i(TAG, realUri);
request = new BasicHttpRequest(method, realUri);
return request;
}
@@ -140,7 +139,7 @@ public class StreamProxy implements Runnable { }
// Read HTTP headers
- Log.d(TAG, "Processing request");
+ Log.i(TAG, "Processing request");
try {
localPath = URLDecoder.decode(request.getRequestLine().getUri(), Constants.UTF_8);
@@ -179,43 +178,47 @@ public class StreamProxy implements Runnable { output = new BufferedOutputStream(client.getOutputStream(), 32*1024);
output.write(headers.getBytes());
- // Loop as long as there's stuff to send
- while (isRunning && !client.isClosed()) {
-
- // See if there's more to send
- File file = new File(localPath);
- int cbSentThisBatch = 0;
- if (file.exists()) {
- FileInputStream input = new FileInputStream(file);
- input.skip(cbSkip);
- int cbToSendThisBatch = input.available();
- while (cbToSendThisBatch > 0) {
- int cbToRead = Math.min(cbToSendThisBatch, buff.length);
- int cbRead = input.read(buff, 0, cbToRead);
- if (cbRead == -1) {
- break;
- }
- cbToSendThisBatch -= cbRead;
- cbToSend -= cbRead;
- output.write(buff, 0, cbRead);
- output.flush();
- cbSkip += cbRead;
- cbSentThisBatch += cbRead;
- }
- input.close();
- }
-
- // Done regardless of whether or not it thinks it is
- if(downloadFile.isWorkDone()) {
- break;
+ if(!downloadFile.isWorkDone()) {
+ // Loop as long as there's stuff to send
+ while (isRunning && !client.isClosed()) {
+
+ // See if there's more to send
+ File file = new File(localPath);
+ int cbSentThisBatch = 0;
+ if (file.exists()) {
+ FileInputStream input = new FileInputStream(file);
+ input.skip(cbSkip);
+ int cbToSendThisBatch = input.available();
+ while (cbToSendThisBatch > 0) {
+ int cbToRead = Math.min(cbToSendThisBatch, buff.length);
+ int cbRead = input.read(buff, 0, cbToRead);
+ if (cbRead == -1) {
+ break;
+ }
+ cbToSendThisBatch -= cbRead;
+ cbToSend -= cbRead;
+ output.write(buff, 0, cbRead);
+ output.flush();
+ cbSkip += cbRead;
+ cbSentThisBatch += cbRead;
+ }
+ input.close();
+ }
+
+ // Done regardless of whether or not it thinks it is
+ if(downloadFile.isWorkDone()) {
+ break;
+ }
+
+ // If we did nothing this batch, block for a second
+ if (cbSentThisBatch == 0) {
+ Log.d(TAG, "Blocking until more data appears (" + cbToSend + ")");
+ Thread.sleep(1000);
+ }
}
-
- // If we did nothing this batch, block for a second
- if (cbSentThisBatch == 0) {
- Log.d(TAG, "Blocking until more data appears (" + cbToSend + ")");
- Thread.sleep(1000);
- }
- }
+ } else {
+ Log.w(TAG, "Requesting data for completely downloaded file");
+ }
}
catch (SocketException socketException) {
Log.e(TAG, "SocketException() thrown, proxy client has probably closed. This can exit harmlessly");
|