Close a connection with an HTTP response
@param \Ratchet\ConnectionInterface $conn
@param int                          $code HTTP status code
@return null
351833
private function close(ConnectionInterface $conn, $code = 400, array $additional_headers = []) {
        $response = new Response($code, array_merge([
            'X-Powered-By' => \Ratchet\VERSION
        ], $additional_headers));

        $conn->send(gPsr\str($response));
        $conn->close();
    }
48827
async def close(self):
        """"""
        if not self._conn:
            return
        c = await self._execute(self._conn.close)
        self._conn = None
        return c
1102188
@Override
	public void close() {
		if (conn != null) {
			LOG.trace("Close connection. conn[{}], hashCode[{}]", conn, conn.hashCode());
			try {
				conn.close();
			} catch (SQLException e) {
				throw new UroborosqlSQLException(e);
			}
			conn = null;
		}
	}
1052519
public function handleConnect($conn) {
        $conn->decor = new IoConnection($conn);
        $conn->decor->resourceId = (int)$conn->stream;

        $uri = $conn->getRemoteAddress();
        $conn->decor->remoteAddress = trim(
            parse_url((strpos($uri, '://') === false ? 'tcp://' : '') . $uri, PHP_URL_HOST),
            '[]'
        );

        $this->app->onOpen($conn->decor);

        $conn->on('data', function ($data) use ($conn) {
            $this->handleData($data, $conn);
        });
        $conn->on('close', function () use ($conn) {
            $this->handleEnd($conn);
        });
        $conn->on('error', function (\Exception $e) use ($conn) {
            $this->handleError($e, $conn);
        });
    }
1051362
public function onClose(Connection $conn)
    {
        $this->onPublishResponse($conn, "CONN_CLOSED", new NsqException("connection close, maybe disposable connection timeout"));

        if (!$conn->isDisposable()) {
            $this->lookup->removeConnection($conn);

            $remainConnNum = count($this->getNsqdConns());
            sys_echo("nsq({$conn->getAddr()}) producer onClose: there are $remainConnNum connections left alive");

            if ($this->lookup->isStopped()/* && $remainConnNum === 0*/) {
                return;
            }

            Task::execute($this->reconnectToNSQD($conn));
        }
    }
