Commit graph

49 commits

Author SHA1 Message Date
Andy Green
659fefe330 cruft remove sigusr2 handling
Signed-off-by: Andy Green <andy@warmcat.com>
2016-04-22 21:58:38 +08:00
Andy Green
3564e3d5e9 libuv add idle processing to force service where needed
https://github.com/warmcat/libwebsockets/issues/485

Signed-off-by: Andy Green <andy@warmcat.com>
2016-04-07 18:56:40 +08:00
Andy Green
5e091c62a8 force service properly when unconsumed rxbuf in ah
Signed-off-by: Andy Green <andy.green@linaro.org>
2016-02-26 10:50:04 +08:00
Andy Green
d2a95e0c82 unix privs change group before user
Otherwise we no longer have privs to change the group after doing the user

Signed-off-by: Andy Green <andy.green@linaro.org>
2016-02-25 15:15:41 +08:00
Andy Green
2c218e705f ah owns rxbuf
This is intended to solve a longstanding problem with the
relationship between http/1.1 keep-alive and the service
loop.

Ah now contain an rx buffer which is used during header
processing, and the ah may not be detached from the wsi
until the rx buffer is exhausted.

Having the rx buffer in the ah means we can delay using the
rx until a later service loop.

Ah which have pending rx force POLLIN service on the wsi
they are attached to automatically, so we can interleave
general service / connections with draining each ah rx
buffer.

The possible http/1.1 situations and their dispositions are:

 1) exactly one set of http headers come.  After processing,
    the ah is detached since no pending rx left.  If more
    headers come later, a fresh ah is aqcuired when available
    and the rx flow control blocks the read until then.

 2) more that one whole set of headers come and we remain in
    http mode (no upgrade).  The ah is left attached and
    returns to the service loop after the first set of headers.
    We will get forced service due to the ah having pending
    content (respecting flowcontrol) and process the pending
    rx in the ah.  If we use it all up, we will detach the
    ah.

 3) one set of http headers come with ws traffic appended.
    We service the headers, do the upgrade, and keep the ah
    until the remaining ws content is used.  When we
    exhausted the ws traffix in the ah rx buffer, we
    detach the ah.

Since there can be any amount of http/1.1 pipelining on a
connection, and each may be expensive to service, it's now
enforced there is a return to the service loop after each
header set is serviced on a connection.

When I added the forced service for ah with pending buffering,
I added support for it to the windows plat code.  However this
is untested.

Signed-off-by: Andy Green <andy.green@linaro.org>
2016-02-15 14:57:55 +08:00
Andy Green
86ed65ff00 libuv integration
This gets the libuv stuff plumbed in and working.

Currently it's only workable for some service thread, and there
is an isolated valgrind problem left

==28425== 128 bytes in 1 blocks are definitely lost in loss record 3 of 3
==28425==    at 0x4C28C50: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==28425==    by 0x4C2AB1E: realloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==28425==    by 0x58BBB27: maybe_resize (core.c:748)
==28425==    by 0x58BBB27: uv__io_start (core.c:787)
==28425==    by 0x58C1B80: uv__signal_loop_once_init (signal.c:225)
==28425==    by 0x58C1B80: uv_signal_init (signal.c:260)
==28425==    by 0x58BF7A6: uv_loop_init (loop.c:66)
==28425==    by 0x4157F5: lws_uv_initloop (libuv.c:89)
==28425==    by 0x405536: main (test-server-libuv.c:284)

libuv wants to sign off on all libuv 'handles' that will close, and
callback to do the close confirmation asynchronously.  The wsi close function
is adapted when libuv is in use to work with libuv accordingly and exit the uv
loop the number of remaining wsi is zero.

Signed-off-by: Andy Green <andy.green@linaro.org>
2016-02-14 09:31:13 +08:00
Andy Green
1b2c9a23e1 clean pre 1.7
Signed-off-by: Andy Green <andy.green@linaro.org>
2016-01-29 23:17:43 +08:00
Andy Green
8c1f6026a7 multithread stability
Signed-off-by: Andy Green <andy.green@linaro.org>
2016-01-26 20:56:56 +08:00
Andy Green
d3a5505542 multithreaded service
This adds support for multithreaded service to lws without adding any
threading or locking code in the library.

