Skip to content

Commit

Permalink
async: signal ESHUTDOWN to all open worker callbacks (#915)
Browse files Browse the repository at this point in the history
o worker callbacks can execute destructors etc.
  • Loading branch information
sreimers authored Aug 24, 2023
1 parent 3ca6c32 commit 3f0b0f0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions include/re_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,10 @@ typedef SSIZE_T ssize_t;
#define EKEYREJECTED 129
#endif

/* Cannot send after transport endpoint shutdown */
#ifndef ESHUTDOWN
#define ESHUTDOWN 108
#endif

/*
* Give the compiler a hint which branch is "likely" or "unlikely" (inspired
Expand Down
15 changes: 15 additions & 0 deletions src/async/async.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,21 @@ static void async_destructor(void *data)
thrd_join(async->thrd[i], NULL);
}

/* Notify worker callbacks (so they can call destructors) */
struct le *le;
LIST_FOREACH(&async->workl, le)
{
struct async_work *work = le->data;
if (work->cb)
work->cb(ESHUTDOWN, work->arg);
}
LIST_FOREACH(&async->curl, le)
{
struct async_work *work = le->data;
if (work->cb)
work->cb(ESHUTDOWN, work->arg);
}

list_flush(&async->workl);
list_flush(&async->curl);
list_flush(&async->freel);
Expand Down

0 comments on commit 3f0b0f0

Please sign in to comment.