Quellcode durchsuchen

MHD_daemon_get_info_{fixed,dynamic}(): return "too early" and "too late" error codes

Evgeny Grin (Karlson2k) vor 1 Jahr
Ursprung
Commit
d1481395ba
3 geänderte Dateien mit 34 neuen und 0 gelöschten Zeilen
  1. 12 0
      src/include/microhttpd2.h
  2. 12 0
      src/include/microhttpd2_main.h.in
  3. 10 0
      src/mhd2/daemon_get_info.c

+ 12 - 0
src/include/microhttpd2.h

@@ -9259,6 +9259,9 @@ union MHD_DaemonInfoFixedData
  *                        (provided by the caller for storing the requested
  *                        information), in bytes
  * @return #MHD_SC_OK if succeed,
+ *         #MHD_SC_TOO_EARLY if the daemon has not been started yet,
+ *         #MHD_SC_TOO_LATE if the daemon is being stopped or has failed,
+ *         #MHD_SC_INFO_GET_TYPE_UNKNOWN if @a info_type value is unknown,
  *         #MHD_SC_INFO_GET_BUFF_TOO_SMALL if @a output_buf_size is too small,
  *         #MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE if the requested information
  *                                              is not available for this
@@ -9290,6 +9293,9 @@ MHD_FN_PAR_NONNULL_ (3) MHD_FN_PAR_OUT_ (3);
  * @param[out] output_buf pointer to union where requested information will
  *                          be stored
  * @return #MHD_SC_OK if succeed,
+ *         #MHD_SC_TOO_EARLY if the daemon has not been started yet,
+ *         #MHD_SC_TOO_LATE if the daemon is being stopped or has failed,
+ *         #MHD_SC_INFO_GET_TYPE_UNKNOWN if @a info_type value is unknown,
  *         #MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE if the requested information
  *                                              is not available for this
  *                                              daemon due to the daemon
@@ -9383,6 +9389,9 @@ union MHD_DaemonInfoDynamicData
  *                        (provided by the caller for storing the requested
  *                        information), in bytes
  * @return #MHD_SC_OK if succeed,
+ *         #MHD_SC_TOO_EARLY if the daemon has not been started yet,
+ *         #MHD_SC_TOO_LATE if the daemon is being stopped or has failed,
+ *         #MHD_SC_INFO_GET_TYPE_UNKNOWN if @a info_type value is unknown,
  *         #MHD_SC_INFO_GET_BUFF_TOO_SMALL if @a output_buf_size is too small,
  *         #MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE if the requested information
  *                                              is not available for this
@@ -9413,6 +9422,9 @@ MHD_FN_PAR_NONNULL_ (3) MHD_FN_PAR_OUT_ (3);
  * @param[out] output_buf the pointer to union to be set to the requested
  *                        information
  * @return #MHD_SC_OK if succeed,
+ *         #MHD_SC_TOO_EARLY if the daemon has not been started yet,
+ *         #MHD_SC_TOO_LATE if the daemon is being stopped or has failed,
+ *         #MHD_SC_INFO_GET_TYPE_UNKNOWN if @a info_type value is unknown,
  *         #MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE if the requested information
  *                                              is not available for this
  *                                              daemon due to the daemon

+ 12 - 0
src/include/microhttpd2_main.h.in

@@ -4637,6 +4637,9 @@ union MHD_DaemonInfoFixedData
  *                        (provided by the caller for storing the requested
  *                        information), in bytes
  * @return #MHD_SC_OK if succeed,
+ *         #MHD_SC_TOO_EARLY if the daemon has not been started yet,
+ *         #MHD_SC_TOO_LATE if the daemon is being stopped or has failed,
+ *         #MHD_SC_INFO_GET_TYPE_UNKNOWN if @a info_type value is unknown,
  *         #MHD_SC_INFO_GET_BUFF_TOO_SMALL if @a output_buf_size is too small,
  *         #MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE if the requested information
  *                                              is not available for this
@@ -4668,6 +4671,9 @@ MHD_FN_PAR_NONNULL_ (3) MHD_FN_PAR_OUT_ (3);
  * @param[out] output_buf pointer to union where requested information will
  *                          be stored
  * @return #MHD_SC_OK if succeed,
+ *         #MHD_SC_TOO_EARLY if the daemon has not been started yet,
+ *         #MHD_SC_TOO_LATE if the daemon is being stopped or has failed,
+ *         #MHD_SC_INFO_GET_TYPE_UNKNOWN if @a info_type value is unknown,
  *         #MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE if the requested information
  *                                              is not available for this
  *                                              daemon due to the daemon
@@ -4761,6 +4767,9 @@ union MHD_DaemonInfoDynamicData
  *                        (provided by the caller for storing the requested
  *                        information), in bytes
  * @return #MHD_SC_OK if succeed,
+ *         #MHD_SC_TOO_EARLY if the daemon has not been started yet,
+ *         #MHD_SC_TOO_LATE if the daemon is being stopped or has failed,
+ *         #MHD_SC_INFO_GET_TYPE_UNKNOWN if @a info_type value is unknown,
  *         #MHD_SC_INFO_GET_BUFF_TOO_SMALL if @a output_buf_size is too small,
  *         #MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE if the requested information
  *                                              is not available for this
@@ -4791,6 +4800,9 @@ MHD_FN_PAR_NONNULL_ (3) MHD_FN_PAR_OUT_ (3);
  * @param[out] output_buf the pointer to union to be set to the requested
  *                        information
  * @return #MHD_SC_OK if succeed,
+ *         #MHD_SC_TOO_EARLY if the daemon has not been started yet,
+ *         #MHD_SC_TOO_LATE if the daemon is being stopped or has failed,
+ *         #MHD_SC_INFO_GET_TYPE_UNKNOWN if @a info_type value is unknown,
  *         #MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE if the requested information
  *                                              is not available for this
  *                                              daemon due to the daemon

+ 10 - 0
src/mhd2/daemon_get_info.c

@@ -43,6 +43,11 @@ MHD_daemon_get_info_fixed_sz (struct MHD_Daemon *daemon,
                               union MHD_DaemonInfoFixedData *output_buf,
                               size_t output_buf_size)
 {
+  if (mhd_DAEMON_STATE_STARTED > daemon->state)
+    return MHD_SC_TOO_EARLY;
+  if (mhd_DAEMON_STATE_STARTED < daemon->state)
+    return MHD_SC_TOO_LATE;
+
   switch (info_type)
   {
   case MHD_DAEMON_INFO_FIXED_LISTEN_SOCKET:
@@ -95,6 +100,11 @@ MHD_daemon_get_info_dynamic_sz (struct MHD_Daemon *daemon,
                                 union MHD_DaemonInfoDynamicData *output_buf,
                                 size_t output_buf_size)
 {
+  if (mhd_DAEMON_STATE_STARTED > daemon->state)
+    return MHD_SC_TOO_EARLY;
+  if (mhd_DAEMON_STATE_STARTED < daemon->state)
+    return MHD_SC_TOO_LATE;
+
   switch (info_type)
   {
   case MHD_DAEMON_INFO_DYNAMIC_MAX_TIME_TO_WAIT: