changed qse_ntime_t to a structure and made related changes

This commit is contained in:
hyung-hwan 2012-11-11 16:07:34 +00:00
parent d6a3bfea8d
commit b94dd042c5
29 changed files with 460 additions and 304 deletions

22
qse/configure vendored
View File

@ -17484,7 +17484,7 @@ _ACEOF
fi
done
for ac_func in fork vfork posix_spawn gettid
for ac_func in fork vfork posix_spawn gettid nanosleep select
do :
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
@ -18565,6 +18565,16 @@ cat >>confdefs.h <<_ACEOF
_ACEOF
fi
ac_fn_c_check_member "$LINENO" "struct stat" "st_birthtim.tv_nsec" "ac_cv_member_struct_stat_st_birthtim_tv_nsec" "$ac_includes_default"
if test "x$ac_cv_member_struct_stat_st_birthtim_tv_nsec" = xyes; then :
cat >>confdefs.h <<_ACEOF
#define HAVE_STRUCT_STAT_ST_BIRTHTIM_TV_NSEC 1
_ACEOF
fi
ac_fn_c_check_member "$LINENO" "struct stat" "st_mtimespec.tv_nsec" "ac_cv_member_struct_stat_st_mtimespec_tv_nsec" "$ac_includes_default"
@ -18575,6 +18585,16 @@ cat >>confdefs.h <<_ACEOF
_ACEOF
fi
ac_fn_c_check_member "$LINENO" "struct stat" "st_birthtimespec.tv_nsec" "ac_cv_member_struct_stat_st_birthtimespec_tv_nsec" "$ac_includes_default"
if test "x$ac_cv_member_struct_stat_st_birthtimespec_tv_nsec" = xyes; then :
cat >>confdefs.h <<_ACEOF
#define HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC_TV_NSEC 1
_ACEOF
fi

View File

