#include #include #include #include #ifdef _WIN32 #define PIPENAME "\\\\?\\pipe\\echo.sock" #else #define PIPENAME "/tmp/echo.sock" #endif uv_loop_t *loop; typedef struct { uv_write_t req; uv_buf_t buf; } write_req_t; void free_write_req(uv_write_t *req) { write_req_t *wr = (write_req_t*) req; free(wr->buf.base); free(wr); } void alloc_buffer(uv_handle_t *handle, size_t suggested_size, uv_buf_t *buf) { buf->base = malloc(suggested_size); buf->len = suggested_size; } void echo_write(uv_write_t *req, int status) { if (status < 0) { fprintf(stderr, "Write error %s\n", uv_err_name(status)); } free_write_req(req); } void echo_read(uv_stream_t *client, ssize_t nread, const uv_buf_t *buf) { if (nread > 0) { write_req_t *req = (write_req_t*) malloc(sizeof(write_req_t)); req->buf = uv_buf_init(buf->base, nread); uv_write((uv_write_t*) req, client, &req->buf, 1, echo_write); return; } if (nread < 0) { if (nread != UV_EOF) fprintf(stderr, "Read error %s\n", uv_err_name(nread)); uv_close((uv_handle_t*) client, NULL); } free(buf->base); } void on_new_connection(uv_stream_t *server, int status) { if (status == -1) { // error! return; } uv_pipe_t *client = (uv_pipe_t*) malloc(sizeof(uv_pipe_t)); uv_pipe_init(loop, client, 0); if (uv_accept(server, (uv_stream_t*) client) == 0) { uv_read_start((uv_stream_t*) client, alloc_buffer, echo_read); } else { uv_close((uv_handle_t*) client, NULL); } } void remove_sock(int sig) { uv_fs_t req; uv_fs_unlink(loop, &req, PIPENAME, NULL); exit(0); } int main() { loop = uv_default_loop(); uv_pipe_t server; uv_pipe_init(loop, &server, 0); signal(SIGINT, remove_sock); int r; if ((r = uv_pipe_bind(&server, PIPENAME))) { fprintf(stderr, "Bind error %s\n", uv_err_name(r)); return 1; } if ((r = uv_listen((uv_stream_t*) &server, 128, on_new_connection))) { fprintf(stderr, "Listen error %s\n", uv_err_name(r)); return 2; } return uv_run(loop, UV_RUN_DEFAULT); } AgeCommit message (Collapse)Author 2021-08-07Merge thorpej-cfargs2.thorpej 2021-04-24Merge thorpej-cfargs branch:thorpej Simplify and make extensible the config_search() / config_found() / config_attach() interfaces: rather than having different variants for which arguments you want pass along, just have a single call that takes a variadic list of tag-value arguments. Adjust all call sites: - Simplify wherever possible; don't pass along arguments that aren't actually needed. - Don't be explicit about what interface attribute is attaching if the device only has one. (More simplification.) - Add a config_probe() function to be used in indirect configuiration situations, making is visibly easier to see when indirect config is in play, and allowing for future change in semantics. (As of now, this is just a wrapper around config_match(), but that is an implementation detail.) Remove unnecessary or redundant interface attributes where they're not needed. There are currently 5 "cfargs" defined: - CFARG_SUBMATCH (submatch function for direct config) - CFARG_SEARCH (search function for indirect config) - CFARG_IATTR (interface attribte) - CFARG_LOCATORS (locators array) - CFARG_DEVHANDLE (devhandle_t - wraps OFW, ACPI, etc. handles) ...and a sentinel value CFARG_EOL. Add some extra sanity checking to ensure that interface attributes aren't ambiguous. Use CFARG_DEVHANDLE in MI FDT, OFW, and ACPI code, and macppc and shark ports to associate those device handles with device_t instance. This will trickle trough to more places over time (need back-end for pre-OFW Sun OBP; any others?). 2020-04-01Newer PC Engines BIOS versions don't set up the Super I/O for GPIO thead way we want so ignore most of the existing settings and enable banks 0 and 1. 2019-11-16PR port-i386/54701: deal with missing pmf platform keys.martin 2019-10-25Add support for Nuvoton NCT5104D GPIO chips, as found on PC Engines APUmartin systems. From Andrew Doran in PR kern/54648.