Skip to content

Commit

Permalink
docs and minor details
Browse files Browse the repository at this point in the history
  • Loading branch information
boazsegev committed Nov 25, 2024
1 parent 768c3e3 commit 8c7b08d
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 80 deletions.
88 changes: 49 additions & 39 deletions fio-stl.h
Original file line number Diff line number Diff line change
Expand Up @@ -10623,7 +10623,7 @@ OS specific patches.
#include <afunix.h>
#endif
#ifndef FIO_SOCK_FD_ISVALID
#define FIO_SOCK_FD_ISVALID(fd) ((size_t)fd <= (size_t)0x7FFFFFFF)
#define FIO_SOCK_FD_ISVALID(fd) ((size_t)(fd) <= (size_t)0x7FFFFFFF)
#endif
/** Acts as POSIX write. Use this macro for portability with WinSock2. */
#define fio_sock_write(fd, data, len) send((fd), (data), (len), 0)
Expand Down Expand Up @@ -34749,7 +34749,11 @@ struct fio_io_protocol_s {
* even if the client did not consume all buffered data.
*/
void (*on_shutdown)(fio_io_s *io);
/** Called when a connection's timeout was reached */
/**
* Called when a connection's timeout was reached
*
* Can be set to `fio_io_touch` if timeout is irrelevant (i.e., UDP).
*/
void (*on_timeout)(fio_io_s *io);
/** Used as a default `on_message` when an IO object subscribes. */

Expand Down Expand Up @@ -35171,7 +35175,6 @@ static void fio___io_on_user_mock(fio_io_s *io, void *i_) {
}
static void fio___io_on_close_mock(void *p1, void *p2) { (void)p1, (void)p2; }
static void fio___io_on_ev_on_timeout(fio_io_s *io) { fio_io_close_now(io); }
static void fio___io_on_timeout_never(fio_io_s *io) { fio_io_touch(io); }

/* Called to perform a non-blocking `read`, same as the system call. */
static ssize_t fio___io_func_default_read(int fd,
Expand Down Expand Up @@ -35642,9 +35645,8 @@ FIO_SFUNC void fio___io_touch(void *io_, void *ignr_) {

/* Resets a socket's timeout counter. */
SFUNC void fio_io_touch(fio_io_s *io) {
if ((fio_atomic_or(&io->flags, FIO___IO_FLAG_TOUCH) & FIO___IO_FLAG_TOUCH))
return;
fio_queue_push_urgent(&FIO___IO.queue, fio___io_touch, fio___io_dup2(io));
if (!(fio_atomic_or(&io->flags, FIO___IO_FLAG_TOUCH) & FIO___IO_FLAG_TOUCH))
fio_queue_push_urgent(&FIO___IO.queue, fio___io_touch, fio___io_dup2(io));
}

/**
Expand Down Expand Up @@ -36094,7 +36096,7 @@ FIO_SFUNC void fio___io_wakeup(void) {
static fio_io_protocol_s FIO___IO_WAKEUP_PROTOCOL = {
.on_data = fio___io_wakeup_cb,
.on_close = fio___io_wakeup_on_close,
.on_timeout = fio___io_on_timeout_never,
.on_timeout = fio_io_touch,
};

FIO_SFUNC void fio___io_wakeup_init(void) {
Expand Down Expand Up @@ -37096,7 +37098,7 @@ static fio_io_protocol_s FIO___IO_LISTEN_PROTOCOL = {
.on_attach = fio___io_listen_on_attach,
.on_data = fio___io_listen_on_data,
.on_close = fio___io_listen_on_close,
.on_timeout = fio___io_on_timeout_never,
.on_timeout = fio_io_touch,
.on_shutdown = fio___io_listen_on_shutdown,
};

Expand Down Expand Up @@ -40094,7 +40096,6 @@ Pub/Sub Cleanup
#if !defined(FIO_INCLUDE_FILE) /* Dev test - ignore line */
#define FIO___DEV___ /* Development inclusion - ignore line */
#define FIO_HTTP_HANDLE /* Development inclusion - ignore line */
#define FIO_STR /* Development inclusion - ignore line */
#include "./include.h" /* Development inclusion - ignore line */
#endif /* Development inclusion - ignore line */
/* *****************************************************************************
Expand Down Expand Up @@ -40134,7 +40135,7 @@ HTTP Handle Settings
* time-stamping is the default.
*/
#define FIO_HTTP_EXACT_LOGGING 0
#ifndef H___FIO_SERVER___H
#ifndef H___FIO_IO___H
#undef FIO_HTTP_EXACT_LOGGING
#define FIO_HTTP_EXACT_LOGGING 1
#endif
Expand Down Expand Up @@ -40164,9 +40165,9 @@ HTTP Handle Settings
#define FIO_HTTP_CACHE_USES_MUTEX 1
#endif

#ifndef FIO_HTTP_CACHE_STATIC_HEADERS
#ifndef FIO_HTTP_PRE_CACHE_KNOWN_HEADERS
/** Adds a static cache for common HTTP header names. */
#define FIO_HTTP_CACHE_STATIC_HEADERS 1
#define FIO_HTTP_PRE_CACHE_KNOWN_HEADERS 1
#endif

#ifndef FIO_HTTP_DEFAULT_INDEX_FILENAME
Expand Down Expand Up @@ -40791,6 +40792,11 @@ SFUNC void fio_http_write_log(fio_http_s *h);
*/
SFUNC int fio_http_from(fio_str_info_s *dest, const fio_http_s *h);

/* date/time string caching for HTTP date header */
SFUNC fio_str_info_s fio_http_date(uint64_t now_in_seconds);

/* date/time string caching for HTTP logging */
SFUNC fio_str_info_s fio_http_log_time(uint64_t now_in_seconds);
/* *****************************************************************************
The HTTP Controller
***************************************************************************** */
Expand Down Expand Up @@ -40941,40 +40947,23 @@ HTTP Handle Implementation - possibly externed functions.
#if defined(FIO_EXTERN_COMPLETE) || !defined(FIO_EXTERN)

/* *****************************************************************************
Helpers - memory allocation & logging time collection
Helpers - reading time
***************************************************************************** */

FIO_LEAK_COUNTER_DEF(http___keystr_allocator)

FIO_SFUNC void fio___http_keystr_free(void *ptr, size_t len) {
if (!ptr)
return;
FIO_LEAK_COUNTER_ON_FREE(http___keystr_allocator);
FIO_MEM_FREE_(ptr, len);
(void)len; /* if unused */
}
FIO_SFUNC void *fio___http_keystr_alloc(size_t capa) {
FIO_LEAK_COUNTER_ON_ALLOC(http___keystr_allocator);
return FIO_MEM_REALLOC_(NULL, 0, capa, 0);
}

#if FIO_HTTP_EXACT_LOGGING
#define FIO___HTTP_TIME_DIV 1000000
#define FIO___HTTP_TIME_UNIT "us"
FIO_IFUNC int64_t fio_http_get_timestump(void) {
return fio_time2micro(fio_time_real());
}
#else
#define FIO___HTTP_TIME_DIV 1000
#define FIO___HTTP_TIME_UNIT "ms"
int64_t fio_srv_last_tick(void);
FIO_IFUNC int64_t fio_http_get_timestump(void) {
return (int64_t)fio_srv_last_tick();
}
#define FIO___HTTP_TIME_DIV 1000
#define FIO___HTTP_TIME_UNIT "ms"
#define fio_http_get_timestump() fio_io_last_tick()
#endif

/* date/time string caching for HTTP date header */
FIO_SFUNC fio_str_info_s fio_http_date(uint64_t now_in_seconds) {
SFUNC fio_str_info_s fio_http_date(uint64_t now_in_seconds) {
static char date_buf[128];
static size_t date_len;
static uint64_t date_buf_val;
Expand All @@ -40987,7 +40976,7 @@ FIO_SFUNC fio_str_info_s fio_http_date(uint64_t now_in_seconds) {
}

/* date/time string caching for HTTP logging */
FIO_SFUNC fio_str_info_s fio_http_log_time(uint64_t now_in_seconds) {
SFUNC fio_str_info_s fio_http_log_time(uint64_t now_in_seconds) {
static char date_buf[128];
static size_t date_len;
static uint64_t date_buf_val;
Expand All @@ -40999,6 +40988,27 @@ FIO_SFUNC fio_str_info_s fio_http_log_time(uint64_t now_in_seconds) {
return FIO_STR_INFO2(date_buf, date_len);
}

/* *****************************************************************************
Helpers - fio_keystr_s memory allocation callbacks
***************************************************************************** */

FIO_LEAK_COUNTER_DEF(http___keystr_allocator)

FIO_SFUNC void fio___http_keystr_free(void *ptr, size_t len) {
if (!ptr)
return;
FIO_LEAK_COUNTER_ON_FREE(http___keystr_allocator);
FIO_MEM_FREE_(ptr, len);
(void)len; /* if unused */
}
FIO_SFUNC void *fio___http_keystr_alloc(size_t capa) {
FIO_LEAK_COUNTER_ON_ALLOC(http___keystr_allocator);
return FIO_MEM_REALLOC_(NULL, 0, capa, 0);
}

/* *****************************************************************************
Helper Types
***************************************************************************** */
#define FIO___RECURSIVE_INCLUDE 1
/* *****************************************************************************
String Cache
Expand All @@ -41017,7 +41027,7 @@ static struct {
#define FIO___HTTP_STR_CACHE_COOKIE 0
#define FIO___HTTP_STR_CACHE_VALUE 1

#if FIO_HTTP_CACHE_STATIC_HEADERS
#if FIO_HTTP_PRE_CACHE_KNOWN_HEADERS

#define FIO___HTTP_STATIC_CACHE_CAPA_BITS 7
#define FIO___HTTP_STATIC_CACHE_CAPA (1U << FIO___HTTP_STATIC_CACHE_CAPA_BITS)
Expand Down Expand Up @@ -41228,7 +41238,7 @@ static void fio___http_str_cached_init(void) {
#undef FIO___HTTP_STATIC_CACHE_STEP_LIMIT
#else
#define fio___http_str_cached_init() (void)0
#endif /* FIO_HTTP_CACHE_STATIC_HEADERS */
#endif /* FIO_HTTP_PRE_CACHE_KNOWN_HEADERS */

FIO_IFUNC char *fio___http_str_cached_inner(size_t group,
uint64_t hash,
Expand Down Expand Up @@ -41264,7 +41274,7 @@ FIO_IFUNC char *fio___http_str_cached(size_t group, fio_str_info_s s) {
}

FIO_IFUNC char *fio___http_str_cached_with_static(fio_str_info_s s) {
#if FIO_HTTP_CACHE_STATIC_HEADERS
#if FIO_HTTP_PRE_CACHE_KNOWN_HEADERS
char *tmp;
if (!s.len)
return NULL;
Expand All @@ -41278,7 +41288,7 @@ FIO_IFUNC char *fio___http_str_cached_with_static(fio_str_info_s s) {
return tmp; /* reference count increased by fio___http_str_cached_static */
}
skip_cache_test:
#endif /* FIO_HTTP_CACHE_STATIC_HEADERS */
#endif /* FIO_HTTP_PRE_CACHE_KNOWN_HEADERS */
return fio_bstr_write(NULL, s.buf, s.len);
}

Expand Down
6 changes: 5 additions & 1 deletion fio-stl.md
Original file line number Diff line number Diff line change
Expand Up @@ -9922,7 +9922,11 @@ struct fio_io_protocol_s {
* even if the client did not consume all buffered data.
*/
void (*on_shutdown)(fio_io_s *io);
/** Called when a connection's timeout was reached */
/**
* Called when a connection's timeout was reached
*
* Can be set to `fio_io_touch` if timeout is irrelevant (i.e., listening / UDP).
*/
void (*on_timeout)(fio_io_s *io);
/** Used as a default `on_message` when an IO object subscribes. */

Expand Down
2 changes: 1 addition & 1 deletion fio-stl/004 sock.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ OS specific patches.
#include <afunix.h>
#endif
#ifndef FIO_SOCK_FD_ISVALID
#define FIO_SOCK_FD_ISVALID(fd) ((size_t)fd <= (size_t)0x7FFFFFFF)
#define FIO_SOCK_FD_ISVALID(fd) ((size_t)(fd) <= (size_t)0x7FFFFFFF)
#endif
/** Acts as POSIX write. Use this macro for portability with WinSock2. */
#define fio_sock_write(fd, data, len) send((fd), (data), (len), 0)
Expand Down
6 changes: 5 additions & 1 deletion fio-stl/400 io api.h
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,11 @@ struct fio_io_protocol_s {
* even if the client did not consume all buffered data.
*/
void (*on_shutdown)(fio_io_s *io);
/** Called when a connection's timeout was reached */
/**
* Called when a connection's timeout was reached
*
* Can be set to `fio_io_touch` if timeout is irrelevant (i.e., UDP).
*/
void (*on_timeout)(fio_io_s *io);
/** Used as a default `on_message` when an IO object subscribes. */

Expand Down
6 changes: 5 additions & 1 deletion fio-stl/400 io.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,11 @@ struct fio_io_protocol_s {
* even if the client did not consume all buffered data.
*/
void (*on_shutdown)(fio_io_s *io);
/** Called when a connection's timeout was reached */
/**
* Called when a connection's timeout was reached
*
* Can be set to `fio_io_touch` if timeout is irrelevant (i.e., listening / UDP).
*/
void (*on_timeout)(fio_io_s *io);
/** Used as a default `on_message` when an IO object subscribes. */

Expand Down
8 changes: 3 additions & 5 deletions fio-stl/401 io types.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ static void fio___io_on_user_mock(fio_io_s *io, void *i_) {
}
static void fio___io_on_close_mock(void *p1, void *p2) { (void)p1, (void)p2; }
static void fio___io_on_ev_on_timeout(fio_io_s *io) { fio_io_close_now(io); }
static void fio___io_on_timeout_never(fio_io_s *io) { fio_io_touch(io); }

/* Called to perform a non-blocking `read`, same as the system call. */
static ssize_t fio___io_func_default_read(int fd,
Expand Down Expand Up @@ -592,9 +591,8 @@ FIO_SFUNC void fio___io_touch(void *io_, void *ignr_) {

/* Resets a socket's timeout counter. */
SFUNC void fio_io_touch(fio_io_s *io) {
if ((fio_atomic_or(&io->flags, FIO___IO_FLAG_TOUCH) & FIO___IO_FLAG_TOUCH))
return;
fio_queue_push_urgent(&FIO___IO.queue, fio___io_touch, fio___io_dup2(io));
if (!(fio_atomic_or(&io->flags, FIO___IO_FLAG_TOUCH) & FIO___IO_FLAG_TOUCH))
fio_queue_push_urgent(&FIO___IO.queue, fio___io_touch, fio___io_dup2(io));
}

/**
Expand Down Expand Up @@ -1044,7 +1042,7 @@ FIO_SFUNC void fio___io_wakeup(void) {
static fio_io_protocol_s FIO___IO_WAKEUP_PROTOCOL = {
.on_data = fio___io_wakeup_cb,
.on_close = fio___io_wakeup_on_close,
.on_timeout = fio___io_on_timeout_never,
.on_timeout = fio_io_touch,
};

FIO_SFUNC void fio___io_wakeup_init(void) {
Expand Down
2 changes: 1 addition & 1 deletion fio-stl/402 io reactor.h
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ static fio_io_protocol_s FIO___IO_LISTEN_PROTOCOL = {
.on_attach = fio___io_listen_on_attach,
.on_data = fio___io_listen_on_data,
.on_close = fio___io_listen_on_close,
.on_timeout = fio___io_on_timeout_never,
.on_timeout = fio_io_touch,
.on_shutdown = fio___io_listen_on_shutdown,
};

Expand Down
Loading

0 comments on commit 8c7b08d

Please sign in to comment.