Stops a local listening socket from accepting connections.

@param bindAddress
the listening address
@param bindPort
the listening port
@param killActiveTunnels
should any active tunnels be closed.
326288
public synchronized void stopLocalForwarding(String bindAddress,
			int bindPort, boolean killActiveTunnels) throws SshException {
		String key = generateKey(bindAddress, bindPort);
		stopLocalForwarding(key, killActiveTunnels);
	}
834137
public synchronized void destroyForPort(int port)
   {
      synchronized(portMap)
      {
         UndertowServerEngine ref = portMap.remove(port);
         if (ref != null)
         {
            if (LOG.isDebugEnabled())
            {
               LOG.debug("Stopping HttpServer Engine on port " + port + ".");
            }
            try
            {
               ref.stop();
            }
            catch (Exception e)
            {
               LOG.warn("", e);
            }
         }
      }
   }
646015
protected final void terminate() {
		if (rebind(connection)) {
			if (log.isTraceEnabled()) {
				log.trace(format(channel(), "Disposing ChannelOperation from a channel"),
						new Exception("ChannelOperation terminal stack"));
			}

			Operators.terminate(OUTBOUND_CLOSE, this);
			// Do not call directly inbound.onInboundComplete()
			// HttpClientOperations need to notify with error
			// when there is no response state
			onInboundComplete();
			if (channel().isActive() && isPersistent()) {
				channel().writeAndFlush(TERMINATED_OPS, this);
			}
			else {
				// Returned value is deliberately ignored
				setSuccess(null);
			}
		}
	}
1150915
public void bind(DatagramChannel channel, int port) throws IOException {
        // select port if wildcarded
        if (port == PORT_ANY) {
            port = portManager.next();
        }

        // try bind
        IOException ex = null;
        for (int q = 0; q < 100; q++) {
            try {
                channel.bind(new InetSocketAddress(bindAddress, port));
                ex = null;
                break;
            } catch (IOException e) {
                ex = e;
                logger.info("Failed trying to bind " + bindAddress + ":" + port);
                port = portManager.next();
            }
        }

        if (ex != null) {
            throw ex;
        }
    }
324497
@Override
    protected void stopInner() {
        /*
         * TODO REST-Server Need to handle inflight operations. What happens to
         * the existing async operations when a channel.close() is issued in
         * Netty?
         */
        if(this.nettyServerChannel != null) {
            this.nettyServerChannel.close();
        }

        if(allChannels != null) {
            allChannels.close().awaitUninterruptibly();
        }
        this.bootstrap.releaseExternalResources();
    }
1194441
@Override
    public void transportClosed(boolean closedByRemotePeer, boolean mayBlock)
    {
    	parentListener.unregisterClient(this);
        try
        {
            if (localConnection != null)
                localConnection.close();
        }
        catch (Exception e)
        {
            log.error("#"+id+" Could not close local connection",e);
        }
        finally
        {
        	localConnection = null;
        }
    }
173880
public static synchronized void cancelNetworkCall(String url, String requestMethod, long endTime, String exception) {
    if (url != null) {
      String id = sanitiseURL(url);
      if ((connections != null) && (connections.containsKey(id))) {
        connections.remove(id);
      }
    }
  }
17748
public void close(VirtualConnection inVC, Exception e) {

        // when the channel above calls close() on the outbound connection then
        // we are done... no need to purge anything off the socket like we do
        // on the inbound side (purge request body if they never read it)

        // pass the close down the chain.
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
            Tr.debug(tc, "Closing this outbound link: " + this + " " + getVirtualConnection());
        }
        setAllowReconnect(false);
        if (!this.earlyReconnectDestroy) {
            super.close(inVC, e);
        } else {
            destroy(e);
        }
    }
1278568
public void close() throws IOException {
        final ManagedBinding binding = this.socketBindingManager.getNamedRegistry().getManagedBinding(this.name);
        if (binding == null) {
            return;
        }
        binding.close();
    }
1150323
synchronized public void closeInbound() throws SSLException {
        /*
         * Currently closes the outbound side as well.  The IETF TLS
         * working group has expressed the opinion that 1/2 open
         * connections are not allowed by the spec.  May change
         * someday in the future.
         */
        if ((debug != null) && Debug.isOn("ssl")) {
            System.out.println(threadName() + ", called closeInbound()");
        }

        /*
         * No need to throw an Exception if we haven't even started yet.
         */
        if ((connectionState != cs_START) && !recvCN) {
            recvCN = true;  // Only receive the Exception once
            fatal(Alerts.alert_internal_error,
                "Inbound closed before receiving peer's close_notify: " +
                "possible truncation attack?");
        } else {
            /*
             * Currently, this is a no-op, but in case we change
             * the close inbound code later.
             */
            closeInboundInternal();
        }
    }
260876
public void listen(final String address, final int port, final boolean useSSL) throws UnknownHostException {

        // Bind and start to accept incoming connections.
        ChannelFuture cf = getServerBootstrap(useSSL).bind(address, port);
        cf.addListener(new ChannelFutureListener() {

            public void operationComplete(final ChannelFuture future) throws Exception {
                if (future.isSuccess()) {
                    context.getEventBus().post(new JNRPEStatusEvent(STATUS.STARTED, this, "JNRPE Server started"));
                    LOG.info(context, "Listening on " + (useSSL ? "SSL/" : "") + address + ":" + port);
                } else {
                    getExecutionContext().getEventBus().post(new JNRPEStatusEvent(STATUS.FAILED, this, "JNRPE Server start failed"));
                    LOG.error(context, "Unable to listen on " + (useSSL ? "SSL/" : "") + address + ":" + port, future.cause());
                }
            }
        });

    }
