Revision 1.01 changes
This commit is contained in:
parent
b705164771
commit
747b6a8672
|
@ -4,3 +4,4 @@ ntimed-client
|
|||
.depend
|
||||
*.o
|
||||
_*
|
||||
*.kdev4
|
||||
|
|
35
compiler.h
35
compiler.h
|
@ -51,28 +51,22 @@
|
|||
typedef uint32_t register_t;
|
||||
#endif
|
||||
|
||||
#ifdef AROS
|
||||
# define HAVE_WAITSELECT
|
||||
#endif
|
||||
|
||||
#ifdef __GNUC__
|
||||
|
||||
#ifdef AOS3
|
||||
/*
|
||||
* GCC 2.95.3
|
||||
*/
|
||||
#include <machine/limits.h>
|
||||
#include <machine/types.h>
|
||||
# if (__GNUC__ == 2 && __GNUC_MINOR__ == 95)
|
||||
# include <math.h>
|
||||
typedef unsigned char uint8_t;
|
||||
typedef unsigned short uint16_t;
|
||||
typedef unsigned int uint32_t;
|
||||
typedef unsigned long long uint64_t;
|
||||
typedef uint32_t uintptr_t;
|
||||
|
||||
static inline double
|
||||
round(double x)
|
||||
{
|
||||
return x > 0.0 ? floor(x + 0.5) : ceil(x - 0.5);
|
||||
}
|
||||
|
||||
# include <sys/types.h>
|
||||
# define round(x) x > 0.0 ? floor(x + 0.5) : ceil(x - 0.5)
|
||||
# define nan(p) 0./0.
|
||||
typedef u_int8_t uint8_t;
|
||||
typedef u_int16_t uint16_t;
|
||||
typedef u_int32_t uint32_t;
|
||||
typedef u_int64_t uint64_t;
|
||||
typedef uint32_t uintptr_t;
|
||||
typedef unsigned int socklen_t;
|
||||
# endif
|
||||
|
||||
# ifdef AROS
|
||||
|
@ -87,9 +81,8 @@ typedef uint32_t register_t;
|
|||
#endif
|
||||
|
||||
#ifdef __GNUC__
|
||||
typedef unsigned int sa_family_t;
|
||||
typedef unsigned int socklen_t;
|
||||
typedef uint16_t in_port_t;
|
||||
typedef unsigned int sa_family_t;
|
||||
#endif
|
||||
|
||||
// Is this needed since we dont use IPv6 ?
|
||||
|
|
|
@ -39,10 +39,8 @@ HDRS='
|
|||
ntp.h
|
||||
ntp_tbl.h
|
||||
net_getaddrinfo.h
|
||||
net_poll.h
|
||||
param_instance.h
|
||||
param_tbl.h
|
||||
tz.h
|
||||
udp.h
|
||||
'
|
||||
|
||||
|
@ -54,7 +52,6 @@ SRCS='
|
|||
combine_delta.c
|
||||
mem.c
|
||||
net_getaddrinfo.c
|
||||
net_poll.c
|
||||
ntp_filter.c
|
||||
ntp_packet.c
|
||||
ntp_peer.c
|
||||
|
@ -67,19 +64,18 @@ SRCS='
|
|||
time_amiga.c
|
||||
time_sim.c
|
||||
time_stuff.c
|
||||
time_unix.c
|
||||
todo.c
|
||||
tz.c
|
||||
udp.c
|
||||
'
|
||||
|
||||
#################################################
|
||||
# TODO: Rewrite logic
|
||||
|
||||
SRCS1='
|
||||
main_amiga_client.c
|
||||
combine_delta.c
|
||||
mem.c
|
||||
net_getaddrinfo.c
|
||||
net_poll.c
|
||||
ntp_filter.c
|
||||
ntp_packet.c
|
||||
ntp_peer.c
|
||||
|
@ -91,8 +87,8 @@ SRCS1='
|
|||
suckaddr.c
|
||||
time_amiga.c
|
||||
time_stuff.c
|
||||
time_unix.c
|
||||
todo.c
|
||||
tz.c
|
||||
udp.c
|
||||
'
|
||||
|
||||
|
@ -101,7 +97,6 @@ SRCS2='
|
|||
combine_delta.c
|
||||
mem.c
|
||||
net_getaddrinfo.c
|
||||
net_poll.c
|
||||
ntp_filter.c
|
||||
ntp_packet.c
|
||||
ntp_peer.c
|
||||
|
@ -113,8 +108,8 @@ SRCS2='
|
|||
suckaddr.c
|
||||
time_amiga.c
|
||||
time_stuff.c
|
||||
time_unix.c
|
||||
todo.c
|
||||
tz.c
|
||||
udp.c
|
||||
'
|
||||
|
||||
|
@ -123,7 +118,6 @@ SRCS3='
|
|||
combine_delta.c
|
||||
mem.c
|
||||
net_getaddrinfo.c
|
||||
net_poll.c
|
||||
ntp_filter.c
|
||||
ntp_packet.c
|
||||
ntp_peer.c
|
||||
|
@ -133,6 +127,7 @@ SRCS3='
|
|||
param.c
|
||||
pll_std.c
|
||||
suckaddr.c
|
||||
time_amiga.c
|
||||
time_sim.c
|
||||
time_stuff.c
|
||||
todo.c
|
||||
|
@ -144,7 +139,6 @@ SRCS4='
|
|||
combine_delta.c
|
||||
mem.c
|
||||
net_getaddrinfo.c
|
||||
net_poll.c
|
||||
ntp_filter.c
|
||||
ntp_packet.c
|
||||
ntp_peer.c
|
||||
|
@ -156,6 +150,7 @@ SRCS4='
|
|||
suckaddr.c
|
||||
time_amiga.c
|
||||
time_stuff.c
|
||||
time_unix.c
|
||||
todo.c
|
||||
udp.c
|
||||
'
|
||||
|
@ -165,9 +160,9 @@ SRCS4='
|
|||
if make -v 2>&1 | grep GNU > /dev/null 2>&1 ; then
|
||||
echo "make is GNU make."
|
||||
VALID=true
|
||||
else
|
||||
echo "Wrong version of make."
|
||||
VALID=false
|
||||
#else
|
||||
# echo "Wrong version of make."
|
||||
# VALID=false
|
||||
fi
|
||||
|
||||
if $VALID ; then
|
||||
|
@ -178,12 +173,15 @@ if $VALID ; then
|
|||
echo ''
|
||||
if [ -n "$1" ] && [ $1 = "AMIGA" ] ; then
|
||||
echo 'CC = gcc'
|
||||
echo "CFLAGS += -O2 -DAOS3 -DWITHTEST -Wall -Werror"
|
||||
echo "CFLAGS = -O2 -DAOS3 -DWITHTEST -Wall -Werror"
|
||||
echo "LDLIBS = -lm"
|
||||
elif [ -n "$1" ] && [ $1 = "AROS" ] ; then
|
||||
echo 'CC = gcc'
|
||||
echo "CFLAGS += -O2 -DAROS -DWITHTEST -Wall -Werror"
|
||||
echo "CFLAGS = -O2 -DAROS -DWITHTEST -Wall -Werror"
|
||||
echo "LDLIBS = -lm"
|
||||
else
|
||||
echo "CFLAGS += -O2 -Wall -DWITHTEST -Werror"
|
||||
echo "CFLAGS = -O2 -Wall -DWITHTEST -Werror"
|
||||
echo "LDLIBS = -lm"
|
||||
fi
|
||||
echo ''
|
||||
|
||||
|
@ -217,7 +215,6 @@ if $VALID ; then
|
|||
done
|
||||
|
||||
#################################################
|
||||
# TODO: Rewrite logic
|
||||
BIN1=""
|
||||
for f in ${SRCS1}
|
||||
do
|
||||
|
@ -245,16 +242,16 @@ if $VALID ; then
|
|||
|
||||
echo
|
||||
echo "ntimed: ${BIN1}"
|
||||
echo " \${CC} \${CFLAGS} -o ntimed ${BIN1} -lm"
|
||||
echo " \${CC} \${CFLAGS} -o ntimed ${BIN1} \${LDLIBS}"
|
||||
echo
|
||||
echo "ntimed-poll: ${BIN2}"
|
||||
echo " \${CC} \${CFLAGS} -o ntimed-poll ${BIN2} -lm"
|
||||
echo " \${CC} \${CFLAGS} -o ntimed-poll ${BIN2} \${LDLIBS}"
|
||||
echo
|
||||
echo "ntimed-sim: ${BIN3}"
|
||||
echo " \${CC} \${CFLAGS} -o ntimed-sim ${BIN3} -lm"
|
||||
echo " \${CC} \${CFLAGS} -o ntimed-sim ${BIN3} \${LDLIBS}"
|
||||
echo
|
||||
echo "ntimed-test: ${BIN4}"
|
||||
echo " \${CC} \${CFLAGS} -o ntimed-test ${BIN4} -lm"
|
||||
echo " \${CC} \${CFLAGS} -o ntimed-test ${BIN4} \${LDLIBS}"
|
||||
echo
|
||||
echo "clean:"
|
||||
echo " rm -f ${l} ntimed ntimed-poll ntimed-sim ntimed-test"
|
||||
|
|
|
@ -25,14 +25,15 @@
|
|||
*
|
||||
*/
|
||||
|
||||
//#include <proto/exec.h>
|
||||
|
||||
#include "ntimed_platform.h"
|
||||
#include "ntimed.h"
|
||||
#include "tz.h"
|
||||
#include "ntp.h"
|
||||
#include "udp.h"
|
||||
|
||||
#define ARGSFORMAT "P=PARAM/K,T=TRACEFILE/K,Z=TIMEZONE/K,SERVERS/M,SYNC/S,SAVE/S,SHOW/S,QUIET/S"
|
||||
const char *vers = "\0$VER: ntimed-poll 0.9 (15.04.2015)";
|
||||
#define ARGSFORMAT "P=PARAM/K,T=TRACEFILE/K,SERVERS/M/A,SYNC/S,SAVE/S,SHOW/S,QUIET/S"
|
||||
const char *vers = "\0$VER: ntimed-client 1.01 (18.04.2015)";
|
||||
|
||||
#define PARAM_CLIENT PARAM_INSTANCE
|
||||
#define PARAM_TABLE_NAME client_param_table
|
||||
|
@ -40,14 +41,9 @@ const char *vers = "\0$VER: ntimed-poll 0.9 (15.04.2015)";
|
|||
#undef PARAM_TABLE_NAME
|
||||
#undef PARAM_CLIENT
|
||||
|
||||
void Time_Amiga(struct todolist *);
|
||||
extern int validtime;
|
||||
|
||||
BOOL savetime;
|
||||
BOOL started_from_wb;
|
||||
struct Library *BattClockBase;
|
||||
struct Library *UtilityBase = NULL;
|
||||
struct Library *SocketBase = NULL;
|
||||
int savetime;
|
||||
int started_from_wb;
|
||||
struct RDArgs *rdargs = NULL;
|
||||
struct ntp_peerset *nps = NULL;
|
||||
struct todolist *tdl = NULL;
|
||||
|
@ -56,7 +52,6 @@ struct udp_socket *usc = NULL;
|
|||
struct ntimedargs {
|
||||
char *params;
|
||||
char *tracefile;
|
||||
char *timezone;
|
||||
char **servers;
|
||||
long synchronize;
|
||||
long save;
|
||||
|
@ -64,15 +59,13 @@ struct ntimedargs {
|
|||
long quiet;
|
||||
};
|
||||
|
||||
static void init_libs(struct ntimedargs *args);
|
||||
static void init_logic(struct ntimedargs *args);
|
||||
static void clean_exit();
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
struct ntimedargs args = {
|
||||
NULL, NULL, NULL, NULL,
|
||||
FALSE, FALSE, FALSE, FALSE
|
||||
NULL, NULL, NULL, FALSE, FALSE, FALSE, FALSE
|
||||
};
|
||||
|
||||
started_from_wb = (argc == 0);
|
||||
|
@ -93,7 +86,7 @@ int main(int argc, char **argv)
|
|||
if (!rdargs)
|
||||
{
|
||||
PrintFault(IoErr(), (ARGPTR)argv[0]);
|
||||
exit(2);
|
||||
exit(5);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -105,11 +98,7 @@ int main(int argc, char **argv)
|
|||
}
|
||||
}
|
||||
|
||||
init_libs(&args);
|
||||
|
||||
if (args.timezone) {
|
||||
ArgTimezone(args.timezone);
|
||||
}
|
||||
amiga_open_libs();
|
||||
|
||||
if (args.tracefile) {
|
||||
ArgTracefile(args.tracefile);
|
||||
|
@ -129,31 +118,6 @@ int main(int argc, char **argv)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void init_libs(struct ntimedargs *args)
|
||||
{
|
||||
if(!(UtilityBase = (struct Library *)OpenLibrary(UTILLIB_NAME, UTILLIB_REV))) {
|
||||
Put(NULL, OCX_DIAG, "Cannot open utility library.\n");
|
||||
exit(2);
|
||||
}
|
||||
|
||||
if (args->save) {
|
||||
BattClockBase = OpenResource(BATTCLOCK_NAME);
|
||||
}
|
||||
|
||||
#ifdef AROS
|
||||
if(!(SocketBase = OpenLibrary(BSDLIB_NAME, BSDLIB_REV))) {
|
||||
Put(NULL, OCX_DIAG, "No TCP/IP Stack running.\n");
|
||||
exit(2);
|
||||
}
|
||||
|
||||
if(SocketBaseTags(SBTM_SETVAL(SBTC_ERRNOPTR(sizeof(errno))), (IPTR)&errno,
|
||||
SBTM_SETVAL(SBTC_HERRNOLONGPTR), (IPTR)&h_errno, TAG_DONE)) {
|
||||
Put(NULL, OCX_DIAG, "Error initializing bsdsocket.\n");
|
||||
exit(2);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static void set_params(char *params)
|
||||
{
|
||||
char *token;
|
||||
|
@ -179,12 +143,6 @@ static void init_logic(struct ntimedargs *args)
|
|||
int i;
|
||||
int npeer = 0;
|
||||
|
||||
Put(NULL, OCX_DEBUG, "Timezone set to %s (UTC%s%.2f) %s\n",
|
||||
tza[tzid].abbr,
|
||||
tza[tzid].offset < 0.0 ? "-" : "+",
|
||||
fabs(tza[tzid].offset),
|
||||
tza[tzid].name);
|
||||
|
||||
tdl = TODO_NewList();
|
||||
Time_Amiga(tdl);
|
||||
|
||||
|
@ -244,22 +202,11 @@ static void clean_exit()
|
|||
usc = NULL;
|
||||
}
|
||||
|
||||
if (UtilityBase != NULL) {
|
||||
CloseLibrary(UtilityBase);
|
||||
UtilityBase = NULL;
|
||||
}
|
||||
|
||||
#ifdef AROS
|
||||
if (SocketBase != NULL) {
|
||||
CloseLibrary(SocketBase);
|
||||
SocketBase = NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (rdargs) {
|
||||
FreeArgs(rdargs);
|
||||
rdargs = NULL;
|
||||
}
|
||||
|
||||
amiga_close_libs();
|
||||
freeall();
|
||||
}
|
||||
|
|
|
@ -27,18 +27,13 @@
|
|||
|
||||
#include "ntimed_platform.h"
|
||||
#include "ntimed.h"
|
||||
#include "tz.h"
|
||||
#include "ntp.h"
|
||||
#include "udp.h"
|
||||
|
||||
#define ARGSFORMAT "D=DURATION/N,M=MONITOR/K,T=TRACEFILE/K,Z=TIMEZONE/K,SERVERS/M,SHOW/S,QUIET/S"
|
||||
const char *vers = "\0$VER: ntimed-poll 0.9 (15.04.2015)";
|
||||
|
||||
void Time_Amiga_Passive(void);
|
||||
#define ARGSFORMAT "D=DURATION/N,M=MONITOR/K,T=TRACEFILE/K,SERVERS/M/A,SHOW/S,QUIET/S"
|
||||
const char *vers = "\0$VER: ntimed-poll 1.01 (18.04.2015)";
|
||||
|
||||
BOOL started_from_wb;
|
||||
struct Library *BattClockBase;
|
||||
struct Library *SocketBase = NULL;
|
||||
struct RDArgs *rdargs = NULL;
|
||||
struct udp_socket *usc = NULL;
|
||||
struct ntp_peerset *npl = NULL;
|
||||
|
@ -48,19 +43,17 @@ struct ntimedargs {
|
|||
long *duration;
|
||||
char *monitor;
|
||||
char *tracefile;
|
||||
char *timezone;
|
||||
char **servers;
|
||||
long show;
|
||||
long quiet;
|
||||
};
|
||||
|
||||
static void init_libs(struct ntimedargs *args);
|
||||
static void init_logic(struct ntimedargs *args);
|
||||
static void clean_exit();
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
struct ntimedargs args = { NULL, NULL, NULL, NULL, NULL, FALSE, FALSE };
|
||||
struct ntimedargs args = { NULL, NULL, NULL, NULL, FALSE, FALSE };
|
||||
|
||||
started_from_wb = (BOOL)argc;
|
||||
|
||||
|
@ -70,7 +63,7 @@ int main(int argc, char **argv)
|
|||
if (!rdargs)
|
||||
{
|
||||
PrintFault(IoErr(), (ARGPTR)argv[0]);
|
||||
exit(2);
|
||||
exit(5);
|
||||
}
|
||||
|
||||
if (!args.quiet) {
|
||||
|
@ -81,13 +74,11 @@ int main(int argc, char **argv)
|
|||
}
|
||||
}
|
||||
|
||||
init_libs(&args);
|
||||
|
||||
if (args.timezone) {
|
||||
ArgTimezone(args.timezone);
|
||||
}
|
||||
amiga_open_libs();
|
||||
|
||||
if (args.tracefile) {
|
||||
ArgTracefile(args.tracefile);
|
||||
}
|
||||
|
||||
init_logic(&args);
|
||||
|
||||
|
@ -97,22 +88,6 @@ int main(int argc, char **argv)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void init_libs(struct ntimedargs *args)
|
||||
{
|
||||
#ifdef AROS
|
||||
if(!(SocketBase = OpenLibrary(BSDLIB_NAME, BSDLIB_REV))) {
|
||||
Put(NULL, OCX_DIAG, "No TCP/IP Stack running.\n");
|
||||
exit(5);
|
||||
}
|
||||
|
||||
if(SocketBaseTags(SBTM_SETVAL(SBTC_ERRNOPTR(sizeof(errno))), (IPTR)&errno,
|
||||
SBTM_SETVAL(SBTC_HERRNOLONGPTR), (IPTR)&h_errno, TAG_DONE)) {
|
||||
Put(NULL, OCX_DIAG, "Error initializing bsdsocket.\n");
|
||||
exit(5);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
mps_filter(struct ocx *ocx, const struct ntp_peer *np)
|
||||
{
|
||||
|
@ -210,11 +185,6 @@ static void init_logic(struct ntimedargs *args)
|
|||
exit(1);
|
||||
}
|
||||
|
||||
Put(NULL, OCX_TRACE, "# Timezone set to %s (UTC%s%.2f)\n",
|
||||
tza[tzid].abbr,
|
||||
tza[tzid].offset < 0.0 ? "-" : "+",
|
||||
fabs(tza[tzid].offset));
|
||||
|
||||
Put(NULL, OCX_TRACE, "# Duration of run set to %d seconds\n", duration);
|
||||
|
||||
TODO_ScheduleRel(tdl, mps_end, NULL, duration, 0, "End task");
|
||||
|
@ -232,17 +202,11 @@ static void clean_exit()
|
|||
usc = NULL;
|
||||
}
|
||||
|
||||
#ifdef AROS
|
||||
if (SocketBase != NULL) {
|
||||
CloseLibrary(SocketBase);
|
||||
SocketBase = NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (rdargs) {
|
||||
FreeArgs(rdargs);
|
||||
rdargs = NULL;
|
||||
}
|
||||
|
||||
amiga_close_libs();
|
||||
freeall();
|
||||
}
|
||||
|
|
|
@ -26,13 +26,12 @@
|
|||
*/
|
||||
|
||||
#include "ntimed_platform.h"
|
||||
#include "mem.h"
|
||||
#include "ntimed.h"
|
||||
#include "ntp.h"
|
||||
#include "udp.h"
|
||||
|
||||
#define ARGSFORMAT "P=PARAM/K,B=BUMP/K,T=TRACEFILE/K,SIMFILE/A,QUIET/S"
|
||||
const char *vers = "\0$VER: ntimed-poll 0.9 (15.04.2015)";
|
||||
const char *vers = "\0$VER: ntimed-sim 1.01 (18.04.2015)";
|
||||
|
||||
#define PARAM_CLIENT PARAM_INSTANCE
|
||||
#define PARAM_TABLE_NAME client_param_table
|
||||
|
@ -66,7 +65,6 @@ SimFile_Open(struct ocx *ocx, const char *fn, struct todolist *tdl,
|
|||
/**********************************************************************/
|
||||
|
||||
BOOL started_from_wb;
|
||||
struct Library *SocketBase = NULL;
|
||||
struct RDArgs *rdargs = NULL;
|
||||
struct todolist *tdl = NULL;
|
||||
|
||||
|
@ -78,7 +76,6 @@ struct ntimedargs {
|
|||
long quiet;
|
||||
};
|
||||
|
||||
static void init_libs(struct ntimedargs *args);
|
||||
static void init_logic(struct ntimedargs *args);
|
||||
static void set_params(char *params);
|
||||
static void clean_exit();
|
||||
|
@ -101,7 +98,7 @@ int main(int argc, char **argv)
|
|||
EnableDebug();
|
||||
}
|
||||
|
||||
init_libs(&args);
|
||||
amiga_close_libs();
|
||||
|
||||
if (args.tracefile) {
|
||||
ArgTracefile(args.tracefile);
|
||||
|
@ -160,38 +157,16 @@ static void init_logic(struct ntimedargs *args)
|
|||
|
||||
/**********************************************************************/
|
||||
|
||||
static void init_libs(struct ntimedargs *args)
|
||||
{
|
||||
#ifdef AROS
|
||||
if(!(SocketBase = OpenLibrary(BSDLIB_NAME, BSDLIB_REV))) {
|
||||
Put(NULL, OCX_DIAG, "No TCP/IP Stack running.\n");
|
||||
exit(2);
|
||||
}
|
||||
|
||||
if(SocketBaseTags(SBTM_SETVAL(SBTC_ERRNOPTR(sizeof(errno))), (IPTR)&errno,
|
||||
SBTM_SETVAL(SBTC_HERRNOLONGPTR), (IPTR)&h_errno, TAG_DONE)) {
|
||||
Put(NULL, OCX_DIAG, "Error initializing bsdsocket.\n");
|
||||
exit(2);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static void clean_exit()
|
||||
{
|
||||
ArgTracefile(NULL);
|
||||
|
||||
#ifdef AROS
|
||||
if (SocketBase != NULL) {
|
||||
CloseLibrary(SocketBase);
|
||||
SocketBase = NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (rdargs) {
|
||||
FreeArgs(rdargs);
|
||||
rdargs = NULL;
|
||||
}
|
||||
|
||||
amiga_close_libs();
|
||||
freeall();
|
||||
}
|
||||
|
||||
|
|
|
@ -29,19 +29,12 @@
|
|||
#include "ntimed.h"
|
||||
#include "ntp.h"
|
||||
|
||||
const char *vers = "\0$VER: ntimed-test 1.01 (18.04.2015)";
|
||||
BOOL started_from_wb;
|
||||
struct Library *BattClockBase;
|
||||
struct Library *SocketBase = NULL;
|
||||
void Time_Amiga_Passive(void);
|
||||
|
||||
static void clean_exit()
|
||||
{
|
||||
#ifdef AROS
|
||||
if (SocketBase != NULL) {
|
||||
CloseLibrary(SocketBase);
|
||||
SocketBase = NULL;
|
||||
}
|
||||
#endif
|
||||
amiga_close_libs();
|
||||
freeall();
|
||||
}
|
||||
|
||||
|
@ -53,20 +46,7 @@ int main(int argc, char * const *argv)
|
|||
(void)argv;
|
||||
|
||||
atexit(clean_exit);
|
||||
|
||||
#ifdef AROS
|
||||
if(!(SocketBase = OpenLibrary(BSDLIB_NAME, BSDLIB_REV))) {
|
||||
Put(NULL, OCX_DIAG, "No TCP/IP Stack running.\n");
|
||||
exit(2);
|
||||
}
|
||||
|
||||
if(SocketBaseTags(SBTM_SETVAL(SBTC_ERRNOPTR(sizeof(errno))), (IPTR)&errno,
|
||||
SBTM_SETVAL(SBTC_HERRNOLONGPTR), (IPTR)&h_errno, TAG_DONE)) {
|
||||
Put(NULL, OCX_DIAG, "Error initializing bsdsocket.\n");
|
||||
exit(2);
|
||||
}
|
||||
#endif
|
||||
|
||||
amiga_open_libs();
|
||||
EnableDebug();
|
||||
Time_Amiga_Passive();
|
||||
TS_RunTest(NULL);
|
||||
|
|
105
net_poll.c
105
net_poll.c
|
@ -1,105 +0,0 @@
|
|||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: APL License
|
||||
*
|
||||
* Copyright (c) 2009 Diego Casorran <dcasorran@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/time.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <netdb.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <signal.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "net_poll.h"
|
||||
|
||||
int poll(struct pollfd *pfds, nfds_t nfds, int timeout)
|
||||
{
|
||||
unsigned int i;
|
||||
int maxfd = -1, ret;
|
||||
fd_set rset,wset,xset;
|
||||
struct timeval timeout_tv, *tvp = NULL;
|
||||
|
||||
if (timeout >= 0)
|
||||
{
|
||||
timeout_tv.tv_sec = (timeout / 1000);
|
||||
timeout_tv.tv_usec = (timeout % 1000) * 1000;
|
||||
tvp = &timeout_tv;
|
||||
}
|
||||
|
||||
if(pfds==NULL||nfds<1)
|
||||
{
|
||||
if(pfds==NULL&&nfds<1&&timeout>=0)
|
||||
{
|
||||
ret = select(0,NULL,NULL,NULL,tvp);
|
||||
return(ret);
|
||||
}
|
||||
|
||||
errno=EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
FD_ZERO (&rset);
|
||||
FD_ZERO (&wset);
|
||||
FD_ZERO (&xset);
|
||||
|
||||
for (i = 0; i < nfds; i++)
|
||||
{
|
||||
pfds[i].revents = 0;
|
||||
|
||||
if (pfds[i].events == 0)
|
||||
continue;
|
||||
|
||||
if (pfds[i].fd > maxfd)
|
||||
maxfd = pfds[i].fd;
|
||||
|
||||
if (pfds[i].events & POLLIN)
|
||||
FD_SET (pfds[i].fd, &rset);
|
||||
|
||||
if (pfds[i].events & POLLOUT)
|
||||
FD_SET (pfds[i].fd, &wset);
|
||||
|
||||
if (pfds[i].events & POLLERR)
|
||||
FD_SET (pfds[i].fd, &xset);
|
||||
}
|
||||
|
||||
ret = select (maxfd + 1, &rset, &wset, &xset, tvp);
|
||||
|
||||
if(ret == -1)
|
||||
return ret;
|
||||
|
||||
for (i = 0; i < nfds; i++)
|
||||
{
|
||||
if (pfds[i].events == 0)
|
||||
continue;
|
||||
|
||||
if (FD_ISSET (pfds[i].fd, &rset))
|
||||
pfds[i].revents |= POLLIN;
|
||||
|
||||
if (FD_ISSET (pfds[i].fd, &wset))
|
||||
pfds[i].revents |= POLLOUT;
|
||||
|
||||
if (FD_ISSET (pfds[i].fd, &xset))
|
||||
pfds[i].revents |= POLLERR;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
54
net_poll.h
54
net_poll.h
|
@ -1,54 +0,0 @@
|
|||
/*-
|
||||
* Copyright (c) 1998 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Charles M. Hannum.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef APOLL_H
|
||||
#define APOLL_H
|
||||
|
||||
struct pollfd {
|
||||
int fd; // file descriptor
|
||||
short events; // events to look for
|
||||
short revents; // events returned
|
||||
};
|
||||
|
||||
typedef unsigned int nfds_t;
|
||||
|
||||
int poll(struct pollfd *, nfds_t, int);
|
||||
|
||||
#define INFTIM -1
|
||||
#define POLLIN 0x0001
|
||||
#define POLLPRI 0x0002
|
||||
#define POLLERR 0x0008
|
||||
#define POLLOUT 0x0004
|
||||
#define POLLHUP 0x0010
|
||||
#define POLLNVAL 0x0020
|
||||
#define POLLRDNORM 0x0040
|
||||
#define POLLRDBAND 0x0080
|
||||
#define POLLWRBAND 0x0100
|
||||
|
||||
#endif
|
|
@ -33,13 +33,13 @@
|
|||
# endif
|
||||
#endif
|
||||
|
||||
#include "mem.h"
|
||||
#include <proto/exec.h>
|
||||
#ifdef AMIGA
|
||||
# include <proto/dos.h>
|
||||
# include <proto/intuition.h>
|
||||
# include <resources/battclock.h>
|
||||
# include <clib/battclock_protos.h>
|
||||
# include <clib/utility_protos.h>
|
||||
#endif
|
||||
|
||||
#ifdef AROS
|
||||
# ifdef Debug
|
||||
|
@ -64,6 +64,8 @@
|
|||
# endif
|
||||
#endif
|
||||
|
||||
#include "mem.h"
|
||||
|
||||
#ifdef AOS3
|
||||
# define ARGPTR STRPTR
|
||||
# define ARGS_FORMAT ARGSFORMAT
|
||||
|
@ -71,6 +73,8 @@
|
|||
# define BSDLIB_REV 04L
|
||||
# define UTILLIB_NAME "utility.library"
|
||||
# define UTILLIB_REV 33L
|
||||
# define LOCALELIB_NAME "locale.library"
|
||||
# define LOCALELIB_REV 33L
|
||||
# define TIMER_NAME TIMERNAME
|
||||
# define BATTCLOCK_NAME BATTCLOCKNAME
|
||||
#endif
|
||||
|
@ -82,18 +86,53 @@
|
|||
# define BSDLIB_REV 04L
|
||||
# define UTILLIB_NAME (CONST_STRPTR)"utility.library"
|
||||
# define UTILLIB_REV 33L
|
||||
# define LOCALELIB_NAME (CONST_STRPTR)"locale.library"
|
||||
# define LOCALELIB_REV 33L
|
||||
# define TIMER_NAME (CONST_STRPTR)TIMERNAME
|
||||
# define BATTCLOCK_NAME (CONST_STRPTR)BATTCLOCKNAME
|
||||
# define APRT IPRT
|
||||
#endif
|
||||
|
||||
#ifndef AMIGA
|
||||
struct timeval {
|
||||
ULONG tv_secs;
|
||||
ULONG tv_micro;
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_POLL
|
||||
#define POLLIN 0x0001
|
||||
struct pollfd {
|
||||
int fd;
|
||||
short events;
|
||||
short revents;
|
||||
};
|
||||
typedef unsigned int nfds_t;
|
||||
int poll(struct pollfd *, nfds_t, int);
|
||||
#endif
|
||||
|
||||
#ifdef AMIGA
|
||||
void amiga_open_libs();
|
||||
void amiga_close_libs();
|
||||
void amiga_save_time(void);
|
||||
void amiga_sync_time(int seconds);
|
||||
void EnableDebug();
|
||||
void EnableTraceDebug();
|
||||
#endif
|
||||
|
||||
#define SetSyncTime amiga_sync_time
|
||||
#ifdef AROS
|
||||
# define settimeofday ntimed_settimeofday
|
||||
# define gettimeofday ntimed_gettimeofday
|
||||
int gettimeofday(struct timeval *tv, struct timezone *tz);
|
||||
int settimeofday(const struct timeval *tv, const struct timezone *tz);
|
||||
#endif
|
||||
|
||||
#ifdef AMIGA
|
||||
# define Time_Amiga Time_Unix
|
||||
# define Time_Amiga_Passive Time_Unix_Passive
|
||||
# define Time_Amiga_Save amiga_save_time
|
||||
# define SetSyncTime amiga_sync_time
|
||||
#endif
|
||||
|
||||
#ifdef Debug
|
||||
# undef Debug
|
||||
|
|
11
ntp_packet.c
11
ntp_packet.c
|
@ -1,5 +1,4 @@
|
|||
/*-
|
||||
* Copyright (c) 2015 Carsten Larsen
|
||||
* Copyright (c) 2014 Poul-Henning Kamp
|
||||
* All rights reserved.
|
||||
*
|
||||
|
@ -65,10 +64,10 @@
|
|||
#include "ntimed_endian.h"
|
||||
|
||||
/*
|
||||
* Seconds between 1900 (NTP epoch) and 1978 (Amiga epoch).
|
||||
* 19 is the number of leapdays.
|
||||
* Seconds between 1900 (NTP epoch) and 1970 (UNIX epoch).
|
||||
* 17 is the number of leapdays.
|
||||
*/
|
||||
#define NTP_AMIGA (((1978U - 1900U) * 365U + 19U) * 24U * 60U * 60U)
|
||||
#define NTP_UNIX (((1970U - 1900U) * 365U + 17U) * 24U * 60U * 60U)
|
||||
|
||||
/**********************************************************************
|
||||
* Picking a NTP packet apart in a safe, byte-order agnostic manner
|
||||
|
@ -79,7 +78,7 @@ ntp64_2ts(struct timestamp *ts, const uint8_t *ptr)
|
|||
{
|
||||
|
||||
INIT_OBJ(ts, TIMESTAMP_MAGIC);
|
||||
ts->sec = Be32dec(ptr) - NTP_AMIGA;
|
||||
ts->sec = Be32dec(ptr) - NTP_UNIX;
|
||||
ts->frac = (uint64_t)Be32dec(ptr + 4) << 32ULL;
|
||||
}
|
||||
|
||||
|
@ -146,7 +145,7 @@ ts_2ntp64(uint8_t *dst, const struct timestamp *ts)
|
|||
{
|
||||
|
||||
CHECK_OBJ_NOTNULL(ts, TIMESTAMP_MAGIC);
|
||||
Be32enc(dst, ts->sec + NTP_AMIGA);
|
||||
Be32enc(dst, ts->sec + NTP_UNIX);
|
||||
Be32enc(dst + 4, ts->frac >> 32ULL);
|
||||
}
|
||||
|
||||
|
|
442
time_amiga.c
442
time_amiga.c
|
@ -26,20 +26,23 @@
|
|||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "ntimed.h"
|
||||
#include "ntimed_platform.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <exec/io.h>
|
||||
#include <exec/types.h>
|
||||
#include <exec/memory.h>
|
||||
#include <devices/timer.h>
|
||||
#include <proto/dos.h>
|
||||
#include <proto/exec.h>
|
||||
#include <proto/timer.h>
|
||||
#include <proto/locale.h>
|
||||
#include <proto/battclock.h>
|
||||
#include <clib/alib_protos.h>
|
||||
#include <clib/exec_protos.h>
|
||||
#include <clib/locale_protos.h>
|
||||
#include <clib/utility_protos.h>
|
||||
#include <clib/battclock_protos.h>
|
||||
|
||||
|
@ -47,116 +50,190 @@
|
|||
#undef Debug
|
||||
#endif
|
||||
|
||||
#include "ntimed.h"
|
||||
#include "ntimed_platform.h"
|
||||
// 2922 is the number of days between 1.1.1970 and 1.1.1978 (2 leap years and 6 normal)
|
||||
#define AMIGAOFFSET 2922 * 24 * 60 * 60
|
||||
int gmtoffset = 0;
|
||||
|
||||
int amiga_get_time(struct timeval *tv);
|
||||
int amiga_set_time(struct timeval *tv);
|
||||
struct timerequest* create_timer();
|
||||
void delete_timer(struct timerequest*);
|
||||
static void adjust_timeval(struct timeval *tv, double offset);
|
||||
|
||||
// Ntimed internals
|
||||
static double adj_offset = 0;
|
||||
static double adj_duration = 0;
|
||||
static double adj_freq = 0;
|
||||
|
||||
static uintptr_t ticker;
|
||||
static struct todolist *kt_tdl;
|
||||
|
||||
#ifndef AMIGA
|
||||
struct timeval {
|
||||
ULONG tv_secs;
|
||||
ULONG tv_micro;
|
||||
};
|
||||
#endif
|
||||
int create_timer();
|
||||
int delete_timer();
|
||||
void adjust_timeval(struct timeval *tv, double offset);
|
||||
|
||||
struct Library *BattClockBase;
|
||||
struct Library *UtilityBase = NULL;
|
||||
struct Library *LocaleBase = NULL;
|
||||
struct Library *SocketBase = NULL;
|
||||
struct Locale *locale = NULL;
|
||||
struct timerequest *request = NULL;
|
||||
struct timeval sync_time;
|
||||
int validtime = 0;
|
||||
int limited_sync = 0;
|
||||
float utcoffset = 0.0;
|
||||
|
||||
/**********************************************************************/
|
||||
|
||||
static void
|
||||
amiga_setfreq(struct ocx *ocx, double frequency)
|
||||
void amiga_open_libs()
|
||||
{
|
||||
//assert(isfinite(frequency));
|
||||
|
||||
// frequency offset (scaled ppm)
|
||||
// long int freq = (long)floor(frequency * (65536 * 1e6));
|
||||
Put(ocx, OCX_TRACE, "KERNPLL %.6e\n", frequency);
|
||||
if(!(LocaleBase = (struct Library *)OpenLibrary(LOCALELIB_NAME, LOCALELIB_REV))) {
|
||||
Put(NULL, OCX_DIAG, "Cannot open locale library.\n");
|
||||
exit(10);
|
||||
}
|
||||
|
||||
static enum todo_e __match_proto__(todo_f)
|
||||
amiga_ticker(struct ocx *ocx, struct todolist *tdl, void *priv)
|
||||
{
|
||||
(void)ocx;
|
||||
AN(tdl);
|
||||
AZ(priv);
|
||||
amiga_setfreq(ocx, adj_freq);
|
||||
ticker = 0;
|
||||
return (TODO_OK);
|
||||
locale = OpenLocale(NULL);
|
||||
gmtoffset = (int)locale->loc_GMTOffset * 60;
|
||||
|
||||
// TODO: use tzlib.a
|
||||
// get tm header and invoke:
|
||||
// time_t now = time(NULL);
|
||||
// struct tm lcl = *localtime(&now)
|
||||
// And use gmt filed from tm header if != 0
|
||||
|
||||
if(!(UtilityBase = (struct Library *)OpenLibrary(UTILLIB_NAME, UTILLIB_REV))) {
|
||||
Put(NULL, OCX_DIAG, "Cannot open utility library.\n");
|
||||
exit(10);
|
||||
}
|
||||
|
||||
static void __match_proto__(tb_adjust_f)
|
||||
amiga_adjust(struct ocx *ocx, double offset, double duration, double frequency)
|
||||
BattClockBase = OpenResource(BATTCLOCK_NAME);
|
||||
|
||||
#ifdef AROS
|
||||
if(!(SocketBase = OpenLibrary(BSDLIB_NAME, BSDLIB_REV))) {
|
||||
Put(NULL, OCX_DIAG, "No TCP/IP Stack running.\n");
|
||||
exit(10);
|
||||
}
|
||||
|
||||
if(SocketBaseTags(SBTM_SETVAL(SBTC_ERRNOPTR(sizeof(errno))), (IPTR)&errno,
|
||||
SBTM_SETVAL(SBTC_HERRNOLONGPTR), (IPTR)&h_errno, TAG_DONE)) {
|
||||
Put(NULL, OCX_DIAG, "Error initializing bsdsocket.\n");
|
||||
exit(10);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (create_timer() != 0) {
|
||||
Put(NULL, OCX_DIAG, "Cannot open timer device.\n");
|
||||
exit(10);
|
||||
}
|
||||
}
|
||||
|
||||
void amiga_close_libs()
|
||||
{
|
||||
double freq;
|
||||
if (request != NULL) {
|
||||
delete_timer();
|
||||
}
|
||||
|
||||
(void)ocx;
|
||||
assert(duration >= 0.0);
|
||||
if (locale != NULL) {
|
||||
CloseLocale(locale);
|
||||
locale = NULL;
|
||||
}
|
||||
|
||||
if (ticker)
|
||||
TODO_Cancel(kt_tdl, &ticker);
|
||||
if (LocaleBase != NULL) {
|
||||
CloseLibrary(LocaleBase);
|
||||
LocaleBase = NULL;
|
||||
}
|
||||
|
||||
adj_offset = offset;
|
||||
adj_duration = floor(duration);
|
||||
if (adj_offset > 0.0 && adj_duration == 0.0)
|
||||
adj_duration = 1.0;
|
||||
adj_freq = frequency;
|
||||
if (UtilityBase != NULL) {
|
||||
CloseLibrary(UtilityBase);
|
||||
UtilityBase = NULL;
|
||||
}
|
||||
|
||||
freq = adj_freq;
|
||||
if (adj_duration > 0.0)
|
||||
freq += adj_offset / adj_duration;
|
||||
amiga_setfreq(ocx, freq);
|
||||
if (adj_duration > 0.0)
|
||||
ticker = TODO_ScheduleRel(kt_tdl, amiga_ticker, NULL,
|
||||
adj_duration, 0.0, "KT_TICK");
|
||||
#ifdef AROS
|
||||
if (SocketBase != NULL) {
|
||||
CloseLibrary(SocketBase);
|
||||
SocketBase = NULL;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
int create_timer()
|
||||
{
|
||||
LONG error;
|
||||
struct MsgPort *port = CreatePort(0, 0);
|
||||
if (port == NULL)
|
||||
return 1;
|
||||
|
||||
request = (struct timerequest*)CreateExtIO(port, sizeof(struct timerequest));
|
||||
if (request == NULL)
|
||||
{
|
||||
DeletePort(port);
|
||||
return 1;
|
||||
}
|
||||
|
||||
error = OpenDevice(TIMER_NAME, UNIT_MICROHZ, (struct IORequest*)request, 0L);
|
||||
if (error != 0)
|
||||
{
|
||||
delete_timer(request);
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int delete_timer()
|
||||
{
|
||||
struct MsgPort *port;
|
||||
if (request == NULL)
|
||||
return 1;
|
||||
|
||||
port = request->tr_node.io_Message.mn_ReplyPort;
|
||||
|
||||
if (port != 0)
|
||||
DeletePort(port);
|
||||
|
||||
CloseDevice((struct IORequest*)request);
|
||||
DeleteExtIO((struct IORequest*)request);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**********************************************************************/
|
||||
|
||||
static void __match_proto__(tb_step_f)
|
||||
amiga_step(struct ocx *ocx, double offset)
|
||||
int gettimeofday(struct timeval *tv, struct timezone *tz)
|
||||
{
|
||||
request->tr_node.io_Command = TR_GETSYSTIME;
|
||||
DoIO((struct IORequest*)request);
|
||||
|
||||
tv->tv_secs = (int)request->tr_time.tv_secs - gmtoffset + AMIGAOFFSET;
|
||||
tv->tv_micro = request->tr_time.tv_micro;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int settimeofday(const struct timeval *tv, const struct timezone *tz)
|
||||
{
|
||||
request->tr_node.io_Command = TR_SETSYSTIME;
|
||||
request->tr_time.tv_secs = (int)tv->tv_secs + gmtoffset - AMIGAOFFSET;
|
||||
request->tr_time.tv_micro = tv->tv_micro;
|
||||
|
||||
DoIO((struct IORequest*)request);
|
||||
|
||||
validtime = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**********************************************************************/
|
||||
|
||||
void amiga_save_time(void)
|
||||
{
|
||||
struct timeval tv;
|
||||
|
||||
Put(ocx, OCX_TRACE, "KERNTIME_STEP %.3e\n", offset);
|
||||
if(!validtime)
|
||||
return;
|
||||
|
||||
AZ(amiga_get_time(&tv));
|
||||
adjust_timeval(&tv, offset);
|
||||
AZ(amiga_set_time(&tv));
|
||||
TB_generation++;
|
||||
ResetBattClock();
|
||||
gettimeofday(&tv, NULL);
|
||||
WriteBattClock(tv.tv_secs + gmtoffset - AMIGAOFFSET);
|
||||
}
|
||||
|
||||
|
||||
/**********************************************************************/
|
||||
|
||||
static struct timestamp * __match_proto__(tb_now_f)
|
||||
amiga_now(struct timestamp *storage)
|
||||
void amiga_sync_time(int seconds)
|
||||
{
|
||||
struct timeval tv;
|
||||
AZ(amiga_get_time(&tv));
|
||||
return (TS_Nanosec(storage, tv.tv_secs, tv.tv_micro * 1000LL));
|
||||
limited_sync = 1;
|
||||
sync_time.tv_secs = seconds;
|
||||
sync_time.tv_micro = 0;
|
||||
}
|
||||
|
||||
/**********************************************************************/
|
||||
|
||||
static int __match_proto__(tb_sleep_f)
|
||||
amiga_sleep(double dur)
|
||||
int amiga_sleep_time(double dur)
|
||||
{
|
||||
ULONG sigs, timersig;
|
||||
struct timerequest *request;
|
||||
struct timeval tv;
|
||||
tv.tv_secs = 0;
|
||||
tv.tv_micro = 0;
|
||||
|
@ -170,10 +247,6 @@ amiga_sleep(double dur)
|
|||
|
||||
adjust_timeval(&tv, dur);
|
||||
|
||||
request = create_timer();
|
||||
if (request == NULL)
|
||||
return 1;
|
||||
|
||||
request->tr_node.io_Command = TR_ADDREQUEST;
|
||||
request->tr_time = tv;
|
||||
|
||||
|
@ -184,160 +257,95 @@ amiga_sleep(double dur)
|
|||
if (sigs & SIGBREAKF_CTRL_C) {
|
||||
AbortIO((struct IORequest*)request);
|
||||
WaitIO((struct IORequest*)request);
|
||||
delete_timer(request);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
delete_timer(request);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**********************************************************************/
|
||||
|
||||
void Time_Amiga(struct todolist *tdl)
|
||||
{
|
||||
AN(tdl);
|
||||
TB_Step = amiga_step;
|
||||
TB_Adjust = amiga_adjust;
|
||||
TB_Sleep = amiga_sleep;
|
||||
TB_Now = amiga_now;
|
||||
kt_tdl = tdl;
|
||||
}
|
||||
|
||||
void Time_Amiga_Passive(void)
|
||||
{
|
||||
TB_Sleep = amiga_sleep;
|
||||
TB_Now = amiga_now;
|
||||
}
|
||||
|
||||
/**********************************************************************/
|
||||
|
||||
struct timerequest* create_timer()
|
||||
{
|
||||
LONG error;
|
||||
struct timerequest *request;
|
||||
struct MsgPort *port = CreatePort(0, 0);
|
||||
if (port == NULL)
|
||||
return NULL;
|
||||
|
||||
request = (struct timerequest*)CreateExtIO(port, sizeof(struct timerequest));
|
||||
if (request == NULL)
|
||||
{
|
||||
DeletePort(port);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
error = OpenDevice(TIMER_NAME, UNIT_MICROHZ, (struct IORequest*)request, 0L);
|
||||
if (error != 0)
|
||||
{
|
||||
delete_timer(request);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return request;
|
||||
}
|
||||
|
||||
void delete_timer(struct timerequest *request)
|
||||
{
|
||||
struct MsgPort *port;
|
||||
if (request == NULL)
|
||||
return;
|
||||
|
||||
port = request->tr_node.io_Message.mn_ReplyPort;
|
||||
|
||||
if (port != 0)
|
||||
DeletePort(port);
|
||||
|
||||
CloseDevice((struct IORequest*)request);
|
||||
DeleteExtIO((struct IORequest*)request);
|
||||
}
|
||||
|
||||
/**********************************************************************/
|
||||
|
||||
int amiga_get_time(struct timeval *tv)
|
||||
{
|
||||
struct timerequest *request;
|
||||
long tzoffset = (long)round(utcoffset * 60.0 * 60.0);
|
||||
|
||||
request = create_timer();
|
||||
if (request == NULL)
|
||||
return 1;
|
||||
|
||||
request->tr_node.io_Command = TR_GETSYSTIME;
|
||||
DoIO((struct IORequest*)request);
|
||||
|
||||
*tv = request->tr_time;
|
||||
tv->tv_secs = (long)tv->tv_secs - tzoffset;
|
||||
|
||||
delete_timer(request);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int amiga_set_time(struct timeval *tv)
|
||||
{
|
||||
struct timerequest *request;
|
||||
long tzoffset = (long)round(utcoffset * 60.0 * 60.0);
|
||||
|
||||
request = create_timer();
|
||||
if (request == NULL)
|
||||
return 1;
|
||||
|
||||
request->tr_node.io_Command = TR_SETSYSTIME;
|
||||
request->tr_time = *tv;
|
||||
request->tr_time.tv_secs += tzoffset;
|
||||
|
||||
DoIO((struct IORequest*)request);
|
||||
|
||||
delete_timer(request);
|
||||
validtime = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**********************************************************************/
|
||||
|
||||
void amiga_save_time(void)
|
||||
{
|
||||
struct timeval tv;
|
||||
long tzoffset;
|
||||
|
||||
if(!validtime)
|
||||
return;
|
||||
|
||||
ResetBattClock();
|
||||
amiga_get_time(&tv);
|
||||
|
||||
tzoffset = (long)round(utcoffset * 60.0 * 60.0);
|
||||
WriteBattClock((long)tv.tv_secs + tzoffset);
|
||||
}
|
||||
|
||||
void amiga_sync_time(int seconds)
|
||||
{
|
||||
limited_sync = 1;
|
||||
sync_time.tv_secs = seconds;
|
||||
sync_time.tv_micro = 0;
|
||||
}
|
||||
|
||||
/**********************************************************************/
|
||||
|
||||
static void adjust_timeval(struct timeval *tv, double offset)
|
||||
void adjust_timeval(struct timeval *tv, double offset)
|
||||
{
|
||||
double d1, d2;
|
||||
long sec, micro;
|
||||
int secs, micro;
|
||||
|
||||
d1 = floor(offset);
|
||||
d2 = offset - d1;
|
||||
|
||||
sec = tv->tv_secs + (long)d1;
|
||||
micro = tv->tv_micro + (long)floor(d2 * 1e6);
|
||||
secs = tv->tv_secs + (int)d1;
|
||||
micro = tv->tv_micro + (int)floor(d2 * 1e6);
|
||||
|
||||
if (micro < 0) {
|
||||
sec -= 1;
|
||||
secs -= 1;
|
||||
micro += 1000000;
|
||||
} else if (micro >= 1000000) {
|
||||
sec += 1;
|
||||
secs += 1;
|
||||
micro -= 1000000;
|
||||
}
|
||||
|
||||
tv->tv_secs = sec;
|
||||
tv->tv_secs = secs;
|
||||
tv->tv_micro = micro;
|
||||
}
|
||||
|
||||
/**********************************************************************/
|
||||
#ifndef HAVE_POLL
|
||||
int poll(struct pollfd *pfds, nfds_t nfds, int timeout)
|
||||
{
|
||||
unsigned int i;
|
||||
int maxfd = -1, ret;
|
||||
fd_set rset,wset,xset;
|
||||
struct timeval timeout_tv, *tvp = NULL;
|
||||
|
||||
if(pfds == NULL || nfds < 1)
|
||||
{
|
||||
return amiga_sleep_time(timeout / 1000);
|
||||
}
|
||||
|
||||
if (timeout >= 0)
|
||||
{
|
||||
timeout_tv.tv_sec = (timeout / 1000);
|
||||
timeout_tv.tv_usec = (timeout % 1000) * 1000;
|
||||
tvp = &timeout_tv;
|
||||
}
|
||||
|
||||
FD_ZERO(&rset);
|
||||
FD_ZERO(&wset);
|
||||
FD_ZERO(&xset);
|
||||
|
||||
for (i = 0; i < nfds; i++)
|
||||
{
|
||||
pfds[i].revents = 0;
|
||||
|
||||
if (pfds[i].events == 0)
|
||||
continue;
|
||||
|
||||
if (pfds[i].fd > maxfd)
|
||||
maxfd = pfds[i].fd;
|
||||
|
||||
if (pfds[i].events & POLLIN)
|
||||
FD_SET(pfds[i].fd, &rset);
|
||||
|
||||
}
|
||||
|
||||
#ifdef HAVE_WAITSELECT
|
||||
ret = WaitSelect(maxfd + 1, &rset, &wset, &xset, tvp, NULL);
|
||||
#else
|
||||
ret = select(maxfd + 1, &rset, &wset, &xset, tvp);
|
||||
#endif
|
||||
|
||||
if(ret == -1)
|
||||
return ret;
|
||||
|
||||
for (i = 0; i < nfds; i++)
|
||||
{
|
||||
if (pfds[i].events == 0)
|
||||
continue;
|
||||
|
||||
if (FD_ISSET(pfds[i].fd, &rset))
|
||||
pfds[i].revents |= POLLIN;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -0,0 +1,262 @@
|
|||
/*-
|
||||
* Copyright (c) 2014 Poul-Henning Kamp
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* UNIX timebase
|
||||
* =============
|
||||
*
|
||||
* Implement the timebase functions on top of a modern UNIX kernel which
|
||||
* has the some version of the Mills/Kamp kernel PLL code and either
|
||||
* [gs]ettimeofday(2) or better: clock_[gs]ettime(2) API.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include "ntimed.h"
|
||||
#include "ntimed_platform.h"
|
||||
|
||||
static double adj_offset = 0;
|
||||
static double adj_duration = 0;
|
||||
static double adj_freq = 0;
|
||||
|
||||
static uintptr_t ticker;
|
||||
static struct todolist *kt_tdl;
|
||||
|
||||
// #undef CLOCK_REALTIME /* Test old unix code */
|
||||
|
||||
/**********************************************************************
|
||||
* The NTP-pll in UNIX kernels apply the offset correction in an
|
||||
* exponential-decay fashion for historical and wrong reasons.
|
||||
*
|
||||
* The short explanation is that this ends up confusing all PLLs I have
|
||||
* ever seen, by introducing mainly odd harmonics of the PLL update period
|
||||
* into all time-measurements in the system.
|
||||
*
|
||||
* A much more sane mode would be to tell the kernel "I want this much
|
||||
* offset accumulated over this many seconds", giving a constant frequency
|
||||
* over the PLL update period while still falling back to the frequency
|
||||
* estimate should the time-steering userland process fail.
|
||||
*
|
||||
* I will add such a mode to the FreeBSD kernel as a reference implementation
|
||||
* at a later date, in the mean time this code implements it by updating the
|
||||
* kernel frequency from userland as needed.
|
||||
*
|
||||
* XXX: Optimise to only wake up when truly needed, rather than every second.
|
||||
* XXX: Requires TODO cancellation.
|
||||
*/
|
||||
|
||||
static void
|
||||
kt_setfreq(struct ocx *ocx, double frequency)
|
||||
{
|
||||
/*
|
||||
struct timex tx;
|
||||
int i;
|
||||
|
||||
assert(isfinite(frequency));
|
||||
|
||||
memset(&tx, 0, sizeof tx);
|
||||
tx.modes = MOD_STATUS;
|
||||
#if defined(MOD_NANO)
|
||||
tx.modes |= MOD_NANO;
|
||||
#elif defined(MOD_MICRO)
|
||||
tx.modes |= MOD_MICRO;
|
||||
#endif
|
||||
|
||||
tx.status = STA_PLL | STA_FREQHOLD;
|
||||
tx.modes = MOD_FREQUENCY;
|
||||
tx.freq = (long)floor(frequency * (65536 * 1e6));
|
||||
errno = 0;
|
||||
i = ntp_adjtime(&tx);
|
||||
*/
|
||||
Put(ocx, OCX_TRACE, "KERNPLL %.6e %d\n", frequency, 0);
|
||||
/* XXX: what is the correct error test here ? */
|
||||
// assert(i >= 0);
|
||||
}
|
||||
|
||||
static enum todo_e __match_proto__(todo_f)
|
||||
kt_ticker(struct ocx *ocx, struct todolist *tdl, void *priv)
|
||||
{
|
||||
|
||||
(void)ocx;
|
||||
AN(tdl);
|
||||
AZ(priv);
|
||||
kt_setfreq(ocx, adj_freq);
|
||||
ticker = 0;
|
||||
return (TODO_OK);
|
||||
}
|
||||
|
||||
static void __match_proto__(tb_adjust_f)
|
||||
kt_adjust(struct ocx *ocx, double offset, double duration, double frequency)
|
||||
{
|
||||
double freq;
|
||||
|
||||
(void)ocx;
|
||||
assert(duration >= 0.0);
|
||||
|
||||
if (ticker)
|
||||
TODO_Cancel(kt_tdl, &ticker);
|
||||
|
||||
adj_offset = offset;
|
||||
adj_duration = floor(duration);
|
||||
if (adj_offset > 0.0 && adj_duration == 0.0)
|
||||
adj_duration = 1.0;
|
||||
adj_freq = frequency;
|
||||
|
||||
freq = adj_freq;
|
||||
if (adj_duration > 0.0)
|
||||
freq += adj_offset / adj_duration;
|
||||
kt_setfreq(ocx, freq);
|
||||
if (adj_duration > 0.0)
|
||||
ticker = TODO_ScheduleRel(kt_tdl, kt_ticker, NULL,
|
||||
adj_duration, 0.0, "KT_TICK");
|
||||
}
|
||||
|
||||
/**********************************************************************/
|
||||
|
||||
#ifdef CLOCK_REALTIME
|
||||
|
||||
static void __match_proto__(tb_step_f)
|
||||
kt_step(struct ocx *ocx, double offset)
|
||||
{
|
||||
double d;
|
||||
struct timespec ts;
|
||||
|
||||
Put(ocx, OCX_TRACE, "KERNTIME_STEP %.3e\n", offset);
|
||||
d = floor(offset);
|
||||
offset -= d;
|
||||
|
||||
AZ(clock_gettime(CLOCK_REALTIME, &ts));
|
||||
ts.tv_sec += (long)d;
|
||||
ts.tv_nsec += (long)floor(offset * 1e9);
|
||||
if (ts.tv_nsec < 0) {
|
||||
ts.tv_sec -= 1;
|
||||
ts.tv_nsec += 1000000000;
|
||||
} else if (ts.tv_nsec >= 1000000000) {
|
||||
ts.tv_sec += 1;
|
||||
ts.tv_nsec -= 1000000000;
|
||||
}
|
||||
AZ(clock_settime(CLOCK_REALTIME, &ts));
|
||||
TB_generation++;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
static void __match_proto__(tb_step_f)
|
||||
kt_step(struct ocx *ocx, double offset)
|
||||
{
|
||||
double d;
|
||||
struct timeval tv;
|
||||
|
||||
Put(ocx, OCX_TRACE, "KERNTIME_STEP %.3e\n", offset);
|
||||
d = floor(offset);
|
||||
offset -= d;
|
||||
|
||||
AZ(gettimeofday(&tv, NULL));
|
||||
tv.tv_sec += (long)d;
|
||||
tv.tv_usec += (long)floor(offset * 1e6);
|
||||
if (tv.tv_usec < 0) {
|
||||
tv.tv_sec -= 1;
|
||||
tv.tv_usec += 1000000;
|
||||
} else if (tv.tv_usec >= 1000000) {
|
||||
tv.tv_sec += 1;
|
||||
tv.tv_usec -= 1000000;
|
||||
}
|
||||
AZ(settimeofday(&tv, NULL));
|
||||
TB_generation++;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/**********************************************************************/
|
||||
|
||||
#if defined (CLOCK_REALTIME)
|
||||
|
||||
static struct timestamp * __match_proto__(tb_now_f)
|
||||
kt_now(struct timestamp *storage)
|
||||
{
|
||||
struct timespec ts;
|
||||
|
||||
AZ(clock_gettime(CLOCK_REALTIME, &ts));
|
||||
return (TS_Nanosec(storage, ts.tv_sec, ts.tv_nsec));
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
static struct timestamp * __match_proto__(tb_now_f)
|
||||
kt_now(struct timestamp *storage)
|
||||
{
|
||||
struct timeval tv;
|
||||
|
||||
AZ(gettimeofday(&tv, NULL));
|
||||
return (TS_Nanosec(storage, tv.tv_sec, tv.tv_usec * 1000LL));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/**********************************************************************/
|
||||
|
||||
static int __match_proto__(tb_sleep_f)
|
||||
kt_sleep(double dur)
|
||||
{
|
||||
struct pollfd fds[1];
|
||||
int i;
|
||||
|
||||
i = poll(fds, 0, (int)floor(dur * 1e3));
|
||||
if (i < 0 && errno == EINTR)
|
||||
return (1);
|
||||
AZ(i);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/**********************************************************************/
|
||||
|
||||
void
|
||||
Time_Unix(struct todolist *tdl)
|
||||
{
|
||||
|
||||
AN(tdl);
|
||||
TB_Step = kt_step;
|
||||
TB_Adjust = kt_adjust;
|
||||
TB_Sleep = kt_sleep;
|
||||
TB_Now = kt_now;
|
||||
kt_tdl = tdl;
|
||||
|
||||
/* XXX: test if we have perms */
|
||||
}
|
||||
|
||||
/**********************************************************************
|
||||
* Non-tweaking subset.
|
||||
*/
|
||||
|
||||
void
|
||||
Time_Unix_Passive(void)
|
||||
{
|
||||
|
||||
TB_Sleep = kt_sleep;
|
||||
TB_Now = kt_now;
|
||||
}
|
81
tz.c
81
tz.c
|
@ -1,81 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2015 Carsten Larsen
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "tz.h"
|
||||
#include "ntimed.h"
|
||||
|
||||
int tzid = 0;
|
||||
|
||||
void ArgTimezone(const char *tz)
|
||||
{
|
||||
unsigned int i;
|
||||
static const unsigned int count = sizeof(tza) / sizeof(struct tzabbr);
|
||||
|
||||
if (tz == NULL)
|
||||
return;
|
||||
|
||||
if (!strcmp(tz, "-")) {
|
||||
tzid = 0;
|
||||
utcoffset = 0.0;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!strcmp(tz, "?")) {
|
||||
PrintTimeZones();
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < count; i++) {
|
||||
if (!strcmp(tza[i].abbr, tz)) {
|
||||
tzid = i;
|
||||
utcoffset = tza[i].offset;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Fail(NULL, 0, "Unknown timezone. Try TIMEZONE=?");
|
||||
}
|
||||
|
||||
void PrintTimeZones()
|
||||
{
|
||||
unsigned int i;
|
||||
static const unsigned int count = sizeof(tza) / sizeof(struct tzabbr);
|
||||
|
||||
for (i = 0; i < count; i++) {
|
||||
Put(NULL, OCX_DEBUG,
|
||||
"%s\t%s%.2f\t%s\n",
|
||||
tza[i].abbr,
|
||||
tza[i].offset < 0.0 ? "-" : "+",
|
||||
fabs(tza[i].offset),
|
||||
tza[i].name);
|
||||
}
|
||||
|
||||
exit(1);
|
||||
}
|
246
tz.h
246
tz.h
|
@ -1,246 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2015 Carsten Larsen
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
extern int tzid;
|
||||
extern float utcoffset;
|
||||
|
||||
void ArgTimezone(const char *tz);
|
||||
void PrintTimeZones();
|
||||
|
||||
typedef struct tzabbr {
|
||||
const char *abbr;
|
||||
const char *name;
|
||||
float offset;
|
||||
} tzabbr;
|
||||
|
||||
static const tzabbr tza[] = {
|
||||
{"Z", "Zulu Time (Coordinated Universal Time)", 0.0},
|
||||
#ifndef SMALL
|
||||
{"ACDT", "Australian Central Daylight Savings Time", 10.5},
|
||||
{"ACST", "Australian Central Standard Time", 9.5},
|
||||
{"ACT", "ASEAN Common Time", 8},
|
||||
{"ADT", "Atlantic Daylight Time", -3},
|
||||
{"AEDT", "Australian Eastern Daylight Savings Time", 11},
|
||||
{"AEST", "Australian Eastern Standard Time", 10},
|
||||
{"AFT", "Afghanistan Time", 4.5},
|
||||
{"AKDT", "Alaska Daylight Time", -8},
|
||||
{"AKST", "Alaska Standard Time", -9},
|
||||
{"AMST", "Armenia Summer Time", 5},
|
||||
{"AMT", "Armenia Time", 4},
|
||||
{"ART", "Argentina Time", -3},
|
||||
{"AST", "Arabia Standard Time", 3},
|
||||
{"AWDT", "Australian Western Daylight Time", 9},
|
||||
{"AWST", "Australian Western Standard Time", 8},
|
||||
{"AZOST", "Azores Standard Time", -1},
|
||||
{"AZT", "Azerbaijan Time", 4},
|
||||
{"BDT", "Brunei Time", 8},
|
||||
{"BIOT", "British Indian Ocean Time", 6},
|
||||
{"BIT", "Baker Island Time", -12},
|
||||
{"BOT", "Bolivia Time", -4},
|
||||
{"BRT", "Brasilia Time", -3},
|
||||
{"BST", "Bangladesh Standard Time", 6},
|
||||
{"BTT", "Bhutan Time", 6},
|
||||
{"CAT", "Central Africa Time", 2},
|
||||
{"CCT", "Cocos Islands Time", 6.5},
|
||||
{"CDT", "Central Daylight Time (North America)", -5},
|
||||
{"CEDT", "Central European Daylight Time", 2},
|
||||
{"CEST", "Central European Summer Time", 2},
|
||||
{"CET", "Central European Time", 1},
|
||||
{"CHADT", "Chatham Daylight Time", 13.75},
|
||||
{"CHAST", "Chatham Standard Time", 12.75},
|
||||
{"CHOT", "Choibalsan", 8},
|
||||
{"ChST", "Chamorro Standard Time", 10},
|
||||
{"CHUT", "Chuuk Time", 10},
|
||||
{"CIST", "Clipperton Island Standard Time", -8},
|
||||
{"CIT", "Central Indonesia Time", 8},
|
||||
{"CKT", "Cook Island Time", -10},
|
||||
{"CLST", "Chile Summer Time", -3},
|
||||
{"CLT", "Chile Standard Time", -4},
|
||||
{"COST", "Colombia Summer Time", -4},
|
||||
{"COT", "Colombia Time", -5},
|
||||
{"CST", "Central Standard Time (North America)", -6},
|
||||
{"CT", "China time", 8},
|
||||
{"CVT", "Cape Verde Time", -1},
|
||||
{"CXT", "Christmas Island Time", 7},
|
||||
{"DAVT", "Davis Time", 7},
|
||||
{"DDUT", "Dumont d'Urville Time", 10},
|
||||
{"EASST", "Easter Island Standard Summer Time", -5},
|
||||
{"EAST", "Easter Island Standard Time", -6},
|
||||
{"EAT", "East Africa Time", 3},
|
||||
{"ECT", "Ecuador Time", -5},
|
||||
{"EDT", "Eastern Daylight Time (North America)", -4},
|
||||
{"EEDT", "Eastern European Daylight Time", 3},
|
||||
{"EEST", "Eastern European Summer Time", 3},
|
||||
{"EET", "Eastern European Time", 2},
|
||||
{"EGST", "Eastern Greenland Summer Time", 0},
|
||||
{"EGT", "Eastern Greenland Time", -1},
|
||||
{"EIT", "Eastern Indonesian Time", 9},
|
||||
{"EST", "Eastern Standard Time (North America)", -5},
|
||||
{"FET", "Further-eastern European Time", 3},
|
||||
{"FJT", "Fiji Time", 12},
|
||||
{"FKST", "Falkland Islands Standard Time", -3},
|
||||
{"FKST", "Falkland Islands Summer Time", -3},
|
||||
{"FKT", "Falkland Islands Time", -4},
|
||||
{"FNT", "Fernando de Noronha Time", -2},
|
||||
{"GALT", "Galapagos Time", -6},
|
||||
{"GAMT", "Gambier Islands", -9},
|
||||
{"GET", "Georgia Standard Time", 4},
|
||||
{"GFT", "French Guiana Time", -3},
|
||||
{"GILT", "Gilbert Island Time", 12},
|
||||
{"GIT", "Gambier Island Time", -9},
|
||||
{"GMT", "Greenwich Mean Time", 0},
|
||||
{"GST", "South Georgia and the South Sandwich Islands", -2},
|
||||
{"GST", "Gulf Standard Time", 4},
|
||||
{"GYT", "Guyana Time", -4},
|
||||
{"HADT", "Hawaii-Aleutian Daylight Time", -9},
|
||||
{"HAEC", "Heure Avancée d'Europe Centrale francised name for CEST", 2},
|
||||
{"HAST", "Hawaii-Aleutian Standard Time", -10},
|
||||
{"HKT", "Hong Kong Time", 8},
|
||||
{"HMT", "Heard and McDonald Islands Time", 5},
|
||||
{"HOVT", "Khovd Time", 7},
|
||||
{"HST", "Hawaii Standard Time", -10},
|
||||
{"ICT", "Indochina Time", 7},
|
||||
{"IDT", "Israel Daylight Time", 3},
|
||||
{"IOT", "Indian Ocean Time", 3},
|
||||
{"IRDT", "Iran Daylight Time", 4.5},
|
||||
{"IRKT", "Irkutsk Time", 8},
|
||||
{"IRST", "Iran Standard Time", 3.5},
|
||||
{"IST", "Indian Standard Time", 5.5},
|
||||
{"JST", "Japan Standard Time", 9},
|
||||
{"KGT", "Kyrgyzstan time", 6},
|
||||
{"KOST", "Kosrae Time", 11},
|
||||
{"KRAT", "Krasnoyarsk Time", 7},
|
||||
{"KST", "Korea Standard Time", 9},
|
||||
{"LHST", "Lord Howe Standard Time", 10.5},
|
||||
{"LINT", "Line Islands Time", 14},
|
||||
{"MAGT", "Magadan Time", 12},
|
||||
{"MART", "Marquesas Islands Time", -8.5},
|
||||
{"MAWT", "Mawson Station Time", 5},
|
||||
{"MDT", "Mountain Daylight Time (North America)", -6},
|
||||
{"MET", "Middle European Time Same zone as CET", 1},
|
||||
{"MEST", "Middle European Saving Time Same zone as CEST", 2},
|
||||
{"MHT", "Marshall Islands", 12},
|
||||
{"MIST", "Macquarie Island Station Time", 11},
|
||||
{"MIT", "Marquesas Islands Time", -8.5},
|
||||
{"MMT", "Myanmar Time", 6.5},
|
||||
{"MSK", "Moscow Time", 3},
|
||||
{"MST", "Myanmar Standard Time", 6.5},
|
||||
{"MUT", "Mauritius Time", 4},
|
||||
{"MVT", "Maldives Time", 5},
|
||||
{"MYT", "Malaysia Time", 8},
|
||||
{"NCT", "New Caledonia Time", 11},
|
||||
{"NDT", "Newfoundland Daylight Time", -1.5},
|
||||
{"NFT", "Norfolk Time", 11.5},
|
||||
{"NPT", "Nepal Time", 5.75},
|
||||
{"NST", "Newfoundland Standard Time", -2.5},
|
||||
{"NT", "Newfoundland Time", -2.5},
|
||||
{"NUT", "Niue Time", -11},
|
||||
{"NZDT", "New Zealand Daylight Time", 13},
|
||||
{"NZST", "New Zealand Standard Time", 12},
|
||||
{"OMST", "Omsk Time", 6},
|
||||
{"ORAT", "Oral Time", 5},
|
||||
{"PDT", "Pacific Daylight Time (North America)", -7},
|
||||
{"PET", "Peru Time", -5},
|
||||
{"PETT", "Kamchatka Time", 12},
|
||||
{"PGT", "Papua New Guinea Time", 10},
|
||||
{"PHOT", "Phoenix Island Time", 13},
|
||||
{"PKT", "Pakistan Standard Time", 5},
|
||||
{"PMDT", "Saint Pierre and Miquelon Daylight time", -2},
|
||||
{"PMST", "Saint Pierre and Miquelon Standard Time", -3},
|
||||
{"PONT", "Pohnpei Standard Time", 11},
|
||||
{"PST", "Pacific Standard Time (North America)", -8},
|
||||
{"PYST", "Paraguay Summer Time (South America)", -3},
|
||||
{"PYT", "Paraguay Time (South America)", -4},
|
||||
{"RET", "Réunion Time", 4},
|
||||
{"ROTT", "Rothera Research Station Time", -3},
|
||||
{"SAKT", "Sakhalin Island time", 11},
|
||||
{"SAMT", "Samara Time", 4},
|
||||
{"SAST", "South African Standard Time", 2},
|
||||
{"SBT", "Solomon Islands Time", 11},
|
||||
{"SCT", "Seychelles Time", 4},
|
||||
{"SGT", "Singapore Time", 8},
|
||||
{"SLST", "Sri Lanka Time", 5.5},
|
||||
{"SRET", "Srednekolymsk Time", 11},
|
||||
{"SRT", "Suriname Time", -3},
|
||||
{"SST", "Samoa Standard Time", -11},
|
||||
{"SYOT", "Showa Station Time", 3},
|
||||
{"TAHT", "Tahiti Time", -10},
|
||||
{"THA", "Thailand Standard Time", 7},
|
||||
{"TFT", "Indian/Kerguelen", 5},
|
||||
{"TJT", "Tajikistan Time", 5},
|
||||
{"TKT", "Tokelau Time", 13},
|
||||
{"TLT", "Timor Leste Time", 9},
|
||||
{"TMT", "Turkmenistan Time", 5},
|
||||
{"TOT", "Tonga Time", 13},
|
||||
{"TVT", "Tuvalu Time", 12},
|
||||
{"UCT", "Coordinated Universal Time", 0},
|
||||
{"ULAT", "Ulaanbaatar Time", 8},
|
||||
{"USZ1", "Kaliningrad Time", 2},
|
||||
{"UTC", "Coordinated Universal Time", 0},
|
||||
{"UYST", "Uruguay Summer Time", -2},
|
||||
{"UYT", "Uruguay Standard Time", -3},
|
||||
{"UZT", "Uzbekistan Time", 5},
|
||||
{"VET", "Venezuelan Standard Time", -3.5},
|
||||
{"VLAT", "Vladivostok Time", 10},
|
||||
{"VOLT", "Volgograd Time", 4},
|
||||
{"VOST", "Vostok Station Time", 6},
|
||||
{"VUT", "Vanuatu Time", 11},
|
||||
{"WAKT", "Wake Island Time", 12},
|
||||
{"WAST", "West Africa Summer Time", 2},
|
||||
{"WAT", "West Africa Time", 1},
|
||||
{"WEDT", "Western European Daylight Time", 1},
|
||||
{"WEST", "Western European Summer Time", 1},
|
||||
{"WET", "Western European Time", 0},
|
||||
{"WIT", "Western Indonesian Time", 7},
|
||||
{"WST", "Western Standard Time", 8},
|
||||
{"YAKT", "Yakutsk Time", 9},
|
||||
{"YEKT", "Yekaterinburg Time", 5},
|
||||
#endif
|
||||
{"+1", "Coordinated Universal Time +1", 1.0},
|
||||
{"+2", "Coordinated Universal Time +2", 2.0},
|
||||
{"+3", "Coordinated Universal Time +3", 3.0},
|
||||
{"+4", "Coordinated Universal Time +4", 4.0},
|
||||
{"+5", "Coordinated Universal Time +5", 5.0},
|
||||
{"+6", "Coordinated Universal Time +6", 6.0},
|
||||
{"+7", "Coordinated Universal Time +7", 7.0},
|
||||
{"+8", "Coordinated Universal Time +8", 8.0},
|
||||
{"+9", "Coordinated Universal Time +9", 9.0},
|
||||
{"+10", "Coordinated Universal Time +10", 10.0},
|
||||
{"+11", "Coordinated Universal Time +11", 11.0},
|
||||
{"+12", "Coordinated Universal Time +12", 12.0},
|
||||
{"-1", "Coordinated Universal Time -1", -1.0},
|
||||
{"-2", "Coordinated Universal Time -2", -2.0},
|
||||
{"-3", "Coordinated Universal Time -3", -3.0},
|
||||
{"-4", "Coordinated Universal Time -4", -4.0},
|
||||
{"-5", "Coordinated Universal Time -5", -5.0},
|
||||
{"-6", "Coordinated Universal Time -6", -6.0},
|
||||
{"-7", "Coordinated Universal Time -7", -7.0},
|
||||
{"-8", "Coordinated Universal Time -8", -8.0},
|
||||
{"-9", "Coordinated Universal Time -9", -9.0},
|
||||
{"-10", "Coordinated Universal Time -10", -10.0},
|
||||
{"-11", "Coordinated Universal Time -11", -11.0},
|
||||
{"-12", "Coordinated Universal Time -12", -12.0}
|
||||
};
|
5
udp.c
5
udp.c
|
@ -39,9 +39,9 @@
|
|||
#include <arpa/inet.h>
|
||||
#include <netdb.h>
|
||||
|
||||
#include "ntimed_platform.h"
|
||||
#include "ntimed.h"
|
||||
#include "udp.h"
|
||||
#include "net_poll.h"
|
||||
|
||||
struct udp_socket {
|
||||
unsigned magic;
|
||||
|
@ -74,9 +74,6 @@ void
|
|||
UDP_Socket_Destroy(struct udp_socket *usc)
|
||||
{
|
||||
CHECK_OBJ_NOTNULL(usc, UDP_SOCKET_MAGIC);
|
||||
#ifdef AOS3
|
||||
close(usc->fd4);
|
||||
#endif
|
||||
#ifdef AROS
|
||||
CloseSocket(usc->fd4);
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue