diff --git a/lib/client-handshake.c b/lib/client-handshake.c index de99a208eb..2dd810c561 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 dc6dacb94f..45e83af51d 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); @@ -774,7 +774,7 @@ libwebsockets_generate_client_handshake(struct libwebsocket_context *context, p += strlen(key_b64); p += sprintf(p, "\x0d\x0a"); if (lws_hdr_simple_ptr(wsi, _WSI_TOKEN_CLIENT_ORIGIN)) - p += sprintf(p, "Origin: %s\x0d\x0a", + p += sprintf(p, "Origin: http://%s\x0d\x0a", lws_hdr_simple_ptr(wsi, _WSI_TOKEN_CLIENT_ORIGIN)); if (lws_hdr_simple_ptr(wsi, _WSI_TOKEN_CLIENT_SENT_PROTOCOLS)) diff --git a/lib/libwebsockets.c b/lib/libwebsockets.c index ce6bae0bba..21377aba26 100644 --- a/lib/libwebsockets.c +++ b/lib/libwebsockets.c @@ -210,6 +210,8 @@ libwebsocket_close_and_free_session(struct libwebsocket_context *context, lwsl_debug("closing http fd %d\n", wsi->u.http.fd); close(wsi->u.http.fd); wsi->u.http.fd = 0; + context->protocols[0].callback(context, wsi, + LWS_CALLBACK_CLOSED_HTTP, wsi->user_space, NULL, 0); } #ifndef LWS_NO_EXTENSIONS @@ -368,6 +370,10 @@ libwebsocket_close_and_free_session(struct libwebsocket_context *context, lwsl_debug("calling back CLOSED\n"); wsi->protocol->callback(context, wsi, LWS_CALLBACK_CLOSED, wsi->user_space, NULL, 0); + } else if ( wsi->mode == LWS_CONNMODE_HTTP_SERVING_ACCEPTED ) { + lwsl_debug("calling back CLOSED_HTTP\n"); + context->protocols[0].callback(context, wsi, + LWS_CALLBACK_CLOSED_HTTP, wsi->user_space, NULL, 0 ); } else lwsl_debug("not calling back closed\n"); diff --git a/lib/libwebsockets.h b/lib/libwebsockets.h index 65bae14534..9f686bd879 100644 --- a/lib/libwebsockets.h +++ b/lib/libwebsockets.h @@ -138,6 +138,7 @@ enum libwebsocket_callback_reasons { LWS_CALLBACK_CLIENT_FILTER_PRE_ESTABLISH, LWS_CALLBACK_CLIENT_ESTABLISHED, LWS_CALLBACK_CLOSED, + LWS_CALLBACK_CLOSED_HTTP, LWS_CALLBACK_RECEIVE, LWS_CALLBACK_CLIENT_RECEIVE, LWS_CALLBACK_CLIENT_RECEIVE_PONG, @@ -419,6 +420,8 @@ struct libwebsocket_extension; * * LWS_CALLBACK_CLOSED: when the websocket session ends * + * LWS_CALLBACK_CLOSED_HTTP: when a HTTP (non-websocket) session ends + * * LWS_CALLBACK_RECEIVE: data has appeared for this server endpoint from a * remote client, it can be found at *in and is * len bytes long diff --git a/lib/output.c b/lib/output.c index ef823c3e9f..224a0f27a5 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 @@ LWS_VISIBLE int libwebsocket_write(struct libwebsocket *wsi, unsigned char *buf, 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 67b17e1eb2..b1cb96fe46 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));