1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <OS.h> 4 #include <Message.h> 5 6 int main(int count, char **args) { 7 8 sem_id portSem = atoi(args[2]); 9 port_id port = atoi(args[1]); 10 11 for (int i=0; i<10; i++) { 12 13 acquire_sem(portSem); 14 15 ssize_t size = port_buffer_size(port); 16 printf("size : %ld\n", size); 17 18 char buffer[size]; 19 int32 code; 20 ssize_t newsize; 21 if ((newsize = read_port(port, &code, buffer, size))==size) { 22 BMessage msg; 23 if (msg.Unflatten(buffer)!=B_OK) { 24 printf("error \n"); 25 } else { 26 msg.PrintToStream(); 27 } 28 } else { 29 printf("error %ld\n", newsize); 30 } 31 32 } 33 } 34