FreeBSD/sys/compat/cloudabi64/cloudabi64_poll.c
/* Converts FreeBSD's struct kevent to CloudABI's event objects. */
Converts FreeBSD's struct kevent to CloudABI's event objects.
Converts FreeBSD ' s struct kevent to CloudABI ' s event objects .
static int
cloudabi64_kevent_copyout(void *arg, struct kevent *kevp, int count)
{
	cloudabi64_event_t ev;
	struct cloudabi64_kevent_args *args;
	int error;
	args = arg;
	while (count-- > 0) {
		memset(&ev, 0, sizeof(ev));
		ev.userdata = (uintptr_t)kevp->udata;
		switch (kevp->filter) {
		case EVFILT_TIMER:
			ev.type = CLOUDABI_EVENTTYPE_CLOCK;
			ev.clock.identifier = kevp->ident;
			break;
		case EVFILT_READ:
			ev.type = CLOUDABI_EVENTTYPE_FD_READ;
			ev.fd_readwrite.fd = kevp->ident;
			break;
		case EVFILT_WRITE:
			ev.type = CLOUDABI_EVENTTYPE_FD_WRITE;
			ev.fd_readwrite.fd = kevp->ident;
			break;
		case EVFILT_PROCDESC:
			ev.type = CLOUDABI_EVENTTYPE_PROC_TERMINATE;
			ev.proc_terminate.fd = kevp->ident;
			break;
		}
		if ((kevp->flags & EV_ERROR) == 0) {
			switch (kevp->filter) {
			case EVFILT_READ:
			case EVFILT_WRITE:
				ev.fd_readwrite.nbytes = kevp->data;
				if ((kevp->flags & EV_EOF) != 0) {
					ev.fd_readwrite.flags |=
					    CLOUDABI_EVENT_FD_READWRITE_HANGUP;
				}
				break;
			case EVFILT_PROCDESC:
				if (WIFSIGNALED(kevp->data)) {
					ev.proc_terminate.signal =
					   convert_signal(WTERMSIG(kevp->data));
					ev.proc_terminate.exitcode = 0;
				} else {
					ev.proc_terminate.signal = 0;
					ev.proc_terminate.exitcode =
					    WEXITSTATUS(kevp->data);
				}
				break;
			}
		} else {
			ev.error = cloudabi_convert_errno(kevp->data);
		}
		++kevp;
		error = copyout(&ev, args->out++, sizeof(ev));
		if (error != 0)
			return (error);
	}
	return (0);
}
static int cloudabi64_kevent_copyout ( void * arg , struct kevent * kevp , int count ) { cloudabi64_event_t ev ; struct cloudabi64_kevent_args * args ; int error ; args = arg ; while ( count -- > 0 ) { memset ( & ev , 0 , sizeof ( ev ) ) ; ev . userdata = ( uintptr_t ) kevp -> udata ; switch ( kevp -> filter ) { case EVFILT_TIMER : ev . type = CLOUDABI_EVENTTYPE_CLOCK ; ev . clock . identifier = kevp -> ident ; break ; case EVFILT_READ : ev . type = CLOUDABI_EVENTTYPE_FD_READ ; ev . fd_readwrite . fd = kevp -> ident ; break ; case EVFILT_WRITE : ev . type = CLOUDABI_EVENTTYPE_FD_WRITE ; ev . fd_readwrite . fd = kevp -> ident ; break ; case EVFILT_PROCDESC : ev . type = CLOUDABI_EVENTTYPE_PROC_TERMINATE ; ev . proc_terminate . fd = kevp -> ident ; break ; } if ( ( kevp -> flags & EV_ERROR ) == 0 ) { switch ( kevp -> filter ) { case EVFILT_READ : case EVFILT_WRITE : ev . fd_readwrite . nbytes = kevp -> data ; if ( ( kevp -> flags & EV_EOF ) != 0 ) { ev . fd_readwrite . flags |= CLOUDABI_EVENT_FD_READWRITE_HANGUP ; } break ; case EVFILT_PROCDESC : if ( WIFSIGNALED ( kevp -> data ) ) { ev . proc_terminate . signal = convert_signal ( WTERMSIG ( kevp -> data ) ) ; ev . proc_terminate . exitcode = 0 ; } else { ev . proc_terminate . signal = 0 ; ev . proc_terminate . exitcode = WEXITSTATUS ( kevp -> data ) ; } break ; } } else { ev . error = cloudabi_convert_errno ( kevp -> data ) ; } ++ kevp ; error = copyout ( & ev , args -> out ++ , sizeof ( ev ) ) ; if ( error != 0 ) return ( error ) ; } return ( 0 ) ; }
Converts FreeBSD's struct kevent to CloudABI's event objects.
Converts FreeBSD ' s struct kevent to CloudABI ' s event objects .
/* Convert fields that should always be present. */ /* Success. */ /* Process got signalled. */ /* Process exited. */ /* Error. */ /* TODO(ed): Copy out multiple entries at once. */