diff --git a/lib/client-handshake.c b/lib/client-handshake.c index de99a208e..2dd810c56 100644 --- a/lib/client-handshake.c +++ b/lib/client-handshake.c @@ -85,7 +85,7 @@ struct libwebsocket *__libwebsocket_client_connect_2( if (context->http_proxy_port) { - n = send(wsi->sock, context->service_buffer, plen, 0); + n = send(wsi->sock, context->service_buffer, plen, MSG_NOSIGNAL); if (n < 0) { compatible_close(wsi->sock); lwsl_debug("ERROR writing to proxy socket\n"); diff --git a/lib/client.c b/lib/client.c index b6236a2b8..94a669471 100644 --- a/lib/client.c +++ b/lib/client.c @@ -229,7 +229,7 @@ int lws_client_socket_service(struct libwebsocket_context *context, else #endif n = send(wsi->sock, context->service_buffer, - p - (char *)context->service_buffer, 0); + p - (char *)context->service_buffer, MSG_NOSIGNAL); lws_latency(context, wsi, "send or SSL_write LWS_CONNMODE...HANDSHAKE", n, n >= 0); diff --git a/lib/output.c b/lib/output.c index 21d40bcd7..644eb71da 100644 --- a/lib/output.c +++ b/lib/output.c @@ -311,7 +311,7 @@ LWS_VISIBLE int libwebsocket_write(struct libwebsocket *wsi, unsigned char *buf, int m; #endif - if (len == 0 && protocol != LWS_WRITE_CLOSE) { + if (len == 0 && protocol != LWS_WRITE_CLOSE && protocol != LWS_WRITE_PING && protocol != LWS_WRITE_PONG) { lwsl_warn("zero length libwebsocket_write attempt\n"); return 0; } @@ -504,7 +504,6 @@ send_raw: LWS_VISIBLE int libwebsockets_serve_http_file_fragment( struct libwebsocket_context *context, struct libwebsocket *wsi) { - int ret = 0; int n, m; while (!lws_send_pipe_choked(wsi)) { @@ -516,7 +515,7 @@ LWS_VISIBLE int libwebsockets_serve_http_file_fragment( if (m < 0) return -1; - wsi->u.http.filepos += n; + wsi->u.http.filepos += m; if (m != n) /* adjust for what was not sent */ lseek(wsi->u.http.fd, m - n, SEEK_CUR); @@ -525,23 +524,23 @@ LWS_VISIBLE int libwebsockets_serve_http_file_fragment( if (n < 0) return -1; /* caller will close */ - if (n < sizeof(context->service_buffer) || - wsi->u.http.filepos == wsi->u.http.filelen) { + if (wsi->u.http.filepos == wsi->u.http.filelen) { wsi->state = WSI_STATE_HTTP; if (wsi->protocol->callback) - ret = user_callback_handle_rxflow( + /* ignore callback returned value */ + user_callback_handle_rxflow( wsi->protocol->callback, context, wsi, LWS_CALLBACK_HTTP_FILE_COMPLETION, wsi->user_space, NULL, 0); - return ret; + return 1; /* >0 indicates completed */ } } lwsl_notice("choked before able to send whole file (post)\n"); libwebsocket_callback_on_writable(context, wsi); - return ret; + return 0; /* indicates further processing must be done */ } /** diff --git a/lib/sha-1.c b/lib/sha-1.c index 6020c227e..1491502d2 100644 --- a/lib/sha-1.c +++ b/lib/sha-1.c @@ -215,7 +215,7 @@ sha1_step(struct sha1_ctxt *ctxt) /*------------------------------------------------------------*/ -void +static void sha1_init(struct sha1_ctxt *ctxt) { bzero(ctxt, sizeof(struct sha1_ctxt)); diff --git a/scripts/FindLibWebSockets.cmake b/scripts/FindLibWebSockets.cmake new file mode 100644 index 000000000..e7d283932 --- /dev/null +++ b/scripts/FindLibWebSockets.cmake @@ -0,0 +1,33 @@ +# This module tries to find libWebsockets library and include files +# +# LIBWEBSOCKETS_INCLUDE_DIR, path where to find libwebsockets.h +# LIBWEBSOCKETS_LIBRARY_DIR, path where to find libwebsockets.so +# LIBWEBSOCKETS_LIBRARIES, the library to link against +# LIBWEBSOCKETS_FOUND, If false, do not try to use libWebSockets +# +# This currently works probably only for Linux + +FIND_PATH ( LIBWEBSOCKETS_INCLUDE_DIR libwebsockets.h + /usr/local/include + /usr/include +) + +FIND_LIBRARY ( LIBWEBSOCKETS_LIBRARIES websockets + /usr/local/lib + /usr/lib +) + +GET_FILENAME_COMPONENT( LIBWEBSOCKETS_LIBRARY_DIR ${LIBWEBSOCKETS_LIBRARIES} PATH ) + +SET ( LIBWEBSOCKETS_FOUND "NO" ) +IF ( LIBWEBSOCKETS_INCLUDE_DIR ) + IF ( LIBWEBSOCKETS_LIBRARIES ) + SET ( LIBWEBSOCKETS_FOUND "YES" ) + ENDIF ( LIBWEBSOCKETS_LIBRARIES ) +ENDIF ( LIBWEBSOCKETS_INCLUDE_DIR ) + +MARK_AS_ADVANCED( + LIBWEBSOCKETS_LIBRARY_DIR + LIBWEBSOCKETS_INCLUDE_DIR + LIBWEBSOCKETS_LIBRARIES +)