861422
public final void closeConnection(final Connection conn) {
        try {
            if (conn != null) {
                conn.close();
            }
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
1250134
def close(self, code=3000, message='Go away!'):
        
        if self.state != CLOSED:
            try:
                self.conn.on_close()
            except:
                LOG.debug("Failed to call on_close().", exc_info=True)
            finally:
                self.state = CLOSED
                self.close_reason = (code, message)
                self.conn = None

            # Bump stats
            self.stats.on_sess_closed(self.transport_name)

            # If we have active handler, notify that session was closed
            if self.handler is not None:
                self.handler.session_closed()
232545
private static boolean finishLastResponse(final HttpConnection conn) {
        InputStream lastResponse = conn.getLastResponseInputStream();
        if(lastResponse != null) {
            conn.setLastResponseInputStream(null);
            try {
                lastResponse.close();
                return true;
            } catch (IOException ioe) {
                // force reconnect.
                return false;
            }
        } else {
            return false;
        }
    }
663613
def release(self, conn):
        
        fut = self._loop.create_future()
        fut.set_result(None)

        if conn in self._terminated:
            assert conn.closed, conn
            self._terminated.remove(conn)
            return fut
        assert conn in self._used, (conn, self._used)
        self._used.remove(conn)
        if not conn.closed:
            in_trans = conn.get_transaction_status()
            if in_trans:
                conn.close()
                return fut
            if self._closing:
                conn.close()
            else:
                self._free.append(conn)
            fut = self._loop.create_task(self._wakeup())
        return fut
1371727
public void close(int statusCode, HandshakeResponse errResponse) {
        log.warn("Closing connection with status: {}", statusCode);
        // remove handshake flag
        session.removeAttribute(Constants.HANDSHAKE_COMPLETE);
        // clear the delay queue
        queue.clear();
        // send http error response
        session.write(errResponse);
        // whether to attempt a nice close or a forceful one
        if (WebSocketTransport.isNiceClose()) {
            // now send close packet with error code
            IoBuffer buf = IoBuffer.allocate(16);
            buf.setAutoExpand(true);
            // all errors except 403 will use 1002
            buf.putUnsigned((short) statusCode);
            try {
                if (statusCode == 1008) {
                    // if its a 403 forbidden
                    buf.put("Policy Violation".getBytes("UTF8"));
                } else {
                    buf.put("Protocol error".getBytes("UTF8"));
                }
            } catch (Exception e) {
                // shouldnt be any text encoding issues...
            }
            buf.flip();
            byte[] errBytes = new byte[buf.remaining()];
            buf.get(errBytes);
            // construct the packet
            Packet packet = Packet.build(errBytes, MessageType.CLOSE);
            WriteFuture writeFuture = session.write(packet);
            writeFuture.addListener(new IoFutureListener<WriteFuture>() {

                @Override
                public void operationComplete(WriteFuture future) {
                    if (future.isWritten()) {
                        log.debug("Close message written");
                        // only set on success for now to skip boolean check later
                        session.setAttribute(Constants.STATUS_CLOSE_WRITTEN, Boolean.TRUE);
                    }
                    future.removeListener(this);
                }

            });
            // adjust close routine to allow for flushing
            CloseFuture closeFuture = session.closeOnFlush();
            closeFuture.addListener(new IoFutureListener<CloseFuture>() {

                public void operationComplete(CloseFuture future) {
                    if (future.isClosed()) {
                        log.debug("Connection is closed");
                    } else {
                        log.debug("Connection is not yet closed");
                    }
                    future.removeListener(this);
                }

            });
        } else {
            // force close
            CloseFuture closeFuture = session.closeNow();
            closeFuture.addListener(new IoFutureListener<CloseFuture>() {

                public void operationComplete(CloseFuture future) {
                    if (future.isClosed()) {
                        log.debug("Connection is closed");
                    } else {
                        log.debug("Connection is not yet closed");
                    }
                    future.removeListener(this);
                }

            });
        }
        log.debug("Close complete");
    }
124563
public function close($reply_code = 0, $reply_text = '', $method_sig = array(0, 0))
    {
        $this->callbacks = array();
        if ($this->is_open === false || $this->connection === null) {
            $this->do_close();

            return null; // already closed
        }
        list($class_id, $method_id, $args) = $this->protocolWriter->channelClose(
            $reply_code,
            $reply_text,
            $method_sig[0],
            $method_sig[1]
        );

        try {
            $this->send_method_frame(array($class_id, $method_id), $args);
        } catch (\Exception $e) {
            $this->do_close();

            throw $e;
        }

        return $this->wait(array(
            $this->waitHelper->get_wait('channel.close_ok')
        ), false, $this->channel_rpc_timeout );
    }
469693
void closeConnection(Connection con) {
        if (com.ibm.websphere.ras.TraceComponent.isAnyTracingEnabled() && LoggingUtil.SESSION_LOGGER_WAS.isLoggable(Level.FINE)) {
            LoggingUtil.SESSION_LOGGER_WAS.entering(methodClassName, methodNames[CLOSE_CONNECTION], "closing " + con);
        }

        try {
            con.close();
        } catch (Throwable t) {
            com.ibm.ws.ffdc.FFDCFilter.processException(t, "com.ibm.ws.session.store.db.DatabaseHashMap.closeConnection", "1056", con);
            LoggingUtil.SESSION_LOGGER_WAS.logp(Level.SEVERE, methodClassName, methodNames[CLOSE_CONNECTION], "CommonMessage.exception", t);
        }

        endDBContext(); // PK06395/d321615
        resumeTransaction();
        if (com.ibm.websphere.ras.TraceComponent.isAnyTracingEnabled() && LoggingUtil.SESSION_LOGGER_WAS.isLoggable(Level.FINER)) {
            LoggingUtil.SESSION_LOGGER_WAS.exiting(methodClassName, methodNames[CLOSE_CONNECTION], "closed " + con);
        }
    }
215150
AmqpClient closeConnection(int replyCode, String replyText, int classId, int methodId1) {
        this.closeConnection(replyCode, replyText, classId, methodId1, null, null);
        return this;
    }
409858
public function detachConnFromUrl(ClientConnection $conn, $url)
    {
        if (isset($this->servConnFree[$url])) {
            $this->servConnFree[$url]->detach($conn);
        }
        if (isset($this->servConn[$url])) {
            $this->servConn[$url]->detach($conn);
        }
    }
1139168
public function sendAndExit($code = null, array $headers = null)
    {
        $this->send($code, $headers);
        exit();
    }
295138
final void close(final ConnectionPoolConnection conn) {
      if(closeQueue != null) {
         closeQueue.add(conn);
      } else {
         closer.close(conn);
      }
   }
1184962
public static void rollbackAndClose(Connection conn) throws SQLException {
        if (conn != null) {
            try {
                conn.rollback();
            } finally {
                conn.close();
            }
        }
    }