Skip to content

Commit

Permalink
Re-fix NPE when toggling HTTP Engine V2
Browse files Browse the repository at this point in the history
  • Loading branch information
chocolateboy committed Apr 7, 2012
1 parent b5b5b59 commit 96901c9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Changelog:
==========

1.??.? -

Re-fix NPE when toggling HTTP Engine V2

1.52.1 - 2012-04-06

Updated MPlayer to SB29 which fixes AC3 audio sync
Expand Down
22 changes: 18 additions & 4 deletions src/main/java/net/pms/network/HTTPServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ public boolean start() throws IOException {
group = new DefaultChannelGroup("myServer");
factory = new NioServerSocketChannelFactory(
Executors.newCachedThreadPool(),
Executors.newCachedThreadPool());
Executors.newCachedThreadPool()
);
ServerBootstrap bootstrap = new ServerBootstrap(factory);
HttpServerPipelineFactory pipeline = new HttpServerPipelineFactory(group);
bootstrap.setPipelineFactory(pipeline);
Expand Down Expand Up @@ -144,25 +145,38 @@ private boolean isAddressFromInterfaceFound(String networkInterfaceName) {
return ia != null;
}

// http://www.ps3mediaserver.org/forum/viewtopic.php?f=6&t=10689&p=48811#p48811
//
// avoid a NPE when a) switching HTTP Engine versions and b) restarting the HTTP server
// by cleaning up based on what's in use (not null) rather than the config state, which
// might be inconsistent.
//
// NOTE: there's little in the way of cleanup to do here as PMS.reset() discards the old
// server and creates a new one
public void stop() {
logger.info("Stopping server on host " + hostName + " and port " + port + "...");
if (!PMS.getConfiguration().isHTTPEngineV2()) {

if (runnable != null) { // HTTP Engine V1
runnable.interrupt();
runnable = null;
}

if (serverSocket != null) { // HTTP Engine V1
try {
serverSocket.close();
serverSocketChannel.close();
} catch (IOException e) {
logger.debug("Caught exception", e);
}
} else if (channel != null) {
} else if (channel != null) { // HTTP Engine V2
if (group != null) {
group.close().awaitUninterruptibly();
}

if (factory != null) {
factory.releaseExternalResources();
}
}

NetworkConfiguration.forgetConfiguration();
}

Expand Down

0 comments on commit 96901c9

Please sign in to comment.