fops-zip
[platform/upstream/libwebsockets.git] / lib / lws-plat-unix.c
1 #include "private-libwebsockets.h"
2
3 #include <pwd.h>
4 #include <grp.h>
5
6 #ifdef LWS_WITH_PLUGINS
7 #include <dlfcn.h>
8 #endif
9 #include <dirent.h>
10
11
12 /*
13  * included from libwebsockets.c for unix builds
14  */
15
16 unsigned long long time_in_microseconds(void)
17 {
18         struct timeval tv;
19         gettimeofday(&tv, NULL);
20         return ((unsigned long long)tv.tv_sec * 1000000LL) + tv.tv_usec;
21 }
22
23 LWS_VISIBLE int
24 lws_get_random(struct lws_context *context, void *buf, int len)
25 {
26         return read(context->fd_random, (char *)buf, len);
27 }
28
29 LWS_VISIBLE int
30 lws_send_pipe_choked(struct lws *wsi)
31 {
32         struct lws_pollfd fds;
33
34         /* treat the fact we got a truncated send pending as if we're choked */
35         if (wsi->trunc_len)
36                 return 1;
37
38         fds.fd = wsi->desc.sockfd;
39         fds.events = POLLOUT;
40         fds.revents = 0;
41
42         if (poll(&fds, 1, 0) != 1)
43                 return 1;
44
45         if ((fds.revents & POLLOUT) == 0)
46                 return 1;
47
48         /* okay to send another packet without blocking */
49
50         return 0;
51 }
52
53 LWS_VISIBLE int
54 lws_poll_listen_fd(struct lws_pollfd *fd)
55 {
56         return poll(fd, 1, 0);
57 }
58
59 LWS_VISIBLE void
60 lws_cancel_service_pt(struct lws *wsi)
61 {
62         struct lws_context_per_thread *pt = &wsi->context->pt[(int)wsi->tsi];
63         char buf = 0;
64
65         if (write(pt->dummy_pipe_fds[1], &buf, sizeof(buf)) != 1)
66                 lwsl_err("Cannot write to dummy pipe");
67 }
68
69 LWS_VISIBLE void
70 lws_cancel_service(struct lws_context *context)
71 {
72         struct lws_context_per_thread *pt = &context->pt[0];
73         char buf = 0, m = context->count_threads;
74
75         while (m--) {
76                 if (write(pt->dummy_pipe_fds[1], &buf, sizeof(buf)) != 1)
77                         lwsl_err("Cannot write to dummy pipe");
78                 pt++;
79         }
80 }
81
82 LWS_VISIBLE void lwsl_emit_syslog(int level, const char *line)
83 {
84         int syslog_level = LOG_DEBUG;
85
86         switch (level) {
87         case LLL_ERR:
88                 syslog_level = LOG_ERR;
89                 break;
90         case LLL_WARN:
91                 syslog_level = LOG_WARNING;
92                 break;
93         case LLL_NOTICE:
94                 syslog_level = LOG_NOTICE;
95                 break;
96         case LLL_INFO:
97                 syslog_level = LOG_INFO;
98                 break;
99         }
100         syslog(syslog_level, "%s", line);
101 }
102
103 LWS_VISIBLE LWS_EXTERN int
104 _lws_plat_service_tsi(struct lws_context *context, int timeout_ms, int tsi)
105 {
106         struct lws_context_per_thread *pt;
107         int n = -1, m, c;
108         char buf;
109
110         /* stay dead once we are dead */
111
112         if (!context || !context->vhost_list)
113                 return 1;
114
115         pt = &context->pt[tsi];
116
117         if (timeout_ms < 0)
118                 goto faked_service;
119
120         lws_libev_run(context, tsi);
121         lws_libuv_run(context, tsi);
122
123         if (!context->service_tid_detected) {
124                 struct lws _lws;
125
126                 memset(&_lws, 0, sizeof(_lws));
127                 _lws.context = context;
128
129                 context->service_tid_detected =
130                         context->vhost_list->protocols[0].callback(
131                         &_lws, LWS_CALLBACK_GET_THREAD_ID, NULL, NULL, 0);
132         }
133         context->service_tid = context->service_tid_detected;
134
135         /*
136          * is there anybody with pending stuff that needs service forcing?
137          */
138         if (!lws_service_adjust_timeout(context, 1, tsi)) {
139                 /* -1 timeout means just do forced service */
140                 _lws_plat_service_tsi(context, -1, pt->tid);
141                 /* still somebody left who wants forced service? */
142                 if (!lws_service_adjust_timeout(context, 1, pt->tid))
143                         /* yes... come back again quickly */
144                         timeout_ms = 0;
145         }
146
147         n = poll(pt->fds, pt->fds_count, timeout_ms);
148
149 #ifdef LWS_OPENSSL_SUPPORT
150         if (!pt->rx_draining_ext_list &&
151             !lws_ssl_anybody_has_buffered_read_tsi(context, tsi) && !n) {
152 #else
153         if (!pt->rx_draining_ext_list && !n) /* poll timeout */ {
154 #endif
155                 lws_service_fd_tsi(context, NULL, tsi);
156                 return 0;
157         }
158
159 faked_service:
160         m = lws_service_flag_pending(context, tsi);
161         if (m)
162                 c = -1; /* unknown limit */
163         else
164                 if (n < 0) {
165                         if (LWS_ERRNO != LWS_EINTR)
166                                 return -1;
167                         return 0;
168                 } else
169                         c = n;
170
171         /* any socket with events to service? */
172         for (n = 0; n < pt->fds_count && c; n++) {
173                 if (!pt->fds[n].revents)
174                         continue;
175
176                 c--;
177
178                 if (pt->fds[n].fd == pt->dummy_pipe_fds[0]) {
179                         if (read(pt->fds[n].fd, &buf, 1) != 1)
180                                 lwsl_err("Cannot read from dummy pipe.");
181                         continue;
182                 }
183
184                 m = lws_service_fd_tsi(context, &pt->fds[n], tsi);
185                 if (m < 0)
186                         return -1;
187                 /* if something closed, retry this slot */
188                 if (m)
189                         n--;
190         }
191
192         return 0;
193 }
194
195 LWS_VISIBLE int
196 lws_plat_check_connection_error(struct lws *wsi)
197 {
198         return 0;
199 }
200
201 LWS_VISIBLE int
202 lws_plat_service(struct lws_context *context, int timeout_ms)
203 {
204         return _lws_plat_service_tsi(context, timeout_ms, 0);
205 }
206
207 LWS_VISIBLE int
208 lws_plat_set_socket_options(struct lws_vhost *vhost, int fd)
209 {
210         int optval = 1;
211         socklen_t optlen = sizeof(optval);
212
213 #if defined(__APPLE__) || \
214     defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || \
215     defined(__NetBSD__) || \
216     defined(__OpenBSD__)
217         struct protoent *tcp_proto;
218 #endif
219
220         if (vhost->ka_time) {
221                 /* enable keepalive on this socket */
222                 optval = 1;
223                 if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE,
224                                (const void *)&optval, optlen) < 0)
225                         return 1;
226
227 #if defined(__APPLE__) || \
228     defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || \
229     defined(__NetBSD__) || \
230         defined(__CYGWIN__) || defined(__OpenBSD__) || defined (__sun)
231
232                 /*
233                  * didn't find a way to set these per-socket, need to
234                  * tune kernel systemwide values
235                  */
236 #else
237                 /* set the keepalive conditions we want on it too */
238                 optval = vhost->ka_time;
239                 if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPIDLE,
240                                (const void *)&optval, optlen) < 0)
241                         return 1;
242
243                 optval = vhost->ka_interval;
244                 if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPINTVL,
245                                (const void *)&optval, optlen) < 0)
246                         return 1;
247
248                 optval = vhost->ka_probes;
249                 if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPCNT,
250                                (const void *)&optval, optlen) < 0)
251                         return 1;
252 #endif
253         }
254
255         /* Disable Nagle */
256         optval = 1;
257 #if defined (__sun)
258         if (setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (const void *)&optval, optlen) < 0)
259                 return 1;
260 #elif !defined(__APPLE__) && \
261       !defined(__FreeBSD__) && !defined(__FreeBSD_kernel__) &&        \
262       !defined(__NetBSD__) && \
263       !defined(__OpenBSD__)
264         if (setsockopt(fd, SOL_TCP, TCP_NODELAY, (const void *)&optval, optlen) < 0)
265                 return 1;
266 #else
267         tcp_proto = getprotobyname("TCP");
268         if (setsockopt(fd, tcp_proto->p_proto, TCP_NODELAY, &optval, optlen) < 0)
269                 return 1;
270 #endif
271
272         /* We are nonblocking... */
273         if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0)
274                 return 1;
275
276         return 0;
277 }
278
279 LWS_VISIBLE void
280 lws_plat_drop_app_privileges(struct lws_context_creation_info *info)
281 {
282         if (info->gid != -1)
283                 if (setgid(info->gid))
284                         lwsl_warn("setgid: %s\n", strerror(LWS_ERRNO));
285
286         if (info->uid != -1) {
287                 struct passwd *p = getpwuid(info->uid);
288
289                 if (p) {
290                         initgroups(p->pw_name, info->gid);
291                         if (setuid(info->uid))
292                                 lwsl_warn("setuid: %s\n", strerror(LWS_ERRNO));
293                         else
294                                 lwsl_notice("Set privs to user '%s'\n", p->pw_name);
295                 } else
296                         lwsl_warn("getpwuid: unable to find uid %d", info->uid);
297         }
298 }
299
300 #ifdef LWS_WITH_PLUGINS
301
302 #if defined(LWS_USE_LIBUV) && UV_VERSION_MAJOR > 0
303
304 /* libuv.c implements these in a cross-platform way */
305
306 #else
307
308 static int filter(const struct dirent *ent)
309 {
310         if (!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, ".."))
311                 return 0;
312
313         return 1;
314 }
315
316 LWS_VISIBLE int
317 lws_plat_plugins_init(struct lws_context * context, const char * const *d)
318 {
319         struct lws_plugin_capability lcaps;
320         struct lws_plugin *plugin;
321         lws_plugin_init_func initfunc;
322         struct dirent **namelist;
323         int n, i, m, ret = 0;
324         char path[256];
325         void *l;
326
327         lwsl_notice("  Plugins:\n");
328
329         while (d && *d) {
330                 n = scandir(*d, &namelist, filter, alphasort);
331                 if (n < 0) {
332                         lwsl_err("Scandir on %s failed\n", *d);
333                         return 1;
334                 }
335
336                 for (i = 0; i < n; i++) {
337                         if (strlen(namelist[i]->d_name) < 7)
338                                 goto inval;
339
340                         lwsl_notice("   %s\n", namelist[i]->d_name);
341
342                         lws_snprintf(path, sizeof(path) - 1, "%s/%s", *d,
343                                  namelist[i]->d_name);
344                         l = dlopen(path, RTLD_NOW);
345                         if (!l) {
346                                 lwsl_err("Error loading DSO: %s\n", dlerror());
347                                 while (i++ < n)
348                                         free(namelist[i]);
349                                 goto bail;
350                         }
351                         /* we could open it, can we get his init function? */
352                         m = lws_snprintf(path, sizeof(path) - 1, "init_%s",
353                                      namelist[i]->d_name + 3 /* snip lib... */);
354                         path[m - 3] = '\0'; /* snip the .so */
355                         initfunc = dlsym(l, path);
356                         if (!initfunc) {
357                                 lwsl_err("Failed to get init on %s: %s",
358                                                 namelist[i]->d_name, dlerror());
359                                 dlclose(l);
360                         }
361                         lcaps.api_magic = LWS_PLUGIN_API_MAGIC;
362                         m = initfunc(context, &lcaps);
363                         if (m) {
364                                 lwsl_err("Initializing %s failed %d\n",
365                                         namelist[i]->d_name, m);
366                                 dlclose(l);
367                                 goto skip;
368                         }
369
370                         plugin = lws_malloc(sizeof(*plugin));
371                         if (!plugin) {
372                                 lwsl_err("OOM\n");
373                                 goto bail;
374                         }
375                         plugin->list = context->plugin_list;
376                         context->plugin_list = plugin;
377                         strncpy(plugin->name, namelist[i]->d_name, sizeof(plugin->name) - 1);
378                         plugin->name[sizeof(plugin->name) - 1] = '\0';
379                         plugin->l = l;
380                         plugin->caps = lcaps;
381                         context->plugin_protocol_count += lcaps.count_protocols;
382                         context->plugin_extension_count += lcaps.count_extensions;
383
384                         free(namelist[i]);
385                         continue;
386
387         skip:
388                         dlclose(l);
389         inval:
390                         free(namelist[i]);
391                 }
392                 free(namelist);
393                 d++;
394         }
395
396 bail:
397         free(namelist);
398
399         return ret;
400 }
401
402 LWS_VISIBLE int
403 lws_plat_plugins_destroy(struct lws_context * context)
404 {
405         struct lws_plugin *plugin = context->plugin_list, *p;
406         lws_plugin_destroy_func func;
407         char path[256];
408         int m;
409
410         if (!plugin)
411                 return 0;
412
413         lwsl_notice("%s\n", __func__);
414
415         while (plugin) {
416                 p = plugin;
417                 m = lws_snprintf(path, sizeof(path) - 1, "destroy_%s", plugin->name + 3);
418                 path[m - 3] = '\0';
419                 func = dlsym(plugin->l, path);
420                 if (!func) {
421                         lwsl_err("Failed to get destroy on %s: %s",
422                                         plugin->name, dlerror());
423                         goto next;
424                 }
425                 m = func(context);
426                 if (m)
427                         lwsl_err("Initializing %s failed %d\n",
428                                 plugin->name, m);
429 next:
430                 dlclose(p->l);
431                 plugin = p->list;
432                 p->list = NULL;
433                 free(p);
434         }
435
436         context->plugin_list = NULL;
437
438         return 0;
439 }
440
441 #endif
442 #endif
443
444
445 #if 0
446 static void
447 sigabrt_handler(int x)
448 {
449         printf("%s\n", __func__);
450         //*(char *)0 = 0;
451 }
452 #endif
453
454 LWS_VISIBLE int
455 lws_plat_context_early_init(void)
456 {
457         signal(SIGPIPE, SIG_IGN);
458
459 //      signal(SIGABRT, sigabrt_handler);
460
461         return 0;
462 }
463
464 LWS_VISIBLE void
465 lws_plat_context_early_destroy(struct lws_context *context)
466 {
467 }
468
469 LWS_VISIBLE void
470 lws_plat_context_late_destroy(struct lws_context *context)
471 {
472         struct lws_context_per_thread *pt = &context->pt[0];
473         int m = context->count_threads;
474
475 #ifdef LWS_WITH_PLUGINS
476         if (context->plugin_list)
477                 lws_plat_plugins_destroy(context);
478 #endif
479
480         if (context->lws_lookup)
481                 lws_free(context->lws_lookup);
482
483         while (m--) {
484                 if (pt->dummy_pipe_fds[0])
485                         close(pt->dummy_pipe_fds[0]);
486                 if (pt->dummy_pipe_fds[1])
487                         close(pt->dummy_pipe_fds[1]);
488                 pt++;
489         }
490         if (!context->fd_random)
491                 lwsl_err("ZERO RANDOM FD\n");
492         if (context->fd_random != LWS_INVALID_FILE)
493                 close(context->fd_random);
494 }
495
496 /* cast a struct sockaddr_in6 * into addr for ipv6 */
497
498 LWS_VISIBLE int
499 lws_interface_to_sa(int ipv6, const char *ifname, struct sockaddr_in *addr,
500                     size_t addrlen)
501 {
502         int rc = -1;
503
504         struct ifaddrs *ifr;
505         struct ifaddrs *ifc;
506 #ifdef LWS_USE_IPV6
507         struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)addr;
508 #endif
509
510         getifaddrs(&ifr);
511         for (ifc = ifr; ifc != NULL && rc; ifc = ifc->ifa_next) {
512                 if (!ifc->ifa_addr)
513                         continue;
514
515                 lwsl_info(" interface %s vs %s\n", ifc->ifa_name, ifname);
516
517                 if (strcmp(ifc->ifa_name, ifname))
518                         continue;
519
520                 switch (ifc->ifa_addr->sa_family) {
521                 case AF_INET:
522 #ifdef LWS_USE_IPV6
523                         if (ipv6) {
524                                 /* map IPv4 to IPv6 */
525                                 bzero((char *)&addr6->sin6_addr,
526                                                 sizeof(struct in6_addr));
527                                 addr6->sin6_addr.s6_addr[10] = 0xff;
528                                 addr6->sin6_addr.s6_addr[11] = 0xff;
529                                 memcpy(&addr6->sin6_addr.s6_addr[12],
530                                         &((struct sockaddr_in *)ifc->ifa_addr)->sin_addr,
531                                                         sizeof(struct in_addr));
532                         } else
533 #endif
534                                 memcpy(addr,
535                                         (struct sockaddr_in *)ifc->ifa_addr,
536                                                     sizeof(struct sockaddr_in));
537                         break;
538 #ifdef LWS_USE_IPV6
539                 case AF_INET6:
540                         memcpy(&addr6->sin6_addr,
541                           &((struct sockaddr_in6 *)ifc->ifa_addr)->sin6_addr,
542                                                        sizeof(struct in6_addr));
543                         break;
544 #endif
545                 default:
546                         continue;
547                 }
548                 rc = 0;
549         }
550
551         freeifaddrs(ifr);
552
553         if (rc == -1) {
554                 /* check if bind to IP address */
555 #ifdef LWS_USE_IPV6
556                 if (inet_pton(AF_INET6, ifname, &addr6->sin6_addr) == 1)
557                         rc = 0;
558                 else
559 #endif
560                 if (inet_pton(AF_INET, ifname, &addr->sin_addr) == 1)
561                         rc = 0;
562         }
563
564         return rc;
565 }
566
567 LWS_VISIBLE void
568 lws_plat_insert_socket_into_fds(struct lws_context *context, struct lws *wsi)
569 {
570         struct lws_context_per_thread *pt = &context->pt[(int)wsi->tsi];
571
572         lws_libev_io(wsi, LWS_EV_START | LWS_EV_READ);
573         lws_libuv_io(wsi, LWS_EV_START | LWS_EV_READ);
574
575         pt->fds[pt->fds_count++].revents = 0;
576 }
577
578 LWS_VISIBLE void
579 lws_plat_delete_socket_from_fds(struct lws_context *context,
580                                                 struct lws *wsi, int m)
581 {
582         struct lws_context_per_thread *pt = &context->pt[(int)wsi->tsi];
583
584         lws_libev_io(wsi, LWS_EV_STOP | LWS_EV_READ | LWS_EV_WRITE);
585         lws_libuv_io(wsi, LWS_EV_STOP | LWS_EV_READ | LWS_EV_WRITE);
586
587         pt->fds_count--;
588 }
589
590 LWS_VISIBLE void
591 lws_plat_service_periodic(struct lws_context *context)
592 {
593         /* if our parent went down, don't linger around */
594         if (context->started_with_parent &&
595             kill(context->started_with_parent, 0) < 0)
596                 kill(getpid(), SIGTERM);
597 }
598
599 LWS_VISIBLE int
600 lws_plat_change_pollfd(struct lws_context *context,
601                       struct lws *wsi, struct lws_pollfd *pfd)
602 {
603         return 0;
604 }
605
606 LWS_VISIBLE const char *
607 lws_plat_inet_ntop(int af, const void *src, char *dst, int cnt)
608 {
609         return inet_ntop(af, src, dst, cnt);
610 }
611
612 LWS_VISIBLE lws_fop_fd_t
613 _lws_plat_file_open(const struct lws_plat_file_ops *fops, const char *filename,
614                     const char *vpath, lws_fop_flags_t *flags)
615 {
616         struct stat stat_buf;
617         int ret = open(filename, (*flags) & LWS_FOP_FLAGS_MASK, 0664);
618         lws_fop_fd_t fop_fd;
619
620         if (ret < 0)
621                 return NULL;
622
623         if (fstat(ret, &stat_buf) < 0)
624                 goto bail;
625
626         fop_fd = malloc(sizeof(*fop_fd));
627         if (!fop_fd)
628                 goto bail;
629
630         fop_fd->fops = fops;
631         fop_fd->flags = *flags;
632         fop_fd->fd = ret;
633         fop_fd->filesystem_priv = NULL; /* we don't use it */
634         fop_fd->len = stat_buf.st_size;
635         fop_fd->pos = 0;
636
637         return fop_fd;
638
639 bail:
640         close(ret);
641         return NULL;
642 }
643
644 LWS_VISIBLE int
645 _lws_plat_file_close(lws_fop_fd_t *fop_fd)
646 {
647         int fd = (*fop_fd)->fd;
648
649         free(*fop_fd);
650         *fop_fd = NULL;
651
652         return close(fd);
653 }
654
655 LWS_VISIBLE lws_fileofs_t
656 _lws_plat_file_seek_cur(lws_fop_fd_t fop_fd, lws_fileofs_t offset)
657 {
658         lws_fileofs_t r;
659
660         if (offset > 0 && offset > fop_fd->len - fop_fd->pos)
661                 offset = fop_fd->len - fop_fd->pos;
662
663         if ((lws_fileofs_t)fop_fd->pos + offset < 0)
664                 offset = -fop_fd->pos;
665
666         r = lseek(fop_fd->fd, offset, SEEK_CUR);
667
668         if (r >= 0)
669                 fop_fd->pos = r;
670         else
671                 lwsl_err("error seeking from cur %ld, offset %ld\n",
672                          fop_fd->pos, offset);
673
674         return r;
675 }
676
677 LWS_VISIBLE int
678 _lws_plat_file_read(lws_fop_fd_t fop_fd, lws_filepos_t *amount,
679                     uint8_t *buf, lws_filepos_t len)
680 {
681         long n;
682
683         n = read((int)fop_fd->fd, buf, len);
684         if (n == -1) {
685                 *amount = 0;
686                 return -1;
687         }
688         fop_fd->pos += n;
689         lwsl_debug("%s: read %ld of req %ld, pos %ld, len %ld\n", __func__, n,
690                    (long)len, fop_fd->pos, fop_fd->len);
691         *amount = n;
692
693         return 0;
694 }
695
696 LWS_VISIBLE int
697 _lws_plat_file_write(lws_fop_fd_t fop_fd, lws_filepos_t *amount,
698                      uint8_t *buf, lws_filepos_t len)
699 {
700         long n;
701
702         n = write((int)fop_fd->fd, buf, len);
703         if (n == -1) {
704                 *amount = 0;
705                 return -1;
706         }
707
708         fop_fd->pos += n;
709         *amount = n;
710
711         return 0;
712 }
713
714
715 LWS_VISIBLE int
716 lws_plat_init(struct lws_context *context,
717               struct lws_context_creation_info *info)
718 {
719         struct lws_context_per_thread *pt = &context->pt[0];
720         int n = context->count_threads, fd;
721
722         /* master context has the global fd lookup array */
723         context->lws_lookup = lws_zalloc(sizeof(struct lws *) *
724                                          context->max_fds);
725         if (context->lws_lookup == NULL) {
726                 lwsl_err("OOM on lws_lookup array for %d connections\n",
727                          context->max_fds);
728                 return 1;
729         }
730
731         lwsl_notice(" mem: platform fd map: %5lu bytes\n",
732                     (unsigned long)(sizeof(struct lws *) * context->max_fds));
733         fd = open(SYSTEM_RANDOM_FILEPATH, O_RDONLY);
734
735         context->fd_random = fd;
736         if (context->fd_random < 0) {
737                 lwsl_err("Unable to open random device %s %d\n",
738                          SYSTEM_RANDOM_FILEPATH, context->fd_random);
739                 return 1;
740         }
741
742         if (!lws_libev_init_fd_table(context) &&
743             !lws_libuv_init_fd_table(context)) {
744                 /* otherwise libev handled it instead */
745
746                 while (n--) {
747                         if (pipe(pt->dummy_pipe_fds)) {
748                                 lwsl_err("Unable to create pipe\n");
749                                 return 1;
750                         }
751
752                         /* use the read end of pipe as first item */
753                         pt->fds[0].fd = pt->dummy_pipe_fds[0];
754                         pt->fds[0].events = LWS_POLLIN;
755                         pt->fds[0].revents = 0;
756                         pt->fds_count = 1;
757                         pt++;
758                 }
759         }
760
761 #ifdef LWS_WITH_PLUGINS
762         if (info->plugin_dirs)
763                 lws_plat_plugins_init(context, info->plugin_dirs);
764 #endif
765
766         return 0;
767 }