1
0
mirror of https://github.com/janet-lang/janet synced 2024-11-17 22:24:49 +00:00

Some bsds return ENODEV for devices like /dev/null

This commit is contained in:
Calvin Rose 2023-10-08 15:09:53 -05:00
parent 8a9be9d837
commit 6c4906605a

View File

@ -1408,12 +1408,18 @@ static void janet_ev_setup_selfpipe(void) {
/* Handle events from the self pipe inside the event loop */ /* Handle events from the self pipe inside the event loop */
static void janet_ev_handle_selfpipe(void) { static void janet_ev_handle_selfpipe(void) {
recur:
JanetSelfPipeEvent response; JanetSelfPipeEvent response;
while (read(janet_vm.selfpipe[0], &response, sizeof(response)) > 0) { int status;
do {
status = read(janet_vm.selfpipe[0], &response, sizeof(response));
} while (status == -1 && errno == EINTR);
if (status > 0) {
if (NULL != response.cb) { if (NULL != response.cb) {
response.cb(response.msg); response.cb(response.msg);
janet_ev_dec_refcount(); janet_ev_dec_refcount();
} }
goto recur;
} }
} }
@ -1660,15 +1666,27 @@ static void timestamp2timespec(struct timespec *t, JanetTimestamp ts) {
void janet_register_stream(JanetStream *stream) { void janet_register_stream(JanetStream *stream) {
struct kevent kevs[2]; struct kevent kevs[2];
EV_SETx(&kevs[0], stream->handle, EVFILT_READ, EV_ADD | EV_ENABLE | EV_CLEAR, 0, 0, stream); int length = 0;
EV_SETx(&kevs[1], stream->handle, EVFILT_WRITE, EV_ADD | EV_ENABLE | EV_CLEAR, 0, 0, stream); if (stream->flags & JANET_STREAM_READABLE) {
EV_SETx(&kevs[length++], stream->handle, EVFILT_READ, EV_ADD | EV_ENABLE | EV_CLEAR, 0, 0, stream);
}
if (stream->flags & JANET_STREAM_WRITABLE) {
EV_SETx(&kevs[length++], stream->handle, EVFILT_WRITE, EV_ADD | EV_ENABLE | EV_CLEAR, 0, 0, stream);
}
int status; int status;
do { do {
status = kevent(janet_vm.kq, kevs, 2, NULL, 0, NULL); status = kevent(janet_vm.kq, kevs, length, NULL, 0, NULL);
} while (status == -1 && errno != EINTR); } while (status == -1 && errno == EINTR);
if (status == -1) { if (status == -1) {
if (errno == ENODEV) {
/* Couldn't add to event loop, so assume that it completes
* synchronously. */
stream->flags |= JANET_STREAM_UNREGISTERED;
} else {
/* Unexpected error */
janet_panicv(janet_ev_lasterr()); janet_panicv(janet_ev_lasterr());
} }
}
} }
#define JANET_KQUEUE_MAX_EVENTS 64 #define JANET_KQUEUE_MAX_EVENTS 64