FreeBSD/sys/compat/cloudabi64/cloudabi64_poll.c
/* Converts CloudABI's subscription objects to FreeBSD's struct kevent. */
Converts CloudABI's subscription objects to FreeBSD's struct kevent.
Converts CloudABI ' s subscription objects to FreeBSD ' s struct kevent .
static int
cloudabi64_kevent_copyin(void *arg, struct kevent *kevp, int count)
{
	cloudabi64_subscription_t sub;
	struct cloudabi64_kevent_args *args;
	cloudabi_timestamp_t ts;
	int error;
	args = arg;
	while (count-- > 0) {
		error = copyin(args->in++, &sub, sizeof(sub));
		if (error != 0)
			return (error);
		memset(kevp, 0, sizeof(*kevp));
		kevp->udata = (void *)sub.userdata;
		switch (sub.type) {
		case CLOUDABI_EVENTTYPE_CLOCK:
			kevp->filter = EVFILT_TIMER;
			kevp->ident = sub.clock.identifier;
			kevp->fflags = NOTE_NSECONDS;
			if ((sub.clock.flags &
			    CLOUDABI_SUBSCRIPTION_CLOCK_ABSTIME) != 0 &&
			    sub.clock.timeout > 0) {
				error = cloudabi_clock_time_get(curthread,
				    sub.clock.clock_id, &ts);
				if (error != 0)
					return (error);
				ts = ts > sub.clock.timeout ? 0 :
				    sub.clock.timeout - ts;
			} else {
				ts = sub.clock.timeout;
			}
			kevp->data = ts > INTPTR_MAX ? INTPTR_MAX : ts;
			break;
		case CLOUDABI_EVENTTYPE_FD_READ:
			kevp->filter = EVFILT_READ;
			kevp->ident = sub.fd_readwrite.fd;
			if ((sub.fd_readwrite.flags &
			    CLOUDABI_SUBSCRIPTION_FD_READWRITE_POLL) != 0)
				kevp->fflags = NOTE_FILE_POLL;
			break;
		case CLOUDABI_EVENTTYPE_FD_WRITE:
			kevp->filter = EVFILT_WRITE;
			kevp->ident = sub.fd_readwrite.fd;
			break;
		case CLOUDABI_EVENTTYPE_PROC_TERMINATE:
			kevp->filter = EVFILT_PROCDESC;
			kevp->ident = sub.proc_terminate.fd;
			kevp->fflags = NOTE_EXIT;
			break;
		}
		if (args->once) {
			kevp->flags = EV_ADD | EV_ONESHOT;
		} else {
			if ((sub.flags & CLOUDABI_SUBSCRIPTION_ADD) != 0)
				kevp->flags |= EV_ADD;
			if ((sub.flags & CLOUDABI_SUBSCRIPTION_CLEAR) != 0)
				kevp->flags |= EV_CLEAR;
			if ((sub.flags & CLOUDABI_SUBSCRIPTION_DELETE) != 0)
				kevp->flags |= EV_DELETE;
			if ((sub.flags & CLOUDABI_SUBSCRIPTION_DISABLE) != 0)
				kevp->flags |= EV_DISABLE;
			if ((sub.flags & CLOUDABI_SUBSCRIPTION_ENABLE) != 0)
				kevp->flags |= EV_ENABLE;
			if ((sub.flags & CLOUDABI_SUBSCRIPTION_ONESHOT) != 0)
				kevp->flags |= EV_ONESHOT;
		}
		++kevp;
	}
	return (0);
}
static int cloudabi64_kevent_copyin ( void * arg , struct kevent * kevp , int count ) { cloudabi64_subscription_t sub ; struct cloudabi64_kevent_args * args ; cloudabi_timestamp_t ts ; int error ; args = arg ; while ( count -- > 0 ) { error = copyin ( args -> in ++ , & sub , sizeof ( sub ) ) ; if ( error != 0 ) return ( error ) ; memset ( kevp , 0 , sizeof ( * kevp ) ) ; kevp -> udata = ( void * ) sub . userdata ; switch ( sub . type ) { case CLOUDABI_EVENTTYPE_CLOCK : kevp -> filter = EVFILT_TIMER ; kevp -> ident = sub . clock . identifier ; kevp -> fflags = NOTE_NSECONDS ; if ( ( sub . clock . flags & CLOUDABI_SUBSCRIPTION_CLOCK_ABSTIME ) != 0 && sub . clock . timeout > 0 ) { error = cloudabi_clock_time_get ( curthread , sub . clock . clock_id , & ts ) ; if ( error != 0 ) return ( error ) ; ts = ts > sub . clock . timeout ? 0 : sub . clock . timeout - ts ; } else { ts = sub . clock . timeout ; } kevp -> data = ts > INTPTR_MAX ? INTPTR_MAX : ts ; break ; case CLOUDABI_EVENTTYPE_FD_READ : kevp -> filter = EVFILT_READ ; kevp -> ident = sub . fd_readwrite . fd ; if ( ( sub . fd_readwrite . flags & CLOUDABI_SUBSCRIPTION_FD_READWRITE_POLL ) != 0 ) kevp -> fflags = NOTE_FILE_POLL ; break ; case CLOUDABI_EVENTTYPE_FD_WRITE : kevp -> filter = EVFILT_WRITE ; kevp -> ident = sub . fd_readwrite . fd ; break ; case CLOUDABI_EVENTTYPE_PROC_TERMINATE : kevp -> filter = EVFILT_PROCDESC ; kevp -> ident = sub . proc_terminate . fd ; kevp -> fflags = NOTE_EXIT ; break ; } if ( args -> once ) { kevp -> flags = EV_ADD | EV_ONESHOT ; } else { if ( ( sub . flags & CLOUDABI_SUBSCRIPTION_ADD ) != 0 ) kevp -> flags |= EV_ADD ; if ( ( sub . flags & CLOUDABI_SUBSCRIPTION_CLEAR ) != 0 ) kevp -> flags |= EV_CLEAR ; if ( ( sub . flags & CLOUDABI_SUBSCRIPTION_DELETE ) != 0 ) kevp -> flags |= EV_DELETE ; if ( ( sub . flags & CLOUDABI_SUBSCRIPTION_DISABLE ) != 0 ) kevp -> flags |= EV_DISABLE ; if ( ( sub . flags & CLOUDABI_SUBSCRIPTION_ENABLE ) != 0 ) kevp -> flags |= EV_ENABLE ; if ( ( sub . flags & CLOUDABI_SUBSCRIPTION_ONESHOT ) != 0 ) kevp -> flags |= EV_ONESHOT ; } ++ kevp ; } return ( 0 ) ; }
Converts CloudABI's subscription objects to FreeBSD's struct kevent.
Converts CloudABI ' s subscription objects to FreeBSD ' s struct kevent .
/* TODO(ed): Copy in multiple entries at once. */ /* Convert absolute timestamp to a relative. */ /* Relative timestamp. */ /* Ignore flags. Simply use oneshot mode. */ /* Translate flags. */