Skip to content

Commit

Permalink
update tick at exit, partitioned cookies and little details
Browse files Browse the repository at this point in the history
  • Loading branch information
boazsegev committed Nov 6, 2023
1 parent 5a09ea1 commit d616981
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 0 deletions.
30 changes: 30 additions & 0 deletions fio-stl.h
Original file line number Diff line number Diff line change
Expand Up @@ -11066,6 +11066,8 @@ typedef enum {
FIO_CLI_ARG_PRINT_HEADER,
} fio_cli_arg_e;

#define FIO_CLI_ARG_NONE FIO_CLI_ARG_PRINT_HEADER

typedef struct {
fio_cli_arg_e t;
const char *l;
Expand Down Expand Up @@ -11225,6 +11227,10 @@ SFUNC size_t fio_cli_each(int (*task)(fio_buf_info_s name,
fio_cli_arg_e arg_type,
void *udata),
void *udata);

/** Returns the argument's expected content type. */
SFUNC fio_cli_arg_e fio_cli_type(char const *name);

/* *****************************************************************************
CLI Implementation
***************************************************************************** */
Expand Down Expand Up @@ -11480,6 +11486,17 @@ SFUNC void __attribute__((destructor)) fio_cli_end(void) {
CLI Public Get/Set API
***************************************************************************** */

/** Returns the argument's expected content type. */
SFUNC fio_cli_arg_e fio_cli_type(char const *name) {
fio_cli_arg_e r = FIO_CLI_ARG_NONE;
fio___cli_aliases_s o = {.name =
fio_cli_str_tmp(FIO_BUF_INFO1((char *)name))};
fio___cli_aliases_s *a = fio___cli_amap_get(&fio___cli_data.aliases, o);
if (a)
r = a->t;
return r;
}

/** Returns the argument's value as a NUL terminated C String. */
SFUNC char const *fio_cli_get(char const *name) {
if (!name)
Expand Down Expand Up @@ -28308,8 +28325,12 @@ SFUNC void *fio_srv_listen(struct fio_srv_listen_args args);
#define fio_srv_listen(...) \
fio_srv_listen((struct fio_srv_listen_args){__VA_ARGS__})

/** Notifies a listener to stop listening. */
SFUNC void fio_srv_listen_stop(void *listener);

/** Returns the URL on which the listener is listening. */
SFUNC fio_buf_info_s fio_srv_listener_url(void *listener);

/* *****************************************************************************
Listening to Incoming Connections
***************************************************************************** */
Expand Down Expand Up @@ -29976,6 +29997,7 @@ static void fio___srv_spawn_worker(void *ignr_1, void *ignr_2) {
if (fio_atomic_or_fetch(&fio___srvdata.stop, 2) != 2)
return;

fio___srvdata.tick = FIO___SRV_GET_TIME_MILLI();
fio_state_callback_force(FIO_CALL_BEFORE_FORK);
/* do not allow master tasks to run in worker */
fio_queue_perform_all(fio___srv_tasks);
Expand Down Expand Up @@ -30469,6 +30491,12 @@ SFUNC void fio_srv_listen_stop(void *listener) {
fio___srv_listen_free(listener);
}

/** Returns the URL on which the listener is listening. */
SFUNC fio_buf_info_s fio_srv_listener_url(void *listener) {
fio___srv_listen_s *l = (fio___srv_listen_s *)listener;
return FIO_BUF_INFO2(l->url, l->url_len);
}

static void fio___srv_listen_on_data_task(void *io_, void *ignr_) {
(void)ignr_;
fio_s *io = (fio_s *)io_;
Expand Down Expand Up @@ -30716,6 +30744,7 @@ Managing data after a fork
FIO_SFUNC void fio___srv_after_fork(void *ignr_) {
(void)ignr_;
fio___srvdata.pid = fio_thread_getpid();
fio___srvdata.tick = FIO___SRV_GET_TIME_MILLI();
fio_queue_perform_all(fio___srv_tasks);
FIO_LIST_EACH(fio_protocol_s,
reserved.protocols,
Expand All @@ -30739,6 +30768,7 @@ FIO_SFUNC void fio___srv_cleanup_at_exit(void *ignr_) {
fio_thread_mutex_destroy(&fio___srvdata.valid_lock);
#endif
#endif /* FIO_VALIDATE_IO_MUTEX / FIO_VALIDITY_MAP_USE */
fio___srvdata.tick = FIO___SRV_GET_TIME_MILLI();
fio_queue_perform_all(fio___srv_tasks);
fio_timer_destroy(fio___srv_timer);
fio_queue_perform_all(fio___srv_tasks);
Expand Down
17 changes: 17 additions & 0 deletions fio-stl/005 cli.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ typedef enum {
FIO_CLI_ARG_PRINT_HEADER,
} fio_cli_arg_e;

#define FIO_CLI_ARG_NONE FIO_CLI_ARG_PRINT_HEADER

typedef struct {
fio_cli_arg_e t;
const char *l;
Expand Down Expand Up @@ -194,6 +196,10 @@ SFUNC size_t fio_cli_each(int (*task)(fio_buf_info_s name,
fio_cli_arg_e arg_type,
void *udata),
void *udata);

/** Returns the argument's expected content type. */
SFUNC fio_cli_arg_e fio_cli_type(char const *name);

/* *****************************************************************************
CLI Implementation
***************************************************************************** */
Expand Down Expand Up @@ -449,6 +455,17 @@ SFUNC void __attribute__((destructor)) fio_cli_end(void) {
CLI Public Get/Set API
***************************************************************************** */

/** Returns the argument's expected content type. */
SFUNC fio_cli_arg_e fio_cli_type(char const *name) {
fio_cli_arg_e r = FIO_CLI_ARG_NONE;
fio___cli_aliases_s o = {.name =
fio_cli_str_tmp(FIO_BUF_INFO1((char *)name))};
fio___cli_aliases_s *a = fio___cli_amap_get(&fio___cli_data.aliases, o);
if (a)
r = a->t;
return r;
}

/** Returns the argument's value as a NUL terminated C String. */
SFUNC char const *fio_cli_get(char const *name) {
if (!name)
Expand Down
13 changes: 13 additions & 0 deletions fio-stl/400 server.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,12 @@ SFUNC void *fio_srv_listen(struct fio_srv_listen_args args);
#define fio_srv_listen(...) \
fio_srv_listen((struct fio_srv_listen_args){__VA_ARGS__})

/** Notifies a listener to stop listening. */
SFUNC void fio_srv_listen_stop(void *listener);

/** Returns the URL on which the listener is listening. */
SFUNC fio_buf_info_s fio_srv_listener_url(void *listener);

/* *****************************************************************************
Listening to Incoming Connections
***************************************************************************** */
Expand Down Expand Up @@ -1825,6 +1829,7 @@ static void fio___srv_spawn_worker(void *ignr_1, void *ignr_2) {
if (fio_atomic_or_fetch(&fio___srvdata.stop, 2) != 2)
return;

fio___srvdata.tick = FIO___SRV_GET_TIME_MILLI();
fio_state_callback_force(FIO_CALL_BEFORE_FORK);
/* do not allow master tasks to run in worker */
fio_queue_perform_all(fio___srv_tasks);
Expand Down Expand Up @@ -2318,6 +2323,12 @@ SFUNC void fio_srv_listen_stop(void *listener) {
fio___srv_listen_free(listener);
}

/** Returns the URL on which the listener is listening. */
SFUNC fio_buf_info_s fio_srv_listener_url(void *listener) {
fio___srv_listen_s *l = (fio___srv_listen_s *)listener;
return FIO_BUF_INFO2(l->url, l->url_len);
}

static void fio___srv_listen_on_data_task(void *io_, void *ignr_) {
(void)ignr_;
fio_s *io = (fio_s *)io_;
Expand Down Expand Up @@ -2565,6 +2576,7 @@ Managing data after a fork
FIO_SFUNC void fio___srv_after_fork(void *ignr_) {
(void)ignr_;
fio___srvdata.pid = fio_thread_getpid();
fio___srvdata.tick = FIO___SRV_GET_TIME_MILLI();
fio_queue_perform_all(fio___srv_tasks);
FIO_LIST_EACH(fio_protocol_s,
reserved.protocols,
Expand All @@ -2588,6 +2600,7 @@ FIO_SFUNC void fio___srv_cleanup_at_exit(void *ignr_) {
fio_thread_mutex_destroy(&fio___srvdata.valid_lock);
#endif
#endif /* FIO_VALIDATE_IO_MUTEX / FIO_VALIDITY_MAP_USE */
fio___srvdata.tick = FIO___SRV_GET_TIME_MILLI();
fio_queue_perform_all(fio___srv_tasks);
fio_timer_destroy(fio___srv_timer);
fio_queue_perform_all(fio___srv_tasks);
Expand Down
12 changes: 12 additions & 0 deletions fio-stl/431 http handle.h
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,11 @@ typedef struct fio_http_cookie_args_s {
unsigned secure : 1;
/** Limit cookie to HTTP (intended to prevent JavaScript access/hijacking).*/
unsigned http_only : 1;
/**
* Set the Partitioned (third party) cookie flag:
* https://developer.mozilla.org/en-US/docs/Web/Privacy/Partitioned_cookies
*/
unsigned partitioned : 1;
} fio_http_cookie_args_s;

/**
Expand Down Expand Up @@ -1693,6 +1698,13 @@ SFUNC int fio_http_cookie_set FIO_NOOP(fio_http_s *h,
"secure; ",
8);
}
if (cookie.partitioned) {
fio_string_write(
&t,
((t.buf == tmp_buf) ? FIO_STRING_ALLOC_COPY : FIO_STRING_REALLOC),
"partitioned; ",
13);
}
switch (cookie.same_site) {
case FIO_HTTP_COOKIE_SAME_SITE_BROWSER_DEFAULT: /* fall through */
default: break;
Expand Down

0 comments on commit d616981

Please sign in to comment.