At context creation time you can request split the service part of the
context into n service domains, which are load-balanced so that the most
idle one gets the next listen socket accept.

There's a single listen socket on one port still.

User code may then spawn n threads doing n service loops / poll()s
simultaneously.  Locking is only required (I think) in the existing
FD lock callbacks already handled by the pthreads server example,
and that locking takes place in user code.  So the library remains
completely agnostic about the threading / locking scheme.

And by default, it's completely compatible with one service thread
so no changes are required by people uninterested in multithreaded
service.

However for people interested in extremely lightweight mass http[s]/
ws[s] service with minimum provisioning, the library can now do
everything out of the box.

To test it, just try

$ libwebsockets-test-server-pthreads -j 8

where -j controls the number of service threads

Signed-off-by: Andy Green <andy.green@linaro.org>
2016-01-19 20:02:36 +08:00
Andy Green
1d719ec87f lws_interface_to_sa
Expose interface handling code as an api
2016-01-16 12:09:38 +08:00
Andy Green
6711266a50 extension permessage deflate
Signed-off-by: Andy Green <andy.green@linaro.org>
2016-01-11 11:34:01 +08:00
Peter Pentchev
da2eab3f66 Recognize Debian GNU/kFreeBSD as FreeBSD-ish.
Some of the FreeBSD-specific code in libwebsockets is related to
the FreeBSD kernel, not the general build environment.  Thus, it is
important to make this distinction, especially when building on
platforms that have a FreeBSD kernel and a non-FreeBSD userland build
environment, such as Debian GNU/kFreeBSD.

When checking for FreeBSD kernel features, also check for the newly
introduced __FreeBSD_kernel__ preprocessor constant; it is present in
the GNU/kFreeBSD kernel and also in FreeBSD itself since the 9.1 release
about three years ago.
2015-12-25 21:15:21 +08:00
Andy Green
3df580066b http header malloc pool implement pool
Signed-off-by: Andy Green <andy.green@linaro.org>
2015-12-25 14:34:20 +08:00
Andy Green
c35b36b1cf detect service tid once and use wsi with valid context to do it
Signed-off-by: Andy Green <andy.green@linaro.org>
2015-12-24 13:00:54 +08:00
Andy Green
400e5a7fed libev complete unix plat context init
https://github.com/warmcat/libwebsockets/issues/381

Signed-off-by: Andy Green <andy.green@linaro.org>
2015-12-23 11:55:06 +08:00
Andy Green
54806b1541 clean internal refactor
- Mainly symbol length reduction
 - Whitespace clean
 - Code refactor for linear flow
 - Audit @Context for API docs vs changes

Signed-off-by: Andy Green <andy.green@linaro.org>
2015-12-17 17:03:59 +08:00
Andy Green
00c6d1579c public api remove context from user callback API BREAK
Since struct lws (wsi) now has his own context pointer,
we were able to remove the need for passing context
almost everywhere in the apis.

In turn, that means there's no real use for context being
passed to every callback; in the rare cases context is
needed user code can get it with lws_get_ctx(wsi)

Signed-off-by: Andy Green <andy.green@linaro.org>
2015-12-17 07:54:44 +08:00
Andy Green
11c05bfa09 public api remove superfluous context params API BREAK
Extend the cleanout caused by wsi having a context pointer
into the public api.

There's no point keeping the 1.5 compatibility work,
we have changed the api in several places and
rebuilt wasn't going to be enough a while ago.

Signed-off-by: Andy Green <andy.green@linaro.org>
2015-12-16 18:19:08 +08:00
Andy Green
6b5de70f4f refactor needless context with wsi paramater passing
Now we bit the bullet and gave each wsi an lws_context *, many
internal apis that take both a context and wsi parameter only
need the wsi.

Also simplify parser code by making a temp var for
allocated_headers * instead of the longwinded
dereference chain everywhere.

Signed-off-by: Andy Green <andy.green@linaro.org>
2015-12-15 21:15:58 +08:00
Andy Green
891628b33c lws_plat_fd add wsi to fops and helpers
Having the lws_context alone doesn't let us track state or act different
by wsi, which is the most interesting usecase.  Eg not only simply track
file position / decompression state per wsi but also act differently
according to wsi authentication state / associated cookies.

Signed-off-by: Andy Green <andy.green@linaro.org>
2015-12-14 06:43:35 +08:00
Andy Green
4e442b7743 lws_plat_fd implement platform default handlers
This is a rewrite of the patch from Soapyman here

https://github.com/warmcat/libwebsockets/pull/363

The main changes compared to Soapyman's original patch are

 - There's no new stuff in the info struct user code does any overrides
   it may want to do explicitly after lws_context_create returns

 - User overrides for file ops can call through (subclass) to the original
   platform implementation using lws_get_fops_plat()

 - A typedef is provided for plat-specific fd type

 - Public helpers are provided to allow user code to be platform-independent
   about file access, using the lws platform file operations underneath:

static inline lws_filefd_type
lws_plat_file_open(struct lws_plat_file_ops *fops, const char *filename,
		   unsigned long *filelen, int flags)

static inline int
lws_plat_file_close(struct lws_plat_file_ops *fops, lws_filefd_type fd)

static inline unsigned long
lws_plat_file_seek_cur(struct lws_plat_file_ops *fops, lws_filefd_type fd,
		       long offset_from_cur_pos)

static inline int
lws_plat_file_read(struct lws_plat_file_ops *fops, lws_filefd_type fd,
		   unsigned long *amount, unsigned char *buf, unsigned long len)

static inline int
lws_plat_file_write(struct lws_plat_file_ops *fops, lws_filefd_type fd,
		    unsigned long *amount, unsigned char *buf, unsigned long len)

There's example documentation and implementation in the test server.

Signed-off-by: Andy Green <andy.green@linaro.org>
2015-12-10 11:01:59 +08:00
Andy Green
4386e36b0b plat combine inits into single lws_plat_init and provide info
Signed-off-by: Andy Green <andy.green@linaro.org>
2015-12-10 07:14:16 +08:00
Andy Green
4b85c1d4ac api rationalization: eliminate all libwebsocket[s]_ prefixes
This nukes all the oldstyle prefixes except in the compatibility code.

struct libwebsockets becomes struct lws too.

The api docs are updated accordingly as are the READMEs that mention
those apis.

Signed-off-by: Andy Green <andy.green@linaro.org>
2015-12-04 11:08:32 +08:00
Andy Green
6230476455 api rationalization use new names internally
Change all internal uses of rationalized public apis to reflect the
new names.

Theer are a few things that got changed as side effect of search/replace
matches, but these are almost all internal.  I added a compatibility define
for the public enum that got renamed.

Theoretically existing code should not notice the difference from these
two patches.  And new code will find the new names.

https://github.com/warmcat/libwebsockets/issues/357

