예제 #1
0
파일: restart.c 프로젝트: JReyLBC/csis4600
int waitfdtimed(int fd, struct timeval end) {
    fd_set readset;
    int retval;
    struct timeval timeout;

    if ((fd < 0) || (fd >= FD_SETSIZE)) {
        errno = EINVAL;
        return -1;
    }
    FD_ZERO(&readset);
    FD_SET(fd, &readset);
    if (gettimeout(end, &timeout) == -1)
        return -1;
    while (((retval = select(fd + 1, &readset, NULL, NULL, &timeout)) == -1)
           && (errno == EINTR)) {
        if (gettimeout(end, &timeout) == -1)
            return -1;
        FD_ZERO(&readset);
        FD_SET(fd, &readset);
    }
    if (retval == 0) {
        errno = ETIME;
        return -1;
    }
    if (retval == -1)
        return -1;
    return 0;
}
예제 #2
0
/**
 * events_timer_register(func, cookie, timeo):
 * Register ${func}(${cookie}) to be run ${timeo} in the future.  Return a
 * cookie which can be passed to events_timer_cancel or events_timer_reset.
 */
void *
events_timer_register(int (*func)(void *), void * cookie,
    const struct timeval * timeo)
{
	struct eventrec * r;
	struct timerrec * t;
	struct timeval tv;

	/* Create the timer queue if it doesn't exist yet. */
	if (Q == NULL) {
		if ((Q = timerqueue_init()) == NULL)
			goto err0;
	}

	/* Bundle into an eventrec record. */
	if ((r = events_mkrec(func, cookie)) == NULL)
		goto err0;

	/* Create a timer record. */
	if ((t = malloc(sizeof(struct timerrec))) == NULL)
		goto err1;
	t->r = r;
	memcpy(&t->tv_orig, timeo, sizeof(struct timeval));

	/* Compute the absolute timeout. */
	if (gettimeout(&tv, &t->tv_orig))
		goto err2;

	/* Add this to the timer queue. */
	if ((t->cookie = timerqueue_add(Q, &tv, t)) == NULL)
		goto err2;

	/* Success! */
	return (t);

err2:
	free(t);
err1:
	events_freerec(r);
err0:
	/* Failure! */
	return (NULL);
}
예제 #3
0
/**
 * events_timer_reset(cookie):
 * Reset the timer for which the cookie ${cookie} was returned by
 * events_timer_register to its initial value.
 */
int
events_timer_reset(void * cookie)
{
	struct timerrec * t = cookie;
	struct timeval tv;

	/* Compute the new timeout. */
	if (gettimeout(&tv, &t->tv_orig))
		goto err0;

	/* Adjust the timer. */
	timerqueue_increase(Q, t->cookie, &tv);

	/* Success! */
	return (0);

err0:
	/* Failure! */
	return (-1);
}
	void Conditional::wait(size_t timeout) throw (ConditionalAbortException)
	{
#ifdef __DEVELOPMENT_ASSERTIONS__
		// assert a locked Conditional
		assert(isLocked());
#endif

		if (_abort) throw ConditionalAbortException(ConditionalAbortException::COND_ABORT);

		if (timeout == 0)
		{
			pthread_cond_wait( &cond, &m_mutex );
			if (_abort) throw ConditionalAbortException(ConditionalAbortException::COND_ABORT);
		}
		else
		{
			struct timespec ts;
			gettimeout(timeout, &ts);
			wait(&ts);
			if (_abort) throw ConditionalAbortException(ConditionalAbortException::COND_ABORT);
		}
	}
예제 #5
0
/*
 * Class:     es_tid_rocksaw_net_RawSocket
 * Method:    __getReceiveTimeout
 * Signature: (I)I
 */
JNIEXPORT jint JNICALL
Java_es_tid_rocksaw_net_RawSocket__1_1getReceiveTimeout
(JNIEnv *env, jclass cls, jint socket)
{
  return gettimeout(socket, SO_RCVTIMEO);
}
예제 #6
0
파일: RawSocket.c 프로젝트: aj04/Project_4
/*
 * Class:     com_savarese_rocksaw_net_RawSocket
 * Method:    __getSendTimeout
 * Signature: (I)I
 */
JNIEXPORT jint JNICALL
Java_com_savarese_rocksaw_net_RawSocket__1_1getSendTimeout
(JNIEnv *env, jclass cls, jint socket)
{
  return gettimeout(socket, SO_SNDTIMEO);
}