Ejemplo n.º 1
0
/** Frees an unlang event, removing it from the request's event loop
 *
 * @param[in] ev	The event to free.
 *
 * @return 0
 */
static int _unlang_event_free(unlang_module_event_t *ev)
{
	if (ev->ev) {
		(void) fr_event_timer_delete(ev->request->el, &(ev->ev));
		return 0;
	}

	if (ev->fd >= 0) {
		(void) fr_event_fd_delete(ev->request->el, ev->fd, FR_EVENT_FILTER_IO);
	}

	return 0;
}
static void mod_vnode_extend(fr_listen_t *li, UNUSED uint32_t fflags)
{
	proto_detail_file_thread_t *thread = talloc_get_type_abort(li->thread_instance, proto_detail_file_thread_t);

	bool has_worker = false;

	pthread_mutex_lock(&thread->worker_mutex);
	has_worker = (thread->num_workers != 0);
	pthread_mutex_unlock(&thread->worker_mutex);

	if (has_worker) return;

	if (thread->ev) fr_event_timer_delete(thread->el, &thread->ev);

	work_init(thread);
}
Ejemplo n.º 3
0
/** Callback called by libcurl to set/unset timers
 *
 * Each rlm_rest_thread_t has a timer event which is controller by libcurl.
 * This allows libcurl to honour timeouts set on requests to remote hosts,
 * and means we don't need to set timeouts for individual I/O events.
 *
 * @param[in] mandle		handle requesting the timer be set/unset.
 * @param[in] timeout_ms	If > 0, how long to wait before calling curl_multi_socket_action.
 *				If == 0, we call curl_multi_socket_action as soon as possible.
 *				If < 0, we delete the timer.
 * @param[in] ctx		The rlm_rest_thread_t specific to this thread.
 * @return
 *	- 0 on success.
 *	- -1 on error.
 */
static int _rest_io_timer_modify(CURLM *mandle, long timeout_ms, void *ctx)
{
	rlm_rest_thread_t	*t = talloc_get_type_abort(ctx, rlm_rest_thread_t);
	CURLMcode		ret;
	int			running = 0;
	struct timeval		now, to_add, when;

	if (timeout_ms == 0) {
		ret = curl_multi_socket_action(mandle, CURL_SOCKET_TIMEOUT, 0, &running);
		if (ret != CURLM_OK) {
			ERROR("Failed servicing curl multi-handle: %s (%i)", curl_multi_strerror(ret), ret);
			return -1;
		}

		DEBUG3("multi-handle %p serviced from CURLMOPT_TIMERFUNCTION callback (%s).  "
		       "%i request(s) in progress, %i requests(s) to dequeue",
		        mandle, __FUNCTION__, running, t->transfers - running);
		return 0;
	}

	if (timeout_ms < 0) {
		if (fr_event_timer_delete(t->el, &t->ev) < 0) {
			PERROR("Failed deleting multi-handle timer");
			return -1;
		}
		DEBUG3("multi-handle %p timer removed", mandle);
		return 0;
	}

	DEBUG3("multi-handle %p will need servicing in %li ms", mandle, timeout_ms);

	gettimeofday(&now, NULL);
	fr_timeval_from_ms(&to_add, (uint64_t)timeout_ms);
	fr_timeval_add(&when, &now, &to_add);

	(void) fr_event_timer_insert(NULL, t->el, &t->ev,
				     &when, _rest_io_timer_expired, t);

	return 0;
}