xref: /haiku/src/tests/system/kernel/port_close_test_1.cpp (revision 17889a8c70dbb3d59c1412f6431968753c767bab)
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 = close_port(id);
32 	printf("close port result 0x%08lx (%s)\n", s, strerror(s));
33 
34 	// BeBook: does return B_BAD_PORT_ID if port was closed
35 	s = write_port(id, 0x5678, data, 20);
36 	printf("write port result 0x%08lx (%s)\n", s, strerror(s));
37 
38 	// BeBook: does block when port is empty, and unblocks when port is written to or deleted
39 	size = port_buffer_size(id);
40 	printf("port_buffer_size %ld (0x%08lx) (%s)\n", size, size, strerror(size));
41 
42 	// BeBook: does block when port is empty, and unblocks when port is written to or deleted
43 	size = read_port(id, &code, data, sizeof(data));
44 	printf("read port code %lx, size %ld (0x%08lx) (%s)\n", code, size, size, strerror(size));
45 
46 	// BeBook: does block when port is empty, and unblocks when port is written to or deleted
47 	size = port_buffer_size(id);
48 	printf("port_buffer_size %ld (0x%08lx) (%s)\n", size, size, strerror(size));
49 
50 	// BeBook: does block when port is empty, and unblocks when port is written to or deleted
51 	size = read_port(id, &code, data, sizeof(data));
52 	printf("read port code %lx, size %ld (0x%08lx) (%s)\n", code, size, size, strerror(size));
53 
54 	printf("port_buffer_size should fail now:\n");
55 
56 	// BeBook: does block when port is empty, and unblocks when port is written to or deleted
57 	size = port_buffer_size(id);
58 	printf("port_buffer_size %ld (0x%08lx) (%s)\n", size, size, strerror(size));
59 
60 	return 0;
61 }
62