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 int 12 main() 13 { 14 port_id id; 15 status_t s; 16 ssize_t size; 17 int32 code; 18 19 char data[100]; 20 21 22 id = create_port(10, "test port"); 23 printf("created port %ld\n", id); 24 25 s = write_port(id, 0x1234, data, 10); 26 printf("write port result 0x%08lx (%s)\n", s, strerror(s)); 27 28 s = write_port(id, 0x5678, data, 20); 29 printf("write port result 0x%08lx (%s)\n", s, strerror(s)); 30 31 s = delete_port(id); 32 printf("delete port result 0x%08lx (%s)\n", s, strerror(s)); 33 34 printf("everything should fail now\n"); 35 36 // BeBook: does return B_BAD_PORT_ID if port was closed 37 s = write_port(id, 0x5678, data, 20); 38 printf("write port result 0x%08lx (%s)\n", s, strerror(s)); 39 40 // BeBook: does block when port is empty, and unblocks when port is written to or deleted 41 size = port_buffer_size(id); 42 printf("port_buffer_size %ld (0x%08lx) (%s)\n", size, size, strerror(size)); 43 44 // BeBook: does block when port is empty, and unblocks when port is written to or deleted 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 return 0; 49 } 50