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 fi
done done
for ac_func in fork vfork posix_spawn gettid for ac_func in fork vfork posix_spawn gettid nanosleep select
do : do :
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var" ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
@ -18565,6 +18565,16 @@ cat >>confdefs.h <<_ACEOF
_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 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" 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 _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 fi

View File

@ -124,7 +124,7 @@ AC_CHECK_FUNCS([utime utimes])
AC_CHECK_FUNCS([sysconf]) AC_CHECK_FUNCS([sysconf])
AC_CHECK_FUNCS([backtrace backtrace_symbols]) AC_CHECK_FUNCS([backtrace backtrace_symbols])
AC_CHECK_FUNCS([fdopendir]) 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([makecontext swapcontext getcontext setcontext])
AC_CHECK_FUNCS([if_nametoindex if_indextoname]) 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_STRUCT_DIRENT_D_TYPE
AC_CHECK_MEMBERS([struct stat.st_birthtime]) AC_CHECK_MEMBERS([struct stat.st_birthtime])
AC_CHECK_MEMBERS([struct stat.st_mtim.tv_nsec]) 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_mtimespec.tv_nsec])
AC_CHECK_MEMBERS([struct stat.st_birthtimespec.tv_nsec])
dnl check the size of primitive data types dnl check the size of primitive data types
AC_CHECK_SIZEOF(char,,[[]]) AC_CHECK_SIZEOF(char,,[[]])

View File

