Sun, 02 Jun 2024 14:28:17 +0200
change nsapi_function_return behavior: move saf return to the end of the event cycle
--- a/src/server/daemon/event.h Sun Jun 02 13:07:48 2024 +0200 +++ b/src/server/daemon/event.h Sun Jun 02 14:28:17 2024 +0200 @@ -48,6 +48,12 @@ int isdefault; } EventHandlerConfig; +typedef struct EVReturn { + Session *sn; + Request *rq; + int ret; +} EVReturn; + int create_event_handler(EventHandlerConfig *cfg); int check_event_handler_cfg(); @@ -69,6 +75,8 @@ int ev_aioread(int fd, aiocb_s *cb); int ev_aiowrite(int fd, aiocb_s *cb); +void ev_saf_return(EventHandler *h, Session *sn, Request *rq, int ret); + #ifdef __cplusplus }
--- a/src/server/daemon/event_bsd.c Sun Jun 02 13:07:48 2024 +0200 +++ b/src/server/daemon/event_bsd.c Sun Jun 02 14:28:17 2024 +0200 @@ -34,6 +34,8 @@ #include "event_bsd.h" +#include "httprequest.h" + EVHandler* evhandler_create(EventHandlerConfig *cfg) { EVHandler *ev = malloc(sizeof(EVHandler)); ev->current = 0; @@ -62,8 +64,6 @@ } -#define EV_MAX_EVENTS 32 - void ev_handle_events(EventHandler *ev) { struct timespec timeout; timeout.tv_nsec = 0; @@ -85,6 +85,7 @@ numchanges = 0; int numfinished = 0; + ev->numret = 0; for(int i=0;i<nev;i++) { Event *event = (Event*)events[i].udata; if(!event) { @@ -144,6 +145,11 @@ Event *event = finished[i]; finished[i]->finish(ev, event); } + // execute return calls + for(int i=0;i<ev->numret;i++) { + EVReturn ret = ev->fnreturn[i]; + nsapi_saf_return(ret.sn, ret.rq, ret.ret); + } } } @@ -206,3 +212,8 @@ int event_removepoll(EventHandler *ev, SYS_NETFD fd) { return ((IOStream*)fd)->poll(fd, ev, IO_POLL_NONE, NULL); } + + +void ev_saf_return(EventHandler *h, Session *sn, Request *rq, int ret) { + h->fnreturn[h->numret++] = (EVReturn){ sn, rq, ret }; +}
--- a/src/server/daemon/event_bsd.h Sun Jun 02 13:07:48 2024 +0200 +++ b/src/server/daemon/event_bsd.h Sun Jun 02 14:28:17 2024 +0200 @@ -38,9 +38,20 @@ #ifdef __cplusplus extern "C" { #endif + +#define EV_MAX_EVENTS 32 struct EventHandler { int kqueue; + + /* + * return call list + */ + EVReturn fnreturn[EV_MAX_EVENTS]; + /* + * number of fnreturn entries + */ + int numret; }; void ev_handle_events(EventHandler *ev);
--- a/src/server/daemon/event_linux.c Sun Jun 02 13:07:48 2024 +0200 +++ b/src/server/daemon/event_linux.c Sun Jun 02 14:28:17 2024 +0200 @@ -40,6 +40,8 @@ #include "event.h" #include "event_linux.h" +#include "httprequest.h" + EVHandler* evhandler_create(EventHandlerConfig *cfg) { EVHandler *ev = malloc(sizeof(EVHandler)); @@ -84,8 +86,6 @@ return ev; } -#define EV_MAX_EVENTS 32 - void ev_handle_events(EventHandler *ev) { int ep = ev->ep; @@ -101,6 +101,7 @@ } int numfinished = 0; + ev->numret = 0; for(int i=0;i<ret;i++) { Event *event = events[i].data.ptr; if(!event) { @@ -167,6 +168,11 @@ Event *event = finished[i]; finished[i]->finish(ev, event); } + // execute return calls + for(int i=0;i<ev->numret;i++) { + EVReturn ret = ev->fnreturn[i]; + nsapi_saf_return(ret.sn, ret.rq, ret.ret); + } } } @@ -244,3 +250,8 @@ int event_removepoll(EventHandler *ev, SYS_NETFD fd) { return ((IOStream*)fd)->poll(fd, ev, IO_POLL_NONE, NULL); } + + +void ev_saf_return(EventHandler *h, Session *sn, Request *rq, int ret) { + h->fnreturn[h->numret++] = (EVReturn){ sn, rq, ret }; +}
--- a/src/server/daemon/event_linux.h Sun Jun 02 13:07:48 2024 +0200 +++ b/src/server/daemon/event_linux.h Sun Jun 02 14:28:17 2024 +0200 @@ -36,6 +36,8 @@ extern "C" { #endif +#define EV_MAX_EVENTS 32 + struct EventHandler { /* * epoll fd @@ -49,6 +51,14 @@ * pipe write fd */ int eventout; + /* + * return call list + */ + EVReturn fnreturn[EV_MAX_EVENTS]; + /* + * number of fnreturn entries + */ + int numret; }; void ev_handle_events(EventHandler *ev);
--- a/src/server/daemon/event_solaris.c Sun Jun 02 13:07:48 2024 +0200 +++ b/src/server/daemon/event_solaris.c Sun Jun 02 14:28:17 2024 +0200 @@ -34,6 +34,8 @@ #include "event_solaris.h" +#include "httprequest.h" + EVHandler* evhandler_create(EventHandlerConfig *cfg) { EVHandler *ev = malloc(sizeof(EVHandler)); ev->current = 0; @@ -61,7 +63,6 @@ return ev; } -#define EV_MAX_EVENTS 32 void ev_handle_events(EventHandler *ev) { port_event_t events[EV_MAX_EVENTS]; @@ -81,6 +82,7 @@ } int numfinished = 0; + ev->numret = 0; for(int i=0;i<nev;i++) { Event *event = events[i].portev_user; if(events[i].portev_source == PORT_SOURCE_AIO) { @@ -124,6 +126,11 @@ Event *event = finished[i]; finished[i]->finish(ev, event); } + // execute return calls + for(int i=0;i<ev->numret;i++) { + EVReturn ret = ev->fnreturn[i]; + nsapi_saf_return(ret.sn, ret.rq, ret.ret); + } } } @@ -225,3 +232,7 @@ int event_removepoll(EventHandler *ev, SYS_NETFD fd) { return ((IOStream*)fd)->poll(fd, ev, IO_POLL_NONE, NULL); } + +void ev_saf_return(EventHandler *h, Session *sn, Request *rq, int ret) { + h->fnreturn[h->numret++] = (EVReturn){ sn, rq, ret }; +}
--- a/src/server/daemon/event_solaris.h Sun Jun 02 13:07:48 2024 +0200 +++ b/src/server/daemon/event_solaris.h Sun Jun 02 14:28:17 2024 +0200 @@ -39,8 +39,20 @@ extern "C" { #endif + +#define EV_MAX_EVENTS 32 + struct EventHandler { int port; + + /* + * return call list + */ + EVReturn fnreturn[EV_MAX_EVENTS]; + /* + * number of fnreturn entries + */ + int numret; }; int ev_convert2sys_events(int events);
--- a/src/server/daemon/httprequest.c Sun Jun 02 13:07:48 2024 +0200 +++ b/src/server/daemon/httprequest.c Sun Jun 02 14:28:17 2024 +0200 @@ -1131,7 +1131,7 @@ return REQ_PROCESSING; } -void nsapi_function_return(Session *session, Request *request, int ret) { +void nsapi_saf_return(Session *session, Request *request, int ret) { NSAPISession *sn = (NSAPISession*)session; NSAPIRequest *rq = (NSAPIRequest*)request; @@ -1144,6 +1144,10 @@ } } +void nsapi_function_return(Session *session, Request *request, int ret) { + ev_saf_return(session->ev, session, request, ret); +} + void nsapi_change_threadpool( NSAPISession *sn, NSAPIRequest *rq,
--- a/src/server/daemon/httprequest.h Sun Jun 02 13:07:48 2024 +0200 +++ b/src/server/daemon/httprequest.h Sun Jun 02 14:28:17 2024 +0200 @@ -93,6 +93,8 @@ int nsapi_handle_request(NSAPISession *sn, NSAPIRequest *rq); int nsapi_finish_request(NSAPISession *sn, NSAPIRequest *rq); +void nsapi_saf_return(Session *sn, Request *rq, int ret);; + void request_free_resources(NSAPISession *sn, NSAPIRequest *rq); int nsapi_authtrans(NSAPISession *sn, NSAPIRequest *rq);