예제 #1
0
/**
 * Remove session from storage.
 * @param[in] sess
 */
void session_remove(struct zsession *sess)
{
    size_t sidx = STORAGE_IDX(sess->ip);
    pthread_rwlock_wrlock(&zinst()->sessions_lock[sidx]);
    HASH_DELETE(hh, zinst()->sessions[sidx], sess);
    pthread_rwlock_unlock(&zinst()->sessions_lock[sidx]);
    session_release(sess); // release from session hash
}
예제 #2
0
파일: io.c 프로젝트: Karm/knot-resolver
void io_deinit(uv_handle_t *handle)
{
	if (!handle) {
		return;
	}
	uv_loop_t *loop = handle->loop;
	if (loop && loop->data) {
		struct worker_ctx *worker = loop->data;
		session_release(worker, handle->data);
	} else {
		session_free(handle->data);
	}
	handle->data = NULL;
}
예제 #3
0
int main(int argc, char *argv[])
{
	int timeout = 0;
	sp_error error;
	int notify_cmdline = 0;
	int notify_events = 0;
	struct timespec ts;
	
	(void)argc;
	(void)argv;

	pthread_mutex_init(&g_notify_mutex, NULL);
	pthread_cond_init(&g_notify_cond, NULL);
	session_init();
	cmd_init(cmd_notify);
	
	do {
		clock_gettime(CLOCK_REALTIME, &ts);
		ts.tv_sec += timeout / 1000;
		ts.tv_nsec += (timeout % 1000) * 1E6;
		if (ts.tv_nsec > 1E9) {
			ts.tv_sec++;
			ts.tv_nsec -= 1E9;
		}

		pthread_mutex_lock(&g_notify_mutex);
		pthread_cond_timedwait(&g_notify_cond, &g_notify_mutex, &ts);
		notify_cmdline = g_notify_cmdline;
		notify_events = g_notify_events;
		g_notify_cmdline = 0;
		g_notify_events = 0;
		pthread_mutex_unlock(&g_notify_mutex);
		if (notify_cmdline) {
			cmd_process();
		}

		if (notify_events) {
			do {
				error = sp_session_process_events(g_session, &timeout);
				if (error != SP_ERROR_OK)
					fprintf(stderr, "error processing events: %s\n",
							sp_error_message(error));
			} while (timeout == 0);
		}

	} while (!is_program_finished());

	session_logout();
	while (session_is_logged_in()) {
       		clock_gettime(CLOCK_REALTIME, &ts);
		ts.tv_sec += 1;

		pthread_mutex_lock(&g_notify_mutex);
		pthread_cond_timedwait(&g_notify_cond, &g_notify_mutex, &ts);
		notify_events = g_notify_events;
		g_notify_events = 0;
		pthread_mutex_unlock(&g_notify_mutex);
		if (notify_events) {
			do {
				error = sp_session_process_events(g_session, &timeout);
				if (error != SP_ERROR_OK)
					fprintf(stderr, "error processing events: %s\n",
							sp_error_message(error));
			} while (timeout == 0);
		}
	}

	session_release();
	cmd_destroy();

	pthread_mutex_destroy(&g_notify_mutex);
	pthread_cond_destroy(&g_notify_cond);

	return 0;

}