66f398f9babf5054ceed104e32de734ddf5cbb8c
[platform/upstream/libwebsockets.git] / lwsws / http.c
1 /*
2  * libwebsockets web server application
3  *
4  * Copyright (C) 2010-2016 Andy Green <andy@warmcat.com>
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public
8  * License as published by the Free Software Foundation:
9  * version 2.1 of the License.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19  * MA  02110-1301  USA
20  */
21 #include "lwsws.h"
22
23 /* http server gets files from this path */
24 #define LOCAL_RESOURCE_PATH INSTALL_DATADIR"/libwebsockets-test-server"
25 char *resource_path = LOCAL_RESOURCE_PATH;
26
27
28
29 /*
30  * We take a strict whitelist approach to stop ../ attacks
31  */
32 struct serveable {
33         const char *urlpath;
34         const char *mimetype;
35 };
36
37 const char * get_mimetype(const char *file)
38 {
39         int n = strlen(file);
40
41         if (n < 5)
42                 return NULL;
43
44         if (!strcmp(&file[n - 4], ".ico"))
45                 return "image/x-icon";
46
47         if (!strcmp(&file[n - 4], ".png"))
48                 return "image/png";
49
50         if (!strcmp(&file[n - 4], ".jpg"))
51                 return "image/jpeg";
52
53         if (!strcmp(&file[n - 5], ".html"))
54                 return "text/html";
55
56         if (!strcmp(&file[n - 4], ".css"))
57                 return "text/css";
58
59         return NULL;
60 }
61
62 /* this protocol server (always the first one) handles HTTP,
63  *
64  * Some misc callbacks that aren't associated with a protocol also turn up only
65  * here on the first protocol server.
66  */
67
68 int callback_http(struct lws *wsi, enum lws_callback_reasons reason, void *user,
69                   void *in, size_t len)
70 {
71         struct per_session_data__http *pss =
72                         (struct per_session_data__http *)user;
73         unsigned char buffer[4096 + LWS_PRE];
74         unsigned long amount, file_len, sent;
75         char leaf_path[1024];
76         const char *mimetype;
77         char *other_headers;
78         unsigned char *end;
79         struct timeval tv;
80         unsigned char *p;
81 #ifndef LWS_NO_CLIENT
82         struct per_session_data__http *pss1;
83         struct lws *wsi1;
84 #endif
85         char buf[256];
86         char b64[64];
87         int n, m;
88 #ifdef EXTERNAL_POLL
89         struct lws_pollargs *pa = (struct lws_pollargs *)in;
90 #endif
91
92 //      lwsl_err("%s: reason %d\n", __func__, reason);
93
94         switch (reason) {
95         case LWS_CALLBACK_HTTP:
96
97                 {
98                         char name[100], rip[50];
99                         lws_get_peer_addresses(wsi, lws_get_socket_fd(wsi), name,
100                                                sizeof(name), rip, sizeof(rip));
101                         sprintf(buf, "%s (%s)", name, rip);
102                         lwsl_notice("HTTP connect from %s\n", buf);
103                 }
104
105                 if (len < 1) {
106                         lws_return_http_status(wsi,
107                                                 HTTP_STATUS_BAD_REQUEST, NULL);
108                         goto try_to_reuse;
109                 }
110
111 #ifndef LWS_NO_CLIENT
112                 if (!strncmp(in, "/proxytest", 10)) {
113                         struct lws_client_connect_info i;
114                         char *rootpath = "/";
115                         const char *p = (const char *)in;
116
117                         if (lws_get_child(wsi))
118                                 break;
119
120                         pss->client_finished = 0;
121                         memset(&i,0, sizeof(i));
122                         i.context = lws_get_context(wsi);
123                         i.address = "git.libwebsockets.org";
124                         i.port = 80;
125                         i.ssl_connection = 0;
126                         if (p[10])
127                                 i.path = (char *)in + 10;
128                         else
129                                 i.path = rootpath;
130                         i.host = "git.libwebsockets.org";
131                         i.origin = NULL;
132                         i.method = "GET";
133                         i.parent_wsi = wsi;
134                         i.uri_replace_from = "git.libwebsockets.org/";
135                         i.uri_replace_to = "/proxytest/";
136                         if (!lws_client_connect_via_info(&i)) {
137                                 lwsl_err("proxy connect fail\n");
138                                 break;
139                         }
140
141
142
143                         break;
144                 }
145 #endif
146
147 #if 1
148                 /* this example server has no concept of directories */
149                 if (strchr((const char *)in + 1, '/')) {
150                         lws_return_http_status(wsi, HTTP_STATUS_FORBIDDEN, NULL);
151                         goto try_to_reuse;
152                 }
153 #endif
154
155 #ifdef LWS_WITH_CGI
156                 if (!strncmp(in, "/cgitest", 8)) {
157                         static char *cmd[] = {
158                                 "/bin/sh",
159                                 "-c",
160                                 INSTALL_DATADIR"/libwebsockets-test-server/lws-cgi-test.sh",
161 //                              "/var/www/cgi-bin/cgit",
162                                 NULL
163                         };
164
165                         lwsl_notice("%s: cgitest\n", __func__);
166                         n = lws_cgi(wsi, cmd, 8, 5);
167                         if (n) {
168                                 lwsl_err("%s: cgi failed\n");
169                                 return -1;
170                         }
171                         p = buffer + LWS_PRE;
172                         end = p + sizeof(buffer) - LWS_PRE;
173
174                         if (lws_add_http_header_status(wsi, 200, &p, end))
175                                 return 1;
176                         if (lws_add_http_header_by_token(wsi, WSI_TOKEN_CONNECTION,
177                                         (unsigned char *)"close", 5, &p, end))
178                                 return 1;
179                         n = lws_write(wsi, buffer + LWS_PRE,
180                                       p - (buffer + LWS_PRE),
181                                       LWS_WRITE_HTTP_HEADERS);
182
183                         /* the cgi starts by outputting headers, we can't
184                          *  finalize the headers until we see the end of that
185                          */
186
187                         break;
188                 }
189 #endif
190
191                 /* if a legal POST URL, let it continue and accept data */
192                 if (lws_hdr_total_length(wsi, WSI_TOKEN_POST_URI))
193                         return 0;
194
195                 /* check for the "send a big file by hand" example case */
196                 lwsl_notice("%s\n", in);
197                 if (!strcmp((const char *)in, "/leaf.jpg")) {
198                         if (strlen(resource_path) > sizeof(leaf_path) - 10)
199                                 return -1;
200                         sprintf(leaf_path, "%s/leaf.jpg", resource_path);
201
202                         /* well, let's demonstrate how to send the hard way */
203
204                         p = buffer + LWS_PRE;
205                         end = p + sizeof(buffer) - LWS_PRE;
206
207                         pss->fd = lws_plat_file_open(wsi, leaf_path, &file_len,
208                                                      LWS_O_RDONLY);
209
210                         if (pss->fd == LWS_INVALID_FILE) {
211                                 lwsl_err("faild to open file %s\n", leaf_path);
212                                 return -1;
213                         }
214
215                         /*
216                          * we will send a big jpeg file, but it could be
217                          * anything.  Set the Content-Type: appropriately
218                          * so the browser knows what to do with it.
219                          *
220                          * Notice we use the APIs to build the header, which
221                          * will do the right thing for HTTP 1/1.1 and HTTP2
222                          * depending on what connection it happens to be working
223                          * on
224                          */
225                         if (lws_add_http_header_status(wsi, 200, &p, end))
226                                 return 1;
227                         if (lws_add_http_header_by_token(wsi, WSI_TOKEN_HTTP_SERVER,
228                                         (unsigned char *)"libwebsockets",
229                                         13, &p, end))
230                                 return 1;
231                         if (lws_add_http_header_by_token(wsi,
232                                         WSI_TOKEN_HTTP_CONTENT_TYPE,
233                                         (unsigned char *)"image/jpeg",
234                                         10, &p, end))
235                                 return 1;
236                         if (lws_add_http_header_content_length(wsi,
237                                                                file_len, &p,
238                                                                end))
239                                 return 1;
240                         if (lws_finalize_http_header(wsi, &p, end))
241                                 return 1;
242
243                         /*
244                          * send the http headers...
245                          * this won't block since it's the first payload sent
246                          * on the connection since it was established
247                          * (too small for partial)
248                          *
249                          * Notice they are sent using LWS_WRITE_HTTP_HEADERS
250                          * which also means you can't send body too in one step,
251                          * this is mandated by changes in HTTP2
252                          */
253
254                         *p = '\0';
255                         lwsl_info("%s\n", buffer + LWS_PRE);
256
257                         n = lws_write(wsi, buffer + LWS_PRE,
258                                       p - (buffer + LWS_PRE),
259                                       LWS_WRITE_HTTP_HEADERS);
260                         if (n < 0) {
261                                 lws_plat_file_close(wsi, pss->fd);
262                                 return -1;
263                         }
264                         /*
265                          * book us a LWS_CALLBACK_HTTP_WRITEABLE callback
266                          */
267                         lws_callback_on_writable(wsi);
268                         break;
269                 }
270
271                 /* if not, send a file the easy way */
272                 if (!strncmp(in, "/cgit-data/", 11)) {
273                         in = (char *)in + 11;
274                         strcpy(buf, "/usr/share/cgit");
275                 } else
276                         strcpy(buf, resource_path);
277
278                 if (strcmp(in, "/")) {
279                         if (*((const char *)in) != '/')
280                                 strcat(buf, "/");
281                         strncat(buf, in, sizeof(buf) - strlen(buf) - 1);
282                 } else /* default file to serve */
283                         strcat(buf, "/test.html");
284                 buf[sizeof(buf) - 1] = '\0';
285
286                 /* refuse to serve files we don't understand */
287                 mimetype = get_mimetype(buf);
288                 if (!mimetype) {
289                         lwsl_err("Unknown mimetype for %s\n", buf);
290                         lws_return_http_status(wsi,
291                                       HTTP_STATUS_UNSUPPORTED_MEDIA_TYPE, NULL);
292                         return -1;
293                 }
294
295                 /* demonstrates how to set a cookie on / */
296
297                 other_headers = leaf_path;
298                 p = (unsigned char *)leaf_path;
299                 if (!strcmp((const char *)in, "/") &&
300                            !lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_COOKIE)) {
301                         /* this isn't very unguessable but it'll do for us */
302                         gettimeofday(&tv, NULL);
303                         n = sprintf(b64, "test=LWS_%u_%u_COOKIE;Max-Age=360000",
304                                 (unsigned int)tv.tv_sec,
305                                 (unsigned int)tv.tv_usec);
306
307                         if (lws_add_http_header_by_name(wsi,
308                                 (unsigned char *)"set-cookie:",
309                                 (unsigned char *)b64, n, &p,
310                                 (unsigned char *)leaf_path + sizeof(leaf_path)))
311                                 return 1;
312                 }
313                 if (lws_is_ssl(wsi) && lws_add_http_header_by_name(wsi,
314                                                 (unsigned char *)
315                                                 "Strict-Transport-Security:",
316                                                 (unsigned char *)
317                                                 "max-age=15768000 ; "
318                                                 "includeSubDomains", 36, &p,
319                                                 (unsigned char *)leaf_path +
320                                                         sizeof(leaf_path)))
321                         return 1;
322                 n = (char *)p - leaf_path;
323
324                 n = lws_serve_http_file(wsi, buf, mimetype, other_headers, n);
325                 if (n < 0 || ((n > 0) && lws_http_transaction_completed(wsi)))
326                         return -1; /* error or can't reuse connection: close the socket */
327
328                 /*
329                  * notice that the sending of the file completes asynchronously,
330                  * we'll get a LWS_CALLBACK_HTTP_FILE_COMPLETION callback when
331                  * it's done
332                  */
333                 break;
334
335         case LWS_CALLBACK_HTTP_BODY:
336                 strncpy(buf, in, 20);
337                 buf[20] = '\0';
338                 if (len < 20)
339                         buf[len] = '\0';
340
341                 lwsl_notice("LWS_CALLBACK_HTTP_BODY: %s... len %d\n",
342                                 (const char *)buf, (int)len);
343
344                 break;
345
346         case LWS_CALLBACK_HTTP_BODY_COMPLETION:
347                 lwsl_notice("LWS_CALLBACK_HTTP_BODY_COMPLETION\n");
348                 /* the whole of the sent body arrived, close or reuse the connection */
349                 lws_return_http_status(wsi, HTTP_STATUS_OK, NULL);
350                 goto try_to_reuse;
351
352         case LWS_CALLBACK_HTTP_FILE_COMPLETION:
353                 goto try_to_reuse;
354
355         case LWS_CALLBACK_HTTP_WRITEABLE:
356                 lwsl_info("LWS_CALLBACK_HTTP_WRITEABLE\n");
357
358                 if (pss->client_finished)
359                         return -1;
360
361                 if (pss->fd == LWS_INVALID_FILE)
362                         goto try_to_reuse;
363 #ifdef LWS_WITH_CGI
364                 if (pss->reason_bf & 1) {
365                         if (lws_cgi_write_split_stdout_headers(wsi) < 0)
366                                 goto bail;
367
368                         pss->reason_bf &= ~1;
369                         break;
370                 }
371 #endif
372 #ifndef LWS_NO_CLIENT
373                 if (pss->reason_bf & 2) {
374                         char *px = buf + LWS_PRE;
375                         int lenx = sizeof(buf) - LWS_PRE;
376                         /*
377                          * our sink is writeable and our source has something
378                          * to read.  So read a lump of source material of
379                          * suitable size to send or what's available, whichever
380                          * is the smaller.
381                          */
382                         pss->reason_bf &= ~2;
383                         wsi1 = lws_get_child(wsi);
384                         if (!wsi1)
385                                 break;
386                         if (lws_http_client_read(wsi1, &px, &lenx) < 0)
387                                 goto bail;
388
389                         if (pss->client_finished)
390                                 return -1;
391                         break;
392                 }
393 #endif
394                 /*
395                  * we can send more of whatever it is we were sending
396                  */
397                 sent = 0;
398                 do {
399                         /* we'd like the send this much */
400                         n = sizeof(buffer) - LWS_PRE;
401
402                         /* but if the peer told us he wants less, we can adapt */
403                         m = lws_get_peer_write_allowance(wsi);
404
405                         /* -1 means not using a protocol that has this info */
406                         if (m == 0)
407                                 /* right now, peer can't handle anything */
408                                 goto later;
409
410                         if (m != -1 && m < n)
411                                 /* he couldn't handle that much */
412                                 n = m;
413
414                         n = lws_plat_file_read(wsi, pss->fd,
415                                                &amount, buffer + LWS_PRE, n);
416                         /* problem reading, close conn */
417                         if (n < 0) {
418                                 lwsl_err("problem reading file\n");
419                                 goto bail;
420                         }
421                         n = (int)amount;
422                         /* sent it all, close conn */
423                         if (n == 0)
424                                 goto penultimate;
425                         /*
426                          * To support HTTP2, must take care about preamble space
427                          *
428                          * identification of when we send the last payload frame
429                          * is handled by the library itself if you sent a
430                          * content-length header
431                          */
432                         m = lws_write(wsi, buffer + LWS_PRE, n, LWS_WRITE_HTTP);
433                         if (m < 0) {
434                                 lwsl_err("write failed\n");
435                                 /* write failed, close conn */
436                                 goto bail;
437                         }
438                         if (m) /* while still active, extend timeout */
439                                 lws_set_timeout(wsi, PENDING_TIMEOUT_HTTP_CONTENT, 5);
440                         sent += m;
441
442                 } while (!lws_send_pipe_choked(wsi) && (sent < 1024 * 1024));
443 later:
444                 lws_callback_on_writable(wsi);
445                 break;
446 penultimate:
447                 lws_plat_file_close(wsi, pss->fd);
448                 pss->fd = LWS_INVALID_FILE;
449                 goto try_to_reuse;
450
451 bail:
452                 lws_plat_file_close(wsi, pss->fd);
453
454                 return -1;
455
456         /*
457          * callback for confirming to continue with client IP appear in
458          * protocol 0 callback since no websocket protocol has been agreed
459          * yet.  You can just ignore this if you won't filter on client IP
460          * since the default unhandled callback return is 0 meaning let the
461          * connection continue.
462          */
463         case LWS_CALLBACK_FILTER_NETWORK_CONNECTION:
464                 /* if we returned non-zero from here, we kill the connection */
465                 break;
466
467 #ifndef LWS_NO_CLIENT
468         case LWS_CALLBACK_ESTABLISHED_CLIENT_HTTP: {
469                 char ctype[64], ctlen = 0;
470                 lwsl_err("LWS_CALLBACK_ESTABLISHED_CLIENT_HTTP\n");
471                 p = buffer + LWS_PRE;
472                 end = p + sizeof(buffer) - LWS_PRE;
473                 if (lws_add_http_header_status(lws_get_parent(wsi), 200, &p, end))
474                         return 1;
475                 if (lws_add_http_header_by_token(lws_get_parent(wsi),
476                                 WSI_TOKEN_HTTP_SERVER,
477                                 (unsigned char *)"libwebsockets",
478                                 13, &p, end))
479                         return 1;
480
481                 ctlen = lws_hdr_copy(wsi, ctype, sizeof(ctype), WSI_TOKEN_HTTP_CONTENT_TYPE);
482                 if (ctlen > 0) {
483                         if (lws_add_http_header_by_token(lws_get_parent(wsi),
484                                 WSI_TOKEN_HTTP_CONTENT_TYPE,
485                                 (unsigned char *)ctype, ctlen, &p, end))
486                                 return 1;
487                 }
488 #if 0
489                 if (lws_add_http_header_content_length(lws_get_parent(wsi),
490                                                        file_len, &p, end))
491                         return 1;
492 #endif
493                 if (lws_finalize_http_header(lws_get_parent(wsi), &p, end))
494                         return 1;
495
496                 *p = '\0';
497                 lwsl_info("%s\n", buffer + LWS_PRE);
498
499                 n = lws_write(lws_get_parent(wsi), buffer + LWS_PRE,
500                               p - (buffer + LWS_PRE),
501                               LWS_WRITE_HTTP_HEADERS);
502                 if (n < 0)
503                         return -1;
504
505                 break; }
506         case LWS_CALLBACK_CLOSED_CLIENT_HTTP:
507                 //lwsl_err("LWS_CALLBACK_CLOSED_CLIENT_HTTP\n");
508                 return -1;
509                 break;
510         case LWS_CALLBACK_RECEIVE_CLIENT_HTTP:
511                 //lwsl_err("LWS_CALLBACK_RECEIVE_CLIENT_HTTP: wsi %p\n", wsi);
512                 assert(lws_get_parent(wsi));
513                 if (!lws_get_parent(wsi))
514                         break;
515                 // lwsl_err("LWS_CALLBACK_RECEIVE_CLIENT_HTTP: wsi %p: sock: %d, parent_wsi: %p, parent_sock:%d,  len %d\n",
516                 //              wsi, lws_get_socket_fd(wsi),
517                 //              lws_get_parent(wsi),
518                 //              lws_get_socket_fd(lws_get_parent(wsi)), len);
519                 pss1 = lws_wsi_user(lws_get_parent(wsi));
520                 pss1->reason_bf |= 2;
521                 lws_callback_on_writable(lws_get_parent(wsi));
522                 break;
523         case LWS_CALLBACK_RECEIVE_CLIENT_HTTP_READ:
524                 //lwsl_err("LWS_CALLBACK_RECEIVE_CLIENT_HTTP_READ len %d\n", len);
525                 assert(lws_get_parent(wsi));
526                 m = lws_write(lws_get_parent(wsi), (unsigned char *)in,
527                                 len, LWS_WRITE_HTTP);
528                 if (m < 0)
529                         return -1;
530                 break;
531         case LWS_CALLBACK_COMPLETED_CLIENT_HTTP:
532                 //lwsl_err("LWS_CALLBACK_COMPLETED_CLIENT_HTTP\n");
533                 assert(lws_get_parent(wsi));
534                 if (!lws_get_parent(wsi))
535                         break;
536                 pss1 = lws_wsi_user(lws_get_parent(wsi));
537                 pss1->client_finished = 1;
538                 break;
539 #endif
540
541 #ifdef LWS_WITH_CGI
542         /* CGI IO events (POLLIN/OUT) appear here our demo user code policy is
543          *
544          *  - POST data goes on subprocess stdin
545          *  - subprocess stdout goes on http via writeable callback
546          *  - subprocess stderr goes to the logs
547          */
548         case LWS_CALLBACK_CGI:
549                 pss->args = *((struct lws_cgi_args *)in);
550                 //lwsl_notice("LWS_CALLBACK_CGI: ch %d\n", pss->args.ch);
551                 switch (pss->args.ch) { /* which of stdin/out/err ? */
552                 case LWS_STDIN:
553                         /* TBD stdin rx flow control */
554                         break;
555                 case LWS_STDOUT:
556                         pss->reason_bf |= 1;
557                         /* when writing to MASTER would not block */
558                         lws_callback_on_writable(wsi);
559                         break;
560                 case LWS_STDERR:
561                         n = read(lws_get_socket_fd(pss->args.stdwsi[LWS_STDERR]),
562                                         buf, 127);
563                         //lwsl_notice("stderr reads %d\n", n);
564                         if (n > 0) {
565                                 if (buf[n - 1] != '\n')
566                                         buf[n++] = '\n';
567                                 buf[n] = '\0';
568                                 lwsl_notice("CGI-stderr: %s\n", buf);
569                         }
570                         break;
571                 }
572                 break;
573
574         case LWS_CALLBACK_CGI_TERMINATED:
575                 //lwsl_notice("LWS_CALLBACK_CGI_TERMINATED\n");
576                 /* because we sent on openended http, close the connection */
577                 return -1;
578
579         case LWS_CALLBACK_CGI_STDIN_DATA:  /* POST body for stdin */
580                 //lwsl_notice("LWS_CALLBACK_CGI_STDIN_DATA\n");
581                 pss->args = *((struct lws_cgi_args *)in);
582                 n = write(lws_get_socket_fd(pss->args.stdwsi[LWS_STDIN]),
583                           pss->args.data, pss->args.len);
584                 //lwsl_notice("LWS_CALLBACK_CGI_STDIN_DATA: write says %d", n);
585                 if (n < pss->args.len)
586                         lwsl_notice("LWS_CALLBACK_CGI_STDIN_DATA: sent %d only %d went",
587                                         n, pss->args.len);
588                 return n;
589 #endif
590
591         /*
592          * callbacks for managing the external poll() array appear in
593          * protocol 0 callback
594          */
595
596         case LWS_CALLBACK_LOCK_POLL:
597                 /*
598                  * lock mutex to protect pollfd state
599                  * called before any other POLL related callback
600                  * if protecting wsi lifecycle change, len == 1
601                  */
602                 test_server_lock(len);
603                 break;
604
605         case LWS_CALLBACK_UNLOCK_POLL:
606                 /*
607                  * unlock mutex to protect pollfd state when
608                  * called after any other POLL related callback
609                  * if protecting wsi lifecycle change, len == 1
610                  */
611                 test_server_unlock(len);
612                 break;
613
614 #ifdef EXTERNAL_POLL
615         case LWS_CALLBACK_ADD_POLL_FD:
616
617                 if (count_pollfds >= max_poll_elements) {
618                         lwsl_err("LWS_CALLBACK_ADD_POLL_FD: too many sockets to track\n");
619                         return 1;
620                 }
621
622                 fd_lookup[pa->fd] = count_pollfds;
623                 pollfds[count_pollfds].fd = pa->fd;
624                 pollfds[count_pollfds].events = pa->events;
625                 pollfds[count_pollfds++].revents = 0;
626                 break;
627
628         case LWS_CALLBACK_DEL_POLL_FD:
629                 if (!--count_pollfds)
630                         break;
631                 m = fd_lookup[pa->fd];
632                 /* have the last guy take up the vacant slot */
633                 pollfds[m] = pollfds[count_pollfds];
634                 fd_lookup[pollfds[count_pollfds].fd] = m;
635                 break;
636
637         case LWS_CALLBACK_CHANGE_MODE_POLL_FD:
638                 pollfds[fd_lookup[pa->fd]].events = pa->events;
639                 break;
640 #endif
641
642         case LWS_CALLBACK_GET_THREAD_ID:
643                 /*
644                  * if you will call "lws_callback_on_writable"
645                  * from a different thread, return the caller thread ID
646                  * here so lws can use this information to work out if it
647                  * should signal the poll() loop to exit and restart early
648                  */
649
650                 /* return pthread_getthreadid_np(); */
651
652                 break;
653
654         default:
655                 break;
656         }
657
658         return 0;
659
660         /* if we're on HTTP1.1 or 2.0, will keep the idle connection alive */
661 try_to_reuse:
662         if (lws_http_transaction_completed(wsi))
663                 return -1;
664
665         return 0;
666 }