@ -648,6 +648,7 @@ public:
int getInt (long_t* v) const; int getInt (long_t* v) const;
int getFlt (flt_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 getStr (const char_t** str, size_t* len) const;
int setVal (val_t* v); int setVal (val_t* v);

View File

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

View File

@ -29,6 +29,7 @@
#include <qse/macros.h> #include <qse/macros.h>
#include <qse/cmn/tio.h> #include <qse/cmn/tio.h>
#include <qse/cmn/nwad.h> #include <qse/cmn/nwad.h>
#include <qse/cmn/time.h>
enum qse_nwio_flag_t enum qse_nwio_flag_t
{ {
@ -74,7 +75,7 @@ typedef enum qse_nwio_errnum_t qse_nwio_errnum_t;
struct qse_nwio_tmout_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; 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_USEC (1000)
#define QSE_NSECS_PER_MSEC (QSE_NSECS_PER_USEC*QSE_USECS_PER_MSEC) #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_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_IS_LEAPYEAR(year) ((!((year)%4) && ((year)%100)) || !((year)%400))
#define QSE_DAYS_PER_YEAR(year) \ #define QSE_DAYS_PER_YEAR(year) \
(QSE_IS_LEAPYEAR(year)? QSE_DAYS_PER_LEAPYEAR: QSE_DAYS_PER_NORMYEAR) (QSE_IS_LEAPYEAR(year)? QSE_DAYS_PER_LEAPYEAR: QSE_DAYS_PER_NORMYEAR)
#define QSE_SECNSEC_TO_MSEC(sec,nsec) \ #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_SEC_TO_MSEC(sec) ((sec) * QSE_MSECS_PER_SEC)
#define QSE_MSEC_TO_SEC(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 * 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). * number of milliseconds since the Epoch (00:00:00 UTC, Jan 1, 1970).
*/ */
typedef qse_long_t qse_ntime_t; typedef struct qse_ntime_t qse_ntime_t;
struct qse_ntime_t
/** {
* The qse_ntprd_t type represents a time period between two time points. qse_long_t sec;
* This is period is defined to be unsigned since a time point is signed. qse_int32_t nsec; /* nanoseconds */
*/ };
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_btime_t qse_btime_t; typedef struct qse_btime_t qse_btime_t;
struct qse_btime_t struct qse_btime_t
{ {
int msec; /* 0-999 */
int sec; /* 0-61 */ int sec; /* 0-61 */
int min; /* 0-59 */ int min; /* 0-59 */
int hour; /* 0-23 */ int hour; /* 0-23 */
@ -118,7 +120,7 @@ int qse_gettime (
* The qse_settime() function sets the current time. * The qse_settime() function sets the current time.
*/ */
int qse_settime ( 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. * The qse_gmtime() function converts numeric time to broken-down time.
*/ */
int qse_gmtime ( int qse_gmtime (
qse_ntime_t nt, const qse_ntime_t* nt,
qse_btime_t* bt qse_btime_t* bt
); );
/** /**
* The qse_localtime() converts numeric time to broken-down time * The qse_localtime() converts numeric time to broken-down time
*/ */
int qse_localtime ( int qse_localtime (
qse_ntime_t nt, const qse_ntime_t* nt,
qse_btime_t* bt qse_btime_t* bt
); );
/** /**
@ -157,16 +159,6 @@ int qse_timelocal (
qse_ntime_t* nt 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 #ifdef __cplusplus
} }
#endif #endif

View File

@ -248,6 +248,9 @@
/* Define to 1 if you have MPI libs and headers. */ /* Define to 1 if you have MPI libs and headers. */
#undef HAVE_MPI #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'. */ /* Define to 1 if you have the <ndir.h> header file, and it defines `DIR'. */
#undef HAVE_NDIR_H #undef HAVE_NDIR_H
@ -293,6 +296,9 @@
/* Define to 1 if you have the `roundl' function. */ /* Define to 1 if you have the `roundl' function. */
#undef HAVE_ROUNDL #undef HAVE_ROUNDL
/* Define to 1 if you have the `select' function. */
#undef HAVE_SELECT
/* Define to 1 if you have the `sendfile' function. */ /* Define to 1 if you have the `sendfile' function. */
#undef HAVE_SENDFILE #undef HAVE_SENDFILE
@ -374,6 +380,12 @@
/* Define to 1 if `st_birthtime' is a member of `struct stat'. */ /* Define to 1 if `st_birthtime' is a member of `struct stat'. */
#undef HAVE_STRUCT_STAT_ST_BIRTHTIME #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'. */ /* Define to 1 if `st_mtimespec.tv_nsec' is a member of `struct stat'. */
#undef HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC #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_EXPORT qse_mchar_t* qse_fmthttptime (
qse_ntime_t nt, const qse_ntime_t* nt,
qse_mchar_t* buf, qse_mchar_t* buf,
qse_size_t bufsz qse_size_t bufsz
); );

View File

@ -137,12 +137,12 @@ struct qse_httpd_scb_t
void (*close) (qse_httpd_t* httpd, void* mux); 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 (*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 (*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) ( 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) ( 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; } mux;
struct struct
@ -580,10 +580,10 @@ QSE_EXPORT void qse_httpd_pushecb (
* The qse_httpd_loop() function starts a httpd server loop. * The qse_httpd_loop() function starts a httpd server loop.
*/ */
QSE_EXPORT int qse_httpd_loop ( QSE_EXPORT int qse_httpd_loop (
qse_httpd_t* httpd, qse_httpd_t* httpd,
qse_httpd_scb_t* scb, qse_httpd_scb_t* scb,
qse_httpd_rcb_t* rcb, qse_httpd_rcb_t* rcb,
qse_ntime_t timeout const qse_ntime_t* tmout
); );
/** /**
@ -845,7 +845,7 @@ QSE_EXPORT void* qse_httpd_getserverxtnstd (
QSE_EXPORT int qse_httpd_loopstd ( QSE_EXPORT int qse_httpd_loopstd (
qse_httpd_t* httpd, 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 */ /** binding device for peer socket */
qse_char_t dev[QSE_UPXD_SESSION_DEV_LEN + 1]; 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 */ /** session's idle-timeout */
qse_ntime_t dormancy; qse_ntime_t dormancy;
} config; } config;

View File

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

View File

@ -160,7 +160,7 @@ int StdAwk::open ()
qse_ntime_t now; 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 don't care if the seed becomes negative or overflows.
* i just convert the signed value to the unsigned one. */ * i just convert the signed value to the unsigned one. */
this->prand = (qse_ulong_t)(this->seed * this->seed * this->seed); 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) if (nargs <= 0)
{ {
this->seed = (qse_gettime (&now) <= -1)? 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 else
{ {
@ -478,16 +478,28 @@ int StdAwk::setioattr (
int tmout; int tmout;
if ((tmout = timeout_code (ptr[1])) >= 0) 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]); ioattr_t* ioattr = find_or_make_ioattr (ptr[0], l[0]);
if (ioattr == QSE_NULL) return -1; 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); return ret.setInt ((long_t)0);
} }
#if defined(QSE_CHAR_IS_WCHAR) #if defined(QSE_CHAR_IS_WCHAR)
@ -541,7 +553,10 @@ int StdAwk::getioattr (
int tmout; int tmout;
if ((tmout = timeout_code(ptr[1])) >= 0) 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) #if defined(QSE_CHAR_IS_WCHAR)
else if (qse_strcasecmp (ptr[1], QSE_T("codepage")) == 0) 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_cmgr_t* cmgr;
qse_char_t cmgr_name[64]; /* i assume that the cmgr name never exceeds this length */ 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; } ioattr_t;
static ioattr_t* get_ioattr (qse_htb_t* tab, const qse_char_t* ptr, qse_size_t len); 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; rxtn->ecb.close = fini_rxtn;
qse_awk_rtx_pushecb (rtx, &rxtn->ecb); 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 don't care if the seed becomes negative or overflows.
* i just convert the signed value to the unsigned one. */ * i just convert the signed value to the unsigned one. */
rxtn->prand = (qse_ulong_t)(rxtn->seed * rxtn->seed * rxtn->seed); 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) if (nargs <= 0)
{ {
rxtn->seed = (qse_gettime (&now) <= -1)? 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 else
{ {
@ -2212,7 +2212,8 @@ static QSE_INLINE void init_ioattr (ioattr_t* ioattr)
for (i = 0; i < QSE_COUNTOF(ioattr->tmout); i++) for (i = 0; i < QSE_COUNTOF(ioattr->tmout); i++)
{ {
/* a negative number for no timeout */ /* 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 /* no error is returned by qse_awk_rtx_strnum() if the second
* parameter is 0. so i don't check for an error */ * parameter is 0. so i don't check for an error */
x = qse_awk_rtx_strtonum (rtx, 0, ptr[2], len[2], &l, &r); 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]); ioattr = find_or_make_ioattr (rtx, &rxtn->cmgrtab, ptr[0], len[0]);
if (ioattr == QSE_NULL) 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; 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) #if defined(QSE_CHAR_IS_WCHAR)
else if (qse_strcasecmp (ptr[1], QSE_T("codepage")) == 0) 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) 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) if (rv == QSE_NULL)
{ {
ret = -1; ret = -1;

View File

@ -258,7 +258,7 @@ int qse_fio_init (
} }
qse_gettime (&now); qse_gettime (&now);
temp_no += (now & 0xFFFFFFFFlu); temp_no += (now.sec & 0xFFFFFFFFlu);
temp_tries = 0; temp_tries = 0;
temp_ptr -= 4; 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) #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 */ /* reverse of http://support.microsoft.com/kb/167296/en-us */
ULARGE_INTEGER li; ULARGE_INTEGER li;
li.LowPart = ft->dwLowDateTime; li.LowPart = ft->dwLowDateTime;
li.HighPart = ft->dwHighDateTime; 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 # error Unsupported 64bit integer type
#endif #endif
/*li.QuadPart /= 10000000;*/ /*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 #endif
@ -511,9 +515,9 @@ qse_fs_ent_t* qse_fs_read (qse_fs_t* fs, int flags)
if (flags & QSE_FS_ENT_TIME) if (flags & QSE_FS_ENT_TIME)
{ {
fs->ent.time.create = filetime_to_ntime (&info->wfd.ftCreationTime); filetime_to_ntime (&info->wfd.ftCreationTime, &fs->ent.time.create);
fs->ent.time.access = filetime_to_ntime (&info->wfd.ftLastAccessTime); filetime_to_ntime (&info->wfd.ftLastAccessTime, &fs->ent.time.access);
fs->ent.time.modify = filetime_to_ntime (&info->wfd.ftLastWriteTime); filetime_to_ntime (&info->wfd.ftLastWriteTime, &fs->ent.time.modify);
fs->ent.type |= QSE_FS_ENT_TIME; 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 (flags & QSE_FS_ENT_TIME)
{ {
#if defined(HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC) #if defined(HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC)
#if defined(HAVE_STRUCT_STAT_ST_BIRTHTIME) #if defined(HAVE_STRUCT_STAT_ST_BIRTHTIM_TV_NSEC)
fs->ent.time.create = fs->ent.time.create.secs = st.st_birthtim.tv_sec;
QSE_SECNSEC_TO_MSEC(st.st_birthtim.tv_sec,st.st_birthtim.tv_nsec); fs->ent.time.create.nsecs = st.st_birthtim.tv_nsec;
#endif #endif
fs->ent.time.access =
QSE_SECNSEC_TO_MSEC(st.st_atim.tv_sec,st.st_atim.tv_nsec); fs->ent.time.access.sec = st.st_atim.tv_sec;
fs->ent.time.modify = fs->ent.time.access.nsec = st.st_atim.tv_nsec;
QSE_SECNSEC_TO_MSEC(st.st_mtim.tv_sec,st.st_mtim.tv_nsec); fs->ent.time.modify.sec = st.st_mtim.tv_sec;
fs->ent.time.change = fs->ent.time.modify.nsec = st.st_mtim.tv_nsec;
QSE_SECNSEC_TO_MSEC(st.st_ctim.tv_sec,st.st_ctim.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) #elif defined(HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC)
#if defined(HAVE_STRUCT_STAT_ST_BIRTHTIME) #if defined(HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC_TV_NSEC)
fs->ent.time.create = st.st_birthtime; fs->ent.time.create.sec = st.st_birthtimespec.tv_sec;
QSE_SECNSEC_TO_MSEC(st.st_birthtimespec.tv_sec,st.st_birthtimespec.tv_nsec); fs->ent.time.create.nsec = st.st_birthtimespec.tv_nsec;
#endif #endif
fs->ent.time.access =
QSE_SECNSEC_TO_MSEC(st.st_atimespec.tv_sec,st.st_atimespec.tv_nsec); fs->ent.time.access.sec = st.st_atimspec.tv_sec;
fs->ent.time.modify = fs->ent.time.access.nsec = st.st_atimspec.tv_nsec;
QSE_SECNSEC_TO_MSEC(st.st_mtimespec.tv_sec,st.st_mtimespec.tv_nsec); fs->ent.time.modify.sec = st.st_mtimspec.tv_sec;
fs->ent.time.change = fs->ent.time.modify.nsec = st.st_mtimspec.tv_nsec;
QSE_SECNSEC_TO_MSEC(st.st_ctimespec.tv_sec,st.st_ctimespec.tv_nsec); fs->ent.time.change.sec = st.st_ctimspec.tv_sec;
fs->ent.time.change.nsec = st.st_ctimspec.tv_nsec;
#else #else
#if defined(HAVE_STRUCT_STAT_ST_BIRTHTIME) #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 #endif
fs->ent.time.access = st.st_atime * QSE_MSECS_PER_SEC; fs->ent.time.access.sec = st.st_atime;
fs->ent.time.modify = st.st_mtime * QSE_MSECS_PER_SEC; fs->ent.time.modify.sec = st.st_mtime;
fs->ent.time.change = st.st_ctime * QSE_MSECS_PER_SEC; fs->ent.time.change.sec = st.st_ctime;
#endif #endif
fs->ent.flags |= QSE_FS_ENT_TIME; fs->ent.flags |= QSE_FS_ENT_TIME;
} }

View File

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

View File

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

View File

@ -48,9 +48,8 @@
#define WIN_EPOCH_DAY (1) #define WIN_EPOCH_DAY (1)
#define EPOCH_DIFF_YEARS (QSE_EPOCH_YEAR-WIN_EPOCH_YEAR) #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_DAYS ((qse_long_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_SECS ((qse_long_t)EPOCH_DIFF_DAYS*24*60*60)
#define EPOCH_DIFF_MSECS ((qse_ntime_t)EPOCH_DIFF_SECS*QSE_MSECS_PER_SEC)
#endif #endif
static const int mdays[2][QSE_MONS_PER_YEAR] = static const int mdays[2][QSE_MONS_PER_YEAR] =
@ -89,6 +88,7 @@ int qse_gettime (qse_ntime_t* t)
#if defined(_WIN32) #if defined(_WIN32)
SYSTEMTIME st; SYSTEMTIME st;
FILETIME ft; FILETIME ft;
ULARGE_INTEGER li;
/* /*
* MSDN: The FILETIME structure is a 64-bit value representing the * MSDN: The FILETIME structure is a 64-bit value representing the
@ -97,8 +97,14 @@ int qse_gettime (qse_ntime_t* t)
GetSystemTime (&st); GetSystemTime (&st);
if (SystemTimeToFileTime (&st, &ft) == FALSE) return -1; 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; return 0;
#elif defined(__OS2__) #elif defined(__OS2__)
@ -121,10 +127,11 @@ int qse_gettime (qse_ntime_t* t)
bt.hour = dt.hours; bt.hour = dt.hours;
bt.min = dt.minutes; bt.min = dt.minutes;
bt.sec = dt.seconds; bt.sec = dt.seconds;
bt.msec = dt.hundredths * 10; /*bt.msec = dt.hundredths * 10;*/
bt.isdst = -1; /* determine dst for me */ bt.isdst = -1; /* determine dst for me */
if (qse_timelocal (&bt, t) <= -1) return -1; if (qse_timelocal (&bt, t) <= -1) return -1;
t->nsec = QSE_MSEC_TO_NSEC(dt.hundredths * 10);
return 0; return 0;
#elif defined(__DOS__) #elif defined(__DOS__)
@ -142,10 +149,11 @@ int qse_gettime (qse_ntime_t* t)
bt.hour = dt.hour; bt.hour = dt.hour;
bt.min = dt.minute; bt.min = dt.minute;
bt.sec = dt.second; bt.sec = dt.second;
bt.msec = dt.hsecond * 10; /*bt.msec = dt.hsecond * 10; */
bt.isdst = -1; /* determine dst for me */ bt.isdst = -1; /* determine dst for me */
if (qse_timelocal (&bt, t) <= -1) return -1; if (qse_timelocal (&bt, t) <= -1) return -1;
t->nsec = QSE_MSEC_TO_NSEC(dt.hsecond * 10);
return 0; return 0;
#else #else
@ -155,19 +163,21 @@ int qse_gettime (qse_ntime_t* t)
n = QSE_GETTIMEOFDAY (&tv, QSE_NULL); n = QSE_GETTIMEOFDAY (&tv, QSE_NULL);
if (n == -1) return -1; if (n == -1) return -1;
*t = (qse_ntime_t)tv.tv_sec * QSE_MSECS_PER_SEC + t->sec = tv.tv_sec;
(qse_ntime_t)tv.tv_usec / QSE_USECS_PER_MSEC; t->nsec = QSE_USEC_TO_NSEC(tv.tv_usec);
return 0; return 0;
#endif #endif
} }
int qse_settime (qse_ntime_t t) int qse_settime (const qse_ntime_t* t)
{ {
#if defined(_WIN32) #if defined(_WIN32)
FILETIME ft; FILETIME ft;
SYSTEMTIME st; 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 (FileTimeToSystemTime (&ft, &st) == FALSE) return -1;
if (SetSystemTime(&st) == FALSE) return -1; if (SetSystemTime(&st) == FALSE) return -1;
return 0; return 0;
@ -187,7 +197,7 @@ int qse_settime (qse_ntime_t t)
dt.hours = bt.hour; dt.hours = bt.hour;
dt.minutes = bt.min; dt.minutes = bt.min;
dt.seconds = bt.sec; dt.seconds = bt.sec;
dt.hundredths = bt.msec / 10; dt.hundredths = QSE_NSEC_TO_MSEC(t->nsec) / 10;
rc = DosSetDateTime (&dt); rc = DosSetDateTime (&dt);
return (rc != NO_ERROR)? -1: 0; return (rc != NO_ERROR)? -1: 0;
@ -206,7 +216,7 @@ int qse_settime (qse_ntime_t t)
dt.hour = bt.hour; dt.hour = bt.hour;
dt.minute = bt.min; dt.minute = bt.min;
dt.second = bt.sec; 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_settime (&dt) != 0) return -1;
if (_dos_setdate (&dd) != 0) return -1; if (_dos_setdate (&dd) != 0) return -1;
@ -217,8 +227,8 @@ int qse_settime (qse_ntime_t t)
struct timeval tv; struct timeval tv;
int n; int n;
tv.tv_sec = t / QSE_MSECS_PER_SEC; tv.tv_sec = t->sec;
tv.tv_usec = (t % QSE_MSECS_PER_SEC) * QSE_USECS_PER_MSEC; tv.tv_usec = QSE_NSEC_TO_USEC(t->nsec);
/* /*
#if defined CLOCK_REALTIME && HAVE_CLOCK_SETTIME #if defined CLOCK_REALTIME && HAVE_CLOCK_SETTIME
@ -237,19 +247,14 @@ int qse_settime (qse_ntime_t t)
#endif #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; int midx;
qse_ntime_t days; /* total days */ qse_long_t days; /* total days */
qse_ntime_t secs; /* the remaining seconds */ qse_long_t secs; /* the remaining seconds */
qse_ntime_t year = QSE_EPOCH_YEAR; qse_long_t year = QSE_EPOCH_YEAR;
nt += offset; secs = nt->sec + offset; /* offset in seconds */
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;
days = secs / QSE_SECS_PER_DAY; days = secs / QSE_SECS_PER_DAY;
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;*/ /*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); breakdown_time (nt, bt, 0);
return 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; struct tm* tm;
time_t t = (time_t)(nt / QSE_MSECS_PER_SEC); time_t t = nt->sec;
qse_ntime_t rem = nt % QSE_MSECS_PER_SEC;
/* TODO: remove dependency on localtime/localtime_r */ /* TODO: remove dependency on localtime/localtime_r */
#if defined(_WIN32) #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)); QSE_MEMSET (bt, 0, QSE_SIZEOF(*bt));
bt->msec = (rem >= 0)? rem: (QSE_MSECS_PER_SEC + rem);
bt->sec = tm->tm_sec; bt->sec = tm->tm_sec;
bt->min = tm->tm_min; bt->min = tm->tm_min;
bt->hour = tm->tm_hour; bt->hour = tm->tm_hour;
@ -409,7 +412,7 @@ int qse_timegm (const qse_btime_t* bt, qse_ntime_t* nt)
#endif #endif
#endif #endif
qse_ntime_t n = 0; qse_long_t n = 0;
int y = bt->year + QSE_BTIME_YEAR_BASE; int y = bt->year + QSE_BTIME_YEAR_BASE;
int midx = QSE_IS_LEAPYEAR(y)? 1: 0; 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_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_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; if (bt->msec > 0) n += QSE_MSECS_PER_SEC - bt->msec;
*nt = -n; *nt = -n; */
nt->sec = -n;
nt->nsec = 0;
} }
else 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->mday - 1) * QSE_HOURS_PER_DAY;
n = (n + bt->hour) * QSE_MINS_PER_HOUR; n = (n + bt->hour) * QSE_MINS_PER_HOUR;
n = (n + bt->min) * QSE_SECS_PER_MIN; 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; 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 */ /* TODO: qse_timelocal - remove dependency on timelocal */
struct tm tm; struct tm tm;
QSE_MEMSET (&tm, 0, QSE_SIZEOF(tm));
tm.tm_sec = bt->sec; tm.tm_sec = bt->sec;
tm.tm_min = bt->min; tm.tm_min = bt->min;
tm.tm_hour = bt->hour; 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_yday = bt->yday;
tm.tm_isdst = bt->isdst; tm.tm_isdst = bt->isdst;
#ifdef HAVE_TIMELOCAL #if defined(HAVE_TIMELOCAL)
*nt = ((qse_ntime_t)timelocal(&tm)*QSE_MSECS_PER_SEC) + bt->msec; nt->sec = timelocal (&tm);
return 0;
#else #else
*nt = ((qse_ntime_t)mktime(&tm)*QSE_MSECS_PER_SEC) + bt->msec; nt->sec = mktime (&tm);
return 0;
#endif #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_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; 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[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); 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[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_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('-'); 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_mchar_t etag[ETAG_LEN_MAX + 1];
qse_size_t etag_len; 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[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_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('-'); 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); 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) || 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 /* i've converted milliseconds to seconds before timestamp comparison
* because st.mtime has the actual milliseconds less than 1 second * 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 */ while (tmp->next) tmp = tmp->next; /* get the last value */
if (qse_parsehttptime (tmp->ptr, &data.if_modified_since) <= -1) 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; 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 /* TODO
qse_httpd_seterrnum (httpd, muxerr_to_errnum(mux)); 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; 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; fd_set r;
struct timeval tv, * tvp; struct timeval tv, * tvp;
if (msec >= 0) if (tmout)
{ {
tv.tv_sec = (msec / 1000); tv.tv_sec = tmout->sec;
tv.tv_usec = ((msec % 1000) * 1000); tv.tv_usec = tmout->nsec;
tvp = &tv; tvp = &tv;
} }
else tvp = QSE_NULL; 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); 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; fd_set w;
struct timeval tv, * tvp; struct timeval tv, * tvp;
if (msec >= 0) if (tmout)
{ {
tv.tv_sec = (msec / 1000); tv.tv_sec = tmout->sec;
tv.tv_usec = ((msec % 1000) * 1000); tv.tv_usec = tmout->nsec;
tvp = &tv; tvp = &tv;
} }
else tvp = QSE_NULL; else tvp = QSE_NULL;
@ -1110,14 +1110,16 @@ static int stat_file (
hst->ino = st.st_ino; hst->ino = st.st_ino;
hst->size = st.st_size; hst->size = st.st_size;
#if defined(HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC) #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) #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 #else
hst->mtime = QSE_SEC_TO_MSEC(st.st_mtime); hst->mtime.sec = st.st_mtime;
hst->mtime.nsec = 0;
#endif #endif
qse_printf (QSE_T("mtime => %ld %ld\n"), (long)st.st_mtime, (long)hst->mtime);
return 0; return 0;
#endif #endif
} }
@ -1790,7 +1792,7 @@ static int format_dir (
return -1; return -1;
} }
qse_localtime (dirent->stat.mtime, &bt); qse_localtime (&dirent->stat.mtime, &bt);
snprintf (tmbuf, QSE_COUNTOF(tmbuf), snprintf (tmbuf, QSE_COUNTOF(tmbuf),
QSE_MT("%04d-%02d-%02d %02d:%02d:%02d"), QSE_MT("%04d-%02d-%02d %02d:%02d:%02d"),
bt.year + QSE_BTIME_YEAR_BASE, bt.mon + 1, bt.mday, 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 ( return qse_httpd_loop (
httpd, &httpd_system_callbacks, 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. /* the task is invoked for triggers.
* check if the client handle is writable */ * 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 /* it is not writable yet. so just skip
* performing the actual task */ * performing the actual task */
@ -1029,10 +1032,10 @@ static void purge_idle_clients (qse_httpd_t* httpd)
while (client) while (client)
{ {
next_client = client->next; next_client = client->next;
if (now <= client->last_active) break; if (now.sec <= client->last_active.sec) break;
if (now - client->last_active < 30000) break; /* TODO: make this time configurable... */ 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); purge_client (httpd, client);
client = next_client; client = next_client;
} }
@ -1087,7 +1090,7 @@ static int dispatch_mux (
perform_client_task (httpd, mux, handle, mask, cbarg); 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, QSE_ASSERTX (httpd->server.list.head != QSE_NULL,
"Add listeners before calling qse_httpd_loop()"); "Add listeners before calling qse_httpd_loop()");
@ -1131,7 +1134,7 @@ qse_printf (QSE_T("no servers are active....\n"));
{ {
int count; int count;
count = httpd->scb->mux.poll (httpd, httpd->mux, timeout); count = httpd->scb->mux.poll (httpd, httpd->mux, tmout);
if (count <= -1) if (count <= -1)
{ {
httpd->errnum = QSE_HTTPD_EIOMUX; httpd->errnum = QSE_HTTPD_EIOMUX;
@ -1184,10 +1187,14 @@ const qse_mchar_t* qse_httpd_fmtgmtimetobb (
if (nt == QSE_NULL) if (nt == QSE_NULL)
{ {
if (qse_gettime(&now) <= -1) now = 0; if (qse_gettime(&now) <= -1)
{
now.sec = 0;
now.nsec = 0;
}
nt = &now; 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]; return httpd->gtbuf[idx];
} }

View File

@ -226,7 +226,8 @@ static qse_upxd_server_session_t* find_server_session (
session->inner.client = *from; session->inner.client = *from;
/* set the default dormancy */ /* 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 */ /* call the configurationc callback for configuration data */
if (upxd->cbs->session.config (upxd, &session->inner) <= -1) 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; next = session->next;
if (session->inner.config.dormancy > 0 && if (session->inner.config.dormancy.sec > 0 &&
now > session->modified && now.sec > session->modified.sec &&
now - session->modified > session->inner.config.dormancy) now.sec - session->modified.sec > session->inner.config.dormancy.sec)
{ {
release_session (upxd, session); 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) static int fnc_sleep (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
{ {
qse_long_t lv; qse_long_t lv;
qse_flt_t fv;
qse_awk_val_t* retv; qse_awk_val_t* retv;
int rx; int rx;
rx = qse_awk_rtx_valtolong ( rx = qse_awk_rtx_valtonum (rtx, qse_awk_rtx_getarg (rtx, 0), &lv, &fv);
rtx, qse_awk_rtx_getarg (rtx, 0), &lv); if (rx == 0)
if (rx >= 0)
{ {
#if defined(_WIN32) #if defined(_WIN32)
Sleep ((DWORD)(lv * 1000)); Sleep ((DWORD)QSE_SEC_TO_MSEC(lv));
rx = 0; rx = 0;
#elif defined(__OS2__) #elif defined(__OS2__)
DosSleep ((ULONG)(lv * 1000)); DosSleep ((ULONG)(QSE_SEC_TO_MSEC(lv));
rx = 0; rx = 0;
#elif defined(__DOS__) #elif defined(__DOS__)
rx = sleep (lv); rx = sleep (lv);
#elif defined(HAVE_NANOSLEEP)
struct timespec req;
req.tv_sec = lv;
req.tv_nsec = 0;
rx = nanosleep (&req, QSE_NULL);
#else #else
rx = sleep (lv); rx = sleep (lv);
#endif #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); retv = qse_awk_rtx_makeintval (rtx, rx);
if (retv == QSE_NULL) return -1; 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_awk_val_t* retv;
qse_ntime_t now; 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; if (retv == QSE_NULL) return -1;
qse_awk_rtx_setretval (rtx, retv); 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) static int fnc_settime (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
{ {
qse_awk_val_t* retv; qse_awk_val_t* retv;
qse_long_t now; qse_ntime_t now;
int rx; int rx;
if (qse_awk_rtx_valtolong (rtx, qse_awk_rtx_getarg (rtx, 0), &now) <= -1 || now.nsec = 0;
qse_settime (now) <= -1) rx = -1;
if (qse_awk_rtx_valtolong (rtx, qse_awk_rtx_getarg (rtx, 0), &now.sec) <= -1 ||
qse_settime (&now) <= -1) rx = -1;
else rx = 0; else rx = 0;
retv = qse_awk_rtx_makeintval (rtx, rx); 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; 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"), qse_printf (QSE_T("%s %16lu %04d-%02d-%02d %02d:%02d %s\n"),
((ent->type == QSE_FS_ENT_SUBDIR)? QSE_T("<D>"): QSE_T(" ")), ((ent->type == QSE_FS_ENT_SUBDIR)? QSE_T("<D>"): QSE_T(" ")),
(unsigned long)ent->size, (unsigned long)ent->size,

View File

@ -17,14 +17,14 @@
if (f() == -1) return -1; \ if (f() == -1) return -1; \
} while (0) } 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) #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) #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 #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 #endif
qse_printf (QSE_T("year: %d\n"), bt->year + QSE_BTIME_YEAR_BASE); qse_printf (QSE_T("year: %d\n"), bt->year + QSE_BTIME_YEAR_BASE);
qse_printf (QSE_T("mon: %d\n"), bt->mon + 1); 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("hour: %d\n"), bt->hour);
qse_printf (QSE_T("min: %d\n"), bt->min); qse_printf (QSE_T("min: %d\n"), bt->min);
qse_printf (QSE_T("sec: %d\n"), bt->sec); 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) static int test1 (void)
{ {
qse_ntime_t nt; qse_ntime_t nt;
qse_btime_t bt; qse_btime_t bt;
int count = 0;
if (qse_gettime (&nt) == -1) if (qse_gettime (&nt) == -1)
{ {
@ -47,67 +48,76 @@ static int test1 (void)
return -1; return -1;
} }
qse_gmtime (nt, &bt); do
print_time (nt, &bt);
qse_printf (QSE_T("-------------------------------\n"));
nt = 9999999;
if (qse_timegm (&bt, &nt) == -1)
{ {
qse_printf (QSE_T("cannot covert back to ntime\n")); qse_gmtime (&nt, &bt);
print_time (&nt, &bt);
qse_printf (QSE_T("-------------------------------\n")); 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 #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) #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 #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 #endif
qse_gmtime (nt, &bt); qse_gmtime (&nt, &bt);
print_time (nt, &bt); print_time (&nt, &bt);
qse_printf (QSE_T("-------------------------------\n")); qse_printf (QSE_T("===================================\n"));
} }
nt *= -1; if (count > 0) break;
qse_gmtime (nt, &bt);
print_time (nt, &bt); nt.sec *= -1;
qse_printf (QSE_T("-------------------------------\n")); count++;
}
while (1);
nt.nsec = 0;
#if (QSE_SIZEOF_LONG_LONG > 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 #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 #endif
{ {
#ifdef _WIN32 #ifdef _WIN32
__time64_t t = (__time64_t)nt; __time64_t t = (__time64_t)nt.sec;
#else #else
time_t t = (time_t)nt; time_t t = (time_t)nt.sec;
#endif #endif
qse_ntime_t qnt = nt * 1000; qse_ntime_t qnt;
struct tm* tm; struct tm* tm;
qse_ntime_t xx; qse_ntime_t xx;
if (qnt >= 0) qnt += rand() % 1000; qnt = nt;
else qnt -= rand() % 1000; #if 0
if (qnt.sec >= 0) qnt.sec += rand() % 1000;
else qnt.sec -= rand() % 1000;
#endif
#ifdef _WIN32 #ifdef _WIN32
tm = _gmtime64 (&t); tm = _gmtime64 (&t);
#else #else
tm = gmtime (&t); tm = gmtime (&t);
#endif #endif
qse_gmtime (qnt, &bt); qse_gmtime (&qnt, &bt);
#ifdef _WIN32 #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) #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 #else
qse_printf (QSE_T(">>> time %ld: "), (long)qnt); qse_printf (QSE_T(">>> time %ld.%ld: "), (long)qnt.sec, (long)qnt.nsec);
#endif #endif
if (tm == QSE_NULL || if (tm == QSE_NULL ||
@ -127,7 +137,7 @@ static int test1 (void)
qse_printf (QSE_T("[GMTIME ERROR %ld]\n"), (long)t); qse_printf (QSE_T("[GMTIME ERROR %ld]\n"), (long)t);
#endif #endif
if (tm == QSE_NULL) qse_printf (QSE_T(">> GMTIME RETURNED NULL\n")); 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")); qse_printf (QSE_T("-------------------------------\n"));
} }
else else
@ -141,18 +151,18 @@ static int test1 (void)
} }
else 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); 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 else
{ {
#ifdef _WIN32 #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) #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 #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 #endif
} }
} }

View File

@ -41,6 +41,7 @@ static void sigint (int sig)
static int httpd_main (int argc, qse_char_t* argv[]) static int httpd_main (int argc, qse_char_t* argv[])
{ {
qse_httpd_t* httpd = QSE_NULL; qse_httpd_t* httpd = QSE_NULL;
qse_ntime_t tmout;
int ret = -1, i; int ret = -1, i;
if (argc <= 1) if (argc <= 1)
@ -79,7 +80,10 @@ static int httpd_main (int argc, qse_char_t* argv[])
signal (SIGPIPE, SIG_IGN); signal (SIGPIPE, SIG_IGN);
qse_httpd_setoption (httpd, QSE_HTTPD_CGIERRTONUL); 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 (SIGINT, SIG_DFL);
signal (SIGPIPE, 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[]) static int httpd_main (int argc, qse_char_t* argv[])
{ {
qse_httpd_t* httpd = QSE_NULL; qse_httpd_t* httpd = QSE_NULL;
qse_ntime_t tmout;
int ret = -1, i; int ret = -1, i;
static qse_httpd_server_cbstd_t cbstd = { makersrc, freersrc }; 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_setname (httpd, QSE_MT("httpd02/qse 1.0"));
qse_httpd_setoption (httpd, QSE_HTTPD_CGIERRTONUL); 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 (SIGINT, SIG_DFL);
signal (SIGPIPE, SIG_DFL); signal (SIGPIPE, SIG_DFL);