-
Notifications
You must be signed in to change notification settings - Fork 192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dest.c: Use monotonic time for cups_enum_dest #1084
base: 2.4.x
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -224,6 +224,8 @@ AC_COMPILE_IFELSE([ | |
dnl See if we have the removefile(3) function for securely removing files | ||
AC_CHECK_FUNCS([removefile]) | ||
|
||
dnl See if | ||
|
||
dnl See if we have libusb... | ||
AC_ARG_ENABLE([libusb], AS_HELP_STRING([--enable-libusb], [use libusb for USB printing])) | ||
|
||
|
@@ -448,6 +450,22 @@ AC_DEFINE_UNQUOTED([CUPS_DEFAULT_SYSTEM_AUTHKEY], ["$CUPS_DEFAULT_SYSTEM_AUTHKEY | |
AC_SUBST([CUPS_SYSTEM_AUTHKEY]) | ||
AC_SUBST([INSTALLXPC]) | ||
|
||
dnl Check if monotonic clock is available | ||
AC_MSG_CHECKING([for monotonic clock]) | ||
AC_LINK_IFELSE([AC_LANG_PROGRAM([ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should be enough to check that |
||
#include <stdlib.h> | ||
#include <time.h> | ||
],[ | ||
struct timespec t; | ||
clock_gettime(CLOCK_MONOTONIC, &t); | ||
]) | ||
],[ | ||
AC_MSG_RESULT([yes]) | ||
AC_DEFINE(HAVE_CLOCK_MONOTONIC) | ||
],[ | ||
AC_MSG_RESULT([no]) | ||
]) | ||
|
||
dnl Check for build components | ||
COMPONENTS="all" | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -138,6 +138,18 @@ typedef struct _cups_namedata_s | |
cups_dest_t *dest; /* Destination */ | ||
} _cups_namedata_t; | ||
|
||
typedef struct _cups_time_s | ||
{ | ||
#if _WIN32 | ||
DWORD t; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd actually like to do away with this kind of structure here - let's just use a |
||
#elif HAVE_CLOCK_MONOTONIC | ||
struct timespec t; | ||
#elif __sun | ||
hrtime_t t; | ||
#else | ||
struct timeval t; | ||
#endif | ||
} _cups_time_t; | ||
|
||
/* | ||
* Local functions... | ||
|
@@ -223,7 +235,8 @@ static const char *cups_dnssd_resolve(cups_dest_t *dest, const char *uri, | |
static int cups_dnssd_resolve_cb(void *context); | ||
static void cups_dnssd_unquote(char *dst, const char *src, | ||
size_t dstsize); | ||
static int cups_elapsed(struct timespec *t); | ||
static void cups_gettimeofday(_cups_time_t *t); | ||
static int cups_elapsed(_cups_time_t *t); | ||
#endif /* HAVE_DNSSD */ | ||
static int cups_enum_dests(http_t *http, unsigned flags, int msec, int *cancel, cups_ptype_t type, cups_ptype_t mask, cups_dest_cb_t cb, void *user_data); | ||
static int cups_find_dest(const char *name, const char *instance, | ||
|
@@ -3400,21 +3413,63 @@ cups_dnssd_unquote(char *dst, /* I - Destination buffer */ | |
} | ||
|
||
|
||
/* | ||
* 'cups_gettimeofday()' - Get the sharpest time possible | ||
*/ | ||
|
||
static void | ||
cups_gettimeofday(_cups_time_t *t) | ||
{ | ||
#if _WIN32 | ||
t->t = GetTickCount(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need to use GetTickCount64, otherwise we have a 49 day wrap problem. |
||
#elif HAVE_CLOCK_MONOTONIC | ||
clock_gettime(CLOCK_MONOTONIC, &t->t); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Even if |
||
#elif __sun | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's not bother with Solaris-specific functions. We don't have any Solaris testing resources. |
||
t->t = gethrtime(); | ||
#else | ||
gettimeofday(&t->t, NULL); | ||
#endif | ||
} | ||
|
||
/* | ||
* 'cups_elapsed()' - Return the elapsed time in milliseconds. | ||
*/ | ||
|
||
static int /* O - Elapsed time in milliseconds */ | ||
cups_elapsed(struct timespec *t) // IO - Previous time | ||
cups_elapsed(_cups_time_t *t) // IO - Previous time | ||
{ | ||
int msecs; /* Milliseconds */ | ||
|
||
#if _WIN32 | ||
DWORD cur = GetTickCount(); | ||
|
||
msecs = (int)(cur - t->t); | ||
|
||
t->t = cur; | ||
|
||
#elif HAVE_CLOCK_MONOTONIC | ||
struct timespec nt; // New time | ||
|
||
clock_gettime(CLOCK_MONOTONIC, &nt); | ||
|
||
msecs = (int)(1000 * (nt.tv_sec - t->tv_sec) + (nt.tv_nsec - t->tv_nsec) / 1000 / 1000); | ||
msecs = (int)(1000 * (nt.tv_sec - t->t.tv_sec) + (nt.tv_nsec - t->t.tv_nsec) / 1000000); | ||
|
||
*t->t = nt; | ||
#elif __sun | ||
hrtime_t cur = gethrtime(); | ||
|
||
*t = nt; | ||
msecs = (int)(cur - t->t); | ||
|
||
t->t = cur; | ||
#else | ||
struct timeval nt; | ||
|
||
gettimeofday(&nt, NULL); | ||
|
||
msecs = (int)(1000 * (nt.tv_sec - t->t.tv_sec) + (nt.tv_usec - t->t.tv_usec) / 1000); | ||
|
||
*t->t = nt; | ||
#endif | ||
|
||
return (msecs); | ||
} | ||
|
@@ -3446,7 +3501,7 @@ cups_enum_dests( | |
int count, /* Number of queries started */ | ||
completed, /* Number of completed queries */ | ||
remaining; /* Remainder of timeout */ | ||
struct timespec curtime; // Current time | ||
_cups_time_t curtime; // Current time | ||
_cups_dnssd_data_t data; /* Data for callback */ | ||
_cups_dnssd_device_t *device; /* Current device */ | ||
# ifdef HAVE_MDNSRESPONDER | ||
|
@@ -3672,7 +3727,7 @@ cups_enum_dests( | |
* Get Bonjour-shared printers... | ||
*/ | ||
|
||
clock_gettime(CLOCK_MONOTONIC, &curtime); | ||
cups_gettimeofday(&curtime); | ||
|
||
# ifdef HAVE_MDNSRESPONDER | ||
if (DNSServiceCreateConnection(&data.main_ref) != kDNSServiceErr_NoError) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
???