254005
static void closeLink(CommsConnection conn) {
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.entry(tc, "closeLink", conn);

    conn.setSchemaSet(null);

    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.exit(tc, "closeLink");
  }
529922
public ChannelFuture bind() {
        validate();
        SocketAddress localAddress = this.localAddress;
        if (localAddress == null) {
            throw new IllegalStateException("localAddress not set");
        }
        return doBind(localAddress);
    }
945107
private void remove(PollController conn)
  {
    if (conn == null) {
      return;
    }

    JniSocketImpl socket = (JniSocketImpl) conn.getSocket();
    int nativeFd = socket.getNativeFd();

    if (_lifecycle.isDestroyed()) {
      return;
    }

    _activeCount.incrementAndGet();

    if (nativeFd > 0) {
      try {
        removeNative(_fd, nativeFd);
      } catch (Throwable e) {
        log.log(Level.WARNING, e.toString(), e);
        _lifecycle.toError();
      }
    }
    
    conn.toKeepaliveClose();

    if (_activeCount.decrementAndGet() == 0 && _lifecycle.isDestroyed()) {
      destroy();
    }
  }
1247994
public static void isSocketBindable(InetSocketAddress addr)
      throws IOException {
    if (addr == null) {
      return;
    }
    ServerSocket socket = new ServerSocket();
    try {
      socket.bind(addr);
    } finally {
      socket.close();
    }
  }
686564
public void close() {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) {
            Tr.entry(this, tc, "close");
        }

        // Doing a channel.close() will actually put the keys associated with this
        // channel
        // into the associated selectors cancelledKey list, but they don't get
        // removed until the
        // next time the selector runs. In some cases, we need to make sure they are
        // really gone before we
        // we close the channel, because another thread may have requested another
        // operation
        // on the channel at the same time, which causes problems on some OS'es.
        // So, cancel them manually and wait for the selector to run once before
        // continuing

        // call super.close() to see if we are using Regular Sockets, and if so, let
        // the parent class handle closing the socket
        super.close();

        if (TraceComponent.isAnyTracingEnabled() && tc.isEventEnabled()) {
            Tr.event(this, tc, "SocketChannel closing, local: " + socket.getLocalSocketAddress() + " remote: " + socket.getRemoteSocketAddress());
        }

        // synchronize on this SocketIOChannel to prevent duplicate closes from
        // being processed
        synchronized (this) {
            if (closed) {
                processClose = false;
            }
            closed = true;
        }

        if (processClose) {

            // checkCancel is only on if we need to manually cancel keys as
            // the socket close() is supposed to do that for us
            if (checkCancel) {
                // Remove socket from current selectors.
                if (channelSelectorRead != null) {
                    SelectionKey k = channelSelectorRead.getKey(channel);
                    if (k != null) {
                        CancelRequest cr = new CancelRequest(k);
                        synchronized (cr) {
                            channelSelectorRead.addCancelRequest(cr);
                            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                                Tr.debug(this, tc, "waiting for read key to be canceled, key is " + k);
                            }
                            try {
                                cr.wait();
                            } catch (InterruptedException e) {
                                // No FFDC code needed
                            }
                        } // end-sync
                    }
                }
                if (channelSelectorWrite != null) {
                    SelectionKey k = channelSelectorWrite.getKey(channel);
                    if (k != null) {
                        CancelRequest cr = new CancelRequest(k);
                        synchronized (cr) {
                            channelSelectorWrite.addCancelRequest(cr);
                            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                                Tr.debug(this, tc, "waiting for write key to be canceled, key is " + k);
                            }
                            try {
                                cr.wait();
                            } catch (InterruptedException e) {
                                // No FFDC code needed
                            }
                        } // end-sync
                    }
                }
            }

            try {
                if (channel != null) {
                    channel.close();
                }

                // need to make sure the keys get cancelled after the close call
                if (channelSelectorRead != null) {
                    channelSelectorRead.wakeup();
                    channelSelectorRead = null;
                }
                if (channelSelectorWrite != null) {
                    channelSelectorWrite.wakeup();
                    channelSelectorWrite = null;
                }

            } catch (Throwable t) {
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                    Tr.debug(this, tc, "Error closing channel: " + t);
                }
                // ignore all shutdown/close errors
            }
        }
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) {
            Tr.exit(this, tc, "close");
        }
    }
720242
public void stop() {
    if (acceptChannel == null || !acceptChannel.isOpen()) {
      LOG.info("Fail to stop server; not yet open.");
      return;
    }
    // Clear all connected socket and related stuff
    for (Map.Entry<SocketChannel, SocketChannelHelper> connections : activeConnections.entrySet()) {
      SocketChannel channel = connections.getKey();
      SocketAddress channelAddress = channel.socket().getRemoteSocketAddress();
      LOG.info("Closing connected channel from client: " + channelAddress);
      LOG.info("Removing all interest on channel: " + channelAddress);
      nioLooper.removeAllInterest(channel);

      // Dispatch the child instance
      onClose(channel);
      // Clear the SocketChannelHelper
      connections.getValue().clear();
    }

    // Clear state inside the HeronServer
    activeConnections.clear();
    requestMap.clear();
    messageMap.clear();
    try {
      acceptChannel.close();
    } catch (IOException e) {
      LOG.log(Level.SEVERE, "Failed to close server", e);
    }
  }