chttpserver · Section 3
chttpsvr_stop
NAME
chttpsvr_stop - close this server's listener
LIBRARY
C Collections (libccollections, -lccollections)
SYNOPSIS
#include <ccollections/chttpserver.h> void chttpsvr_stop(chttpsvr srv);
DESCRIPTION
Removes the listener socket that chttpsvr_start registered from the shared reactor and closes it. For a Unix domain socket listener it then removes the socket file, but only while the path still names the socket that this server created. The call returns at once, and the shared reactor and every other registered listener keep running. Calling it again changes nothing: On a server that never started, or that has already stopped, chttpsvr_stop does nothing. It also does nothing, without any error, when srv is CHTTPSVR_NULL or a stale handle of a server that has already been destroyed. Connections that the server accepted before this call stay open, and the server does not close them. A request in progress runs until it completes, and a keep-alive connection is served request after request for as long as the client keeps it open, until the idle timeout closes it as on a running server. That is true across a later restart of the same handle with chttpsvr_start as well, and the restarted server serves such a connection under its new configuration. chttpsvr_destroy waits for these in-flight requests to drain completely and closes every idle connection that is left before it frees the resources of the server. It is safe to call this function with CHTTPSVR_NULL (0). It may run at the same time as a chttpsvr_start that restarts the same handle on another thread. The restart doesn't race this call: it waits until the old listener is completely torn down here and then binds a new one.
WARNINGS
This function is synchronous and NOT async-signal-safe. Do not call it from a signal handler; call chttpsvr_engine_stop() there. It takes internal locks that the interrupted thread may already hold, for example inside chttpsvr_start() or chttpsvr_destroy(), and the calling thread then deadlocks on itself. For a shutdown hook driven by a signal use chttpsvr_engine_stop(), the only function that is documented as async-signal-safe, because it moves all of this work off the interrupted thread.
SEE ALSO
chttpsvr_start(3), chttpsvr_is_running(3), chttpsvr_engine_stop(3), chttpsvr_engine_wait(3)