int get_input_handle(void) { static int h = -1; if (h >= 0) return h; if (be_pipe(ihpipe) < 0) return -1; if ((inth = start_thr(input_handle_th, NULL, "input_thread")) < 0) { closesocket(ihpipe[0]); closesocket(ihpipe[1]); fatal_exit("Can't spawn input thread"); } return h = ihpipe[0]; }
int get_input_handle() { static int h = -1; if (h >= 0) return h; if (be_pipe(ihpipe) < 0) return -1; if ((inth = start_thr(input_handle_th, NULL, "input_thread")) < 0) { closesocket(ihpipe[0]); closesocket(ihpipe[1]); return -1; } return h = ihpipe[0]; }
int get_output_handle(void) { static int h = -1; if (h >= 0) return h; if (be_pipe(ohpipe) < 0) return -1; if (start_thr(output_handle_th, NULL, "output_thread") < 0) { closesocket(ohpipe[0]); closesocket(ohpipe[1]); return -1; } return h = ohpipe[1]; }
int start_thread(void (*fn)(void *, int), void *ptr, int l) { int p[2]; struct tdata *t; if (c_pipe(p) < 0) return -1; t = malloc(sizeof(*t) + l); if (!t) return -1; t->fn = fn; t->h = p[1]; memcpy(t->data, ptr, l); if (start_thr((void (*)(void *)) bgt, t, "elinks_thread") < 0) { close(p[0]); close(p[1]); mem_free(t); return -1; } return p[0]; }