};
struct monitor *monitor_get(void);
+gboolean monitor_get_debug_mode(void);
+void monitor_set_debug_mode(gboolean on);
int monitor_thread_init(struct monitor *monitor);
void monitor_thread_exit(struct monitor *monitor);
int request_server_init(void);
void request_server_exit(void);
+
#endif
#include <monitor/monitor.h>
static struct monitor g_monitor;
+static gboolean g_debug_mode;
struct monitor *monitor_get(void)
{
return &g_monitor;
}
+gboolean monitor_get_debug_mode(void)
+{
+ return g_debug_mode;
+}
+
+void monitor_set_debug_mode(gboolean on)
+{
+ g_debug_mode = on;
+}
+
static int monitor_setup(void *data, void *user_data)
{
int ret;
struct sockaddr_in ip_address;
struct timeval wait;
int server_unix_socket;
- int server_ip_socket;
+ int server_ip_socket = 0;
int unix_addrlen;
int ip_addrlen;
int ret;
if (ret < 0)
goto error_out;
- /* initialize TCP socket */
- ret = init_ip_socket(&server_ip_socket, &ip_address, &ip_addrlen);
- if (ret < 0)
- goto error_out_close_server_unix_socket;
-
while (g_request_server_run) {
FD_ZERO(&fds);
FD_SET(server_unix_socket, &fds);
- FD_SET(server_ip_socket, &fds);
+ if (server_ip_socket)
+ FD_SET(server_ip_socket, &fds);
wait.tv_sec = 1;
wait.tv_usec = 0;
create_request_client(new_socket);
}
- if (FD_ISSET(server_ip_socket, &fds)) {
+ if (server_ip_socket && FD_ISSET(server_ip_socket, &fds)) {
int new_socket = accept(server_ip_socket, (struct sockaddr *)&ip_address,
(socklen_t *)&ip_addrlen);
create_request_client(new_socket);
}
+
+ if (!server_ip_socket && (monitor_get_debug_mode() == TRUE)) {
+ /*
+ * FIXME:
+ * server_ip_socket activation can be deferred since it
+ * will be done after timeout of select is expired. So,
+ * when the timeout is extended, this activation should be
+ * done by other ways in order to prevent unacceptable
+ * delays.
+ */
+ ret = init_ip_socket(&server_ip_socket, &ip_address, &ip_addrlen);
+ if (ret < 0)
+ goto error_out_close_server_unix_socket;
+ } else if (server_ip_socket && (monitor_get_debug_mode() == FALSE)) {
+ close(server_ip_socket);
+ server_ip_socket = 0;
+ }
}
- close(server_ip_socket);
close(server_unix_socket);
+ if (server_ip_socket)
+ close(server_ip_socket);
return THREAD_RETURN_DONE;
error_out_close:
- close(server_ip_socket);
+ if (server_ip_socket)
+ close(server_ip_socket);
error_out_close_server_unix_socket:
close(server_unix_socket);
error_out: