run_ntp_server.c 1.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/*
 * Copyright (C) 2003-2011 The Music Player Daemon Project
 * http://www.musicpd.org
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#include "config.h"
#include "ntp_server.h"
22
#include "signals.h"
23
#include "io_thread.h"
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41

#include <glib.h>

#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>

#ifdef WIN32
#include <ws2tcpip.h>
#include <winsock.h>
#else
#include <sys/socket.h>
#include <netdb.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#endif

42 43 44
void
on_quit(void)
{
45
	io_thread_quit();
46 47
}

48 49 50
int
main(G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv)
{
51
	g_thread_init(NULL);
52
	signals_init();
53
	io_thread_init();
54

55 56 57
	struct ntp_server ntp;
	ntp_server_init(&ntp);

58 59 60 61 62
	GError *error = NULL;
	if (!ntp_server_open(&ntp, &error)) {
		io_thread_deinit();
		g_printerr("%s\n", error->message);
		g_error_free(error);
63 64 65
		return EXIT_FAILURE;
	}

66
	io_thread_run();
67 68

	ntp_server_close(&ntp);
69
	io_thread_deinit();
70 71
	return EXIT_SUCCESS;
}