diff options
author | Paul Hawke <paul.hawke@gmail.com> | 2014-01-28 20:27:59 -0800 |
---|---|---|
committer | Paul Hawke <paul.hawke@gmail.com> | 2014-01-28 20:27:59 -0800 |
commit | a61c6366263366b8b6939446267a919617cf731a (patch) | |
tree | ae4e4dade1caa7536b015bf77c0500fd0bbe3a71 | |
parent | 0bf521d4c4bfa18d53b3a1acf9b7a5fd1a06845a (diff) | |
parent | 0ad8e8a948f2a3d347ff633eccc875363fdbbb19 (diff) | |
download | nanohttpd-a61c6366263366b8b6939446267a919617cf731a.tar.gz |
Merge pull request #90 from BjoernAkAManf/patch-3
Code Cleanup
-rw-r--r-- | core/src/main/java/fi/iki/elonen/NanoHTTPD.java | 51 |
1 files changed, 23 insertions, 28 deletions
diff --git a/core/src/main/java/fi/iki/elonen/NanoHTTPD.java b/core/src/main/java/fi/iki/elonen/NanoHTTPD.java index 6f14306..5a0e896 100644 --- a/core/src/main/java/fi/iki/elonen/NanoHTTPD.java +++ b/core/src/main/java/fi/iki/elonen/NanoHTTPD.java @@ -176,36 +176,31 @@ public abstract class NanoHTTPD { registerConnection(finalAccept); finalAccept.setSoTimeout(SOCKET_READ_TIMEOUT); final InputStream inputStream = finalAccept.getInputStream(); - if (inputStream == null) { - safeClose(finalAccept); - unRegisterConnection(finalAccept); - } else { - asyncRunner.exec(new Runnable() { - @Override - public void run() { - OutputStream outputStream = null; - try { - outputStream = finalAccept.getOutputStream(); - TempFileManager tempFileManager = tempFileManagerFactory.create(); - HTTPSession session = new HTTPSession(tempFileManager, inputStream, outputStream, finalAccept.getInetAddress()); - while (!finalAccept.isClosed()) { - session.execute(); - } - } catch (Exception e) { - // When the socket is closed by the client, we throw our own SocketException - // to break the "keep alive" loop above. - if (!(e instanceof SocketException && "NanoHttpd Shutdown".equals(e.getMessage()))) { - e.printStackTrace(); - } - } finally { - safeClose(outputStream); - safeClose(inputStream); - safeClose(finalAccept); - unRegisterConnection(finalAccept); + asyncRunner.exec(new Runnable() { + @Override + public void run() { + OutputStream outputStream = null; + try { + outputStream = finalAccept.getOutputStream(); + TempFileManager tempFileManager = tempFileManagerFactory.create(); + HTTPSession session = new HTTPSession(tempFileManager, inputStream, outputStream, finalAccept.getInetAddress()); + while (!finalAccept.isClosed()) { + session.execute(); + } + } catch (Exception e) { + // When the socket is closed by the client, we throw our own SocketException + // to break the "keep alive" loop above. + if (!(e instanceof SocketException && "NanoHttpd Shutdown".equals(e.getMessage()))) { + e.printStackTrace(); } + } finally { + safeClose(outputStream); + safeClose(inputStream); + safeClose(finalAccept); + unRegisterConnection(finalAccept); } - }); - } + } + }); } catch (IOException e) { } } while (!myServerSocket.isClosed()); |