Example #1
0
int main()
{
	wire_thread_init(&wire_main);
	wire_fd_init();
	wire_init(&task_hello, "hello", hello, "world!", WIRE_STACK_ALLOC(4096));
	wire_init(&task_bye, "bye", bye, "world!", WIRE_STACK_ALLOC(4096));
	wire_thread_run();
	return 0;
}
Example #2
0
static void producer(void *arg)
{
	UNUSED(arg);
	wire_wait_t wait;
	wire_wait_list_t wait_list;

	wire_wait_init(&wait);
	wire_wait_list_init(&wait_list);
	wire_wait_chain(&wait_list, &wait);

	printf("Producer starting\n");
	wire_init(&task_consumer, "consumer", consumer, &wait, WIRE_STACK_ALLOC(4096));

	wire_list_wait(&wait_list);
	printf("We've been woken up\n");

	printf("Now wait out the first wait\n");
	wire_fd_wait_msec(100);

	printf("Now reset the wait and wait for it again\n");
	wire_wait_reset(&wait);
	wire_list_wait(&wait_list);

	wire_wait_unchain(&wait);
	printf("Producer finished\n");
}
Example #3
0
int main()
{
	wire_thread_init(&wire_main);
	wire_fd_init();
	wire_init(&task_producer, "producer", producer, NULL, WIRE_STACK_ALLOC(4096));
	wire_thread_run();
	return 0;
}
Example #4
0
int main()
{
	struct timespec start;
	struct timespec end;

	stop = steps;

	clock_gettime(CLOCK_MONOTONIC, &start);
	wire_thread_init(&wire_main);
	wire_init(&task_hello, "hello", action, NULL, WIRE_STACK_ALLOC(4096));
	wire_init(&task_bye, "bye", action, NULL, WIRE_STACK_ALLOC(4096));
	wire_thread_run();
	clock_gettime(CLOCK_MONOTONIC, &end);

	printf("Doing %d steps took %ld seconds and %ld nanoseconds\n", steps, end.tv_sec - start.tv_sec, end.tv_nsec - start.tv_nsec);

	unsigned long long steps_factor = steps * 1000;
	unsigned long long msecs = (end.tv_sec - start.tv_sec) * 1000;
	msecs += (end.tv_nsec - start.tv_nsec) / (1000 * 1000);
	printf("yields per sec = %llu\n", steps_factor / msecs);

	return 0;
}
Example #5
0
int main(void)
{
    plan_lazy();

    wire_ctx_t wire = { 0 };

    dnssec_binary_t buffer = { .size = 20, .data = (uint8_t []) {
        0xc8, 0x25, 0x19, 0x3c, 0x96, 0xe6, 0x59, 0xf7, 0x2b, 0x94,
              0x83, 0xb3, 0x3e, 0x6f, 0xb9, 0x01, 0xe2, 0x91, 0xa8, 0xa9,
    }
                             };

    wire = wire_init(buffer.data + 10, 10);
    ok(wire_read_u8(&wire) == 0x83, "wire_init()");

    wire = wire_init_binary(&buffer);
    ok(wire_read_u8(&wire) == 0xc8, "wire_init_binary()");

    // read operations

    wire_seek(&wire, 5);
    ok(wire_read_u8(&wire) == 0xe6, "wire_seek() forward");
    wire_seek(&wire, 3);
    ok(wire_read_u8(&wire) == 0x3c, "wire_seek() backward");

    wire_seek(&wire, 10);
    ok(wire_read_u8(&wire) == 0x83, "wire_read_u8()");
    ok(wire_read_u16(&wire) == 45886, "wire_read_u16()");
    ok(wire_tell(&wire) == 13, "wire_tell()");
    ok(wire_available(&wire) == 7, "wire_available()");

    dnssec_binary_t ref = { 0 };
    wire_available_binary(&wire, &ref);
    ok(ref.data == buffer.data + 13 && ref.size == 7, "wire_available_binary()");

    uint8_t in[6] = { 0 };
    wire_seek(&wire, 4);
    wire_read(&wire, in, 6);
    ok(memcmp(in, buffer.data + 4, 6) == 0 && wire_tell(&wire) == 10,
       "wire_read()");

    // write operations

    wire_seek(&wire, 0);

    wire_write_u8(&wire, 0x42);
    ok(buffer.data[0] == 0x42 && wire_tell(&wire) == 1,
       "wire_write_u8()");
    wire_write_u16(&wire, 44513);
    ok(memcmp(buffer.data + 1, "\xad\xe1", 2) == 0 && wire_tell(&wire) == 3,
       "wire_write_u16()");

    wire_seek(&wire, 12);
    const uint8_t out[7] = { 0xc0, 0x1d, 0xca, 0xfe, 0xde, 0xad, 0xbe };
    wire_write(&wire, out, 7);
    ok(memcmp(buffer.data + 12, out, 7) == 0 && wire_tell(&wire) == 19,
       "wire_write()");

    dnssec_binary_t bignum = { .data = (uint8_t *)out, .size = 4 };
    const uint8_t expect[8] = { 0x00, 0x00, 0x00, 0x00, 0xc0, 0x1d, 0xca, 0xfe };
    wire_seek(&wire, 2);
    wire_write_bignum(&wire, 8, &bignum);
    ok(memcmp(buffer.data + 2, expect, 8) == 0 && wire_tell(&wire) == 10,
       "wire_write_ralign()");

    return 0;
}
Example #6
0
static void register_shutdown_handler(void)
{
	wire_init(&signal_task, "signalfd", signal_task_run, NULL, WIRE_STACK_ALLOC(4096));
}