@ -124,7 +124,7 @@ AC_CHECK_FUNCS([utime utimes])
AC_CHECK_FUNCS([sysconf])
AC_CHECK_FUNCS([backtrace backtrace_symbols])
AC_CHECK_FUNCS([fdopendir])
AC_CHECK_FUNCS([fork vfork posix_spawn gettid])
AC_CHECK_FUNCS([fork vfork posix_spawn gettid nanosleep select])
AC_CHECK_FUNCS([makecontext swapcontext getcontext setcontext])
AC_CHECK_FUNCS([if_nametoindex if_indextoname])
@ -243,7 +243,9 @@ AM_CONDITIONAL(HAVE_LIBUCI, test "${ac_cv_lib_uci_uci_alloc_context}" = "yes" -a
AC_STRUCT_DIRENT_D_TYPE
AC_CHECK_MEMBERS([struct stat.st_birthtime])
AC_CHECK_MEMBERS([struct stat.st_mtim.tv_nsec])
AC_CHECK_MEMBERS([struct stat.st_birthtim.tv_nsec])
AC_CHECK_MEMBERS([struct stat.st_mtimespec.tv_nsec])
AC_CHECK_MEMBERS([struct stat.st_birthtimespec.tv_nsec])
dnl check the size of primitive data types
AC_CHECK_SIZEOF(char,,[[]])

View File

@ -648,6 +648,7 @@ public:
int getInt (long_t* v) const;
int getFlt (flt_t* v) const;
int getNum (long_t* lv, flt_t* fv) const;
int getStr (const char_t** str, size_t* len) const;
int setVal (val_t* v);

View File

@ -23,6 +23,7 @@
#include <qse/awk/Awk.hpp>
#include <qse/cmn/StdMmgr.hpp>
#include <qse/cmn/time.h>
/// @file
/// Standard AWK Interpreter
@ -228,13 +229,16 @@ public:
{
qse_cmgr_t* cmgr;
char_t cmgr_name[64]; // i assume that the cmgr name never exceeds this length.
int tmout[4];
qse_ntime_t tmout[4];
ioattr_t (): cmgr (QSE_NULL)
{
this->cmgr_name[0] = QSE_T('\0');
for (size_t i = 0; i < QSE_COUNTOF(this->tmout); i++)
this->tmout[i] = -999;
{
this->tmout[i].sec = -999;
this->tmout[i].nsec = 0;
}
}
};

View File

@ -112,8 +112,8 @@ int qse_mux_delete (
);
int qse_mux_poll (
qse_mux_t* mux,
qse_ntime_t timeout
qse_mux_t* mux,
const qse_ntime_t* tmout
);
#ifdef __cplusplus

View File

@ -29,6 +29,7 @@
#include <qse/macros.h>
#include <qse/cmn/tio.h>
#include <qse/cmn/nwad.h>
#include <qse/cmn/time.h>
enum qse_nwio_flag_t
{
@ -74,7 +75,7 @@ typedef enum qse_nwio_errnum_t qse_nwio_errnum_t;
struct qse_nwio_tmout_t
{
int r, w, c, a;
qse_ntime_t r, w, c, a;
};
typedef struct qse_nwio_tmout_t qse_nwio_tmout_t;

View File

@ -55,42 +55,44 @@
#define QSE_NSECS_PER_USEC (1000)
#define QSE_NSECS_PER_MSEC (QSE_NSECS_PER_USEC*QSE_USECS_PER_MSEC)
#define QSE_USECS_PER_SEC (QSE_USECS_PER_MSEC*QSE_MSECS_PER_SEC)
#define QSE_NSECS_PER_SEC (QSE_NSECS_PER_USEC*QSE_USECS_PER_MSEC*QSE_MSECS_PER_SEC)
#define QSE_IS_LEAPYEAR(year) ((!((year)%4) && ((year)%100)) || !((year)%400))
#define QSE_DAYS_PER_YEAR(year) \
(QSE_IS_LEAPYEAR(year)? QSE_DAYS_PER_LEAPYEAR: QSE_DAYS_PER_NORMYEAR)
#define QSE_SECNSEC_TO_MSEC(sec,nsec) \
(((qse_ntime_t)(sec) * QSE_MSECS_PER_SEC) + ((qse_ntime_t)(nsec) / QSE_NSECS_PER_MSEC))
(((qse_long_t)(sec) * QSE_MSECS_PER_SEC) + ((qse_long_t)(nsec) / QSE_NSECS_PER_MSEC))
#define QSE_SEC_TO_MSEC(sec) ((sec) * QSE_MSECS_PER_SEC)
#define QSE_MSEC_TO_SEC(sec) ((sec) / QSE_MSECS_PER_SEC)
#define QSE_USEC_TO_NSEC(usec) ((usec) * QSE_NSECS_PER_USEC)
#define QSE_NSEC_TO_USEC(nsec) ((nsec) / QSE_NSECS_PER_USEC)
#define QSE_MSEC_TO_NSEC(msec) ((msec) * QSE_NSECS_PER_MSEC)
#define QSE_NSEC_TO_MSEC(nsec) ((nsec) / QSE_NSECS_PER_MSEC)
#define QSE_SEC_TO_NSEC(sec) ((sec) * QSE_NSECS_PER_SEC)
#define QSE_NSEC_TO_SEC(nsec) ((nsec) / QSE_NSECS_PER_SEC)
#define QSE_SEC_TO_USEC(sec) ((sec) * QSE_USECS_PER_SEC)
#define QSE_USEC_TO_SEC(usec) ((usec) / QSE_USECS_PER_SEC)
/**
* The qse_ntime_t type defines a numeric time type expressed in the
* number of milliseconds since the Epoch (00:00:00 UTC, Jan 1, 1970).
*/
typedef qse_long_t qse_ntime_t;
/**
* The qse_ntprd_t type represents a time period between two time points.
* This is period is defined to be unsigned since a time point is signed.
*/
typedef qse_ulong_t qse_ntprd_t;
/**
* The qse_ntoff_t type represents the amount of increment or decrement
* from a certain time point. It is defined to be type-compatible with
* #qse_ntime_t and expresses that you're dealing with time offset or amount,
* not an absolute time point.
*/
typedef qse_ntime_t qse_ntoff_t;
typedef struct qse_ntime_t qse_ntime_t;
struct qse_ntime_t
{
qse_long_t sec;
qse_int32_t nsec; /* nanoseconds */
};
typedef struct qse_btime_t qse_btime_t;
struct qse_btime_t
{
int msec; /* 0-999 */
int sec; /* 0-61 */
int min; /* 0-59 */
int hour; /* 0-23 */
@ -118,7 +120,7 @@ int qse_gettime (
* The qse_settime() function sets the current time.
*/
int qse_settime (
qse_ntime_t nt
const qse_ntime_t* nt
);
@ -126,16 +128,16 @@ int qse_settime (
* The qse_gmtime() function converts numeric time to broken-down time.
*/
int qse_gmtime (
qse_ntime_t nt,
qse_btime_t* bt
const qse_ntime_t* nt,
qse_btime_t* bt
);
/**
* The qse_localtime() converts numeric time to broken-down time
*/
int qse_localtime (
qse_ntime_t nt,
qse_btime_t* bt
const qse_ntime_t* nt,
qse_btime_t* bt
);
/**
@ -157,16 +159,6 @@ int qse_timelocal (
qse_ntime_t* nt
);
/**
* The qse_strftime() functions formats time.
*/
qse_size_t qse_strftime (
qse_char_t* buf,
qse_size_t size,
const qse_char_t* fmt,
qse_btime_t* bt
);
#ifdef __cplusplus
}
#endif

View File

@ -248,6 +248,9 @@
/* Define to 1 if you have MPI libs and headers. */
#undef HAVE_MPI
/* Define to 1 if you have the `nanosleep' function. */
#undef HAVE_NANOSLEEP
/* Define to 1 if you have the <ndir.h> header file, and it defines `DIR'. */
#undef HAVE_NDIR_H
@ -293,6 +296,9 @@
/* Define to 1 if you have the `roundl' function. */
#undef HAVE_ROUNDL
/* Define to 1 if you have the `select' function. */
#undef HAVE_SELECT
/* Define to 1 if you have the `sendfile' function. */
#undef HAVE_SENDFILE
@ -374,6 +380,12 @@
/* Define to 1 if `st_birthtime' is a member of `struct stat'. */
#undef HAVE_STRUCT_STAT_ST_BIRTHTIME
/* Define to 1 if `st_birthtimespec.tv_nsec' is a member of `struct stat'. */
#undef HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC_TV_NSEC
/* Define to 1 if `st_birthtim.tv_nsec' is a member of `struct stat'. */
#undef HAVE_STRUCT_STAT_ST_BIRTHTIM_TV_NSEC
/* Define to 1 if `st_mtimespec.tv_nsec' is a member of `struct stat'. */
#undef HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC

View File

@ -190,7 +190,7 @@ QSE_EXPORT int qse_parsehttptime (
);
QSE_EXPORT qse_mchar_t* qse_fmthttptime (
qse_ntime_t nt,
const qse_ntime_t* nt,
qse_mchar_t* buf,
qse_size_t bufsz
);

View File

@ -137,12 +137,12 @@ struct qse_httpd_scb_t
void (*close) (qse_httpd_t* httpd, void* mux);
int (*addhnd) (qse_httpd_t* httpd, void* mux, qse_ubi_t handle, int mask, void* cbarg);
int (*delhnd) (qse_httpd_t* httpd, void* mux, qse_ubi_t handle);
int (*poll) (qse_httpd_t* httpd, void* mux, qse_ntime_t timeout);
int (*poll) (qse_httpd_t* httpd, void* mux, const qse_ntime_t* tmout);
int (*readable) (
qse_httpd_t* httpd, qse_ubi_t handle, qse_ntoff_t timeout);
qse_httpd_t* httpd, qse_ubi_t handle, const qse_ntime_t* tmout);
int (*writable) (
qse_httpd_t* httpd, qse_ubi_t handle, qse_ntoff_t timeout);
qse_httpd_t* httpd, qse_ubi_t handle, const qse_ntime_t* tmout);
} mux;
struct
@ -580,10 +580,10 @@ QSE_EXPORT void qse_httpd_pushecb (
* The qse_httpd_loop() function starts a httpd server loop.
*/
QSE_EXPORT int qse_httpd_loop (
qse_httpd_t* httpd,
qse_httpd_scb_t* scb,
qse_httpd_rcb_t* rcb,
qse_ntime_t timeout
qse_httpd_t* httpd,
qse_httpd_scb_t* scb,
qse_httpd_rcb_t* rcb,
const qse_ntime_t* tmout
);
/**
@ -845,7 +845,7 @@ QSE_EXPORT void* qse_httpd_getserverxtnstd (
QSE_EXPORT int qse_httpd_loopstd (
qse_httpd_t* httpd,
qse_ntime_t timeout
const qse_ntime_t* tmout
);

View File

@ -80,7 +80,7 @@ struct qse_upxd_session_t
/** binding device for peer socket */
qse_char_t dev[QSE_UPXD_SESSION_DEV_LEN + 1];
#define QSE_UPXD_SESSION_DORMANCY (30000)
#define QSE_UPXD_SESSION_DORMANCY (30)
/** session's idle-timeout */
qse_ntime_t dormancy;
} config;

View File

@ -377,7 +377,7 @@ Awk::Value::operator const Awk::char_t* () const
{
const Awk::char_t* ptr;
size_t len;
if (Awk::Value::getStr (&ptr, &len) <= -1) ptr = QSE_T("");
if (Awk::Value::getStr (&ptr, &len) <= -1) ptr = EMPTY_STRING;
return ptr;
}
@ -385,16 +385,14 @@ int Awk::Value::getInt (long_t* v) const
{
long_t lv = 0;
QSE_ASSERT (val != QSE_NULL);
QSE_ASSERT (this->val != QSE_NULL);
if (run != QSE_NULL &&
val->type != QSE_AWK_VAL_NIL &&
val->type != QSE_AWK_VAL_MAP)
if (run != QSE_NULL)
{
int n = qse_awk_rtx_valtolong (run->rtx, val, &lv);
int n = qse_awk_rtx_valtolong (this->run->rtx, this->val, &lv);
if (n <= -1)
{
run->awk->retrieveError (run);
run->awk->retrieveError (this->run);
return -1;
}
}
@ -407,16 +405,14 @@ int Awk::Value::getFlt (flt_t* v) const
{
flt_t rv = 0;
QSE_ASSERT (val != QSE_NULL);
QSE_ASSERT (this->val != QSE_NULL);
if (run != QSE_NULL &&
val->type != QSE_AWK_VAL_NIL &&
val->type != QSE_AWK_VAL_MAP)
if (this->run)
{
int n = qse_awk_rtx_valtoflt (run->rtx, val, &rv);
int n = qse_awk_rtx_valtoflt (this->run->rtx, this->val, &rv);
if (n <= -1)
{
run->awk->retrieveError (run);
run->awk->retrieveError (this->run);
return -1;
}
}
@ -425,21 +421,38 @@ int Awk::Value::getFlt (flt_t* v) const
return 0;
}
int Awk::Value::getNum (long_t* lv, flt_t* fv) const
{
QSE_ASSERT (this->val != QSE_NULL);
if (this->run != QSE_NULL)
{
int n = qse_awk_rtx_valtonum (this->run->rtx, this->val, lv, fv);
if (n <= -1)
{
run->awk->retrieveError (this->run);
return -1;
}
return n;
}
*lv = 0;
return 0;
}
int Awk::Value::getStr (const char_t** str, size_t* len) const
{
const char_t* p = EMPTY_STRING;
size_t l = 0;
QSE_ASSERT (val != QSE_NULL);
QSE_ASSERT (this->val != QSE_NULL);
if (run != QSE_NULL &&
val->type != QSE_AWK_VAL_NIL &&
val->type != QSE_AWK_VAL_MAP)
if (this->run != QSE_NULL)
{
if (val->type == QSE_AWK_VAL_STR)
if (this->val->type == QSE_AWK_VAL_STR)
{
p = ((qse_awk_val_str_t*)val)->val.ptr;
l = ((qse_awk_val_str_t*)val)->val.len;
p = ((qse_awk_val_str_t*)this->val)->val.ptr;
l = ((qse_awk_val_str_t*)this->val)->val.len;
}
else
{
@ -447,9 +460,9 @@ int Awk::Value::getStr (const char_t** str, size_t* len) const
{
qse_awk_rtx_valtostr_out_t out;
out.type = QSE_AWK_RTX_VALTOSTR_CPLDUP;
if (qse_awk_rtx_valtostr (run->rtx, val, &out) <= -1)
if (qse_awk_rtx_valtostr (this->run->rtx, this->val, &out) <= -1)
{
run->awk->retrieveError (run);
run->awk->retrieveError (this->run);
return -1;
}

View File

@ -160,7 +160,7 @@ int StdAwk::open ()
qse_ntime_t now;
this->seed = (qse_gettime(&now) <= -1)? 0u: (long_t)now;
this->seed = (qse_gettime(&now) <= -1)? 0u: ((long_t)now.sec + (long_t)now.nsec);
/* i don't care if the seed becomes negative or overflows.
* i just convert the signed value to the unsigned one. */
this->prand = (qse_ulong_t)(this->seed * this->seed * this->seed);
@ -368,7 +368,7 @@ int StdAwk::srand (Run& run, Value& ret, const Value* args, size_t nargs,
if (nargs <= 0)
{
this->seed = (qse_gettime (&now) <= -1)?
(this->seed * this->seed): (long_t)now;
(this->seed * this->seed): ((long_t)now.sec + (long_t)now.nsec);
}
else
{
@ -478,16 +478,28 @@ int StdAwk::setioattr (
int tmout;
if ((tmout = timeout_code (ptr[1])) >= 0)
{
long_t tmout_val = args[2].toInt();
long_t lv;
flt_t fv;
int n;
n = args[2].getNum(&lv, &fv);
if (n <= -1) return -1;
if (tmout_val < QSE_TYPE_MIN(int) ||
tmout_val > QSE_TYPE_MAX(int))
return ret.setInt ((long_t)-1);
ioattr_t* ioattr = find_or_make_ioattr (ptr[0], l[0]);
if (ioattr == QSE_NULL) return -1;
ioattr->tmout[tmout] = tmout_val;
if (n == 0)
{
ioattr->tmout[tmout].sec = lv;
ioattr->tmout[tmout].nsec = 0;
}
else
{
qse_flt_t nsec;
ioattr->tmout[tmout].sec = (qse_long_t)fv;
nsec = fv - ioattr->tmout[tmout].sec;
ioattr->tmout[tmout].nsec = QSE_SEC_TO_NSEC(nsec);
}
return ret.setInt ((long_t)0);
}
#if defined(QSE_CHAR_IS_WCHAR)
@ -541,7 +553,10 @@ int StdAwk::getioattr (
int tmout;
if ((tmout = timeout_code(ptr[1])) >= 0)
{
return ret.setInt ((long_t)ioattr->tmout[tmout]);
if (ioattr->tmout[tmout].nsec == 0)
return ret.setInt ((long_t)ioattr->tmout[tmout].sec);
else
return ret.setFlt ((qse_flt_t)ioattr->tmout[tmout].sec + QSE_NSEC_TO_SEC((qse_flt_t)ioattr->tmout[tmout].nsec));
}
#if defined(QSE_CHAR_IS_WCHAR)
else if (qse_strcasecmp (ptr[1], QSE_T("codepage")) == 0)

View File

@ -152,7 +152,7 @@ typedef struct ioattr_t
{
qse_cmgr_t* cmgr;
qse_char_t cmgr_name[64]; /* i assume that the cmgr name never exceeds this length */
int tmout[4];
qse_ntime_t tmout[4];
} ioattr_t;
static ioattr_t* get_ioattr (qse_htb_t* tab, const qse_char_t* ptr, qse_size_t len);
@ -2021,7 +2021,7 @@ qse_awk_rtx_t* qse_awk_rtx_openstd (
rxtn->ecb.close = fini_rxtn;
qse_awk_rtx_pushecb (rtx, &rxtn->ecb);
rxtn->seed = (qse_gettime (&now) <= -1)? 0u: (qse_long_t)now;
rxtn->seed = (qse_gettime (&now) <= -1)? 0u: ((qse_long_t)now.sec + (qse_long_t)now.nsec);
/* i don't care if the seed becomes negative or overflows.
* i just convert the signed value to the unsigned one. */
rxtn->prand = (qse_ulong_t)(rxtn->seed * rxtn->seed * rxtn->seed);
@ -2113,7 +2113,7 @@ static int fnc_srand (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
if (nargs <= 0)
{
rxtn->seed = (qse_gettime (&now) <= -1)?
(rxtn->seed * rxtn->seed): (qse_long_t)now;
(rxtn->seed * rxtn->seed): ((qse_long_t)now.sec + (qse_long_t)now.nsec);
}
else
{
@ -2212,7 +2212,8 @@ static QSE_INLINE void init_ioattr (ioattr_t* ioattr)
for (i = 0; i < QSE_COUNTOF(ioattr->tmout); i++)
{
/* a negative number for no timeout */
ioattr->tmout[i] = -999;
ioattr->tmout[i].sec = -999;
ioattr->tmout[i].nsec = 0;
}
}
@ -2301,14 +2302,8 @@ static int fnc_setioattr (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
/* no error is returned by qse_awk_rtx_strnum() if the second
* parameter is 0. so i don't check for an error */
x = qse_awk_rtx_strtonum (rtx, 0, ptr[2], len[2], &l, &r);
if (x >= 1) l = (qse_long_t)r;
if (x == 0) r = (qse_flt_t)l;
if (l < QSE_TYPE_MIN(int) || l > QSE_TYPE_MAX(int))
{
fret = -1;
goto done;
}
ioattr = find_or_make_ioattr (rtx, &rxtn->cmgrtab, ptr[0], len[0]);
if (ioattr == QSE_NULL)
{
@ -2316,7 +2311,18 @@ static int fnc_setioattr (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
goto done;
}
ioattr->tmout[tmout] = l;
if (x == 0)
{
ioattr->tmout[tmout].sec = l;
ioattr->tmout[tmout].nsec = 0;
}
else if (x >= 1)
{
qse_flt_t nsec;
ioattr->tmout[tmout].sec = (qse_long_t)r;
nsec = r - ioattr->tmout[tmout].sec;
ioattr->tmout[tmout].nsec = QSE_SEC_TO_NSEC(nsec);
}
}
#if defined(QSE_CHAR_IS_WCHAR)
else if (qse_strcasecmp (ptr[1], QSE_T("codepage")) == 0)
@ -2424,7 +2430,10 @@ static int fnc_getioattr (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
if ((tmout = timeout_code (ptr[1])) >= 0)
{
rv = qse_awk_rtx_makeintval (rtx, ioattr->tmout[tmout]);
if (ioattr->tmout[tmout].nsec == 0)
rv = qse_awk_rtx_makeintval (rtx, ioattr->tmout[tmout].sec);
else
rv = qse_awk_rtx_makefltval (rtx, (qse_flt_t)ioattr->tmout[tmout].sec + QSE_NSEC_TO_SEC((qse_flt_t)ioattr->tmout[tmout].nsec));
if (rv == QSE_NULL)
{
ret = -1;

View File

@ -258,7 +258,7 @@ int qse_fio_init (
}
qse_gettime (&now);
temp_no += (now & 0xFFFFFFFFlu);
temp_no += (now.sec & 0xFFFFFFFFlu);
temp_tries = 0;
temp_ptr -= 4;

View File

@ -368,10 +368,11 @@ static int set_entry_name (qse_fs_t* fs, const qse_mchar_t* name)
}
#if defined(_WIN32)
static QSE_INLINE qse_ntime_t filetime_to_ntime (const FILETIME* ft)
static QSE_INLINE void filetime_to_ntime (const FILETIME* ft, qse_ntime_t* nt)
{
/* reverse of http://support.microsoft.com/kb/167296/en-us */
ULARGE_INTEGER li;
li.LowPart = ft->dwLowDateTime;
li.HighPart = ft->dwHighDateTime;
@ -383,9 +384,12 @@ static QSE_INLINE qse_ntime_t filetime_to_ntime (const FILETIME* ft)
# error Unsupported 64bit integer type
#endif
/*li.QuadPart /= 10000000;*/
li.QuadPart /= 10000;
/*li.QuadPart /= 10000;
return li.QuadPart;*/
return li.QuadPart;
/* li.QuadPart is in the 100-nanosecond intervals */
nt->sec = li.QuadPart / (QSE_NSECS_PER_SEC / 100);
nt->nsec = (li.QuadPart % (QSE_NSECS_PER_SEC / 100)) * 100;
}
#endif
@ -511,9 +515,9 @@ qse_fs_ent_t* qse_fs_read (qse_fs_t* fs, int flags)
if (flags & QSE_FS_ENT_TIME)
{
fs->ent.time.create = filetime_to_ntime (&info->wfd.ftCreationTime);
fs->ent.time.access = filetime_to_ntime (&info->wfd.ftLastAccessTime);
fs->ent.time.modify = filetime_to_ntime (&info->wfd.ftLastWriteTime);
filetime_to_ntime (&info->wfd.ftCreationTime, &fs->ent.time.create);
filetime_to_ntime (&info->wfd.ftLastAccessTime, &fs->ent.time.access);
filetime_to_ntime (&info->wfd.ftLastWriteTime, &fs->ent.time.modify);
fs->ent.type |= QSE_FS_ENT_TIME;
}
@ -642,34 +646,36 @@ qse_fs_ent_t* qse_fs_read (qse_fs_t* fs, int flags)
if (flags & QSE_FS_ENT_TIME)
{
#if defined(HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC)
#if defined(HAVE_STRUCT_STAT_ST_BIRTHTIME)
fs->ent.time.create =
QSE_SECNSEC_TO_MSEC(st.st_birthtim.tv_sec,st.st_birthtim.tv_nsec);
#if defined(HAVE_STRUCT_STAT_ST_BIRTHTIM_TV_NSEC)
fs->ent.time.create.secs = st.st_birthtim.tv_sec;
fs->ent.time.create.nsecs = st.st_birthtim.tv_nsec;
#endif
fs->ent.time.access =
QSE_SECNSEC_TO_MSEC(st.st_atim.tv_sec,st.st_atim.tv_nsec);
fs->ent.time.modify =
QSE_SECNSEC_TO_MSEC(st.st_mtim.tv_sec,st.st_mtim.tv_nsec);
fs->ent.time.change =
QSE_SECNSEC_TO_MSEC(st.st_ctim.tv_sec,st.st_ctim.tv_nsec);
fs->ent.time.access.sec = st.st_atim.tv_sec;
fs->ent.time.access.nsec = st.st_atim.tv_nsec;
fs->ent.time.modify.sec = st.st_mtim.tv_sec;
fs->ent.time.modify.nsec = st.st_mtim.tv_nsec;
fs->ent.time.change.sec = st.st_ctim.tv_sec;
fs->ent.time.change.nsec = st.st_ctim.tv_nsec;
#elif defined(HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC)
#if defined(HAVE_STRUCT_STAT_ST_BIRTHTIME)
fs->ent.time.create = st.st_birthtime;
QSE_SECNSEC_TO_MSEC(st.st_birthtimespec.tv_sec,st.st_birthtimespec.tv_nsec);
#if defined(HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC_TV_NSEC)
fs->ent.time.create.sec = st.st_birthtimespec.tv_sec;
fs->ent.time.create.nsec = st.st_birthtimespec.tv_nsec;
#endif
fs->ent.time.access =
QSE_SECNSEC_TO_MSEC(st.st_atimespec.tv_sec,st.st_atimespec.tv_nsec);
fs->ent.time.modify =
QSE_SECNSEC_TO_MSEC(st.st_mtimespec.tv_sec,st.st_mtimespec.tv_nsec);
fs->ent.time.change =
QSE_SECNSEC_TO_MSEC(st.st_ctimespec.tv_sec,st.st_ctimespec.tv_nsec);
fs->ent.time.access.sec = st.st_atimspec.tv_sec;
fs->ent.time.access.nsec = st.st_atimspec.tv_nsec;
fs->ent.time.modify.sec = st.st_mtimspec.tv_sec;
fs->ent.time.modify.nsec = st.st_mtimspec.tv_nsec;
fs->ent.time.change.sec = st.st_ctimspec.tv_sec;
fs->ent.time.change.nsec = st.st_ctimspec.tv_nsec;
#else
#if defined(HAVE_STRUCT_STAT_ST_BIRTHTIME)
fs->ent.time.create = st.st_birthtime * QSE_MSECS_PER_SEC;
fs->ent.time.create.sec = st.st_birthtime;
#endif
fs->ent.time.access = st.st_atime * QSE_MSECS_PER_SEC;
fs->ent.time.modify = st.st_mtime * QSE_MSECS_PER_SEC;
fs->ent.time.change = st.st_ctime * QSE_MSECS_PER_SEC;
fs->ent.time.access.sec = st.st_atime;
fs->ent.time.modify.sec = st.st_mtime;
fs->ent.time.change.sec = st.st_ctime;
#endif
fs->ent.flags |= QSE_FS_ENT_TIME;
}

View File

@ -533,14 +533,14 @@ done:
#endif
}
int qse_mux_poll (qse_mux_t* mux, qse_ntime_t timeout)
int qse_mux_poll (qse_mux_t* mux, const qse_ntime_t* tmout)
{
#if defined(USE_SELECT)
struct timeval tv;
int n;
tv.tv_sec = timeout / QSE_MSECS_PER_SEC;
tv.tv_usec = (timeout % QSE_MSECS_PER_SEC) * QSE_USECS_PER_MSEC;
tv.tv_sec = tmout->sec;
tv.tv_usec = QSE_NSEC_TO_USEC (tmout->nsec);
mux->tmprset = mux->rset;
mux->tmpwset = mux->wset;
@ -579,10 +579,10 @@ int qse_mux_poll (qse_mux_t* mux, qse_ntime_t timeout)
return n;
#elif defined(USE_EPOLL)
int nfds, i, mask;
int nfds, i;
qse_mux_evt_t* evt, xevt;
nfds = epoll_wait (mux->fd, mux->ee.ptr, mux->ee.len, timeout);
nfds = epoll_wait (mux->fd, mux->ee.ptr, mux->ee.len, QSE_SECNSEC_TO_MSEC(tmout->sec,tmout->nsec));
if (nfds <= -1)
{
mux->errnum = syserr_to_errnum(errno);
@ -605,10 +605,8 @@ int qse_mux_poll (qse_mux_t* mux, qse_ntime_t timeout)
if (mux->ee.ptr[i].events & EPOLLHUP)
{
if (evt->mask & QSE_MUX_IN)
xevt.mask |= QSE_MUX_IN;
if (evt->mask & QSE_MUX_OUT)
xevt.mask |= QSE_MUX_OUT;
if (evt->mask & QSE_MUX_IN) xevt.mask |= QSE_MUX_IN;
if (evt->mask & QSE_MUX_OUT) xevt.mask |= QSE_MUX_OUT;
}
mux->evtfun (mux, &xevt);

View File

@ -65,6 +65,8 @@ union sockaddr_t
};
#endif
#define TMOUT_ENABLED(tmout) (tmout.sec >= 0 && tmout.nsec >= 0)
static int nwad_to_sockaddr (const qse_nwad_t* nwad, int* family, void* addr)
{
int addrsize = -1;
@ -252,7 +254,7 @@ static qse_nwio_errnum_t tio_errnum_to_nwio_errnum (qse_tio_t* tio)
}
}
static int wait_for_data (qse_nwio_t* nwio, int tmout, int what)
static int wait_for_data (qse_nwio_t* nwio, const qse_ntime_t* tmout, int what)
{
int xret;
@ -265,8 +267,8 @@ static int wait_for_data (qse_nwio_t* nwio, int tmout, int what)
FD_SET (nwio->handle, &fds[what]);
tv.tv_sec = tmout / QSE_MSECS_PER_SEC;
tv.tv_usec = (tmout % QSE_MSECS_PER_SEC) * QSE_USECS_PER_MSEC;
tv.tv_sec = tmout->sec;
tv.tv_usec = QSE_NSEC_TO_USEC (tmout->nsec);
xret = select (nwio->handle + 1, &fds[0], &fds[1], QSE_NULL, &tv);
if (xret == SOCKET_ERROR)
@ -281,10 +283,12 @@ static int wait_for_data (qse_nwio_t* nwio, int tmout, int what)
}
#elif defined(__OS2__)
int count[2] = { 0, 0 };
long tmout_msecs;
count[what]++;
xret = os2_select (&nwio->handle, count[0], count[1], 0, tmout);
tmout_msecs = QSE_SECNSEC_TO_MSEC (tmout->sec, tmout->nsec);
xret = os2_select (&nwio->handle, count[0], count[1], 0, tmout_msecs);
if (xret <= -1)
{
nwio->errnum = syserr_to_errnum (sock_errno());
@ -309,8 +313,8 @@ static int wait_for_data (qse_nwio_t* nwio, int tmout, int what)
FD_SET (nwio->handle, &fds[what]);
tv.tv_sec = tmout / QSE_MSECS_PER_SEC;
tv.tv_usec = (tmout % QSE_MSECS_PER_SEC) * QSE_USECS_PER_MSEC;
tv.tv_sec = tmout->sec;
tv.tv_usec = QSE_NSEC_TO_USEC (tmout->nsec);
xret = select (nwio->handle + 1, &fds[0], &fds[1], QSE_NULL, &tv);
if (xret <= -1)
@ -375,10 +379,10 @@ int qse_nwio_init (
if (tmout) nwio->tmout = *tmout;
else
{
nwio->tmout.r = -1;
nwio->tmout.w = -1;
nwio->tmout.c = -1;
nwio->tmout.a = -1;
nwio->tmout.r.sec = -1;
nwio->tmout.w.sec = -1;
nwio->tmout.c.sec = -1;
nwio->tmout.a.sec = -1;
}
#if defined(AF_INET)
@ -437,8 +441,8 @@ int qse_nwio_init (
goto oops;
}
if (nwio->tmout.a >= 0 &&
wait_for_data (nwio, nwio->tmout.a, 0) <= -1) goto oops;
if (TMOUT_ENABLED(nwio->tmout.a) &&
wait_for_data (nwio, &nwio->tmout.a, 0) <= -1) goto oops;
handle = accept (nwio->handle, (struct sockaddr*)&addr, &addrlen);
if (handle == INVALID_SOCKET)
@ -459,7 +463,7 @@ int qse_nwio_init (
{
int xret;
if (nwio->tmout.c >= 0 && (flags & QSE_NWIO_TCP))
if (TMOUT_ENABLED(nwio->tmout.c) && (flags & QSE_NWIO_TCP))
{
unsigned long cmd = 1;
@ -472,7 +476,7 @@ int qse_nwio_init (
xret = connect (nwio->handle, (struct sockaddr*)&addr, addrlen);
if (nwio->tmout.c >= 0 && (flags & QSE_NWIO_TCP))
if (TMOUT_ENABLED(nwio->tmout.c) && (flags & QSE_NWIO_TCP))
{
unsigned long cmd = 0;
@ -483,7 +487,7 @@ int qse_nwio_init (
goto oops;
}
if (wait_for_data (nwio, nwio->tmout.c, 1) <= -1) goto oops;
if (wait_for_data (nwio, &nwio->tmout.c, 1) <= -1) goto oops;
else
{
int xlen;
@ -550,8 +554,8 @@ int qse_nwio_init (
goto oops;
}
if (nwio->tmout.a >= 0 &&
wait_for_data (nwio, nwio->tmout.a, 0) <= -1) goto oops;
if (TMOUT_ENABLED(nwio->tmout.a) &&
wait_for_data (nwio, &nwio->tmout.a, 0) <= -1) goto oops;
handle = accept (nwio->handle, (struct sockaddr*)&addr, &addrlen);
if (handle <= -1)
@ -572,7 +576,7 @@ int qse_nwio_init (
{
int xret;
if (nwio->tmout.c >= 0 && (flags & QSE_NWIO_TCP))
if (TMOUT_ENABLED(nwio->tmout.c) && (flags & QSE_NWIO_TCP))
{
int noblk = 1;
@ -585,7 +589,7 @@ int qse_nwio_init (
xret = connect (nwio->handle, (struct sockaddr*)&addr, addrlen);
if (nwio->tmout.c >= 0 && (flags & QSE_NWIO_TCP))
if (TMOUT_ENABLED(nwio->tmout.c) && (flags & QSE_NWIO_TCP))
{
int noblk = 0;
@ -596,7 +600,7 @@ int qse_nwio_init (
goto oops;
}
if (wait_for_data (nwio, nwio->tmout.c, 1) <= -1) goto oops;
if (wait_for_data (nwio, &nwio->tmout.c, 1) <= -1) goto oops;
else
{
int xlen, xerr;
@ -679,8 +683,8 @@ int qse_nwio_init (
goto oops;
}
if (nwio->tmout.a >= 0 &&
wait_for_data (nwio, nwio->tmout.a, 0) <= -1) goto oops;
if (TMOUT_ENABLED(nwio->tmout.a) &&
wait_for_data (nwio, &nwio->tmout.a, 0) <= -1) goto oops;
handle = accept (nwio->handle, (struct sockaddr*)&addr, &addrlen);
if (handle <= -1)
@ -701,7 +705,7 @@ int qse_nwio_init (
{
int orgfl, xret;
if (nwio->tmout.c >= 0 && (flags & QSE_NWIO_TCP))
if (TMOUT_ENABLED(nwio->tmout.c) && (flags & QSE_NWIO_TCP))
{
orgfl = fcntl (nwio->handle, F_GETFL, 0);
if (orgfl <= -1 ||
@ -714,7 +718,7 @@ int qse_nwio_init (
xret = connect (nwio->handle, (struct sockaddr*)&addr, addrlen);
if (nwio->tmout.c >= 0 && (flags & QSE_NWIO_TCP))
if (TMOUT_ENABLED(nwio->tmout.c) && (flags & QSE_NWIO_TCP))
{
if ((xret <= -1 && errno != EINPROGRESS) ||
fcntl (nwio->handle, F_SETFL, orgfl) <= -1)
@ -723,7 +727,7 @@ int qse_nwio_init (
goto oops;
}
if (wait_for_data (nwio, nwio->tmout.c, 1) <= -1) goto oops;
if (wait_for_data (nwio, &nwio->tmout.c, 1) <= -1) goto oops;
else
{
#if defined(HAVE_SOCKLEN_T)
@ -908,8 +912,8 @@ static qse_ssize_t nwio_read (qse_nwio_t* nwio, void* buf, qse_size_t size)
addrlen = QSE_SIZEOF(addr);
if (nwio->tmout.a >= 0 &&
wait_for_data (nwio, nwio->tmout.a, 0) <= -1) return -1;
if (TMOUT_ENABLED(nwio->tmout.a) &&
wait_for_data (nwio, &nwio->tmout.a, 0) <= -1) return -1;
count = recvfrom (
nwio->handle, buf, size, 0,
@ -932,8 +936,8 @@ static qse_ssize_t nwio_read (qse_nwio_t* nwio, void* buf, qse_size_t size)
}
else
{
if (nwio->tmout.r >= 0 &&
wait_for_data (nwio, nwio->tmout.r, 0) <= -1) return -1;
if (TMOUT_ENABLED(nwio->tmout.r) &&
wait_for_data (nwio, &nwio->tmout.r, 0) <= -1) return -1;
count = recv (nwio->handle, buf, size, 0);
if (count == SOCKET_ERROR) nwio->errnum = syserr_to_errnum (WSAGetLastError());
@ -952,8 +956,8 @@ static qse_ssize_t nwio_read (qse_nwio_t* nwio, void* buf, qse_size_t size)
addrlen = QSE_SIZEOF(addr);
if (nwio->tmout.a >= 0 &&
wait_for_data (nwio, nwio->tmout.a, 0) <= -1) return -1;
if (TMOUT_ENABLED(nwio->tmout.a) &&
wait_for_data (nwio, &nwio->tmout.a, 0) <= -1) return -1;
n = recvfrom (
nwio->handle, buf, size, 0,
@ -976,8 +980,8 @@ static qse_ssize_t nwio_read (qse_nwio_t* nwio, void* buf, qse_size_t size)
}
else
{
if (nwio->tmout.r >= 0 &&
wait_for_data (nwio, nwio->tmout.r, 0) <= -1) return -1;
if (TMOUT_ENABLED(nwio->tmout.r) &&
wait_for_data (nwio, &nwio->tmout.r, 0) <= -1) return -1;
n = recv (nwio->handle, buf, size, 0);
if (n <= -1) nwio->errnum = syserr_to_errnum (sock_errno());
@ -1012,8 +1016,8 @@ reread:
* like the 'nc' utility does.
* so i treat this recvfrom() as if it is accept().
*/
if (nwio->tmout.a >= 0 &&
wait_for_data (nwio, nwio->tmout.a, 0) <= -1) return -1;
if (TMOUT_ENABLED(nwio->tmout.a) &&
wait_for_data (nwio, &nwio->tmout.a, 0) <= -1) return -1;
n = recvfrom (
nwio->handle, buf, size, 0,
@ -1045,8 +1049,8 @@ reread:
}
else
{
if (nwio->tmout.r >= 0 &&
wait_for_data (nwio, nwio->tmout.r, 0) <= -1) return -1;
if (TMOUT_ENABLED(nwio->tmout.r) &&
wait_for_data (nwio, &nwio->tmout.r, 0) <= -1) return -1;
n = recv (nwio->handle, buf, size, 0);
if (n <= -1)
@ -1102,8 +1106,8 @@ static qse_ssize_t nwio_write (qse_nwio_t* nwio, const void* data, qse_size_t si
if (size > (QSE_TYPE_MAX(qse_ssize_t) & QSE_TYPE_MAX(int)))
size = QSE_TYPE_MAX(qse_ssize_t) & QSE_TYPE_MAX(int);
if (nwio->tmout.w >= 0 &&
wait_for_data (nwio, nwio->tmout.w, 1) <= -1) return -1;
if (TMOUT_ENABLED(nwio->tmout.w) &&
wait_for_data (nwio, &nwio->tmout.w, 1) <= -1) return -1;
count = send (nwio->handle, data, size, 0);
if (count == SOCKET_ERROR) nwio->errnum = syserr_to_errnum (WSAGetLastError());
@ -1114,8 +1118,8 @@ static qse_ssize_t nwio_write (qse_nwio_t* nwio, const void* data, qse_size_t si
if (size > (QSE_TYPE_MAX(qse_ssize_t) & QSE_TYPE_MAX(int)))
size = QSE_TYPE_MAX(qse_ssize_t) & QSE_TYPE_MAX(int);
if (nwio->tmout.w >= 0 &&
wait_for_data (nwio, nwio->tmout.w, 1) <= -1) return -1;
if (TMOUT_ENABLED(nwio->tmout.w) &&
wait_for_data (nwio, &nwio->tmout.w, 1) <= -1) return -1;
n = send (nwio->handle, data, size, 0);
if (n <= -1) nwio->errnum = syserr_to_errnum (sock_errno());
@ -1132,8 +1136,8 @@ static qse_ssize_t nwio_write (qse_nwio_t* nwio, const void* data, qse_size_t si
size = QSE_TYPE_MAX(qse_ssize_t) & QSE_TYPE_MAX(size_t);
rewrite:
if (nwio->tmout.w >= 0 &&
wait_for_data (nwio, nwio->tmout.w, 1) <= -1) return -1;
if (TMOUT_ENABLED(nwio->tmout.w) &&
wait_for_data (nwio, &nwio->tmout.w, 1) <= -1) return -1;
n = send (nwio->handle, data, size, 0);
if (n <= -1)

View File

@ -48,9 +48,8 @@
#define WIN_EPOCH_DAY (1)
#define EPOCH_DIFF_YEARS (QSE_EPOCH_YEAR-WIN_EPOCH_YEAR)
#define EPOCH_DIFF_DAYS ((qse_ntime_t)EPOCH_DIFF_YEARS*365+EPOCH_DIFF_YEARS/4-3)
#define EPOCH_DIFF_SECS ((qse_ntime_t)EPOCH_DIFF_DAYS*24*60*60)
#define EPOCH_DIFF_MSECS ((qse_ntime_t)EPOCH_DIFF_SECS*QSE_MSECS_PER_SEC)
#define EPOCH_DIFF_DAYS ((qse_long_t)EPOCH_DIFF_YEARS*365+EPOCH_DIFF_YEARS/4-3)
#define EPOCH_DIFF_SECS ((qse_long_t)EPOCH_DIFF_DAYS*24*60*60)
#endif
static const int mdays[2][QSE_MONS_PER_YEAR] =
@ -89,6 +88,7 @@ int qse_gettime (qse_ntime_t* t)
#if defined(_WIN32)
SYSTEMTIME st;
FILETIME ft;
ULARGE_INTEGER li;
/*
* MSDN: The FILETIME structure is a 64-bit value representing the
@ -97,8 +97,14 @@ int qse_gettime (qse_ntime_t* t)
GetSystemTime (&st);
if (SystemTimeToFileTime (&st, &ft) == FALSE) return -1;
*t = ((qse_ntime_t)(*((qse_int64_t*)&ft)) / (10 * 1000));
*t -= EPOCH_DIFF_MSECS;
li.LowPart = ft.dwLowDateTime;
li.HighPart = ft.dwHighDateTime;
/* li.QuadPart is in the 100-nanosecond intervals */
t->sec = (li.QuadPart / (QSE_NSECS_PER_SEC / 100)) - EPOCH_DIFF_SECS;
t->nsec = (li.QuadPart % (QSE_NSECS_PER_SEC / 100)) * 100;
return 0;
#elif defined(__OS2__)
@ -121,10 +127,11 @@ int qse_gettime (qse_ntime_t* t)
bt.hour = dt.hours;
bt.min = dt.minutes;
bt.sec = dt.seconds;
bt.msec = dt.hundredths * 10;
/*bt.msec = dt.hundredths * 10;*/
bt.isdst = -1; /* determine dst for me */
if (qse_timelocal (&bt, t) <= -1) return -1;
t->nsec = QSE_MSEC_TO_NSEC(dt.hundredths * 10);
return 0;
#elif defined(__DOS__)
@ -142,10 +149,11 @@ int qse_gettime (qse_ntime_t* t)
bt.hour = dt.hour;
bt.min = dt.minute;
bt.sec = dt.second;
bt.msec = dt.hsecond * 10;
/*bt.msec = dt.hsecond * 10; */
bt.isdst = -1; /* determine dst for me */
if (qse_timelocal (&bt, t) <= -1) return -1;
t->nsec = QSE_MSEC_TO_NSEC(dt.hsecond * 10);
return 0;
#else
@ -155,19 +163,21 @@ int qse_gettime (qse_ntime_t* t)
n = QSE_GETTIMEOFDAY (&tv, QSE_NULL);
if (n == -1) return -1;
*t = (qse_ntime_t)tv.tv_sec * QSE_MSECS_PER_SEC +
(qse_ntime_t)tv.tv_usec / QSE_USECS_PER_MSEC;
t->sec = tv.tv_sec;
t->nsec = QSE_USEC_TO_NSEC(tv.tv_usec);
return 0;
#endif
}
int qse_settime (qse_ntime_t t)
int qse_settime (const qse_ntime_t* t)
{
#if defined(_WIN32)
FILETIME ft;
SYSTEMTIME st;
*((qse_int64_t*)&ft) = ((t + EPOCH_DIFF_MSECS) * (10 * 1000));
/**((qse_int64_t*)&ft) = ((t + EPOCH_DIFF_MSECS) * (10 * 1000));*/
*((qse_int64_t*)&ft) =
(QSE_SEC_TO_NSEC(t->sec + EPOCH_DIFF_SECS) / 100) + (t->nsec / 100);
if (FileTimeToSystemTime (&ft, &st) == FALSE) return -1;
if (SetSystemTime(&st) == FALSE) return -1;
return 0;
@ -187,7 +197,7 @@ int qse_settime (qse_ntime_t t)
dt.hours = bt.hour;
dt.minutes = bt.min;
dt.seconds = bt.sec;
dt.hundredths = bt.msec / 10;
dt.hundredths = QSE_NSEC_TO_MSEC(t->nsec) / 10;
rc = DosSetDateTime (&dt);
return (rc != NO_ERROR)? -1: 0;
@ -206,7 +216,7 @@ int qse_settime (qse_ntime_t t)
dt.hour = bt.hour;
dt.minute = bt.min;
dt.second = bt.sec;
dt.hsecond = bt.msec / 10;
dt.hsecond = QSE_NSEC_TO_MSEC(t->nsec) / 10;
if (_dos_settime (&dt) != 0) return -1;
if (_dos_setdate (&dd) != 0) return -1;
@ -217,8 +227,8 @@ int qse_settime (qse_ntime_t t)
struct timeval tv;
int n;
tv.tv_sec = t / QSE_MSECS_PER_SEC;
tv.tv_usec = (t % QSE_MSECS_PER_SEC) * QSE_USECS_PER_MSEC;
tv.tv_sec = t->sec;
tv.tv_usec = QSE_NSEC_TO_USEC(t->nsec);
/*
#if defined CLOCK_REALTIME && HAVE_CLOCK_SETTIME
@ -237,19 +247,14 @@ int qse_settime (qse_ntime_t t)
#endif
}
static void breakdown_time (qse_ntime_t nt, qse_btime_t* bt, qse_ntoff_t offset)
static void breakdown_time (const qse_ntime_t* nt, qse_btime_t* bt, qse_long_t offset)
{
int midx;
qse_ntime_t days; /* total days */
qse_ntime_t secs; /* the remaining seconds */
qse_ntime_t year = QSE_EPOCH_YEAR;
qse_long_t days; /* total days */
qse_long_t secs; /* the remaining seconds */
qse_long_t year = QSE_EPOCH_YEAR;
nt += offset;
bt->msec = nt % QSE_MSECS_PER_SEC;
if (bt->msec < 0) bt->msec = QSE_MSECS_PER_SEC + bt->msec;
secs = nt / QSE_MSECS_PER_SEC;
secs = nt->sec + offset; /* offset in seconds */
days = secs / QSE_SECS_PER_DAY;
secs %= QSE_SECS_PER_DAY;
@ -305,17 +310,16 @@ static void breakdown_time (qse_ntime_t nt, qse_btime_t* bt, qse_ntoff_t offset)
/*bt->offset = offset;*/
}
int qse_gmtime (qse_ntime_t nt, qse_btime_t* bt)
int qse_gmtime (const qse_ntime_t* nt, qse_btime_t* bt)
{
breakdown_time (nt, bt, 0);
return 0;
}
int qse_localtime (qse_ntime_t nt, qse_btime_t* bt)
int qse_localtime (const qse_ntime_t* nt, qse_btime_t* bt)
{
struct tm* tm;
time_t t = (time_t)(nt / QSE_MSECS_PER_SEC);
qse_ntime_t rem = nt % QSE_MSECS_PER_SEC;
time_t t = nt->sec;
/* TODO: remove dependency on localtime/localtime_r */
#if defined(_WIN32)
@ -342,7 +346,6 @@ int qse_localtime (qse_ntime_t nt, qse_btime_t* bt)
QSE_MEMSET (bt, 0, QSE_SIZEOF(*bt));
bt->msec = (rem >= 0)? rem: (QSE_MSECS_PER_SEC + rem);
bt->sec = tm->tm_sec;
bt->min = tm->tm_min;
bt->hour = tm->tm_hour;
@ -409,7 +412,7 @@ int qse_timegm (const qse_btime_t* bt, qse_ntime_t* nt)
#endif
#endif
qse_ntime_t n = 0;
qse_long_t n = 0;
int y = bt->year + QSE_BTIME_YEAR_BASE;
int midx = QSE_IS_LEAPYEAR(y)? 1: 0;
@ -434,10 +437,13 @@ int qse_timegm (const qse_btime_t* bt, qse_ntime_t* nt)
n = (n + QSE_HOURS_PER_DAY - bt->hour - 1) * QSE_MINS_PER_HOUR;
n = (n + QSE_MINS_PER_HOUR - bt->min - 1) * QSE_SECS_PER_MIN;
n = (n + QSE_SECS_PER_MIN - bt->sec) * QSE_MSECS_PER_SEC;
n = (n + QSE_SECS_PER_MIN - bt->sec); /* * QSE_MSECS_PER_SEC;
if (bt->msec > 0) n += QSE_MSECS_PER_SEC - bt->msec;
*nt = -n;
*nt = -n; */
nt->sec = -n;
nt->nsec = 0;
}
else
{
@ -454,9 +460,12 @@ int qse_timegm (const qse_btime_t* bt, qse_ntime_t* nt)
n = (n + bt->mday - 1) * QSE_HOURS_PER_DAY;
n = (n + bt->hour) * QSE_MINS_PER_HOUR;
n = (n + bt->min) * QSE_SECS_PER_MIN;
n = (n + bt->sec) * QSE_MSECS_PER_SEC;
n = (n + bt->sec); /* QSE_MSECS_PER_SEC;
*nt = n + bt->msec;
*nt = n + bt->msec;*/
nt->sec = n;
nt->nsec = 0;
}
return 0;
@ -467,6 +476,7 @@ int qse_timelocal (const qse_btime_t* bt, qse_ntime_t* nt)
/* TODO: qse_timelocal - remove dependency on timelocal */
struct tm tm;
QSE_MEMSET (&tm, 0, QSE_SIZEOF(tm));
tm.tm_sec = bt->sec;
tm.tm_min = bt->min;
tm.tm_hour = bt->hour;
@ -477,11 +487,12 @@ int qse_timelocal (const qse_btime_t* bt, qse_ntime_t* nt)
tm.tm_yday = bt->yday;
tm.tm_isdst = bt->isdst;
#ifdef HAVE_TIMELOCAL
*nt = ((qse_ntime_t)timelocal(&tm)*QSE_MSECS_PER_SEC) + bt->msec;
return 0;
#if defined(HAVE_TIMELOCAL)
nt->sec = timelocal (&tm);
#else
*nt = ((qse_ntime_t)mktime(&tm)*QSE_MSECS_PER_SEC) + bt->msec;
return 0;
nt->sec = mktime (&tm);
#endif
nt->nsec = 0;
return 0;
}

View File

@ -369,7 +369,7 @@ int qse_parsehttptime (const qse_mchar_t* str, qse_ntime_t* nt)
}
qse_mchar_t* qse_fmthttptime (
qse_ntime_t nt, qse_mchar_t* buf, qse_size_t bufsz)
const qse_ntime_t* nt, qse_mchar_t* buf, qse_size_t bufsz)
{
qse_btime_t bt;

View File

@ -222,7 +222,9 @@ static QSE_INLINE int task_main_file (
qse_fmtuintmaxtombs (tmp[2], QSE_COUNTOF(tmp[2]), file->range.to, 10, -1, QSE_MT('\0'), QSE_NULL);
qse_fmtuintmaxtombs (tmp[3], QSE_COUNTOF(tmp[3]), st.size, 10, -1, QSE_MT('\0'), QSE_NULL);
etag_len = qse_fmtuintmaxtombs (&etag[0], QSE_COUNTOF(etag), st.mtime, 16, -1, QSE_MT('\0'), QSE_NULL);
etag_len = qse_fmtuintmaxtombs (&etag[0], QSE_COUNTOF(etag), st.mtime.sec, 16, -1, QSE_MT('\0'), QSE_NULL);
etag[etag_len++] = QSE_MT('-');
etag_len += qse_fmtuintmaxtombs (&etag[etag_len], QSE_COUNTOF(etag), st.mtime.nsec, 16, -1, QSE_MT('\0'), QSE_NULL);
etag[etag_len++] = QSE_MT('-');
etag_len += qse_fmtuintmaxtombs (&etag[etag_len], QSE_COUNTOF(etag) - etag_len, st.size, 16, -1, QSE_MT('\0'), QSE_NULL);
etag[etag_len++] = QSE_MT('-');
@ -258,7 +260,9 @@ static QSE_INLINE int task_main_file (
qse_mchar_t etag[ETAG_LEN_MAX + 1];
qse_size_t etag_len;
etag_len = qse_fmtuintmaxtombs (&etag[0], QSE_COUNTOF(etag), st.mtime, 16, -1, QSE_MT('\0'), QSE_NULL);
etag_len = qse_fmtuintmaxtombs (&etag[0], QSE_COUNTOF(etag), st.mtime.sec, 16, -1, QSE_MT('\0'), QSE_NULL);
etag[etag_len++] = QSE_MT('-');
etag_len += qse_fmtuintmaxtombs (&etag[etag_len], QSE_COUNTOF(etag), st.mtime.nsec, 16, -1, QSE_MT('\0'), QSE_NULL);
etag[etag_len++] = QSE_MT('-');
etag_len += qse_fmtuintmaxtombs (&etag[etag_len], QSE_COUNTOF(etag) - etag_len, st.size, 16, -1, QSE_MT('\0'), QSE_NULL);
etag[etag_len++] = QSE_MT('-');
@ -267,7 +271,7 @@ static QSE_INLINE int task_main_file (
etag_len += qse_fmtuintmaxtombs (&etag[etag_len], QSE_COUNTOF(etag) - etag_len, st.dev, 16, -1, QSE_MT('\0'), QSE_NULL);
if ((file->if_none_match[0] != QSE_MT('\0') && qse_mbscmp (etag, file->if_none_match) == 0) ||
(file->if_modified_since > 0 && QSE_MSEC_TO_SEC(st.mtime) <= QSE_MSEC_TO_SEC(file->if_modified_since)))
(file->if_modified_since.sec > 0 && st.mtime.sec <= file->if_modified_since.sec))
{
/* i've converted milliseconds to seconds before timestamp comparison
* because st.mtime has the actual milliseconds less than 1 second
@ -368,7 +372,10 @@ qse_httpd_task_t* qse_httpd_entaskfile (
{
while (tmp->next) tmp = tmp->next; /* get the last value */
if (qse_parsehttptime (tmp->ptr, &data.if_modified_since) <= -1)
data.if_modified_since = 0;
{
data.if_modified_since.sec = 0;
data.if_modified_since.nsec = 0;
}
}
}

View File

@ -1015,9 +1015,9 @@ static int mux_delhnd (qse_httpd_t* httpd, void* vmux, qse_ubi_t handle)
return 0;
}
static int mux_poll (qse_httpd_t* httpd, void* vmux, qse_ntime_t timeout)
static int mux_poll (qse_httpd_t* httpd, void* vmux, const qse_ntime_t* tmout)
{
if (qse_mux_poll ((qse_mux_t*)vmux, timeout) <= -1)
if (qse_mux_poll ((qse_mux_t*)vmux, tmout) <= -1)
{
/* TODO
qse_httpd_seterrnum (httpd, muxerr_to_errnum(mux));
@ -1028,15 +1028,15 @@ static int mux_poll (qse_httpd_t* httpd, void* vmux, qse_ntime_t timeout)
return 0;
}
static int mux_readable (qse_httpd_t* httpd, qse_ubi_t handle, qse_ntoff_t msec)
static int mux_readable (qse_httpd_t* httpd, qse_ubi_t handle, const qse_ntime_t* tmout)
{
fd_set r;
struct timeval tv, * tvp;
if (msec >= 0)
if (tmout)
{
tv.tv_sec = (msec / 1000);
tv.tv_usec = ((msec % 1000) * 1000);
tv.tv_sec = tmout->sec;
tv.tv_usec = tmout->nsec;
tvp = &tv;
}
else tvp = QSE_NULL;
@ -1047,15 +1047,15 @@ static int mux_readable (qse_httpd_t* httpd, qse_ubi_t handle, qse_ntoff_t msec)
return select (handle.i + 1, &r, QSE_NULL, QSE_NULL, tvp);
}
static int mux_writable (qse_httpd_t* httpd, qse_ubi_t handle, qse_ntoff_t msec)
static int mux_writable (qse_httpd_t* httpd, qse_ubi_t handle, const qse_ntime_t* tmout)
{
fd_set w;
struct timeval tv, * tvp;
if (msec >= 0)
if (tmout)
{
tv.tv_sec = (msec / 1000);
tv.tv_usec = ((msec % 1000) * 1000);
tv.tv_sec = tmout->sec;
tv.tv_usec = tmout->nsec;
tvp = &tv;
}
else tvp = QSE_NULL;
@ -1110,14 +1110,16 @@ static int stat_file (
hst->ino = st.st_ino;
hst->size = st.st_size;
#if defined(HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC)
hst->mtime = QSE_SECNSEC_TO_MSEC(st.st_mtim.tv_sec,st.st_mtim.tv_nsec);
hst->mtime.sec = st.st_mtim.tv_sec;
hst->mtime.nsec = st.st_mtim.tv_nsec;
#elif defined(HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC)
hst->mtime = QSE_SECNSEC_TO_MSEC(st.st_mtimespec.tv_sec,st.st_mtimespec.tv_nsec);
hst->mtime.sec = st.st_mtimespec.tv_sec;
hst->mtime.nsec = st.st_mtimespec.tv_nsec;
#else
hst->mtime = QSE_SEC_TO_MSEC(st.st_mtime);
hst->mtime.sec = st.st_mtime;
hst->mtime.nsec = 0;
#endif
qse_printf (QSE_T("mtime => %ld %ld\n"), (long)st.st_mtime, (long)hst->mtime);
return 0;
#endif
}
@ -1790,7 +1792,7 @@ static int format_dir (
return -1;
}
qse_localtime (dirent->stat.mtime, &bt);
qse_localtime (&dirent->stat.mtime, &bt);
snprintf (tmbuf, QSE_COUNTOF(tmbuf),
QSE_MT("%04d-%02d-%02d %02d:%02d:%02d"),
bt.year + QSE_BTIME_YEAR_BASE, bt.mon + 1, bt.mday,
@ -2431,9 +2433,9 @@ void* qse_httpd_getserverxtnstd (qse_httpd_t* httpd, qse_httpd_server_t* server)
/* ------------------------------------------------------------------- */
int qse_httpd_loopstd (qse_httpd_t* httpd, qse_ntime_t timeout)
int qse_httpd_loopstd (qse_httpd_t* httpd, const qse_ntime_t* tmout)
{
return qse_httpd_loop (
httpd, &httpd_system_callbacks,
&httpd_request_callbacks, timeout);
&httpd_request_callbacks, tmout);
}

View File

@ -765,7 +765,10 @@ qse_printf (QSE_T("ERROR: mute client got no more task [%d] failed...\n"), (int)
{
/* the task is invoked for triggers.
* check if the client handle is writable */
if (httpd->scb->mux.writable (httpd, client->handle, 0) <= 0)
qse_ntime_t tmout;
tmout.sec = 0;
tmout.nsec = 0;
if (httpd->scb->mux.writable (httpd, client->handle, &tmout) <= 0)
{
/* it is not writable yet. so just skip
* performing the actual task */
@ -1029,10 +1032,10 @@ static void purge_idle_clients (qse_httpd_t* httpd)
while (client)
{
next_client = client->next;
if (now <= client->last_active) break;
if (now - client->last_active < 30000) break; /* TODO: make this time configurable... */
if (now.sec <= client->last_active.sec) break;
if (now.sec - client->last_active.sec < 30) break; /* TODO: make this time configurable... */
qse_printf (QSE_T("PURGING IDLE CLIENT XXXXXXXXXXXXXX %d\n"), (int)(now - client->last_active));
qse_printf (QSE_T("PURGING IDLE CLIENT XXXXXXXXXXXXXX %d\n"), (int)(now.sec - client->last_active.sec));
purge_client (httpd, client);
client = next_client;
}
@ -1087,7 +1090,7 @@ static int dispatch_mux (
perform_client_task (httpd, mux, handle, mask, cbarg);
}
int qse_httpd_loop (qse_httpd_t* httpd, qse_httpd_scb_t* scb, qse_httpd_rcb_t* rcb, qse_ntime_t timeout)
int qse_httpd_loop (qse_httpd_t* httpd, qse_httpd_scb_t* scb, qse_httpd_rcb_t* rcb, const qse_ntime_t* tmout)
{
QSE_ASSERTX (httpd->server.list.head != QSE_NULL,
"Add listeners before calling qse_httpd_loop()");
@ -1131,7 +1134,7 @@ qse_printf (QSE_T("no servers are active....\n"));
{
int count;
count = httpd->scb->mux.poll (httpd, httpd->mux, timeout);
count = httpd->scb->mux.poll (httpd, httpd->mux, tmout);
if (count <= -1)
{
httpd->errnum = QSE_HTTPD_EIOMUX;
@ -1184,10 +1187,14 @@ const qse_mchar_t* qse_httpd_fmtgmtimetobb (
if (nt == QSE_NULL)
{
if (qse_gettime(&now) <= -1) now = 0;
if (qse_gettime(&now) <= -1)
{
now.sec = 0;
now.nsec = 0;
}
nt = &now;
}
qse_fmthttptime (*nt, httpd->gtbuf[idx], QSE_COUNTOF(httpd->gtbuf[idx]));
qse_fmthttptime (nt, httpd->gtbuf[idx], QSE_COUNTOF(httpd->gtbuf[idx]));
return httpd->gtbuf[idx];
}

View File

@ -226,7 +226,8 @@ static qse_upxd_server_session_t* find_server_session (
session->inner.client = *from;
/* set the default dormancy */
session->inner.config.dormancy = QSE_UPXD_SESSION_DORMANCY;
session->inner.config.dormancy.sec = QSE_UPXD_SESSION_DORMANCY;
session->inner.config.dormancy.nsec = 0;
/* call the configurationc callback for configuration data */
if (upxd->cbs->session.config (upxd, &session->inner) <= -1)
@ -455,9 +456,9 @@ static QSE_INLINE void purge_idle_sessions_in_server (
{
next = session->next;
if (session->inner.config.dormancy > 0 &&
now > session->modified &&
now - session->modified > session->inner.config.dormancy)
if (session->inner.config.dormancy.sec > 0 &&
now.sec > session->modified.sec &&
now.sec - session->modified.sec > session->inner.config.dormancy.sec)
{
release_session (upxd, session);
}

View File

@ -373,25 +373,56 @@ static int fnc_getegid (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
static int fnc_sleep (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
{
qse_long_t lv;
qse_flt_t fv;
qse_awk_val_t* retv;
int rx;
rx = qse_awk_rtx_valtolong (
rtx, qse_awk_rtx_getarg (rtx, 0), &lv);
if (rx >= 0)
rx = qse_awk_rtx_valtonum (rtx, qse_awk_rtx_getarg (rtx, 0), &lv, &fv);
if (rx == 0)
{
#if defined(_WIN32)
Sleep ((DWORD)(lv * 1000));
Sleep ((DWORD)QSE_SEC_TO_MSEC(lv));
rx = 0;
#elif defined(__OS2__)
DosSleep ((ULONG)(lv * 1000));
DosSleep ((ULONG)(QSE_SEC_TO_MSEC(lv));
rx = 0;
#elif defined(__DOS__)
rx = sleep (lv);
#elif defined(HAVE_NANOSLEEP)
struct timespec req;
req.tv_sec = lv;
req.tv_nsec = 0;
rx = nanosleep (&req, QSE_NULL);
#else
rx = sleep (lv);
#endif
}
else if (rx >= 1)
{
#if defined(_WIN32)
Sleep ((DWORD)QSE_SEC_TO_MSEC(fv));
rx = 0;
#elif defined(__OS2__)
DosSleep ((ULONG)QSE_SEC_TO_MSEC(fv));
rx = 0;
#elif defined(__DOS__)
/* no high-resolution sleep() is available */
rx = sleep ((qse_long_t)fv);
#elif defined(HAVE_NANOSLEEP)
struct timespec req;
req.tv_sec = (qse_long_t)fv;
req.tv_nsec = QSE_SEC_TO_NSEC(fv - req.tv_sec);
rx = nanosleep (&req, QSE_NULL);
#elif defined(HAVE_SELECT)
struct timeval req;
req.tv_sec = (qse_long_t)fv;
req.tv_nsec = QSE_SEC_TO_USEC(fv - req.tv_sec);
rx = select (0, QSE_NULL, QSE_NULL, QSE_NULL, &req);
#else
/* no high-resolution sleep() is available */
rx = sleep ((qse_long_t)fv);
#endif
}
retv = qse_awk_rtx_makeintval (rtx, rx);
if (retv == QSE_NULL) return -1;
@ -405,9 +436,9 @@ static int fnc_gettime (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
qse_awk_val_t* retv;
qse_ntime_t now;
if (qse_gettime (&now) <= -1) now = 0;
if (qse_gettime (&now) <= -1) now.sec = 0;
retv = qse_awk_rtx_makeintval (rtx, now);
retv = qse_awk_rtx_makeintval (rtx, now.sec);
if (retv == QSE_NULL) return -1;
qse_awk_rtx_setretval (rtx, retv);
@ -417,11 +448,13 @@ static int fnc_gettime (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
static int fnc_settime (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
{
qse_awk_val_t* retv;
qse_long_t now;
qse_ntime_t now;
int rx;
if (qse_awk_rtx_valtolong (rtx, qse_awk_rtx_getarg (rtx, 0), &now) <= -1 ||
qse_settime (now) <= -1) rx = -1;
now.nsec = 0;
if (qse_awk_rtx_valtolong (rtx, qse_awk_rtx_getarg (rtx, 0), &now.sec) <= -1 ||
qse_settime (&now) <= -1) rx = -1;
else rx = 0;
retv = qse_awk_rtx_makeintval (rtx, rx);

View File

@ -37,7 +37,7 @@ static void list (qse_fs_t* fs, const qse_char_t* name)
break;
}
qse_localtime (ent->time.modify, &bt);
qse_localtime (&ent->time.modify, &bt);
qse_printf (QSE_T("%s %16lu %04d-%02d-%02d %02d:%02d %s\n"),
((ent->type == QSE_FS_ENT_SUBDIR)? QSE_T("<D>"): QSE_T(" ")),
(unsigned long)ent->size,

View File

@ -17,14 +17,14 @@
if (f() == -1) return -1; \
} while (0)
void print_time (qse_ntime_t nt, const qse_btime_t* bt)
void print_time (const qse_ntime_t* nt, const qse_btime_t* bt)
{
#if defined(_WIN32)
qse_printf (QSE_T("TIME: %I64d\n"), (__int64)nt);
qse_printf (QSE_T("TIME: %I64d.%I64d\n"), (__int64)nt->sec, (__int64)nt->nsec);
#elif (QSE_SIZEOF_LONG_LONG > 0)
qse_printf (QSE_T("TIME: %lld\n"), (long long)nt);
qse_printf (QSE_T("TIME: %lld.%lld\n"), (long long)nt->sec, (long long)nt->nsec);
#else
qse_printf (QSE_T("TIME: %ld\n"), (long)nt);
qse_printf (QSE_T("TIME: %ld.%ld\n"), (long)nt->sec, (long)nt->nsec);
#endif
qse_printf (QSE_T("year: %d\n"), bt->year + QSE_BTIME_YEAR_BASE);
qse_printf (QSE_T("mon: %d\n"), bt->mon + 1);
@ -33,13 +33,14 @@ void print_time (qse_ntime_t nt, const qse_btime_t* bt)
qse_printf (QSE_T("hour: %d\n"), bt->hour);
qse_printf (QSE_T("min: %d\n"), bt->min);
qse_printf (QSE_T("sec: %d\n"), bt->sec);
qse_printf (QSE_T("msec: %d\n"), bt->msec);
/*qse_printf (QSE_T("msec: %d\n"), bt->msec);*/
}
static int test1 (void)
{
qse_ntime_t nt;
qse_btime_t bt;
int count = 0;
if (qse_gettime (&nt) == -1)
{
@ -47,67 +48,76 @@ static int test1 (void)
return -1;
}
qse_gmtime (nt, &bt);
print_time (nt, &bt);
qse_printf (QSE_T("-------------------------------\n"));
nt = 9999999;
if (qse_timegm (&bt, &nt) == -1)
do
{
qse_printf (QSE_T("cannot covert back to ntime\n"));
qse_gmtime (&nt, &bt);
print_time (&nt, &bt);
qse_printf (QSE_T("-------------------------------\n"));
}
else
{
if (qse_timegm (&bt, &nt) == -1)
{
qse_printf (QSE_T("cannot covert back to ntime\n"));
qse_printf (QSE_T("===================================\n"));
}
else
{
/* note that nt.nsec is set to 0 after qse_timegm()
* since qse_btime_t doesn't have the nsec field. */
#ifdef _WIN32
qse_printf (QSE_T("back to ntime: %I64d\n"), (__int64)nt);
qse_printf (QSE_T("back to ntime: %I64d.%I64d\n"), (__int64)nt.sec, (__int64)nt.nsec);
#elif (QSE_SIZEOF_LONG_LONG > 0)
qse_printf (QSE_T("back to ntime: %lld\n"), (long long)nt);
qse_printf (QSE_T("back to ntime: %lld.%lld\n"), (long long)nt.sec, (long long)nt.nsec);
#else
qse_printf (QSE_T("back to ntime: %ld\n"), (long)nt);
qse_printf (QSE_T("back to ntime: %ld\.%ldn"), (long)nt.sec, (long)nt.nsec);
#endif
qse_gmtime (nt, &bt);
print_time (nt, &bt);
qse_printf (QSE_T("-------------------------------\n"));
}
qse_gmtime (&nt, &bt);
print_time (&nt, &bt);
qse_printf (QSE_T("===================================\n"));
}
nt *= -1;
qse_gmtime (nt, &bt);
print_time (nt, &bt);
qse_printf (QSE_T("-------------------------------\n"));
if (count > 0) break;
nt.sec *= -1;
count++;
}
while (1);
nt.nsec = 0;
#if (QSE_SIZEOF_LONG_LONG > 0)
for (nt = (qse_ntime_t)QSE_TYPE_MIN(int); nt <= (qse_ntime_t)QSE_TYPE_MAX(int); nt += QSE_SECS_PER_DAY)
for (nt.sec = (qse_long_t)QSE_TYPE_MIN(int); nt.sec <= (qse_long_t)QSE_TYPE_MAX(int); nt.sec += QSE_SECS_PER_DAY)
#else
for (nt = QSE_TYPE_MIN(int); nt < (QSE_TYPE_MAX(int) - QSE_SECS_PER_DAY * 2); nt += QSE_SECS_PER_DAY)
for (nt.sec = QSE_TYPE_MIN(int); nt.sec < (QSE_TYPE_MAX(int) - QSE_SECS_PER_DAY * 2); nt.sec += QSE_SECS_PER_DAY)
#endif
{
#ifdef _WIN32
__time64_t t = (__time64_t)nt;
__time64_t t = (__time64_t)nt.sec;
#else
time_t t = (time_t)nt;
time_t t = (time_t)nt.sec;
#endif
qse_ntime_t qnt = nt * 1000;
qse_ntime_t qnt;
struct tm* tm;
qse_ntime_t xx;
if (qnt >= 0) qnt += rand() % 1000;
else qnt -= rand() % 1000;
qnt = nt;
#if 0
if (qnt.sec >= 0) qnt.sec += rand() % 1000;
else qnt.sec -= rand() % 1000;
#endif
#ifdef _WIN32
tm = _gmtime64 (&t);
#else
tm = gmtime (&t);
#endif
qse_gmtime (qnt, &bt);
qse_gmtime (&qnt, &bt);
#ifdef _WIN32
qse_printf (QSE_T(">>> time %I64d: "), (__int64)qnt);
qse_printf (QSE_T(">>> time %I64d.%I64d: "), (__int64)qnt.sec, (__int64)qnt.nsec);
#elif (QSE_SIZEOF_LONG_LONG > 0)
qse_printf (QSE_T(">>> time %lld: "), (long long)qnt);
qse_printf (QSE_T(">>> time %lld.%lld: "), (long long)qnt.sec, (long long)qnt.nsec);
#else
qse_printf (QSE_T(">>> time %ld: "), (long)qnt);
qse_printf (QSE_T(">>> time %ld.%ld: "), (long)qnt.sec, (long)qnt.nsec);
#endif
if (tm == QSE_NULL ||
@ -127,7 +137,7 @@ static int test1 (void)
qse_printf (QSE_T("[GMTIME ERROR %ld]\n"), (long)t);
#endif
if (tm == QSE_NULL) qse_printf (QSE_T(">> GMTIME RETURNED NULL\n"));
print_time (qnt, &bt);
print_time (&qnt, &bt);
qse_printf (QSE_T("-------------------------------\n"));
}
else
@ -141,18 +151,18 @@ static int test1 (void)
}
else
{
if (xx == qnt)
if (xx.sec == qnt.sec && xx.nsec == qnt.nsec)
{
qse_printf (QSE_T("[TIMEGM OK %d/%d/%d %d:%d:%d]\n"), bt.year + QSE_BTIME_YEAR_BASE, bt.mon + 1, bt.mday, bt.hour, bt.min, bt.sec);
}
else
{
#ifdef _WIN32
qse_printf (QSE_T("[TIMEGM ERROR %I64d, %d/%d/%d %d:%d:%d]\n"), (__int64)xx, bt.year + QSE_BTIME_YEAR_BASE, bt.mon + 1, bt.mday, bt.hour, bt.min, bt.sec);
qse_printf (QSE_T("[TIMEGM ERROR %I64d.%I64d, %d/%d/%d %d:%d:%d]\n"), (__int64)xx.sec, (__int64)xx.nsec, bt.year + QSE_BTIME_YEAR_BASE, bt.mon + 1, bt.mday, bt.hour, bt.min, bt.sec);
#elif (QSE_SIZEOF_LONG_LONG > 0)
qse_printf (QSE_T("[TIMEGM ERROR %lld, %d/%d/%d %d:%d:%d]\n"), (long long)xx, bt.year + QSE_BTIME_YEAR_BASE, bt.mon + 1, bt.mday, bt.hour, bt.min, bt.sec);
qse_printf (QSE_T("[TIMEGM ERROR %lld.%lld, %d/%d/%d %d:%d:%d]\n"), (long long)xx.sec, (long long)xx.nsec, bt.year + QSE_BTIME_YEAR_BASE, bt.mon + 1, bt.mday, bt.hour, bt.min, bt.sec);
#else
qse_printf (QSE_T("[TIMEGM ERROR %ld, %d/%d/%d %d:%d:%d]\n"), (long)xx, bt.year + QSE_BTIME_YEAR_BASE, bt.mon + 1, bt.mday, bt.hour, bt.min, bt.sec);
qse_printf (QSE_T("[TIMEGM ERROR %ld.%ld, %d/%d/%d %d:%d:%d]\n"), (long)xx.sec, (long)xx.nsec, bt.year + QSE_BTIME_YEAR_BASE, bt.mon + 1, bt.mday, bt.hour, bt.min, bt.sec);
#endif
}
}

View File

@ -41,6 +41,7 @@ static void sigint (int sig)
static int httpd_main (int argc, qse_char_t* argv[])
{
qse_httpd_t* httpd = QSE_NULL;
qse_ntime_t tmout;
int ret = -1, i;
if (argc <= 1)
@ -79,7 +80,10 @@ static int httpd_main (int argc, qse_char_t* argv[])
signal (SIGPIPE, SIG_IGN);
qse_httpd_setoption (httpd, QSE_HTTPD_CGIERRTONUL);
ret = qse_httpd_loopstd (httpd, 10000);
tmout.sec = 10;
tmout.nsec = 0;
ret = qse_httpd_loopstd (httpd, &tmout);
signal (SIGINT, SIG_DFL);
signal (SIGPIPE, SIG_DFL);

View File

@ -184,6 +184,7 @@ static qse_httpd_server_t* attach_server (
static int httpd_main (int argc, qse_char_t* argv[])
{
qse_httpd_t* httpd = QSE_NULL;
qse_ntime_t tmout;
int ret = -1, i;
static qse_httpd_server_cbstd_t cbstd = { makersrc, freersrc };
@ -217,7 +218,10 @@ static int httpd_main (int argc, qse_char_t* argv[])
qse_httpd_setname (httpd, QSE_MT("httpd02/qse 1.0"));
qse_httpd_setoption (httpd, QSE_HTTPD_CGIERRTONUL);
ret = qse_httpd_loopstd (httpd, 10000);
tmout.sec = 10;
tmout.nsec = 0;
ret = qse_httpd_loopstd (httpd, &tmout);
signal (SIGINT, SIG_DFL);
signal (SIGPIPE, SIG_DFL);