mirror of
https://github.com/warmcat/libwebsockets.git
synced 2025-03-09 00:00:04 +01:00
unixskt: add test server support and cleanup inode on exit
This commit is contained in:
parent
422cbf24bd
commit
5acbb04b51
3 changed files with 38 additions and 2 deletions
|
@ -177,6 +177,28 @@ to toggle the creation and destruction of an identical second vhost on port + 1.
|
|||
This is intended as a test and demonstration for how to bring up and remove
|
||||
vhosts dynamically.
|
||||
|
||||
@section unixskt Testing Unix Socket Server support
|
||||
|
||||
Start the test server with -U and the path to create the unix domain socket
|
||||
|
||||
```
|
||||
$ libwebsockets-test-server -U /tmp/uds
|
||||
```
|
||||
|
||||
On exit, lws will delete the socket inode.
|
||||
|
||||
To test the client side, eg
|
||||
|
||||
```
|
||||
$ nc -C -U /tmp/uds -i 30
|
||||
```
|
||||
|
||||
and type
|
||||
|
||||
`GET / HTTP/1.1`
|
||||
|
||||
followed by two ENTER. The contents of test.html should be returned.
|
||||
|
||||
@section wscl Testing websocket client support
|
||||
|
||||
If you run the test server as described above, you can also
|
||||
|
|
|
@ -715,7 +715,7 @@ lws_create_vhost(struct lws_context *context,
|
|||
#ifdef LWS_WITH_UNIX_SOCK
|
||||
if (LWS_UNIX_SOCK_ENABLED(context)) {
|
||||
lwsl_notice("Creating Vhost '%s' path \"%s\", %d protocols\n",
|
||||
vh->name, info->iface, vh->count_protocols);
|
||||
vh->name, vh->iface, vh->count_protocols);
|
||||
} else
|
||||
#endif
|
||||
lwsl_notice("Creating Vhost '%s' port %d, %d protocols, IPv6 %s\n",
|
||||
|
@ -1609,6 +1609,14 @@ lws_vhost_destroy2(struct lws_vhost *vh)
|
|||
pthread_mutex_destroy(&vh->lock);
|
||||
#endif
|
||||
|
||||
#if defined(LWS_WITH_UNIX_SOCK)
|
||||
if (LWS_UNIX_SOCK_ENABLED(context)) {
|
||||
n = unlink(vh->iface);
|
||||
if (n)
|
||||
lwsl_info("Closing unix socket %s: errno %d\n",
|
||||
vh->iface, errno);
|
||||
}
|
||||
#endif
|
||||
/*
|
||||
* although async event callbacks may still come for wsi handles with
|
||||
* pending close in the case of asycn event library like libuv,
|
||||
|
|
|
@ -218,6 +218,7 @@ static struct option options[] = {
|
|||
#endif
|
||||
#endif
|
||||
{ "libev", no_argument, NULL, 'e' },
|
||||
{ "unix-socket", required_argument, NULL, 'U' },
|
||||
#ifndef LWS_NO_DAEMONIZE
|
||||
{ "daemonize", no_argument, NULL, 'D' },
|
||||
#endif
|
||||
|
@ -261,7 +262,7 @@ int main(int argc, char **argv)
|
|||
info.port = 7681;
|
||||
|
||||
while (n >= 0) {
|
||||
n = getopt_long(argc, argv, "eci:hsap:d:Dr:C:K:A:R:vu:g:P:k", options, NULL);
|
||||
n = getopt_long(argc, argv, "eci:hsap:d:Dr:C:K:A:R:vu:g:P:kU:", options, NULL);
|
||||
if (n < 0)
|
||||
continue;
|
||||
switch (n) {
|
||||
|
@ -299,6 +300,11 @@ int main(int argc, char **argv)
|
|||
lws_strncpy(interface_name, optarg, sizeof interface_name);
|
||||
iface = interface_name;
|
||||
break;
|
||||
case 'U':
|
||||
lws_strncpy(interface_name, optarg, sizeof interface_name);
|
||||
iface = interface_name;
|
||||
opts |= LWS_SERVER_OPTION_UNIX_SOCK;
|
||||
break;
|
||||
case 'k':
|
||||
info.bind_iface = 1;
|
||||
#if defined(LWS_HAVE_SYS_CAPABILITY_H) && defined(LWS_HAVE_LIBCAP)
|
||||
|
|
Loading…
Add table
Reference in a new issue