1 /* 2 * Copyright 2006, Marcus Overhagen, <marcus@overhagen.de> 3 * Distributed under the terms of the MIT License. 4 */ 5 6 7 #include <OS.h> 8 #include <stdio.h> 9 #include <string.h> 10 11 12 /* 13 * 14 */ 15 16 port_id id; 17 char data[100]; 18 19 int32 20 test_thread(void *) 21 { 22 ssize_t size; 23 24 printf("port_buffer_size...\n"); 25 size = port_buffer_size(id); 26 printf("port_buffer_size size %ld (0x%08lx) (%s)\n", size, size, strerror(size)); 27 28 return 0; 29 } 30 31 32 int 33 main() 34 { 35 status_t s; 36 ssize_t size; 37 int32 code; 38 39 id = create_port(1, "test port"); 40 printf("created port %ld\n", id); 41 42 s = write_port(id, 0x1234, data, 10); 43 printf("write port result 0x%08lx (%s)\n", s, strerror(s)); 44 45 size = read_port(id, &code, data, sizeof(data)); 46 printf("read port code %lx, size %ld (0x%08lx) (%s)\n", code, size, size, strerror(size)); 47 48 printf("port_buffer_size should block for 5 seconds now, as port is empty, until port is deleted\n"); 49 50 thread_id thread = spawn_thread(test_thread, "test thread", B_NORMAL_PRIORITY, NULL); 51 resume_thread(thread); 52 snooze(5000000); 53 54 printf("delete port...\n"); 55 s = delete_port(id); 56 printf("delete port result 0x%08lx (%s)\n", s, strerror(s)); 57 58 printf("waiting for thread to terminate\n"); 59 wait_for_thread(thread, &s); 60 61 return 0; 62 } 63