Skip to content

Commit

Permalink
what's in a name?
Browse files Browse the repository at this point in the history
  • Loading branch information
boazsegev committed Oct 22, 2024
1 parent 711981c commit 396bb55
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 49 deletions.
9 changes: 4 additions & 5 deletions examples/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ FIO_SFUNC void client_on_eventsource(fio_http_s *h,
fio_buf_info_s id,
fio_buf_info_s event,
fio_buf_info_s data);
/** Called after a WebSocket / SSE connection is closed (for cleanup). */
FIO_SFUNC void client_on_close(fio_http_s *h);
/** Called after HTTP / WebSocket / SSE cycle had finished (for cleanup). */
FIO_SFUNC void client_on_finish(fio_http_s *h);

/** Called for show... when the outgoing buffer appears empty. */
FIO_SFUNC void client_on_ready(fio_http_s *h);
Expand Down Expand Up @@ -153,8 +153,7 @@ FIO_SFUNC void open_client_connection(void *is_http) {
.on_message = client_on_message,
.on_ready = client_on_ready,
.on_eventsource = client_on_eventsource,
.on_close = client_on_close,
.on_finish = client_on_close,
.on_finish = client_on_finish,
.timeout = (fio_cli_get_i("-t")),
.ws_timeout = (fio_cli_get_i("-t")),
.connect_timeout = (fio_cli_get_i("-w"))),
Expand Down Expand Up @@ -333,7 +332,7 @@ FIO_SFUNC void client_on_eventsource(fio_http_s *h,
(void)h;
}
/** Called after a WebSocket / SSE connection is closed (for cleanup). */
FIO_SFUNC void client_on_close(fio_http_s *h) {
FIO_SFUNC void client_on_finish(fio_http_s *h) {
if (!fio_cli_get_bool("-b"))
FIO_LOG_INFO("Connection Closed");
fio_srv_stop();
Expand Down
36 changes: 17 additions & 19 deletions fio-stl.h
Original file line number Diff line number Diff line change
Expand Up @@ -11231,8 +11231,8 @@ typedef enum {
FIO_CALL_ON_CHILD_CRUSH,
/** Called by each worker thread in a Server Async queue as it ends. */
FIO_CALL_ON_WORKER_THREAD_END,
/** Called just before finishing up (both on child and parent processes). */
FIO_CALL_ON_FINISH,
/** Called when wither a *Worker* or *Master* stopped. */
FIO_CALL_ON_STOP,
/** An alternative to the system's at_exit. */
FIO_CALL_AT_EXIT,
/** used for testing and array allocation - must be last. */
Expand Down Expand Up @@ -11322,7 +11322,7 @@ static const char *FIO___STATE_TASKS_NAMES[FIO_CALL_NEVER + 1] = {
[FIO_CALL_ON_PARENT_CRUSH] = "ON_PARENT_CRUSH",
[FIO_CALL_ON_CHILD_CRUSH] = "ON_CHILD_CRUSH",
[FIO_CALL_ON_WORKER_THREAD_END] = "ON_WORKER_THREAD_END",
[FIO_CALL_ON_FINISH] = "ON_FINISH",
[FIO_CALL_ON_STOP] = "ON_FINISH",
[FIO_CALL_AT_EXIT] = "AT_EXIT",
[FIO_CALL_NEVER] = "NEVER",
};
Expand Down Expand Up @@ -31461,7 +31461,7 @@ typedef struct fio_srv_listen_args {
*
* This will be called separately for every process before exiting.
*/
void (*on_finish)(fio_protocol_s *protocol, void *udata);
void (*on_stop)(fio_protocol_s *protocol, void *udata);
/**
* Selects a queue that will be used to schedule a pre-accept task.
* May be used to test user thread stress levels before accepting connections.
Expand Down Expand Up @@ -31689,7 +31689,7 @@ SFUNC void fio_srv_run_every(fio_timer_schedule_args_s args);
* * Opaque user data:
* void *udata2
* * Called when the timer is done (finished):
* void (*on_finish)(void *, void *)
* void (*on_stop)(void *, void *)
* * Timer interval, in milliseconds:
* uint32_t every
* * The number of times the timer should be performed. -1 == infinity:
Expand Down Expand Up @@ -32626,7 +32626,7 @@ FIO_SFUNC void fio_s_destroy(fio_s *io) {
/* store info, as it might be freed if the protocol is freed. */
if (FIO_LIST_IS_EMPTY(&io->pr->reserved.ios))
FIO_LIST_REMOVE_RESET(&io->pr->reserved.protocols);
/* call on_finish / free callbacks . */
/* call on_stop / free callbacks . */
io->pr->io_functions.cleanup(io->tls);
io->pr->on_close(io->udata); /* may destroy protocol object! */
fio___srv_env_safe_destroy(&io->env);
Expand Down Expand Up @@ -33116,7 +33116,7 @@ FIO_SFUNC void fio___srv_work(int is_worker) {
}
fio_queue_perform_all(fio___srv_tasks);
fio_queue_perform_all(fio___srv_tasks);
fio_state_callback_force(FIO_CALL_ON_FINISH);
fio_state_callback_force(FIO_CALL_ON_STOP);
fio_queue_perform_all(fio___srv_tasks);
fio___srvdata.workers = 0;
}
Expand All @@ -33138,7 +33138,7 @@ static void *fio___srv_worker_sentinel(void *pid_data) {
int status = 0;
(void)status;
fio_thread_t thr = fio_thread_current();
fio_state_callback_add(FIO_CALL_ON_FINISH,
fio_state_callback_add(FIO_CALL_ON_STOP,
fio___srv_wait_for_worker,
(void *)thr);
if (fio_thread_waitpid(pid, &status, 0) != pid && !fio___srvdata.stop)
Expand All @@ -33151,7 +33151,7 @@ static void *fio___srv_worker_sentinel(void *pid_data) {
FIO_ASSERT_DEBUG(
0,
"DEBUG mode prevents worker re-spawning, now crashing parent.");
fio_state_callback_remove(FIO_CALL_ON_FINISH,
fio_state_callback_remove(FIO_CALL_ON_STOP,
fio___srv_wait_for_worker,
(void *)thr);
fio_thread_detach(&thr);
Expand Down Expand Up @@ -33476,7 +33476,7 @@ typedef struct {
fio_queue_s *queue;
fio_s *io;
void (*on_start)(fio_protocol_s *protocol, void *udata);
void (*on_finish)(fio_protocol_s *protocol, void *udata);
void (*on_stop)(fio_protocol_s *protocol, void *udata);
int owner;
int fd;
size_t ref_count;
Expand Down Expand Up @@ -33518,8 +33518,8 @@ static void fio___srv_listen_free(void *l_) {
}
#endif

if (l->on_finish)
l->on_finish(l->protocol, l->udata);
if (l->on_stop)
l->on_stop(l->protocol, l->udata);

if (l->hide_from_log)
FIO_LOG_DEBUG2("(%d) stopped listening @ %.*s",
Expand Down Expand Up @@ -33704,7 +33704,7 @@ SFUNC void *fio_srv_listen FIO_NOOP(struct fio_srv_listen_args args) {
.tls_ctx = built_tls,
.queue_for_accept = args.queue_for_accept,
.on_start = args.on_start,
.on_finish = args.on_finish,
.on_stop = args.on_stop,
.owner = fio___srvdata.pid,
.url_len = url_buf.len,
.hide_from_log = args.hide_from_log,
Expand Down Expand Up @@ -40825,9 +40825,7 @@ static int fio_http1___start(fio_http1_parser_s *p,
eol -= eol[-1] == '\r';

/* parse first line */
if (start[0] > ('0' - 1) && start[0] < ('9' + 1))
goto parse_response_line;
/* request: method path version */
/* request: method path version ; response: version code txt */
if (!(tmp = (char *)FIO_MEMCHR(start, ' ', (size_t)(eol - start))))
return -1;
wrd[0] = FIO_BUF_INFO2(start, (size_t)(tmp - start));
Expand All @@ -40839,7 +40837,7 @@ static int fio_http1___start(fio_http1_parser_s *p,
if (start >= eol)
return -1;
wrd[2] = FIO_BUF_INFO2(start, (size_t)(eol - start));
if (fio_c2i(wrd[1].buf[0]) < 10)
if (fio_c2i(wrd[1].buf[0]) < 10) /* test if path or code */
goto parse_response_line;
if (wrd[2].len > 14)
wrd[2].len = 14;
Expand Down Expand Up @@ -42437,7 +42435,7 @@ static void fio___http_listen_on_start(fio_protocol_s *protocol, void *u) {
: fio_srv_queue());
}

static void fio___http_listen_on_finished(fio_protocol_s *p, void *u) {
static void fio___http_listen_on_stop(fio_protocol_s *p, void *u) {
(void)u;
fio___http_protocol_free(
FIO_PTR_FROM_FIELD(fio___http_protocol_s,
Expand All @@ -42455,7 +42453,7 @@ SFUNC void *fio_http_listen FIO_NOOP(const char *url, fio_http_settings_s s) {
.protocol = &p->state[FIO___HTTP_PROTOCOL_ACCEPT].protocol,
.tls = s.tls,
.on_start = fio___http_listen_on_start,
.on_finish = fio___http_listen_on_finished,
.on_stop = fio___http_listen_on_stop,
.queue_for_accept = p->settings.queue);
return listener;
}
Expand Down
6 changes: 3 additions & 3 deletions fio-stl.md
Original file line number Diff line number Diff line change
Expand Up @@ -3889,7 +3889,7 @@ The callback should accept a single `void *` as an argument.

Events are performed either in the order in which they were registered or in reverse order, depending on the context.

These are the possible `event` values, note that some of them are only relevant in the context of the `FIO_SERVER` module:
These are the possible `event` values, note that some of them are only relevant in the context of the `FIO_SERVER` module and were designed for the server's use:

```c
typedef enum {
Expand Down Expand Up @@ -3938,8 +3938,8 @@ typedef enum {
FIO_CALL_ON_CHILD_CRUSH,
/** Called by each worker thread in a Server Async queue as it ends. */
FIO_CALL_ON_WORKER_THREAD_END,
/** Called just before finishing up (both on child and parent processes). */
FIO_CALL_ON_FINISH,
/** Called when wither a *Worker* or *Master* stopped. */
FIO_CALL_ON_STOP,
/** An alternative to the system's at_exit. */
FIO_CALL_AT_EXIT,
/** used for testing and array allocation - must be last. */
Expand Down
6 changes: 3 additions & 3 deletions fio-stl/004 state callbacks.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ typedef enum {
FIO_CALL_ON_CHILD_CRUSH,
/** Called by each worker thread in a Server Async queue as it ends. */
FIO_CALL_ON_WORKER_THREAD_END,
/** Called just before finishing up (both on child and parent processes). */
FIO_CALL_ON_FINISH,
/** Called when wither a *Worker* or *Master* stopped. */
FIO_CALL_ON_STOP,
/** An alternative to the system's at_exit. */
FIO_CALL_AT_EXIT,
/** used for testing and array allocation - must be last. */
Expand Down Expand Up @@ -161,7 +161,7 @@ static const char *FIO___STATE_TASKS_NAMES[FIO_CALL_NEVER + 1] = {
[FIO_CALL_ON_PARENT_CRUSH] = "ON_PARENT_CRUSH",
[FIO_CALL_ON_CHILD_CRUSH] = "ON_CHILD_CRUSH",
[FIO_CALL_ON_WORKER_THREAD_END] = "ON_WORKER_THREAD_END",
[FIO_CALL_ON_FINISH] = "ON_FINISH",
[FIO_CALL_ON_STOP] = "ON_FINISH",
[FIO_CALL_AT_EXIT] = "AT_EXIT",
[FIO_CALL_NEVER] = "NEVER",
};
Expand Down
6 changes: 3 additions & 3 deletions fio-stl/004 state callbacks.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ The callback should accept a single `void *` as an argument.
Events are performed either in the order in which they were registered or in reverse order, depending on the context.
These are the possible `event` values, note that some of them are only relevant in the context of the `FIO_SERVER` module:
These are the possible `event` values, note that some of them are only relevant in the context of the `FIO_SERVER` module and were designed for the server's use:
```c
typedef enum {
Expand Down Expand Up @@ -73,8 +73,8 @@ typedef enum {
FIO_CALL_ON_CHILD_CRUSH,
/** Called by each worker thread in a Server Async queue as it ends. */
FIO_CALL_ON_WORKER_THREAD_END,
/** Called just before finishing up (both on child and parent processes). */
FIO_CALL_ON_FINISH,
/** Called when wither a *Worker* or *Master* stopped. */
FIO_CALL_ON_STOP,
/** An alternative to the system's at_exit. */
FIO_CALL_AT_EXIT,
/** used for testing and array allocation - must be last. */
Expand Down
20 changes: 10 additions & 10 deletions fio-stl/400 server.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ typedef struct fio_srv_listen_args {
*
* This will be called separately for every process before exiting.
*/
void (*on_finish)(fio_protocol_s *protocol, void *udata);
void (*on_stop)(fio_protocol_s *protocol, void *udata);
/**
* Selects a queue that will be used to schedule a pre-accept task.
* May be used to test user thread stress levels before accepting connections.
Expand Down Expand Up @@ -370,7 +370,7 @@ SFUNC void fio_srv_run_every(fio_timer_schedule_args_s args);
* * Opaque user data:
* void *udata2
* * Called when the timer is done (finished):
* void (*on_finish)(void *, void *)
* void (*on_stop)(void *, void *)
* * Timer interval, in milliseconds:
* uint32_t every
* * The number of times the timer should be performed. -1 == infinity:
Expand Down Expand Up @@ -1307,7 +1307,7 @@ FIO_SFUNC void fio_s_destroy(fio_s *io) {
/* store info, as it might be freed if the protocol is freed. */
if (FIO_LIST_IS_EMPTY(&io->pr->reserved.ios))
FIO_LIST_REMOVE_RESET(&io->pr->reserved.protocols);
/* call on_finish / free callbacks . */
/* call on_stop / free callbacks . */
io->pr->io_functions.cleanup(io->tls);
io->pr->on_close(io->udata); /* may destroy protocol object! */
fio___srv_env_safe_destroy(&io->env);
Expand Down Expand Up @@ -1797,7 +1797,7 @@ FIO_SFUNC void fio___srv_work(int is_worker) {
}
fio_queue_perform_all(fio___srv_tasks);
fio_queue_perform_all(fio___srv_tasks);
fio_state_callback_force(FIO_CALL_ON_FINISH);
fio_state_callback_force(FIO_CALL_ON_STOP);
fio_queue_perform_all(fio___srv_tasks);
fio___srvdata.workers = 0;
}
Expand All @@ -1819,7 +1819,7 @@ static void *fio___srv_worker_sentinel(void *pid_data) {
int status = 0;
(void)status;
fio_thread_t thr = fio_thread_current();
fio_state_callback_add(FIO_CALL_ON_FINISH,
fio_state_callback_add(FIO_CALL_ON_STOP,
fio___srv_wait_for_worker,
(void *)thr);
if (fio_thread_waitpid(pid, &status, 0) != pid && !fio___srvdata.stop)
Expand All @@ -1832,7 +1832,7 @@ static void *fio___srv_worker_sentinel(void *pid_data) {
FIO_ASSERT_DEBUG(
0,
"DEBUG mode prevents worker re-spawning, now crashing parent.");
fio_state_callback_remove(FIO_CALL_ON_FINISH,
fio_state_callback_remove(FIO_CALL_ON_STOP,
fio___srv_wait_for_worker,
(void *)thr);
fio_thread_detach(&thr);
Expand Down Expand Up @@ -2157,7 +2157,7 @@ typedef struct {
fio_queue_s *queue;
fio_s *io;
void (*on_start)(fio_protocol_s *protocol, void *udata);
void (*on_finish)(fio_protocol_s *protocol, void *udata);
void (*on_stop)(fio_protocol_s *protocol, void *udata);
int owner;
int fd;
size_t ref_count;
Expand Down Expand Up @@ -2199,8 +2199,8 @@ static void fio___srv_listen_free(void *l_) {
}
#endif

if (l->on_finish)
l->on_finish(l->protocol, l->udata);
if (l->on_stop)
l->on_stop(l->protocol, l->udata);

if (l->hide_from_log)
FIO_LOG_DEBUG2("(%d) stopped listening @ %.*s",
Expand Down Expand Up @@ -2385,7 +2385,7 @@ SFUNC void *fio_srv_listen FIO_NOOP(struct fio_srv_listen_args args) {
.tls_ctx = built_tls,
.queue_for_accept = args.queue_for_accept,
.on_start = args.on_start,
.on_finish = args.on_finish,
.on_stop = args.on_stop,
.owner = fio___srvdata.pid,
.url_len = url_buf.len,
.hide_from_log = args.hide_from_log,
Expand Down
6 changes: 2 additions & 4 deletions fio-stl/431 http1 parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,7 @@ static int fio_http1___start(fio_http1_parser_s *p,
eol -= eol[-1] == '\r';

/* parse first line */
if (start[0] > ('0' - 1) && start[0] < ('9' + 1))
goto parse_response_line;
/* request: method path version */
/* request: method path version ; response: version code txt */
if (!(tmp = (char *)FIO_MEMCHR(start, ' ', (size_t)(eol - start))))
return -1;
wrd[0] = FIO_BUF_INFO2(start, (size_t)(tmp - start));
Expand All @@ -207,7 +205,7 @@ static int fio_http1___start(fio_http1_parser_s *p,
if (start >= eol)
return -1;
wrd[2] = FIO_BUF_INFO2(start, (size_t)(eol - start));
if (fio_c2i(wrd[1].buf[0]) < 10)
if (fio_c2i(wrd[1].buf[0]) < 10) /* test if path or code */
goto parse_response_line;
if (wrd[2].len > 14)
wrd[2].len = 14;
Expand Down
4 changes: 2 additions & 2 deletions fio-stl/439 http.h
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,7 @@ static void fio___http_listen_on_start(fio_protocol_s *protocol, void *u) {
: fio_srv_queue());
}

static void fio___http_listen_on_finished(fio_protocol_s *p, void *u) {
static void fio___http_listen_on_stop(fio_protocol_s *p, void *u) {
(void)u;
fio___http_protocol_free(
FIO_PTR_FROM_FIELD(fio___http_protocol_s,
Expand All @@ -845,7 +845,7 @@ SFUNC void *fio_http_listen FIO_NOOP(const char *url, fio_http_settings_s s) {
.protocol = &p->state[FIO___HTTP_PROTOCOL_ACCEPT].protocol,
.tls = s.tls,
.on_start = fio___http_listen_on_start,
.on_finish = fio___http_listen_on_finished,
.on_stop = fio___http_listen_on_stop,
.queue_for_accept = p->settings.queue);
return listener;
}
Expand Down

0 comments on commit 396bb55

Please sign in to comment.