@@ -836,7 +836,7 @@ void handle_disconnect_client(connection_t *c)
836836 send_http_headers (c , STATUS_503 , "application/json" , NULL );
837837 snprintf (response , sizeof (response ),
838838 "{\"success\":false,\"error\":\"Status system not initialized\"}" );
839- connection_queue_output_and_flush (c , (const uint8_t * )response , strlen (response ), 1 );
839+ connection_queue_output_and_flush (c , (const uint8_t * )response , strlen (response ));
840840 return ;
841841 }
842842
@@ -846,7 +846,7 @@ void handle_disconnect_client(connection_t *c)
846846 send_http_headers (c , STATUS_400 , "application/json" , NULL );
847847 snprintf (response , sizeof (response ),
848848 "{\"success\":false,\"error\":\"Method not allowed. Use POST or DELETE\"}" );
849- connection_queue_output_and_flush (c , (const uint8_t * )response , strlen (response ), 1 );
849+ connection_queue_output_and_flush (c , (const uint8_t * )response , strlen (response ));
850850 return ;
851851 }
852852
@@ -858,7 +858,7 @@ void handle_disconnect_client(connection_t *c)
858858 send_http_headers (c , STATUS_400 , "application/json" , NULL );
859859 snprintf (response , sizeof (response ),
860860 "{\"success\":false,\"error\":\"Missing 'client_id' parameter in request body\"}" );
861- connection_queue_output_and_flush (c , (const uint8_t * )response , strlen (response ), 1 );
861+ connection_queue_output_and_flush (c , (const uint8_t * )response , strlen (response ));
862862 return ;
863863 }
864864 }
@@ -867,7 +867,7 @@ void handle_disconnect_client(connection_t *c)
867867 send_http_headers (c , STATUS_400 , "application/json" , NULL );
868868 snprintf (response , sizeof (response ),
869869 "{\"success\":false,\"error\":\"Missing request body\"}" );
870- connection_queue_output_and_flush (c , (const uint8_t * )response , strlen (response ), 1 );
870+ connection_queue_output_and_flush (c , (const uint8_t * )response , strlen (response ));
871871 return ;
872872 }
873873
@@ -877,7 +877,7 @@ void handle_disconnect_client(connection_t *c)
877877 send_http_headers (c , STATUS_400 , "application/json" , NULL );
878878 snprintf (response , sizeof (response ),
879879 "{\"success\":false,\"error\":\"Empty client_id\"}" );
880- connection_queue_output_and_flush (c , (const uint8_t * )response , strlen (response ), 1 );
880+ connection_queue_output_and_flush (c , (const uint8_t * )response , strlen (response ));
881881 return ;
882882 }
883883
@@ -915,7 +915,7 @@ void handle_disconnect_client(connection_t *c)
915915 "{\"success\":false,\"error\":\"Client not found or already disconnected\"}" );
916916 }
917917
918- connection_queue_output_and_flush (c , (const uint8_t * )response , strlen (response ), 1 );
918+ connection_queue_output_and_flush (c , (const uint8_t * )response , strlen (response ));
919919}
920920
921921/**
@@ -934,7 +934,7 @@ void handle_set_log_level(connection_t *c)
934934 send_http_headers (c , STATUS_400 , "application/json" , NULL );
935935 snprintf (response , sizeof (response ),
936936 "{\"success\":false,\"error\":\"Method not allowed. Use PUT or PATCH\"}" );
937- connection_queue_output_and_flush (c , (const uint8_t * )response , strlen (response ), 1 );
937+ connection_queue_output_and_flush (c , (const uint8_t * )response , strlen (response ));
938938 return ;
939939 }
940940
@@ -946,7 +946,7 @@ void handle_set_log_level(connection_t *c)
946946 send_http_headers (c , STATUS_400 , "application/json" , NULL );
947947 snprintf (response , sizeof (response ),
948948 "{\"success\":false,\"error\":\"Missing 'level' parameter in request body\"}" );
949- connection_queue_output_and_flush (c , (const uint8_t * )response , strlen (response ), 1 );
949+ connection_queue_output_and_flush (c , (const uint8_t * )response , strlen (response ));
950950 return ;
951951 }
952952 }
@@ -955,7 +955,7 @@ void handle_set_log_level(connection_t *c)
955955 send_http_headers (c , STATUS_400 , "application/json" , NULL );
956956 snprintf (response , sizeof (response ),
957957 "{\"success\":false,\"error\":\"Missing request body\"}" );
958- connection_queue_output_and_flush (c , (const uint8_t * )response , strlen (response ), 1 );
958+ connection_queue_output_and_flush (c , (const uint8_t * )response , strlen (response ));
959959 return ;
960960 }
961961
@@ -966,7 +966,7 @@ void handle_set_log_level(connection_t *c)
966966 send_http_headers (c , STATUS_400 , "application/json" , NULL );
967967 snprintf (response , sizeof (response ),
968968 "{\"success\":false,\"error\":\"Invalid log level (must be 0-4)\"}" );
969- connection_queue_output_and_flush (c , (const uint8_t * )response , strlen (response ), 1 );
969+ connection_queue_output_and_flush (c , (const uint8_t * )response , strlen (response ));
970970 return ;
971971 }
972972
@@ -975,13 +975,12 @@ void handle_set_log_level(connection_t *c)
975975 {
976976 status_shared -> current_log_level = new_level ;
977977 }
978- config .verbosity = new_level ;
979978 send_http_headers (c , STATUS_200 , "application/json" , NULL );
980979
981980 snprintf (response , sizeof (response ),
982981 "{\"success\":true,\"message\":\"Log level changed to %s\"}" ,
983982 status_get_log_level_name (new_level ));
984- connection_queue_output_and_flush (c , (const uint8_t * )response , strlen (response ), 1 );
983+ connection_queue_output_and_flush (c , (const uint8_t * )response , strlen (response ));
985984}
986985
987986/**
@@ -996,7 +995,6 @@ int status_handle_sse_init(connection_t *c)
996995 /* Send SSE headers */
997996 send_http_headers (c , STATUS_200 , "text/event-stream" , NULL );
998997
999- c -> sse_active = 1 ;
1000998 c -> sse_sent_initial = 0 ;
1001999 c -> sse_last_write_index = -1 ;
10021000 c -> sse_last_log_count = 0 ;
@@ -1011,7 +1009,7 @@ int status_handle_sse_init(connection_t *c)
10111009
10121010 if (len > 0 )
10131011 {
1014- connection_queue_output_and_flush (c , (const uint8_t * )tmp , (size_t )len , 0 );
1012+ connection_queue_output_and_flush (c , (const uint8_t * )tmp , (size_t )len );
10151013 }
10161014
10171015 c -> state = CONN_SSE ;
@@ -1035,7 +1033,7 @@ int status_handle_sse_notification(connection_t *conn_head)
10351033 * so we must build a separate payload for each connection */
10361034 for (connection_t * cc = conn_head ; cc ; cc = cc -> next )
10371035 {
1038- if (! cc -> sse_active )
1036+ if (cc -> state != CONN_SSE )
10391037 continue ;
10401038
10411039 char tmp [SSE_BUFFER_SIZE ];
@@ -1046,8 +1044,9 @@ int status_handle_sse_notification(connection_t *conn_head)
10461044
10471045 if (len > 0 )
10481046 {
1049- if (connection_queue_output_and_flush (cc , (const uint8_t * )tmp , (size_t )len , 0 ) == 0 )
1047+ if (connection_queue_output_and_flush (cc , (const uint8_t * )tmp , (size_t )len ) == 0 )
10501048 {
1049+ cc -> state = CONN_SSE ;
10511050 updated_count ++ ;
10521051 }
10531052 }
@@ -1065,7 +1064,7 @@ int status_handle_sse_notification(connection_t *conn_head)
10651064 */
10661065int status_handle_sse_heartbeat (connection_t * c , int64_t now )
10671066{
1068- if (!c || ! c -> sse_active )
1067+ if (!c || c -> state != CONN_SSE )
10691068 return -1 ;
10701069
10711070 /* Check if heartbeat is needed */
0 commit comments