Signed-off-by: Andy Green <andy.green@linaro.org>
2015-12-04 08:43:54 +08:00
Thomas Greenslade
a2a4b0b084 additional https post fix
https://github.com/warmcat/libwebsockets/pull/298#issuecomment-147316562
2015-10-12 16:06:26 +08:00
=?UTF-8?q?Joakim=20S=C3=B6derberg?=
caf7e3d63b Fix potential memory leak
- Got rid of ifdef _WIN32 stuff adn moved to plat_ files instead.
- Also, check all calls to lws_zalloc, was potential failure on WIN32
- Made context destory enable to destroy a half inited context as well. This way I got get rid of some of the error handling complexity in libwebsocket_create_context
- Added TODOs for some potential problems I see where things might be leaking and such
2015-10-12 10:05:18 +08:00
Pokrovskiy
20636ec970 Fix broken libev support in client mode
Maybe it will be better to move all lws_libev_io() inside
lws_change_pollfd() to avoid similar problems in future.
The same for lws_libev_accept() and insert_wsi_socket_into_fds().
2015-04-22 07:50:44 +08:00
Andy Green
3a9f79e693 use initgroups in plat unix
Signed-off-by: Andy Green <andy.green@linaro.org>
2015-03-04 16:16:41 +08:00
banthonywalker
418a49b9e8 Subject: [PATCH] call lws_plat_inet_ntop instead of inet_ntop 2015-02-28 21:53:47 +08:00
Andy Green
30edd910b6 ssl pending buffered reads unbreak NO_SSL
Signed-off-by: Andy Green <andy.green@linaro.org>
2015-01-29 09:42:22 +08:00
Andy Green
5281560000 ssl pending buffered reads use linked list
Signed-off-by: Andy Green <andy.green@linaro.org>
2015-01-29 08:36:18 +08:00
Imo Farcher
97a748a2d0 plat unix 64 bit timestamps on 32-bit os
Signed-off-by: Imo Farcher <ifar@gmx.net>
2015-01-26 15:39:36 +08:00
Andy Green
abb48113e7 coverity 83657 plat unix check setsockopt return
Signed-off-by: Andy Green <andy.green@linaro.org>
2014-11-30 13:10:26 +08:00
Andy Green
24109f40ae coverity 83659 plat unix check fstat return
Signed-off-by: Andy Green <andy.green@linaro.org>
2014-11-30 13:10:26 +08:00
Andy Green
956a08a9c0 coverity 83660 plat unix check fcntl return
Signed-off-by: Andy Green <andy.green@linaro.org>
2014-11-30 13:10:26 +08:00
Andy Green
66a5faa633 coverity 83671 dead code
Signed-off-by: Andy Green <andy.green@linaro.org>
2014-11-30 12:48:22 +08:00
Andy Green
609ec85869 ssl optimize poll when buffered ssl read data
Signed-off-by: Andy Green <andy.green@linaro.org>
2014-10-09 08:29:22 +08:00
Andy Green
fe3e3e61ec ssl fix pending reads stuck in ssl layer
Signed-off-by: Andy Green <andy.green@linaro.org>
2014-10-08 12:15:29 +08:00
Aurelian Pop
d07ea3bf40 Fix TCP keepalive use in UNIX systems 2014-07-29 15:36:06 +03:00
geq
d6827f7741 fix build on OpenBSD 2014-07-06 09:36:43 +08:00
vpeter4
7cc7ae476a Fix for binding socket to a specific interface (fixes #116)
also allow binding to IP address with @iface info.iface = "eth0"; info.iface
 = "192.168.1.5";
2014-04-28 07:32:14 +08:00
vpeter4
4dd8ada592 Disable compile warning: no newline at end of file 2014-04-27 13:28:22 +02:00
Andy Green
a717df2739 refactor libev eliminate all code ifdefs
Signed-off-by: Andy Green <andy.green@linaro.org>
2014-04-11 13:14:37 +08:00
Andy Green
c57037a555 refactor ssl related code into ssl.c
Signed-off-by: Andy Green <andy.green@linaro.org>
2014-04-03 10:17:00 +08:00
Andy Green
a654fc0d50 clean move lws_plat externs
Signed-off-by: Andy Green <andy.green@linaro.org>
2014-04-03 07:16:40 +08:00
Andy Green
1cd3ba6fdc ipv6 use lws_plat_ to avoid win naming collision
Signed-off-by: Andy Green <andy.green@linaro.org>
2014-04-02 23:03:23 +08:00
Andy Green
e40aa9b920 plat change to build selection by cmake
Signed-off-by: Andy Green <andy.green@linaro.org>
2014-04-02 21:04:03 +08:00
Andy Green
158e804cb7 refactor out WIN32 tests from code
This gets rid of all the platform-dependent #ifdef stuff and
migrates it into the new lws-plat-xxx.c files.

These are then included in a one-time test in libwebsockets.c
according basically to Windows or not.

The idea is from now on, all Windows-specific code should go in
lws-plat-win.c, where any kind of Windows perversion like DWORD
is fine.

Any new functions going in there should be named lws_plat_...
and be defined in all the lws-plat-xxx.c file (currently just
win32 and unix platforms are supported).

Signed-off-by: Andy Green <andy.green@linaro.org>
2014-04-02 14:25:10 +08:00
Andy Green
bfaea95f60 clean libwebsockets.c
Signed-off-by: None <None>
2014-03-31 11:01:32 +08:00