- dsi->header.dsi_flags = DSIFL_REQUEST;
- dsi->header.dsi_command = DSIFUNC_CLOSE;
- dsi->header.dsi_requestID = htons(dsi_serverID(dsi));
- dsi->header.dsi_code = dsi->header.dsi_reserved = htonl(0);
- dsi->cmdlen = 0;
-
- dsi_send(dsi);
- dsi->proto_close(dsi);
+ if (!(dsi->flags & DSI_SLEEPING) && !(dsi->flags & DSI_DISCONNECTED)) {
+ dsi->header.dsi_flags = DSIFL_REQUEST;
+ dsi->header.dsi_command = DSIFUNC_CLOSE;
+ dsi->header.dsi_requestID = htons(dsi_serverID(dsi));
+ dsi->header.dsi_data.dsi_code = dsi->header.dsi_reserved = htonl(0);
+ dsi->cmdlen = 0;
+ dsi_send(dsi);
+ dsi->proto_close(dsi);
+ }