void test_o_connection_local_data_transfer()
{
	try
	{

		struct o_native_thread * th = o_native_thread_new("server", test_o_connection_private_listen_thread);
		o_native_thread_start(th);

		o_native_thread_current_sleep(400);

		struct o_connection * client_con = o_connection_remote_new(HOST_TEST, PORT_TEST);
		struct o_connection_remote * client = (struct o_connection_remote *) client_con;

		o_connection_remote_write_int(client, 10);
		int val = o_connection_remote_read_int(client);
		assert_true(val == 10, "error transfer int");

		o_connection_remote_write_byte(client, 10);
		char val_c = o_connection_remote_read_byte(client);
		assert_true(val_c == 10, "error transfer byte");

		o_connection_remote_write_short(client, 10);
		short val_s = o_connection_remote_read_short(client);
		assert_true(val_s == 10, "error transfer short");

		o_connection_remote_write_long64(client, 10);
		long long val_64 = o_connection_remote_read_long64(client);
		assert_true(val_64 == 10, "error transfer long 64");

		unsigned char to_send[15] =
		{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 };
		o_connection_remote_write_bytes(client, to_send, 15);

		int number;
		unsigned char *bytes = o_connection_remote_read_bytes(client, &number);
		assert_true(number == 15, "error transfer size of byte array");
		int i;
		for (i = 0; i < 15; ++i)
			assert_true(bytes[i] == to_send[i], "error transfer content of byte array");
		o_free(bytes);

		char * string = "test string";
		o_connection_remote_write_string(client, string);
		char * string_ret = o_connection_remote_read_string(client);
		assert_true(strcmp(string, string_ret) == 0, "error transfer string");
		o_free(string_ret);

		o_connection_free(client_con);
	}
	catch (struct o_exception, e)
	{
		char buf[512];
		sprintf(buf, "Error Message %s", o_exception_message(e));
		fail(buf);
	}
	end_try;
}
void o_native_socket_selector_simple_select()
{
	struct o_native_thread * accept_th = o_native_thread_new("thread", o_native_write_thread);
	o_native_thread_start(accept_th);
	o_native_thread_current_sleep(10);
	struct o_native_socket * sock = 0;
	try
	{
		sock = o_native_socket_connect("127.0.0.1", 2000);
	}
	catch(struct o_exception, ex)
	{
		fail("failed connect");
		o_free(ex);
	}
	end_try;
	int val = 10;
	struct o_native_socket_selector * sel = o_native_socket_selector_new();
	o_native_socket_selector_add_socket(sel, sock);
	o_native_socket_send(sock, &val, sizeof(int));
	struct o_native_socket * ret_sock = o_native_socket_selector_select(sel, -1);
	struct o_native_socket * ret_sock1 = o_native_socket_selector_select(sel, 10);
	o_native_socket_selector_end_select(sel, ret_sock);
	ret_sock = o_native_socket_selector_select(sel, -1);
	o_native_thread_current_sleep(10);
	int size = sizeof(int);
	val = 0;
	o_native_socket_recv(ret_sock, &val, &size, 0);
	assert_true(val == 10, "Readed value not the same of send");
	assert_false(ret_sock == 0, "The selector fail");
	assert_false(ret_sock == ret_sock1, "Error select return two time same socket.");
	assert_true(ret_sock1 == 0, "The selector is valid");
	o_native_socket_close(ret_sock);
	o_native_socket_selector_free(sel);
	o_native_thread_release(accept_th);
}