Giter Site home page Giter Site logo

zhaojh329 / libuwsc Goto Github PK

View Code? Open in Web Editor NEW
287.0 287.0 53.0 258 KB

A Lightweight and fully asynchronous WebSocket client library based on libev

License: MIT License

CMake 9.58% C 87.46% Lua 2.96%
cyassl libev libwebsocket lightweight lua-binding mbedtls openssl websocket wolfssl

libuwsc's Introduction

Hi there 👋

visitors

libuwsc's People

Contributors

dmitigr avatar ffontaine avatar neheb avatar spot62 avatar zhaojh329 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

libuwsc's Issues

uwsc gets stuck seeking to SEEK_CUR then exits

I'm just using an ev_timer and sending a static/compiled string every 20 seconds.

Here's an strace of what eventually happens after about 10 minutes.

open("/dev/urandom", O_RDONLY|O_LARGEFILE) = 102
readv(102, [{iov_base="\226\234\325", iov_len=3}, {iov_base="\5{0mk\354~WF\333\307\227\307\352,\222\203\247\32\0030\5\204o\235\232n\242<\nR,"..., iov_len=1024}], 2) = 1027
_llseek(102, -1023, [0], SEEK_CUR)      = 0
close(102)                              = 0
rt_sigprocmask(SIG_BLOCK, ~[RTMIN RT_1 RT_2], [], 16) = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 16) = 0
rt_sigprocmask(SIG_BLOCK, ~[RTMIN RT_1 RT_2], [], 16) = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 16) = 0
rt_sigprocmask(SIG_BLOCK, ~[RTMIN RT_1 RT_2], [], 16) = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 16) = 0
rt_sigprocmask(SIG_BLOCK, ~[RTMIN RT_1 RT_2], [], 16) = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 16) = 0
_llseek(6, -285, [227], SEEK_CUR)       = 0
_llseek(99, -285, [227], SEEK_CUR)      = 0
_llseek(97, -285, [227], SEEK_CUR)      = 0
_llseek(95, -285, [227], SEEK_CUR)      = 0
_llseek(93, -285, [227], SEEK_CUR)      = 0
_llseek(91, -285, [227], SEEK_CUR)      = 0
_llseek(89, -285, [227], SEEK_CUR)      = 0
_llseek(87, -285, [227], SEEK_CUR)      = 0
_llseek(85, -285, [227], SEEK_CUR)      = 0
_llseek(83, -285, [227], SEEK_CUR)      = 0
_llseek(81, -285, [227], SEEK_CUR)      = 0
_llseek(79, -285, [227], SEEK_CUR)      = 0
_llseek(77, -285, [227], SEEK_CUR)      = 0
_llseek(75, -285, [227], SEEK_CUR)      = 0
_llseek(73, -285, [227], SEEK_CUR)      = 0
_llseek(71, -285, [227], SEEK_CUR)      = 0
_llseek(69, -285, [227], SEEK_CUR)      = 0
_llseek(67, -285, [227], SEEK_CUR)      = 0
_llseek(65, -285, [227], SEEK_CUR)      = 0
_llseek(63, -285, [227], SEEK_CUR)      = 0
_llseek(61, -285, [227], SEEK_CUR)      = 0
_llseek(59, -285, [227], SEEK_CUR)      = 0
_llseek(57, -285, [227], SEEK_CUR)      = 0
_llseek(55, -285, [227], SEEK_CUR)      = 0
_llseek(53, -285, [227], SEEK_CUR)      = 0
_llseek(51, -285, [227], SEEK_CUR)      = 0
_llseek(49, -285, [227], SEEK_CUR)      = 0
_llseek(47, -285, [227], SEEK_CUR)      = 0
_llseek(45, -285, [227], SEEK_CUR)      = 0
_llseek(43, -285, [227], SEEK_CUR)      = 0
_llseek(41, -285, [227], SEEK_CUR)      = 0
_llseek(39, -285, [227], SEEK_CUR)      = 0
_llseek(37, -285, [227], SEEK_CUR)      = 0
_llseek(35, -285, [227], SEEK_CUR)      = 0
_llseek(33, -285, [227], SEEK_CUR)      = 0
_llseek(31, -285, [227], SEEK_CUR)      = 0
_llseek(29, -285, [227], SEEK_CUR)      = 0
_llseek(27, -285, [227], SEEK_CUR)      = 0
_llseek(25, -285, [227], SEEK_CUR)      = 0
_llseek(23, -285, [227], SEEK_CUR)      = 0
_llseek(21, -285, [227], SEEK_CUR)      = 0
_llseek(19, -285, [227], SEEK_CUR)      = 0
_llseek(17, -285, [227], SEEK_CUR)      = 0
_llseek(15, -285, [227], SEEK_CUR)      = 0
_llseek(13, -285, [227], SEEK_CUR)      = 0
_llseek(11, -285, [227], SEEK_CUR)      = 0
_llseek(9, -285, [227], SEEK_CUR)       = 0
_llseek(7, -285, [227], SEEK_CUR)       = 0
exit_group(0)                           = ?
+++ exited with 0 +++

What's this all about?

Invalid header error

I replaced example.c url with this.
ws://www.bitmex.com/realtime

When I run, it gives the following error
(example.c:91) onerror:2: Invalid header

I'm able to connect to the same url with javascript in browser.
var ws = new WebSocket('ws://www.bitmex.com/realtime');

wss://echo.websocket.org - This url is working good from example.c

sha1_transform() causes buffer overflow

Hello.
sha1_transform() in the sha1.c declares a block[1] of union type, which is
union char64long16 {
uint8_t c[64];
uint32_t l[16];
};

and access until block->l[79] by R0 MACRO.
It makes a buffer overflow.
would you fix this problem?

Library installation by vcpkg

Do you intend to make the library available to be installed via vcpkg? It would be much easier and more practical and besides it would be available for installation for both Linux and Windows

examples require SSL

-musl/bin/ld: src/libuwsc.so.3.3.5: undefined reference to `mbedtls_ssl_config_free'
/home/mangix/devstuff/openwrt/staging_dir/toolchain-powerpc_464fp_gcc-11.2.0_musl/lib/gcc/powerpc-openwrt-linux-musl/11.2.0/../../../../powerpc-openwrt-linux-musl/bin/ld: src/libuwsc.so.3.3.5: undefined reference to `mbedtls_ctr_drbg_init'
/home/mangix/devstuff/openwrt/staging_dir/toolchain-powerpc_464fp_gcc-11.2.0_musl/lib/gcc/powerpc-openwrt-linux-musl/11.2.0/../../../../powerpc-openwrt-linux-musl/bin/ld: src/libuwsc.so.3.3.5: undefined reference to `mbedtls_ssl_read'
/home/mangix/devstuff/openwrt/staging_dir/toolchain-powerpc_464fp_gcc-11.2.0_musl/lib/gcc/powerpc-openwrt-linux-musl/11.2.0/../../../../powerpc-openwrt-linux-musl/bin/ld: src/libuwsc.so.3.3.5: undefined reference to `mbedtls_ssl_setup'
/home/mangix/devstuff/openwrt/staging_dir/toolchain-powerpc_464fp_gcc-11.2.0_musl/lib/gcc/powerpc-openwrt-linux-musl/11.2.0/../../../../powerpc-openwrt-linux-musl/bin/ld: src/libuwsc.so.3.3.5: undefined reference to `mbedtls_ctr_drbg_random'
/home/mangix/devstuff/openwrt/staging_dir/toolchain-powerpc_464fp_gcc-11.2.0_musl/lib/gcc/powerpc-openwrt-linux-musl/11.2.0/../../../../powerpc-openwrt-linux-musl/bin/ld: src/libuwsc.so.3.3.5: undefined reference to `mbedtls_ssl_free'
/home/mangix/devstuff/openwrt/staging_dir/toolchain-powerpc_464fp_gcc-11.2.0_musl/lib/gcc/powerpc-openwrt-linux-musl/11.2.0/../../../../powerpc-openwrt-linux-musl/bin/ld: src/libuwsc.so.3.3.5: undefined reference to `mbedtls_ssl_config_init'
/home/mangix/devstuff/openwrt/staging_dir/toolchain-powerpc_464fp_gcc-11.2.0_musl/lib/gcc/powerpc-openwrt-linux-musl/11.2.0/../../../../powerpc-openwrt-linux-musl/bin/ld: src/libuwsc.so.3.3.5: undefined reference to `mbedtls_ssl_conf_ca_chain'
/home/mangix/devstuff/openwrt/staging_dir/toolchain-powerpc_464fp_gcc-11.2.0_musl/lib/gcc/powerpc-openwrt-linux-musl/11.2.0/../../../../powerpc-openwrt-linux-musl/bin/ld: src/libuwsc.so.3.3.5: undefined reference to `mbedtls_ssl_init'
/home/mangix/devstuff/openwrt/staging_dir/toolchain-powerpc_464fp_gcc-11.2.0_musl/lib/gcc/powerpc-openwrt-linux-musl/11.2.0/../../../../powerpc-openwrt-linux-musl/bin/ld: src/libuwsc.so.3.3.5: undefined reference to `mbedtls_ssl_set_bio'
/home/mangix/devstuff/openwrt/staging_dir/toolchain-powerpc_464fp_gcc-11.2.0_musl/lib/gcc/powerpc-openwrt-linux-musl/11.2.0/../../../../powerpc-openwrt-linux-musl/bin/ld: src/libuwsc.so.3.3.5: undefined reference to `mbedtls_ctr_drbg_seed'
/home/mangix/devstuff/openwrt/staging_dir/toolchain-powerpc_464fp_gcc-11.2.0_musl/lib/gcc/powerpc-openwrt-linux-musl/11.2.0/../../../../powerpc-openwrt-linux-musl/bin/ld: src/libuwsc.so.3.3.5: undefined reference to `mbedtls_ssl_write'
/home/mangix/devstuff/openwrt/staging_dir/toolchain-powerpc_464fp_gcc-11.2.0_musl/lib/gcc/powerpc-openwrt-linux-musl/11.2.0/../../../../powerpc-openwrt-linux-musl/bin/ld: src/libuwsc.so.3.3.5: undefined reference to `mbedtls_net_recv'
/home/mangix/devstuff/openwrt/staging_dir/toolchain-powerpc_464fp_gcc-11.2.0_musl/lib/gcc/powerpc-openwrt-linux-musl/11.2.0/../../../../powerpc-openwrt-linux-musl/bin/ld: src/libuwsc.so.3.3.5: undefined reference to `mbedtls_entropy_init'
/home/mangix/devstuff/openwrt/staging_dir/toolchain-powerpc_464fp_gcc-11.2.0_musl/lib/gcc/powerpc-openwrt-linux-musl/11.2.0/../../../../powerpc-openwrt-linux-musl/bin/ld: src/libuwsc.so.3.3.5: undefined reference to `mbedtls_ssl_conf_rng'
/home/mangix/devstuff/openwrt/staging_dir/toolchain-powerpc_464fp_gcc-11.2.0_musl/lib/gcc/powerpc-openwrt-linux-musl/11.2.0/../../../../powerpc-openwrt-linux-musl/bin/ld: src/libuwsc.so.3.3.5: undefined reference to `mbedtls_net_init'
/home/mangix/devstuff/openwrt/staging_dir/toolchain-powerpc_464fp_gcc-11.2.0_musl/lib/gcc/powerpc-openwrt-linux-musl/11.2.0/../../../../powerpc-openwrt-linux-musl/bin/ld: src/libuwsc.so.3.3.5: undefined reference to `mbedtls_x509_crt_init'
/home/mangix/devstuff/openwrt/staging_dir/toolchain-powerpc_464fp_gcc-11.2.0_musl/lib/gcc/powerpc-openwrt-linux-musl/11.2.0/../../../../powerpc-openwrt-linux-musl/bin/ld: src/libuwsc.so.3.3.5: undefined reference to `mbedtls_ssl_conf_authmode'
/home/mangix/devstuff/openwrt/staging_dir/toolchain-powerpc_464fp_gcc-11.2.0_musl/lib/gcc/powerpc-openwrt-linux-musl/11.2.0/../../../../powerpc-openwrt-linux-musl/bin/ld: src/libuwsc.so.3.3.5: undefined reference to `mbedtls_ssl_handshake'
/home/mangix/devstuff/openwrt/staging_dir/toolchain-powerpc_464fp_gcc-11.2.0_musl/lib/gcc/powerpc-openwrt-linux-musl/11.2.0/../../../../powerpc-openwrt-linux-musl/bin/ld: src/libuwsc.so.3.3.5: undefined reference to `mbedtls_ssl_set_hostname'
/home/mangix/devstuff/openwrt/staging_dir/toolchain-powerpc_464fp_gcc-11.2.0_musl/lib/gcc/powerpc-openwrt-linux-musl/11.2.0/../../../../powerpc-openwrt-linux-musl/bin/ld: src/libuwsc.so.3.3.5: undefined reference to `mbedtls_net_send'
/home/mangix/devstuff/openwrt/staging_dir/toolchain-powerpc_464fp_gcc-11.2.0_musl/lib/gcc/powerpc-openwrt-linux-musl/11.2.0/../../../../powerpc-openwrt-linux-musl/bin/ld: src/libuwsc.so.3.3.5: undefined reference to `mbedtls_ssl_config_defaults'
/home/mangix/devstuff/openwrt/staging_dir/toolchain-powerpc_464fp_gcc-11.2.0_musl/lib/gcc/powerpc-openwrt-linux-musl/11.2.0/../../../../powerpc-openwrt-linux-musl/bin/ld: src/libuwsc.so.3.3.5: undefined reference to `mbedtls_entropy_func'
collect2: error: ld returned 1 exit status

Build failed on Macos

Is this lib compatible with MacOS, iOS or Android? I try to build it on MacOS but it fails.
Also, is it threat safe?

with '-Wno-misleading-indentation'

error: unknown warning option '-Wno-misleading-indentation'; did you mean '-Wno-binding-in-condition'? [-Werror,-Wunknown-warning-option]

with -Wno-binding-in-condition

uwsc.c:66:12: error: implicit declaration of function 'htobe16' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
    code = htobe16(code & 0xFFFF);
           ^
uwsc.c:117:29: error: implicit declaration of function 'be16toh' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
        frame->payloadlen = be16toh(buffer_pull_u16(rb));
                            ^
uwsc.c:122:15: error: implicit declaration of function 'be64toh' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
        len = be64toh(buffer_pull_u64(rb));
              ^
uwsc.c:122:15: note: did you mean 'be16toh'?
uwsc.c:117:29: note: 'be16toh' declared here
        frame->payloadlen = be16toh(buffer_pull_u16(rb));
                            ^
uwsc.c:421:28: error: implicit declaration of function 'htobe16' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
        buffer_put_u16(wb, htobe16(len));
                           ^
uwsc.c:424:28: error: implicit declaration of function 'htobe64' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
        buffer_put_u64(wb, htobe64(len));
                           ^
uwsc.c:462:28: error: implicit declaration of function 'htobe16' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
        buffer_put_u16(wb, htobe16(len));
                           ^
uwsc.c:465:28: error: implicit declaration of function 'htobe64' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
        buffer_put_u64(wb, htobe64(len));
                           ^
uwsc.c:575:36: error: use of undeclared identifier 'SOCK_NONBLOCK'
    sock = tcp_connect(host, port, SOCK_NONBLOCK | SOCK_CLOEXEC, &inprogress, &eai);
                                   ^
uwsc.c:575:52: error: use of undeclared identifier 'SOCK_CLOEXEC'
    sock = tcp_connect(host, port, SOCK_NONBLOCK | SOCK_CLOEXEC, &inprogress, &eai);
                                                   ^

uwsc_new 2nd argument from char*

warning: assignment to 'void (*)(struct uwsc_client *, void *, size_t,  _Bool)' {aka 'void (*)(struct uwsc_client *, void *, unsigned int,  _Bool)'} from incompatible pointer type 'void (*)(struct uwsc_client *, char *, size_t,  _Bool)' {aka 'void (*)(struct uwsc_client *, char *, unsigned int,  _Bool)'} [-Wincompatible-pointer-types]
  cl->onmessage = uwsc_onmessage;
                ^

Do you have any idea how to fix that, I'm getting the address from argv.

CPU load 100%

When run as a service, it increases the CPU load to 100%

[bug] Issue with UWSC_OP_TEXT scrambling data

Description

When using libuwsc I noticed that the JSON strings I was getting back were often scrambled and this caused the parser to fail. So I wrote a program to reproduce this problem in a way that was clear. The program establishes a connection with the websocket server provided by https://www.websocket.org/echo.html (wss://echo.websocket.org). This server sends a text reply whenever it receives a message containing the text of the message. My program will send a message with a predefined sample text every three seconds. This can be used to test if libuwsc is mutating the data that is being received.

Output of program
Short-mode output

Using the latest upstream (8bad3e1), the output of short mode is like this most of the time:

=====================================================
Sent: "This is a sample string." # This is what is sent to the WS url
OK: content==test: "This is a sample string." # This is what is received in response, it should be the same
=====================================================
Sent: "This is a sample string."
OK: content==test: "This is a sample string."
=====================================================
Sent: "This is a sample string."
OK: content==test: "This is a sample string."
=====================================================
Sent: "This is a sample string."
OK: content==test: "This is a sample string."
=====================================================

This indicates that libuwsc is doing its job. However, sometimes this will happen:

Sent: "This is a sample string."
ERR: content!=test: "This is a sample string.□libuwsc"
=====================================================

The string "libuwsc" is appended to the returned result. This is the most common error. If left running for long enough, this can occur:

Sent: "This is a sample string."
ERR: content!=test: "This is a sample string.otocol Handshake"
=====================================================
Sent: "This is a sample string."
ERR: content!=test: "This is a sample string.ndshake"
=====================================================
Sent: "This is a sample string."
ERR: content!=test: "This is a sample string.de"
=====================================================
Sent: "This is a sample string."
ERR: content!=test: "This is a sample string. 00:26:47 GMT"
=====================================================
Sent: "This is a sample string."
ERR: content!=test: "This is a sample string.□libuwsc"
=====================================================
Sent: "This is a sample string."
ERR: content!=test: "This is a sample string.k2c="
=====================================================
Sent: "This is a sample string."
ERR: content!=test: "This is a sample string.way"
=====================================================

I'm not sure where these appended strings are coming from. Maybe additional data in the received payload? Immediately after this:

Sent: "This is a sample string."
ERR: content!=test: "This is a sample string.
□libuwsc□↑This is a sample string.□↑This is a sample string.□↑This is a sample string.□libuwsc□↑This is a sample string.□↑This is a sample string.□↑This is a sample string.□libuwsc□↑This is a sample string.□↑This is a sample string.□↑This is a sample string.□↑This is a sample string.□libuwsc□↑This is a sample string.□↑This is a sample string.□↑This is a sample string.□↑This is a sample string.□libuwsc□↑This is a sample string.□↑This is a sample string.□↑This is a sample string.□libuwsc□↑This is a sample string.□↑This is a sample string.□↑This is a sample string.□libuwsc□↑This is a sample string.□↑This is a sample string.□↑This is a sample string.□↑This is a sample string.□libuwsc□↑This is a sample string.□↑This is a sample string.□↑This is a sample string.□↑This is a sample string.□libuwsc□↑This is a sample string.□↑This is a sample string.□↑This is a sample string.□libuwsc□↑This is a sample string.□↑This is a sample string.□↑This is a sample string.□↑This is a sample string.□libuwsc□↑This is a sample string.□↑This is a sample string.□↑This is a sample string.□libuwsc□↑This is a sample string.□↑This is a sample string.□↑This is a sample string.□↑This is a sample string.□libuwsc□↑This is a sample string.□↑This is a sample string.□↑This is a sample string.□↑This is a sample string.□libuwsc□↑This is a sample string.□↑This is a sample string.□↑This is a sample string.□libuwsc□↑This is a sample string.□↑This is a sample string.□↑This is a sample string.□↑This is a sample string.□libuwsc□↑This is a sample string.□↑This is a sample string.□↑This is a sample string.□libuwsc□↑This is a sample string.□↑This is a sample string.□↑This is a sample string.□↑This is a sample string.□libuwsc□↑This is a sample string.□↑This is a sample string.□↑This is a sample string.□libuwsc□↑This is a sample string.□↑This is a sample string.□↑This is a sample string.□↑This is a sample string.□libuwsc□↑This is a sample string.□↑This is a sample string.□↑This is a sample string.□libuwsc□↑This is a sample string.□↑This is a sample string.□↑This is a sample string.□↑This is a sample string.□libuwsc□↑This is a sample string.□↑This is a sample string.□↑This is a sample string.□libuwsc□↑This is a sample string.□↑This is a sample string.□↑This is a sample string.□↑This is a sample string.□libuwsc□↑This is a sample string.□↑This is a sample string.□↑This is a sample string.□libuwsc□↑This is a sample string.□↑This is a sample string.□↑This is a sample string.□↑This is a sample string.□libuwsc□↑This is a sample string.□↑This is a sample string.□↑This is a sample string.□libuwsc□↑This is a sample string.□↑This is a sample string.□↑This is a sample string.□↑This is a sample string.□libuwsc□↑This is a sample string.□↑This is a sample string.□↑This is a sample string.□libuwsc□↑This is a sample string.□↑This is a sample string.□↑This is a sample string.□↑This is a sample string.□libuwsc□↑This is a sample string.□↑This is a sample string.□↑This is a sample string.□libuwsc□↑This is a sample string.□↑This is a sample string.□↑This is a sample string.□↑This is a sample string.□libuwsc□↑This is a sample string.□↑This is a sample string.□↑This is a sample string.□↑This is a sample string.□libuwsc□↑This is a sample string.□↑This is a sample string.□↑This is a sample string.□libuwsc□↑This is a sample string.□↑This is a sample string.□↑This is a sample string.□↑This is a sample string.□libuwsc□↑This is a sample string.□↑This is a sample string.□↑This is a sample string.□libuwsc□↑This is a sample string.□↑This is a sample string.□↑This is a sample string.□libuwsc□↑This is a sample string.□↑This is a sample string.□↑This is a sample string.□↑This is a sample string.□libuwsc□↑This is a sample string.□↑This is a sample string.□↑This is a sample string.□libuwsc□↑This is a sample string.□↑This is a sample string.□↑This is a sample string.□↑This i"
=====================================================

Long-mode output

My test has two modes because it is much easier to reproduce with a larger amount of text. Proper functioning looks like:

Sent: "10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
"
OK: content==test: "10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
"
=====================================================

In a brief amount of iterations:

Sent: "10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
"
ERR: content!=test: "10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
□libuwsc4 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
□~10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
□~10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
□libuwsc□~10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
□~10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
□~10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
□libuwsc□~10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
□~10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
□~10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
□~10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
□libuwsc□~10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
□~10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
□~10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
□~10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 9"
=====================================================

Given this we can see that for whatever reason the text is being duplicated, often separated with garbage characters and the string "libuwsc". A repetition always starts with the beginning of the string but is sometimes truncated at the end.

To reproduce

Clone curz46/libuwsc-test and follow the instructions in the README.md. Run the program using ./bin/test and select a mode. Leave the program running until error is observed.

Questions

  • How could this be occurring?
  • Which parts of the source are related to the receiving and passing of text to onmessage?
  • Which parts of the source could be responsible?

Thanks, Dylan

Client Need to ignore the Reason-Phrase(Switching Protocols) and operate solely on the Status-Code

Client Need to ignore the Reason-Phrase(Switching Protocols) and operate solely on the Status-Code

Different websocket servers respond differently to HTTP upgrades

GET /ws?device=1&devid=dev&description=My%20Device%20Description&keepalive=5 HTTP/1.1
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Key: rb8NoBZ9hyKyBDez/VLqOQ==
Sec-WebSocket-Version: 13
Host: 172.19.12.71:5912

HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Accept: 5ZGFlM/1c+0u8ebA/aKdbGDGXCw=

GET /ws?device=1&devid=dev&description=My%20Device%20Description&keepalive=5 HTTP/1.1
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Key: r/Yb4H5NKtECyumcRl4/hQ==
Sec-WebSocket-Version: 13
Host: 172.19.12.71:8080

HTTP/1.1 101
Upgrade: websocket
Connection: upgrade
Sec-WebSocket-Accept: BP2DC5lXawTktU4OTmiVuGB5FCI=
Date: Fri, 26 Apr 2019 03:02:44 GMT

Libuwsc and rtty only support aarch64?

RT, I just tested building in ubuntu-18.04-amd64-docker env and found an error:

Scanning dependencies of target uwsc
[  5%] Building C object src/CMakeFiles/uwsc.dir/uwsc.c.o
[ 11%] Building C object src/CMakeFiles/uwsc.dir/log.c.o
[ 16%] Building C object src/CMakeFiles/uwsc.dir/utils.c.o
[ 22%] Building C object src/CMakeFiles/uwsc.dir/buffer.c.o
[ 27%] Building C object src/CMakeFiles/uwsc.dir/sha1.c.o
[ 33%] Building C object src/CMakeFiles/uwsc.dir/base64.c.o
[ 38%] Building C object src/CMakeFiles/uwsc.dir/ssl.c.o
make[2]: *** No rule to make target '/usr/lib/aarch64-linux-gnu/libev.so', needed by 'src/libuwsc.so.3.2.2'.  Stop.
CMakeFiles/Makefile2:87: recipe for target 'src/CMakeFiles/uwsc.dir/all' failed
make[1]: *** [src/CMakeFiles/uwsc.dir/all] Error 2
Makefile:129: recipe for target 'all' failed
make: *** [all] Error 2

This is my dockerfile, those COPY are the source code I downloaded from the release. 'install-rtty-6.sh' is the official script to build rtty you provided. I just modifed it to use the local source code.

FROM amd64/ubuntu:18.04
USER root

# change to Asia/Shanghai
ENV TZ=Asia/Shanghai

COPY rtty/libuwsc-3.2.2/ /root/libuwsc-3.2.2/
COPY rtty/install-rtty-6.sh /root/
COPY rtty/rtty-6.6.1/ /root/rtty-6.6.1/
COPY rtty/supervisor-linux-amd64 /root/

RUN sed -i s@/archive.ubuntu.com/@/mirrors.aliyun.com/@g /etc/apt/sources.list \
    && apt-get clean \
    && apt-get update -y \
    && apt-get install -y apt-utils libev-dev \
    && chmod 777 /root/install-rtty-6.sh \
    && cd /root \
    && /bin/sh install-rtty-6.sh \
    && chmod 777 /root/supervisor-linux-amd64

CMD ["/root/supervisor-linux-amd64"]

How do you install libev on windows 10?

I downloaded the libev files.

Doesn't explain how it's used or installed.

and cmake for libuwsc throws errors for not able to find libev...

how to make cmake compile libuwsc with libev?

Thanks.

Specified protocol was not requested by the client.

Hello,

I am trying to connect to a nodejs websocket server using libuwsc and I get the error "Specified protocol was not requested by the client." when doing request.accept('echo-protocol', request.origin).
I understand this to be the protocol set and can not see this in the libuwsc library, am I missing something here?

Many thanks,
J

Killed by SIGPIPE

Just writing this here to inform.

libuwsc includes no callback to handle something like messages written to a socket that has been closed on the remote end.

Basically, the kernel will send SIGPIPE to your program when this happens. This will kill the program.

All you need to do is:

include <signal.h>

Then in main():

sigaction(SIGPIPE, &(struct sigaction){SIG_IGN}, NULL);

You could also set up a function to handle this signal, but you shouldn't need to.

fragmentation support

Hi, thanks for this library. I wanted to ask if anyone can help with adding fragmentation support.

在多线程下跑,不同的线程使用不同的loop, 发现了个问题

提示 libev: a signal must not be attached to two different loops... ,这个应该是libev的问题,大概意思是例子里面的方法 signal_cb 方法只能被一个loop绑定,请问这个问题该怎么解决? 我就是想通过给线程发sigint信号让线程退出,现在却没法绑定。。。。。。

Memory leak with SSL enabled, openssl

I download the example.

admin@dev:~/collect-v2/clients/cclient$ wget https://raw.githubusercontent.com/zhaojh329/libuwsc/master/example/example.c
--2020-01-08 14:39:29--  https://raw.githubusercontent.com/zhaojh329/libuwsc/master/example/example.c
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 151.101.52.133
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|151.101.52.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 4317 (4.2K) [text/plain]
Saving to: ‘example.c’

example.c                                            100%[=====================================================================================================================>]   4.22K  --.-KB/s    in 0.002s  

2020-01-08 14:39:29 (2.69 MB/s) - ‘example.c’ saved [4317/4317]

I compile it.

admin@dev:~/collect-v2/clients/cclient$ gcc -I/usr/local/include/uwsc -I/usr/include/json-c -I/usr/local/include -L/usr/local/lib -L/usr/local/lib/uwsc -lpthread -ljson-c -lev -luwsc -o example example.c 

I run the program and valgrind using -u ws://localhost/ws

You can see there are no memory leaks reported by valgrind.

admin@dev:~/collect-v2/clients/cclient$ valgrind --leak-check=full ./example -u ws://localhost/ws
==3970== Memcheck, a memory error detector
==3970== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==3970== Using Valgrind-3.12.0.SVN and LibVEX; rerun with -h for copyright info
==3970== Command: ./example -u ws://localhost/ws
==3970== 
2020/01/08 14:40:35 (example.c:141) Libuwsc: 3.3.2
2020/01/08 14:40:36 (example.c:147) Start connect...
2020/01/08 14:40:36 (example.c:91) onerror:2: Invalid header
==3970== 
==3970== HEAP SUMMARY:
==3970==     in use at exit: 1,016 bytes in 6 blocks
==3970==   total heap usage: 66 allocs, 60 frees, 43,855 bytes allocated
==3970== 
==3970== LEAK SUMMARY:
==3970==    definitely lost: 0 bytes in 0 blocks
==3970==    indirectly lost: 0 bytes in 0 blocks
==3970==      possibly lost: 0 bytes in 0 blocks
==3970==    still reachable: 1,016 bytes in 6 blocks
==3970==         suppressed: 0 bytes in 0 blocks
==3970== Reachable blocks (those to which a pointer was found) are not shown.
==3970== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==3970== 
==3970== For counts of detected and suppressed errors, rerun with: -v
==3970== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

I run the program using an SSL URL and valgrind using -u wss://localhost/ws

You can see the program has a memory leak from libuwsc! Can you fix this please?

admin@dev:~/collect-v2/clients/cclient$ valgrind --leak-check=full ./example -u wss://localhost/ws
==3971== Memcheck, a memory error detector
==3971== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==3971== Using Valgrind-3.12.0.SVN and LibVEX; rerun with -h for copyright info
==3971== Command: ./example -u wss://localhost/ws
==3971== 
2020/01/08 14:40:40 (example.c:141) Libuwsc: 3.3.2
2020/01/08 14:40:40 (example.c:147) Start connect...
2020/01/08 14:40:41 (ssl.c:141) (null)
2020/01/08 14:40:41 (example.c:91) onerror:7: ssl handshake failed
==3971== 
==3971== HEAP SUMMARY:
==3971==     in use at exit: 162,494 bytes in 2,922 blocks
==3971==   total heap usage: 4,628 allocs, 1,706 frees, 370,000 bytes allocated
==3971== 
==3971== 73,990 (824 direct, 73,166 indirect) bytes in 1 blocks are definitely lost in loss record 296 of 296
==3971==    at 0x4C2BBAF: malloc (vg_replace_malloc.c:299)
==3971==    by 0x61FDC87: CRYPTO_malloc (in /usr/lib/x86_64-linux-gnu/libcrypto.so.1.0.2)
==3971==    by 0x5F5E2EF: SSL_new (in /usr/lib/x86_64-linux-gnu/libssl.so.1.0.2)
==3971==    by 0x5473783: uwsc_ssl_init (in /usr/local/lib/libuwsc.so.3.3.2)
==3971==    by 0x54715FC: uwsc_init (in /usr/local/lib/libuwsc.so.3.3.2)
==3971==    by 0x54716A3: uwsc_new (in /usr/local/lib/libuwsc.so.3.3.2)
==3971==    by 0x109173: main (in /home/admin/collect-v2/clients/cclient/example)
==3971== 
==3971== LEAK SUMMARY:
==3971==    definitely lost: 824 bytes in 1 blocks
==3971==    indirectly lost: 73,166 bytes in 37 blocks
==3971==      possibly lost: 0 bytes in 0 blocks
==3971==    still reachable: 88,504 bytes in 2,884 blocks
==3971==         suppressed: 0 bytes in 0 blocks
==3971== Reachable blocks (those to which a pointer was found) are not shown.
==3971== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==3971== 
==3971== For counts of detected and suppressed errors, rerun with: -v
==3971== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)

cannot reconnect after error or close event and ev_break()

If I call ev_break on error or close, cl will be re-created with uwsc_new()

If I start the client it works fine, if I kill the server and restart it then the client just keeps saying:

2020/01/06 17:40:26 (cclient.c:87) Start connect...
2020/01/06 17:40:26 (cclient.c:62) onerror:6: Connect timeout

What do I need to reset so that uwsc_new() will reconnect as if it hadn't before?

Here is the code I am using in the main() loop:

int main(int argc, char **argv)
{
    const char *url = "wss://dev.sundialcommunications.com:8550/ws";
    struct ev_loop *loop = EV_DEFAULT;
    int ping_interval = 10;	/* second */
    static struct ev_timer timeout_watcher;

    uwsc_log_info("Libuwsc: %s\n", UWSC_VERSION_STRING);

    // reconnects when there is a disconnect or error
    while (1) {
	cl = uwsc_new(loop, url, ping_interval, NULL);
	if (!cl)
	    return -1;

	uwsc_log_info("Start connect...\n");

	cl->onopen = uwsc_onopen;
	cl->onmessage = uwsc_onmessage;
	cl->onerror = uwsc_onerror;
	cl->onclose = uwsc_onclose;

	ev_timer_init (&timeout_watcher, timer_cb, 10, 10);
	ev_timer_start (loop, &timeout_watcher);

	ev_run(loop, 0);

	// it will get to here if ev_break is called

	free(cl);

	sleep(10);
    }
    
    return 0;
}

cl->send() with long messages

I have no problem with cl->send() on messages with only a few thousand characters.

If I try to send a message with 40,000 characters, I get this:

*** Error in `./cclient': malloc(): memory corruption: 0x000055f07a5cc240 ***
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x70bfb)[0x7f8f73628bfb]
/lib/x86_64-linux-gnu/libc.so.6(+0x76fc6)[0x7f8f7362efc6]
/lib/x86_64-linux-gnu/libc.so.6(+0x79089)[0x7f8f73631089]
/lib/x86_64-linux-gnu/libc.so.6(__libc_malloc+0x54)[0x7f8f73632f64]
/lib/x86_64-linux-gnu/libc.so.6(+0x6755d)[0x7f8f7361f55d]
/usr/local/lib/libuwsc.so.3.3.2(get_nonce+0x1c)[0x7f8f7395a9b0]
/usr/local/lib/libuwsc.so.3.3.2(+0x3014)[0x7f8f7395a014]
./cclient(+0x341a)[0x55f07920141a]
/usr/local/lib/libuwsc.so.3.3.2(+0x2d9a)[0x7f8f73959d9a]
/usr/lib/x86_64-linux-gnu/libev.so.4(ev_invoke_pending+0x53)[0x7f8f73b63413]
/usr/lib/x86_64-linux-gnu/libev.so.4(ev_run+0x966)[0x7f8f73b66a06]
./cclient(+0x3847)[0x55f079201847]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf1)[0x7f8f735d82e1]
./cclient(+0x1a0a)[0x55f0791ffa0a]
======= Memory map: ========
55f0791fe000-55f079203000 r-xp 00000000 ca:01 1187736                    /home/admin/collect-v2/clients/cclient/cclient
55f079402000-55f079403000 r--p 00004000 ca:01 1187736                    /home/admin/collect-v2/clients/cclient/cclient
55f079403000-55f079404000 rw-p 00005000 ca:01 1187736                    /home/admin/collect-v2/clients/cclient/cclient
55f07a59b000-55f07a620000 rw-p 00000000 00:00 0                          [heap]
7f8f6c000000-7f8f6c021000 rw-p 00000000 00:00 0 
7f8f6c021000-7f8f70000000 ---p 00000000 00:00 0 
7f8f7219a000-7f8f721b0000 r-xp 00000000 ca:01 263298                     /lib/x86_64-linux-gnu/libgcc_s.so.1
7f8f721b0000-7f8f723af000 ---p 00016000 ca:01 263298                     /lib/x86_64-linux-gnu/libgcc_s.so.1
7f8f723af000-7f8f723b0000 r--p 00015000 ca:01 263298                     /lib/x86_64-linux-gnu/libgcc_s.so.1
7f8f723b0000-7f8f723b1000 rw-p 00016000 ca:01 263298                     /lib/x86_64-linux-gnu/libgcc_s.so.1
7f8f723b1000-7f8f723c5000 r-xp 00000000 ca:01 263363                     /lib/x86_64-linux-gnu/libresolv-2.24.so
7f8f723c5000-7f8f725c4000 ---p 00014000 ca:01 263363                     /lib/x86_64-linux-gnu/libresolv-2.24.so
7f8f725c4000-7f8f725c5000 r--p 00013000 ca:01 263363                     /lib/x86_64-linux-gnu/libresolv-2.24.so
7f8f725c5000-7f8f725c6000 rw-p 00014000 ca:01 263363                     /lib/x86_64-linux-gnu/libresolv-2.24.so
7f8f725c6000-7f8f725c8000 rw-p 00000000 00:00 0 
7f8f725c8000-7f8f725cd000 r-xp 00000000 ca:01 263356                     /lib/x86_64-linux-gnu/libnss_dns-2.24.so
7f8f725cd000-7f8f727cc000 ---p 00005000 ca:01 263356                     /lib/x86_64-linux-gnu/libnss_dns-2.24.so
7f8f727cc000-7f8f727cd000 r--p 00004000 ca:01 263356                     /lib/x86_64-linux-gnu/libnss_dns-2.24.so
7f8f727cd000-7f8f727ce000 rw-p 00005000 ca:01 263356                     /lib/x86_64-linux-gnu/libnss_dns-2.24.so
7f8f727ce000-7f8f727d8000 r-xp 00000000 ca:01 263357                     /lib/x86_64-linux-gnu/libnss_files-2.24.so
7f8f727d8000-7f8f729d8000 ---p 0000a000 ca:01 263357                     /lib/x86_64-linux-gnu/libnss_files-2.24.so
7f8f729d8000-7f8f729d9000 r--p 0000a000 ca:01 263357                     /lib/x86_64-linux-gnu/libnss_files-2.24.so
7f8f729d9000-7f8f729da000 rw-p 0000b000 ca:01 263357                     /lib/x86_64-linux-gnu/libnss_files-2.24.so
7f8f729da000-7f8f729e0000 rw-p 00000000 00:00 0 
7f8f729e0000-7f8f72c18000 r-xp 00000000 ca:01 265703                     /usr/lib/x86_64-linux-gnu/libcrypto.so.1.0.2
7f8f72c18000-7f8f72e18000 ---p 00238000 ca:01 265703                     /usr/lib/x86_64-linux-gnu/libcrypto.so.1.0.2
7f8f72e18000-7f8f72e34000 r--p 00238000 ca:01 265703                     /usr/lib/x86_64-linux-gnu/libcrypto.so.1.0.2
7f8f72e34000-7f8f72e43000 rw-p 00254000 ca:01 265703                     /usr/lib/x86_64-linux-gnu/libcrypto.so.1.0.2
7f8f72e43000-7f8f72e47000 rw-p 00000000 00:00 0 
7f8f72e47000-7f8f72ea7000 r-xp 00000000 ca:01 265705                     /usr/lib/x86_64-linux-gnu/libssl.so.1.0.2
7f8f72ea7000-7f8f730a6000 ---p 00060000 ca:01 265705                     /usr/lib/x86_64-linux-gnu/libssl.so.1.0.2
7f8f730a6000-7f8f730aa000 r--p 0005f000 ca:01 265705                     /usr/lib/x86_64-linux-gnu/libssl.so.1.0.2
7f8f730aa000-7f8f730b0000 rw-p 00063000 ca:01 265705                     /usr/lib/x86_64-linux-gnu/libssl.so.1.0.2
7f8f730b0000-7f8f730b3000 r-xp 00000000 ca:01 263350                     /lib/x86_64-linux-gnu/libdl-2.24.so
7f8f730b3000-7f8f732b2000 ---p 00003000 ca:01 263350                     /lib/x86_64-linux-gnu/libdl-2.24.so
7f8f732b2000-7f8f732b3000 r--p 00002000 ca:01 263350                     /lib/x86_64-linux-gnu/libdl-2.24.so
7f8f732b3000-7f8f732b4000 rw-p 00003000 ca:01 263350                     /lib/x86_64-linux-gnu/libdl-2.24.so
7f8f732b4000-7f8f733b7000 r-xp 00000000 ca:01 263351                     /lib/x86_64-linux-gnu/libm-2.24.so
7f8f733b7000-7f8f735b6000 ---p 00103000 ca:01 263351                     /lib/x86_64-linux-gnu/libm-2.24.so
7f8f735b6000-7f8f735b7000 r--p 00102000 ca:01 263351                     /lib/x86_64-linux-gnu/libm-2.24.so
7f8f735b7000-7f8f735b8000 rw-p 00103000 ca:01 263351                     /lib/x86_64-linux-gnu/libm-2.24.so
7f8f735b8000-7f8f7374d000 r-xp 00000000 ca:01 263347                     /lib/x86_64-linux-gnu/libc-2.24.so
7f8f7374d000-7f8f7394d000 ---p 00195000 ca:01 263347                     /lib/x86_64-linux-gnu/libc-2.24.so
7f8f7394d000-7f8f73951000 r--p 00195000 ca:01 263347                     /lib/x86_64-linux-gnu/libc-2.24.so
7f8f73951000-7f8f73953000 rw-p 00199000 ca:01 263347                     /lib/x86_64-linux-gnu/libc-2.24.so
7f8f73953000-7f8f73957000 rw-p 00000000 00:00 0 
7f8f73957000-7f8f7395e000 r-xp 00000000 ca:01 300479                     /usr/local/lib/libuwsc.so.3.3.2
7f8f7395e000-7f8f73b5d000 ---p 00007000 ca:01 300479                     /usr/local/lib/libuwsc.so.3.3.2
7f8f73b5d000-7f8f73b5e000 r--p 00006000 ca:01 300479                     /usr/local/lib/libuwsc.so.3.3.2
7f8f73b5e000-7f8f73b5f000 rw-p 00007000 ca:01 300479                     /usr/local/lib/libuwsc.so.3.3.2
7f8f73b5f000-7f8f73b6c000 r-xp 00000000 ca:01 299998                     /usr/lib/x86_64-linux-gnu/libev.so.4.0.0
7f8f73b6c000-7f8f73d6b000 ---p 0000d000 ca:01 299998                     /usr/lib/x86_64-linux-gnu/libev.so.4.0.0
7f8f73d6b000-7f8f73d6c000 r--p 0000c000 ca:01 299998                     /usr/lib/x86_64-linux-gnu/libev.so.4.0.0
7f8f73d6c000-7f8f73d6d000 rw-p 0000d000 ca:01 299998                     /usr/lib/x86_64-linux-gnu/libev.so.4.0.0
7f8f73d6d000-7f8f73d77000 r-xp 00000000 ca:01 265438                     /lib/x86_64-linux-gnu/libjson-c.so.3.0.1
7f8f73d77000-7f8f73f76000 ---p 0000a000 ca:01 265438                     /lib/x86_64-linux-gnu/libjson-c.so.3.0.1
7f8f73f76000-7f8f73f77000 r--p 00009000 ca:01 265438                     /lib/x86_64-linux-gnu/libjson-c.so.3.0.1
7f8f73f77000-7f8f73f78000 rw-p 0000a000 ca:01 265438                     /lib/x86_64-linux-gnu/libjson-c.so.3.0.1
7f8f73f78000-7f8f73f9b000 r-xp 00000000 ca:01 263343                     /lib/x86_64-linux-gnu/ld-2.24.so
7f8f7418c000-7f8f74192000 rw-p 00000000 00:00 0 
7f8f7419a000-7f8f7419b000 rw-p 00000000 00:00 0 
7f8f7419b000-7f8f7419c000 r--p 00023000 ca:01 263343                     /lib/x86_64-linux-gnu/ld-2.24.so
7f8f7419c000-7f8f7419d000 rw-p 00024000 ca:01 263343                     /lib/x86_64-linux-gnu/ld-2.24.so
7f8f7419d000-7f8f7419e000 rw-p 00000000 00:00 0 
7ffe458d9000-7ffe458fa000 rw-p 00000000 00:00 0                          [stack]
7ffe45924000-7ffe45926000 r--p 00000000 00:00 0                          [vvar]
7ffe45926000-7ffe45928000 r-xp 00000000 00:00 0                          [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0                  [vsyscall]
Aborted

running example.c gives error

I did all these steps in order as in README.md successfully.

sudo apt install libev-dev libssl-dev

git clone --recursive https://github.com/zhaojh329/libuwsc.git
cd libuwsc
mkdir build && cd build
cmake ..
make && sudo make install

I'm not able to complile example.c with
gcc example.c

it gives this error

../example/example.c:30:10: fatal error: uwsc.h: No such file or directory
#include "uwsc.h"

C++ wrapper

Hello,

I would like to implement a simple C++ wrapper and place it into src/cxx. Is this feature appreciated?

Thanks.

Need to build libuwsc example.c incorporating libev and libuwsc in single monolithic binary

I need to build example (from example.c) in partially static configuration, without libev.so and without libuwsc.so, which will not be available on a target system (that is, I will copy binary "example" to target system, but the target system will not have installed libev or libuwsc.)

Host (where I will build) is Ubuntu 18.04, 64-bit. Target (where I will execute) is Ubuntu 18.04, 64-bit, but has no shared libraries for libev and libuwsc.

I tested libuwsc initially as cloned from github - it works well (I tested example to communicate OK with existing websocket echo server.)

On host (where I will build), I tried changing cmake command from cmake .. to this:

cmake .. -DBUILD_STATIC_LIBS=ON -DBUILD_SHARED_LIBS=OFF

The result build process is now:

$ make
[ 11%] Building C object src/CMakeFiles/uwsc_s.dir/uwsc.c.o
[ 22%] Building C object src/CMakeFiles/uwsc_s.dir/log.c.o
[ 33%] Building C object src/CMakeFiles/uwsc_s.dir/utils.c.o
[ 44%] Building C object src/CMakeFiles/uwsc_s.dir/buffer/buffer.c.o
[ 55%] Building C object src/CMakeFiles/uwsc_s.dir/sha1.c.o
[ 66%] Building C object src/CMakeFiles/uwsc_s.dir/ssl.c.o
[ 77%] Linking C static library libuwsc.a
[ 77%] Built target uwsc_s
Scanning dependencies of target example
[ 88%] Building C object example/CMakeFiles/example.dir/example.c.o
[100%] Linking C executable example
[100%] Built target example

Now, example (binary) grows from 13408 to 42616 bytes, but when I move example binary to target system (target does not have libev or libuwsc intalled), executing ./example results:

./example: error while loading shared libraries: libev.so.4: cannot open shared object file: No such file or directory

The source system (where I am building) has libev.a (static) and libev.so (shared), but resulting binary example still is referencing libev.so, so it cannot start.

I am not expert on cmake, I think my problem is with with cmake.

Thank you for any help!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.