[354] Close http files even on bad clients.

Thanks to jbwdevries.

Bug: https://github.com/eclipse/mosquitto/issues/354
This commit is contained in:
Roger A. Light 2017-01-20 18:25:04 +00:00
parent 7f66bf1f65
commit 8171a975ae
2 changed files with 13 additions and 0 deletions

View File

@ -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.

View File

@ -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: