Nilorea Library
C utilities for networking, threading, graphics
Loading...
Searching...
No Matches
TIMERS: generally used headers, defines, timers, allocators,...

Data Structures

struct  N_TIME
 Timing Structure. More...

Macros

#define N_TIME_HTTP_DATE_LEN   30
 buffer size for n_time_http_date(): "Thu, 01 Jan 1970 00:00:00 GMT" + NUL
#define N_TIME_RFC2822_LEN   32
 buffer size for n_time_rfc2822(): "Thu, 01 Jan 1970 00:00:00 +0000" + NUL
#define N_TIME_RFC3339_LEN   26
 buffer size for n_time_rfc3339(): "1970-01-01T00:00:00+00:00" + NUL

Functions

time_t get_msec (N_TIME *timer)
 Poll any N_TIME HiTimer, returning msec.
time_t get_sec (N_TIME *timer)
 Poll any N_TIME HiTimer, returning sec.
time_t get_usec (N_TIME *timer)
 Poll any N_TIME HiTimer, returning usec.
int n_time_http_date (time_t t, char *out, size_t size)
 format t as an HTTP date (RFC 9110 IMF-fixdate, always GMT)
int n_time_parse_http_date (const char *s, size_t len, time_t *t)
 parse an HTTP date in IMF-fixdate form ("Sun, 06 Nov 1994 08:49:37 GMT")
int n_time_parse_rfc3339 (const char *s, size_t len, time_t *t)
 parse "YYYY-MM-DD[T| ]HH:MM:SS[Z|+hh:mm|-hh:mm]"
int n_time_rfc2822 (time_t t, long offset, char *out, size_t size)
 format t as an RFC 2822 date with a numeric offset, as RSS wants
int n_time_rfc3339 (time_t t, long offset, char *out, size_t size)
 format t as RFC 3339 / ISO 8601 with a numeric offset
void PAUSE (void)
 for the 'press a key to continue'
int start_HiTimer (N_TIME *timer)
 Init or restart from zero any N_TIME HiTimer.
void u_sleep (unsigned int usec)
 sleep for the given number of microseconds

Detailed Description


Data Structure Documentation

◆ N_TIME

struct N_TIME
Collaboration diagram for N_TIME:
Data Fields
struct timeval currentTime current time
time_t delta time since last poll
struct timeval startTime start time

Macro Definition Documentation

◆ N_TIME_HTTP_DATE_LEN

#define N_TIME_HTTP_DATE_LEN   30

buffer size for n_time_http_date(): "Thu, 01 Jan 1970 00:00:00 GMT" + NUL

Examples
ex_time_formats.c.

Definition at line 90 of file n_time.h.

Referenced by n_http_response_head(), n_time_http_date(), and test_format().

◆ N_TIME_RFC2822_LEN

#define N_TIME_RFC2822_LEN   32

buffer size for n_time_rfc2822(): "Thu, 01 Jan 1970 00:00:00 +0000" + NUL

Examples
ex_time_formats.c.

Definition at line 92 of file n_time.h.

Referenced by n_time_rfc2822(), and test_format().

◆ N_TIME_RFC3339_LEN

#define N_TIME_RFC3339_LEN   26

buffer size for n_time_rfc3339(): "1970-01-01T00:00:00+00:00" + NUL

Examples
ex_time_formats.c.

Definition at line 94 of file n_time.h.

Referenced by n_time_rfc3339(), and test_format().

Function Documentation

◆ get_msec()

time_t get_msec ( N_TIME * timer)

Poll any N_TIME HiTimer, returning msec.

Poll any N_TIME HiTimer, returning msec.

Parameters
timerAny N_TIMER *timer you wanna poll
Returns
The elapsed number of msec for the given N_TIME *timer

Definition at line 129 of file n_time.c.

References __n_assert, N_TIME::currentTime, N_TIME::delta, and N_TIME::startTime.

Referenced by main(), and main().

Here is the caller graph for this function:

◆ get_sec()

time_t get_sec ( N_TIME * timer)

Poll any N_TIME HiTimer, returning sec.

Poll any N_TIME HiTimer, returning sec.

Parameters
timerAny N_TIMER *timer you wanna poll
Returns
The elapsed number of sec for the given N_TIME *timer

Definition at line 150 of file n_time.c.

References __n_assert, N_TIME::currentTime, N_TIME::delta, and N_TIME::startTime.

◆ get_usec()

time_t get_usec ( N_TIME * timer)

Poll any N_TIME HiTimer, returning usec.

Poll any N_TIME HiTimer, returning usec.

Parameters
timerAny N_TIMER *timer you wanna poll
Returns
The elapsed number of usec for the given N_TIME *timer

Definition at line 108 of file n_time.c.

References __n_assert, N_TIME::currentTime, N_TIME::delta, and N_TIME::startTime.

Referenced by _netw_timed_connect(), main(), main(), manage_particle(), n_kafka_polling_thread(), and netw_connect_ex_to().

Here is the caller graph for this function:

◆ n_time_http_date()

int n_time_http_date ( time_t t,
char * out,
size_t size )

format t as an HTTP date (RFC 9110 IMF-fixdate, always GMT)

For Date, Last-Modified and Expires. Pure calendar arithmetic: no locale, no TZ, no gmtime(), the same result on every platform. Years 1 to 9999.

Parameters
tseconds since the Unix epoch
outdestination, at least N_TIME_HTTP_DATE_LEN bytes
sizesize of out
Returns
TRUE, or FALSE when out is NULL / too small or t out of range
Parameters
tseconds since the Unix epoch
outdestination, at least N_TIME_HTTP_DATE_LEN bytes
sizesize of out
Returns
TRUE, or FALSE when out is NULL / too small or t out of range

Definition at line 237 of file n_time.c.

References _civil_of(), _month_names, _wday_names, _n_civil::hour, _n_civil::mday, _n_civil::min, _n_civil::mon, N_TIME_HTTP_DATE_LEN, _n_civil::sec, _n_civil::wday_idx, and _n_civil::year.

Referenced by n_http_response_head(), test_format(), and test_parse().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ n_time_parse_http_date()

int n_time_parse_http_date ( const char * s,
size_t len,
time_t * t )

parse an HTTP date in IMF-fixdate form ("Sun, 06 Nov 1994 08:49:37 GMT")

Strict: exactly that shape, a weekday that matches the date, real calendar values (no Feb 30, no hour 24, no leap second). The obsolete RFC 850 and asctime forms are refused; a caller handling If-Modified-Since then just ignores the header, which is always safe.

Parameters
sthe text (may be NULL only when len is 0)
lenits length
treceives seconds since the Unix epoch
Returns
TRUE on success, FALSE otherwise

parse an HTTP date in IMF-fixdate form ("Sun, 06 Nov 1994 08:49:37 GMT")

Parameters
sthe text (may be NULL only when len is 0)
lenits length
treceives seconds since the Unix epoch
Returns
TRUE on success, FALSE otherwise

Definition at line 313 of file n_time.c.

References _civil_of(), _civil_to_time(), _digits(), _month_names, _wday_names, h(), and _n_civil::wday_idx.

Referenced by parses(), and test_parse().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ n_time_parse_rfc3339()

int n_time_parse_rfc3339 ( const char * s,
size_t len,
time_t * t )

parse "YYYY-MM-DD[T| ]HH:MM:SS[Z|+hh:mm|-hh:mm]"

RFC 3339 timestamps, and the SQL "YYYY-MM-DD HH:MM:SS" form; without a zone the time is UTC. No fractional seconds. Calendar values checked.

Parameters
sthe text (may be NULL only when len is 0)
lenits length
treceives seconds since the Unix epoch
Returns
TRUE on success, FALSE otherwise

parse "YYYY-MM-DD[T| ]HH:MM:SS[Z|+hh:mm|-hh:mm]"

Parameters
sthe text (may be NULL only when len is 0)
lenits length
treceives seconds since the Unix epoch
Returns
TRUE on success, FALSE otherwise

Definition at line 340 of file n_time.c.

References _civil_to_time(), _digits(), and h().

Referenced by parses(), and test_parse().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ n_time_rfc2822()

int n_time_rfc2822 ( time_t t,
long offset,
char * out,
size_t size )

format t as an RFC 2822 date with a numeric offset, as RSS wants

"Thu, 01 Jan 1970 01:00:00 +0100": the local time at offset seconds east of UTC (PHP's date(DATE_RSS) output for that zone).

Parameters
tseconds since the Unix epoch
offsetoffset from UTC in seconds, a multiple of 60, |offset| < 86400
outdestination, at least N_TIME_RFC2822_LEN bytes
sizesize of out
Returns
TRUE, or FALSE on a bad argument

format t as an RFC 2822 date with a numeric offset, as RSS wants

Parameters
tseconds since the Unix epoch
offsetoffset from UTC in seconds, a multiple of 60, |offset| < 86400
outdestination, at least N_TIME_RFC2822_LEN bytes
sizesize of out
Returns
TRUE, or FALSE on a bad argument

Definition at line 254 of file n_time.c.

References _civil_of(), _month_names, _offset_ok(), _wday_names, _n_civil::hour, _n_civil::mday, _n_civil::min, _n_civil::mon, N_TIME_RFC2822_LEN, _n_civil::sec, _n_civil::wday_idx, and _n_civil::year.

Referenced by test_format().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ n_time_rfc3339()

int n_time_rfc3339 ( time_t t,
long offset,
char * out,
size_t size )

format t as RFC 3339 / ISO 8601 with a numeric offset

"1970-01-01T01:00:00+01:00" (PHP's date('c') for that zone; offset 0 gives "+00:00", not "Z").

Parameters
tseconds since the Unix epoch
offsetoffset from UTC in seconds, a multiple of 60, |offset| < 86400
outdestination, at least N_TIME_RFC3339_LEN bytes
sizesize of out
Returns
TRUE, or FALSE on a bad argument

format t as RFC 3339 / ISO 8601 with a numeric offset

Parameters
tseconds since the Unix epoch
offsetoffset from UTC in seconds, a multiple of 60, |offset| < 86400
outdestination, at least N_TIME_RFC3339_LEN bytes
sizesize of out
Returns
TRUE, or FALSE on a bad argument

Definition at line 272 of file n_time.c.

References _civil_of(), _offset_ok(), _n_civil::hour, _n_civil::mday, _n_civil::min, _n_civil::mon, N_TIME_RFC3339_LEN, _n_civil::sec, and _n_civil::year.

Referenced by test_format(), and test_parse().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ PAUSE()

void PAUSE ( void )

for the 'press a key to continue'

for the 'press a key to continue'

Definition at line 63 of file n_time.c.

References LOG_DEBUG, LOG_ERR, and n_log.

◆ start_HiTimer()

int start_HiTimer ( N_TIME * timer)

Init or restart from zero any N_TIME HiTimer.

Init or restart from zero any N_TIME HiTimer.

Parameters
timerAny N_TIMER *timer you wanna start or reset
Returns
TRUE or FALSE

Definition at line 86 of file n_time.c.

References __n_assert, N_TIME::delta, and N_TIME::startTime.

Referenced by _netw_timed_connect(), init_particle_system(), main(), main(), main(), n_kafka_polling_thread(), and netw_connect_ex_to().

Here is the caller graph for this function:

◆ u_sleep()

void u_sleep ( unsigned int usec)

sleep for the given number of microseconds

sleep for the given number of microseconds

Parameters
usecNumber of usec to sleep

Definition at line 55 of file n_time.c.

Referenced by destroy_threaded_pool(), handle_client(), main(), main(), main(), manage_client(), netw_accept_pool_thread_func(), netw_send_func(), netw_wait_msg(), recv_ssl_data(), run_client(), run_server(), send_ssl_data(), and wait_for_threaded_pool().

Here is the caller graph for this function: