1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
/*
* Hot Beverage Companion – server module
*
* Copyright (C) 2017-2018 Gediminas Jakutis
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; version 2.1
* of the License.
*
* 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/udp.h>
#include <poll.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <arpa/inet.h>
#include <stddef.h>
#include <stdlib.h>
#include <time.h>
#include "util.h"
#include "net.h"
#include "ui.h"
static int init(int argc, char ***argv, const unsigned short int port, enum uitype ui);
int main(int argc, char **argv)
{
int ret;
int nd;
nd = init(argc, &argv, 2191, UI_DEFAULT);
if (nd == ERROR) {
ret = nd;
goto fail;
}
ret = ui_startloop();
fail:
net_close(nd);
return ret;
}
static int init(int argc, char ***argv, const unsigned short int port, enum uitype ui)
{
int ret = A_OK;
int nd;
nd = net_init(port);
if (nd == ERROR) {
ret = nd;
goto fail;
}
ret = ui_init(argc, argv, ui, nd, DEFAULT_PERIOD);
if (ret == ERROR) {
net_close(nd);
goto fail;
}
fail:
return ret;
}
|