diff --git a/ChangeLog.txt b/ChangeLog.txt index c1d6cbfc..9c9f6cd8 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -3,6 +3,8 @@ Broker: - maximum_connections now applies to websockets listeners. Closes #271. - Allow bridges to use TLS with IPv6. - Don't error on zero length persistence files. Closes #316. +- For http only websockets clients, close files served over http in all cases + when the client disconnects. Closes #354. Client library: - Clients can now use TLS with IPv6. diff --git a/src/websockets.c b/src/websockets.c index 975a10c0..529aaff4 100644 --- a/src/websockets.c +++ b/src/websockets.c @@ -521,6 +521,7 @@ static int callback_http(struct libwebsocket_context *context, (unsigned int)filestat.st_size); if(libwebsocket_write(wsi, buf, buflen, LWS_WRITE_HTTP) < 0){ fclose(u->fptr); + u->fptr = NULL; return -1; } libwebsocket_callback_on_writable(context, wsi); @@ -546,6 +547,7 @@ static int callback_http(struct libwebsocket_context *context, buflen = fread(buf, 1, sizeof(buf), u->fptr); if(buflen < 1){ fclose(u->fptr); + u->fptr = NULL; return -1; } wlen = libwebsocket_write(wsi, buf, buflen, LWS_WRITE_HTTP); @@ -566,6 +568,15 @@ static int callback_http(struct libwebsocket_context *context, }else{ return -1; } + + case LWS_CALLBACK_CLOSED: + case LWS_CALLBACK_CLOSED_HTTP: + case LWS_CALLBACK_HTTP_FILE_COMPLETION: + if(u && u->fptr){ + fclose(u->fptr); + u->fptr = NULL; + } + break; #endif default: