-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
76 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,40 @@ | ||
#include "log.h" | ||
#include "utils.h" | ||
#include "frob.h" | ||
#include "npthfix.h" | ||
#include "tasks.h" | ||
#include <unistd.h> | ||
#include <signal.h> | ||
#include <sys/resource.h> | ||
#include <pthread.h> | ||
|
||
union iopair { | ||
int fd[2]; | ||
struct { | ||
int r, w; | ||
}; | ||
}; | ||
|
||
static union iopair get_main(void) { | ||
union iopair ret = { .r = STDIN_FILENO, .w = STDOUT_FILENO }; | ||
ucsp_info_and_adjust_fds(&ret.w, &ret.r); | ||
return ret; | ||
} | ||
|
||
static union iopair make_pipe(void) { | ||
union iopair ret; | ||
xpipe(ret.fd); | ||
return ret; | ||
} | ||
|
||
int main(const int ac, const char* av[static const ac]) { | ||
if (ac != 3) | ||
return 1; | ||
int fd_fo_main = STDOUT_FILENO, fd_fi_main = STDIN_FILENO; | ||
ucsp_info_and_adjust_fds(&fd_fo_main, &fd_fi_main); | ||
int frontend_pipe[2]; | ||
xpipe(frontend_pipe); | ||
struct ThreadBag thr[] = { | ||
npth_define(fsm_wireformat, "wp", .from_wire = fd_fi_main, .to_wire = fd_fo_main, .to_fronted = STDOUT_FILENO) | ||
const union iopair foreign = get_main(), internal[] = { make_pipe() }; | ||
struct task* t[] = { | ||
create_task("wp", fsm_wireformat, .from_wire = foreign.r, .to_wire = foreign.w, .to_fronted = internal[0].w) | ||
}; | ||
for (size_t i = 0; i < lengthof(thr); i++) { | ||
pthread_create(&thr[i].handle, NULL, thr[i].entry, thr[i].arg); | ||
pthread_setname_np(thr[i].handle, thr[i].name); | ||
} | ||
for (size_t i = 0; i < lengthof(thr); i++) | ||
pthread_join(thr[i].handle, NULL); | ||
return EXIT_SUCCESS; | ||
int error = 0; | ||
for (size_t i = 0; i < lengthof(t); i++) | ||
error |= teardown_task(t[i]); | ||
return error ? EXIT_FAILURE : EXIT_SUCCESS; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#pragma once | ||
#include "utils.h" | ||
|
||
typedef void* (* const entry_t)(void*); | ||
|
||
struct task; | ||
union retval { | ||
void* ptr; | ||
int num; | ||
}; | ||
|
||
#define create_task(Name, Entry, ...) create_task_(Name, Entry, &(struct Entry ## _args){ __VA_ARGS__ }); | ||
struct task* create_task_(const char* name, entry_t entry, const void* arg); | ||
int teardown_task(struct task*); | ||
|
||
size_t send_message(int fd, const input_t* p, const input_t* pe) __attribute__((nonnull(2,3))); | ||
size_t recv_message(int fd, size_t size, input_t p[static size], const input_t** pe) __attribute__((nonnull(3,4))); | ||
|
||
inline size_t send_message_buf(const int fd, const size_t size, const input_t buf[static const size]) { | ||
return send_message(fd, buf, buf + size); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters