Esempio n. 1
0
static wd_transfer_t * wd_transfer_init(wd_transfer_t *transfer) {
	transfer->queue				= -1;
	transfer->queue_lock		= wi_condition_lock_init_with_condition(wi_condition_lock_alloc(), 0);
	transfer->queue_time		= wi_time_interval();
	transfer->state				= WD_TRANSFER_QUEUED;
	transfer->finished_lock		= wi_condition_lock_init_with_condition(wi_condition_lock_alloc(), 0);
	
	return transfer;
}
Esempio n. 2
0
static wd_transfer_t * wd_transfer_init_with_user(wd_transfer_t *transfer, wd_user_t *user) {
	transfer->state			= WD_TRANSFER_QUEUED;
	transfer->queue_time	= wi_time_interval();
	transfer->user			= wi_retain(user);
	transfer->hash			= wi_retain(wi_data_sha1(wi_data_with_random_bytes(1024)));
	transfer->socket_lock	= wi_lock_init(wi_lock_alloc());
	transfer->state_lock	= wi_condition_lock_init_with_condition(wi_condition_lock_alloc(), transfer->state);
	transfer->fd			= -1;

	return transfer;
}
Esempio n. 3
0
void wd_transfers_initialize(void) {
	wd_transfer_runtime_id = wi_runtime_register_class(&wd_transfer_runtime_class);

	wd_transfers = wi_array_init(wi_mutable_array_alloc());

	wd_transfers_status_lock = wi_lock_init(wi_lock_alloc());
	
	wd_transfers_user_downloads = wi_dictionary_init_with_capacity_and_callbacks(wi_mutable_dictionary_alloc(),
		0, wi_dictionary_default_key_callbacks, wi_dictionary_null_value_callbacks);

	wd_transfers_user_uploads = wi_dictionary_init_with_capacity_and_callbacks(wi_mutable_dictionary_alloc(),
		0, wi_dictionary_default_key_callbacks, wi_dictionary_null_value_callbacks);
	
	wd_transfers_queue_lock = wi_condition_lock_init_with_condition(wi_condition_lock_alloc(), 0);
}
Esempio n. 4
0
void wi_test_fsevents(void) {
#ifdef WI_PTHREADS
	wi_string_t			*directory;
	
	wi_test_fsevents_fsevents = wi_fsevents_init(wi_fsevents_alloc());
	
	if(!wi_test_fsevents_fsevents) {
		if(wi_error_domain() != WI_ERROR_DOMAIN_LIBWIRED && wi_error_code() != WI_ERROR_FSEVENTS_NOTSUPP)
			WI_TEST_ASSERT_NOT_NULL(wi_test_fsevents_fsevents, "%m");
		
		return;
	}
	
	directory = wi_fs_temporary_path_with_template(WI_STR("/tmp/libwired-fsevents.XXXXXXXX"));
	
	wi_fs_create_directory(directory, 0700);
	
	wi_fsevents_add_path(wi_test_fsevents_fsevents, directory);
	wi_fsevents_set_callback(wi_test_fsevents_fsevents, wi_test_fsevents_callback);
	
	wi_test_fsevents_lock = wi_condition_lock_init_with_condition(wi_condition_lock_alloc(), 0);
	
	if(!wi_thread_create_thread(wi_test_fsevents_thread, NULL))
		WI_TEST_FAIL("%m");
	
	wi_thread_sleep(0.1);
	
	wi_string_write_to_file(WI_STR("foo"), wi_string_by_appending_path_component(directory, WI_STR("file")));
	
	wi_condition_lock_lock_when_condition(wi_test_fsevents_lock, 1, 0.0);
	
	if(!wi_test_fsevents_path)
		WI_TEST_FAIL("No fsevents callback received");
	else
		WI_TEST_ASSERT_EQUAL_INSTANCES(wi_test_fsevents_path, directory, "");
	
	wi_condition_lock_unlock(wi_test_fsevents_lock);

	wi_fs_delete_path(directory);
	
	wi_release(wi_test_fsevents_lock);
	wi_release(wi_test_fsevents_fsevents);
	wi_release(wi_test_fsevents_path);
#endif
}
Esempio n. 5
0
void wi_test_timer(void) {
#ifdef WI_PTHREADS
	wi_timer_t		*timer;
	
	_wi_test_timer_lock = wi_autorelease(wi_condition_lock_init_with_condition(wi_condition_lock_alloc(), 0));
	
	timer = wi_autorelease(wi_timer_init_with_function(wi_timer_alloc(), _wi_test_timer_function, 0.001, false));
	wi_timer_schedule(timer);
	
	if(wi_condition_lock_lock_when_condition(_wi_test_timer_lock, 1, 1.0)) {
		WI_TEST_ASSERT_EQUALS(_wi_test_timer_hits, 5U, "");
		wi_condition_lock_unlock(_wi_test_timer_lock);
	} else {
		WI_TEST_FAIL("Timed out waiting for timer, currently at %u %s",
			_wi_test_timer_hits, _wi_test_timer_hits == 1 ? "hit" : "hits");
	}
#endif
}
void wi_test_filesystem_events(void) {
#if defined(WI_FILESYSTEM_EVENTS)
    wi_filesystem_events_t  *filesystem_events;
    wi_string_t             *path;
    wi_boolean_t            result;
    
    _wi_test_filesystem_events_lock = wi_autorelease(wi_condition_lock_init_with_condition(wi_condition_lock_alloc(), 0));
    _wi_test_filesystem_events_paths = wi_mutable_set();
    
    path = wi_filesystem_temporary_path_with_template(WI_STR("/tmp/libwired-test-filesystem.XXXXXXX"));
    
    WI_TEST_ASSERT_NOT_NULL(path, "");
    
    result = wi_filesystem_create_directory_at_path(path);
    
    WI_TEST_ASSERT_TRUE(result, "");
    
    filesystem_events = wi_filesystem_events();
    
    WI_TEST_ASSERT_NOT_NULL(filesystem_events, "");
    
    result = wi_filesystem_events_add_path_with_callback(filesystem_events, path, _wi_test_filesystem_events_callback);
    
    WI_TEST_ASSERT_TRUE(result, "");
    
    result = wi_string_write_utf8_string_to_path(WI_STR("hello world"), wi_string_by_appending_path_component(path, WI_STR("foobar")));
    
    WI_TEST_ASSERT_TRUE(result, "");
    
    if(!wi_condition_lock_lock_when_condition(_wi_test_filesystem_events_lock, 1, 1.0))
        WI_TEST_FAIL("timed out waiting for filesystem events thread");
    
    WI_TEST_ASSERT_EQUAL_INSTANCES(_wi_test_filesystem_events_paths, wi_set_with_data(path, NULL), "");
    
    wi_condition_lock_unlock(_wi_test_filesystem_events_lock);
#endif
}
Esempio n. 7
0
wi_condition_lock_t * wi_condition_lock_init(wi_condition_lock_t *lock) {
	return wi_condition_lock_init_with_condition(lock, 0);
}
Esempio n. 8
0
void wi_timer_initialize(void) {
	_wi_timers			= wi_array_init(wi_mutable_array_alloc());
	_wi_timer_lock		= wi_condition_lock_init_with_condition(wi_condition_lock_alloc(), 0);
}