For your reference (because I mention library functions below), libwebsockets documentation can be found here: https://github.com/warmcat/libwebsockets/blob/master/libwebsockets-api-doc.html#L466
Site can be found here: http://libwebsockets.org/trac/libwebsockets
My problem is that if I pass in a 1 or 2 for the ssl_connection parameter of libwebsocket_client_connect() function I get a segfault.
My code Is written in c++.
Wanting to find out where it's happening, I ran my code in gdb (after having added the -g flag). After the segfault, I ran backtrace. This is what I got:
0x00007ffff7748c43 in SSL_ctrl () from /lib/x86_64-linux-gnu/libssl.so.1.0.0 (gdb) backtrace
0 0x00007ffff7748c43 in SSL_ctrl () from /lib/x86_64-linux-gnu/libssl.so.1.0.0
1 0x00007ffff7503aa2 in lws_client_socket_service () from /usr/local/lib/libwebsockets.so.5.0.0
2 0x00007ffff74fe606 in libwebsocket_service_fd () from /usr/local/lib/libwebsockets.so.5.0.0
3 0x00007ffff7504029 in libwebsocket_client_connect_2 () from /usr/local/lib/libwebsockets.so.5.0.0
4 0x00007ffff75037d5 in lws_client_socket_service () from /usr/local/lib/libwebsockets.so.5.0.0
5 0x00007ffff74fe606 in libwebsocket_service_fd () from /usr/local/lib/libwebsockets.so.5.0.0
6 0x00007ffff7505980 in lws_plat_service () from /usr/local/lib/libwebsockets.so.5.0.0
There's more, but pertinent info is above...
As can be seen above, the segfault occurs in the SSL_ctrl() function.
If anyone has gotten a segfault from libwebsockets SSL_ctrl() function and solved it, please let me know.
If anyone can tell me how to build libwebsockets (using make, cmake, or otherwise) with debug flags and/or make it so that it writes verbosely to some log file and/or make it so I can step into the functions with gdb, I would very much appreciate it!
To build the libwebsockets with DEBUG options , use -DCMAKE_BUILD_TYPE=DEBUG argument with Cmake .
Please make sure that all the earlier versions of libwebsockets.h(that were build with out the -DCMAKE_BUILD_TYPE=DEBUG option) are removed and make a clean build with the -DCMAKE_BUILD_TYPE=DEBUG argument enabled.
After this to enable debug while execution use -d option set to the log level
if my executable is sock, then to enable the debug log while running use
./sock 127.0.0.1 -p 9000 -d 65535
that will give output like
[1449754712:6654] CLIENT: lws_client_connect: direct conn
[1449754712:6654] CLIENT: lws_client_connect_2
[1449754712:6654] CLIENT: lws_client_connect_2: address 127.0.0.1
Reason :35
Reason :32
Reason :36
[1449754712:6655] CLIENT: nonblocking connect retry