adopt: LWS_SERVER_OPTION_ONLY_RAW to indicate a vhost only serves raw
authorAndy Green <andy@warmcat.com>
Wed, 5 Apr 2017 23:57:45 +0000 (07:57 +0800)
committerAndy Green <andy@warmcat.com>
Wed, 5 Apr 2017 23:57:45 +0000 (07:57 +0800)
lib/libwebsockets.h
lib/server.c

index ed716e89a65e7e94fccd214b8ab9299185f66602..a9601135b67cfcb67fd683d772a3cf69a22fb5cd 100644 (file)
@@ -1696,6 +1696,10 @@ enum lws_context_options {
        /**< (VH) if invalid http is coming in the first line,  */
        LWS_SERVER_OPTION_LIBEVENT                              = (1 << 21),
        /**< (CTX) Use libevent event loop */
+       LWS_SERVER_OPTION_ONLY_RAW                              = (1 << 22),
+       /**< (VH) All connections to this vhost / port are RAW as soon as
+        * the connection is accepted, no HTTP is going to be coming.
+        */
 
        /****** add new things just above ---^ ******/
 };
index 2de0e6a40b23a8eea3004901c24499e8cd70426e..b23776732f26811f25409f304d7b0342e197144f 100644 (file)
@@ -2018,6 +2018,8 @@ lws_server_socket_service(struct lws_context *context, struct lws *wsi,
        struct lws_context_per_thread *pt = &context->pt[(int)wsi->tsi];
        lws_sockfd_type accept_fd = LWS_SOCK_INVALID;
        struct allocated_headers *ah;
+       lws_sock_file_fd_type fd;
+       int opts = LWS_ADOPT_SOCKET | LWS_ADOPT_ALLOW_SSL;
 #if LWS_POSIX
        struct sockaddr_in cli_addr;
        socklen_t clilen;
@@ -2301,7 +2303,12 @@ try_pollout:
                                break;
                        }
 
-                       if (!lws_adopt_socket_vhost(wsi->vhost, accept_fd))
+                       if (!(wsi->vhost->options & LWS_SERVER_OPTION_ONLY_RAW))
+                               opts |= LWS_ADOPT_HTTP;
+
+                       fd.sockfd = accept_fd;
+                       if (!lws_adopt_descriptor_vhost(wsi->vhost, opts, fd,
+                                                       NULL, NULL))
                                /* already closed cleanly as necessary */
                                return 1;