Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update client-http.c #2893

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"cmake.configureOnOpen": true
}
1 change: 1 addition & 0 deletions include/libwebsockets.h
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,7 @@ lws_fx_string(const lws_fx_t *a, char *buf, size_t size);
#if defined(LWS_ROLE_MQTT)
#include <libwebsockets/lws-mqtt.h>
#endif
#include <libwebsockets/lws-assert.h>
#include <libwebsockets/lws-client.h>
#include <libwebsockets/lws-http.h>
#include <libwebsockets/lws-spa.h>
Expand Down
21 changes: 21 additions & 0 deletions include/libwebsockets/lws-assert.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#if !defined(__LWS_ASSERT_H__)
#define __LWS_ASSERT_H__




typedef void (*lws_assert_cb)(const char *file, int line, const char *expression);
void lws_set_assert_cb(lws_assert_cb cb);

#ifdef LWS_ENABLE_CUSTOM_ASSERT
void lws_assert(const char *file, int line, const char *expression);
# ifdef assert
# undef assert
# endif
#define assert(expression) (void)((expression) || (lws_assert(__FILE__, __LINE__, #expression), 0))
#endif




#endif
1 change: 1 addition & 0 deletions lib/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ if (NOT LWS_ONLY_SSPC)

list(APPEND SOURCES
core/alloc.c
core/assert.c
core/buflist.c
core/context.c
core/lws_map.c
Expand Down
16 changes: 16 additions & 0 deletions lib/core/assert.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include "private-lib-core.h"

static lws_assert_cb assert_cb = NULL;

void lws_set_assert_cb(lws_assert_cb cb) {
assert_cb = cb;
}

void lws_assert(const char *file, int line, const char *expression) {
if (assert_cb != NULL) {
assert_cb(file, line, expression);
} else {
fprintf(stderr, "Assertion failed: %s, file %s, line %d\n", expression, file, line);
abort();
}
}
1 change: 1 addition & 0 deletions lib/core/private-lib-core.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@
*
*/

#define LWS_ENABLE_CUSTOM_ASSERT
#include "libwebsockets.h"

/*
Expand Down
2 changes: 1 addition & 1 deletion lib/roles/http/client/client-http.c
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ lws_http_client_socket_service(struct lws *wsi, struct lws_pollfd *pollfd)
lwsl_debug("ERROR writing to client socket\n");
lws_close_free_wsi(wsi, LWS_CLOSE_STATUS_NOSTATUS,
"cws");
return 0;
return -1; // closed wsi so let callers know
case LWS_SSL_CAPABLE_MORE_SERVICE:
lws_callback_on_writable(wsi);
break;
Expand Down
5 changes: 5 additions & 0 deletions make.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
rm -rf build
mkdir build
cd build
cmake .. -DLWS_WITH_MINIMAL_EXAMPLES=1
make