ntp_server: use the I/O thread
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
#include "config.h"
|
||||
#include "ntp_server.h"
|
||||
#include "signals.h"
|
||||
#include "io_thread.h"
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
@@ -39,12 +40,10 @@
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
|
||||
static bool quit = false;
|
||||
|
||||
void
|
||||
on_quit(void)
|
||||
{
|
||||
quit = true;
|
||||
io_thread_quit();
|
||||
}
|
||||
|
||||
static int bind_host(int sd, char *hostname, unsigned long ulAddr,
|
||||
@@ -122,27 +121,25 @@ open_udp_socket(char *hostname, unsigned short *port)
|
||||
int
|
||||
main(G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv)
|
||||
{
|
||||
g_thread_init(NULL);
|
||||
signals_init();
|
||||
io_thread_init();
|
||||
|
||||
struct ntp_server ntp;
|
||||
ntp_server_init(&ntp);
|
||||
|
||||
ntp.fd = open_udp_socket(NULL, &ntp.port);
|
||||
if (ntp.fd < 0) {
|
||||
int fd = open_udp_socket(NULL, &ntp.port);
|
||||
if (fd < 0) {
|
||||
g_printerr("Failed to create UDP socket\n");
|
||||
ntp_server_close(&ntp);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
while (!quit) {
|
||||
struct timeval tv = {
|
||||
.tv_sec = 1,
|
||||
.tv_usec = 0,
|
||||
};
|
||||
ntp_server_open(&ntp, fd);
|
||||
|
||||
ntp_server_check(&ntp, &tv);
|
||||
}
|
||||
io_thread_run();
|
||||
|
||||
ntp_server_close(&ntp);
|
||||
io_thread_deinit();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
@@ -18,6 +18,7 @@
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "io_thread.h"
|
||||
#include "output_plugin.h"
|
||||
#include "output_internal.h"
|
||||
#include "output_control.h"
|
||||
@@ -36,6 +37,7 @@
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
struct playlist g_playlist;
|
||||
|
||||
@@ -146,6 +148,13 @@ int main(int argc, char **argv)
|
||||
return 1;
|
||||
}
|
||||
|
||||
io_thread_init();
|
||||
if (!io_thread_start(&error)) {
|
||||
g_warning("%s", error->message);
|
||||
g_error_free(error);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
/* initialize the audio output */
|
||||
|
||||
if (!load_audio_output(&ao, argv[2]))
|
||||
@@ -216,6 +225,8 @@ int main(int argc, char **argv)
|
||||
ao_plugin_finish(ao.plugin, ao.data);
|
||||
g_mutex_free(ao.mutex);
|
||||
|
||||
io_thread_deinit();
|
||||
|
||||
config_global_finish();
|
||||
|
||||
return 0;
|
||||
|
Reference in New Issue
Block a user