FreeRDP
TestStreamPool.c
1 
2 #include <winpr/crt.h>
3 #include <winpr/stream.h>
4 #include <winpr/collections.h>
5 
6 #define BUFFER_SIZE 16384
7 
8 int TestStreamPool(int argc, char* argv[])
9 {
10  wStream* s[5] = { 0 };
11  char buffer[8192] = { 0 };
12 
13  WINPR_UNUSED(argc);
14  WINPR_UNUSED(argv);
15 
16  wStreamPool* pool = StreamPool_New(TRUE, BUFFER_SIZE);
17 
18  s[0] = StreamPool_Take(pool, 0);
19  s[1] = StreamPool_Take(pool, 0);
20  s[2] = StreamPool_Take(pool, 0);
21 
22  printf("%s\n", StreamPool_GetStatistics(pool, buffer, sizeof(buffer)));
23 
24  Stream_Release(s[0]);
25  Stream_Release(s[1]);
26  Stream_Release(s[2]);
27 
28  printf("%s\n", StreamPool_GetStatistics(pool, buffer, sizeof(buffer)));
29 
30  s[3] = StreamPool_Take(pool, 0);
31  s[4] = StreamPool_Take(pool, 0);
32 
33  printf("%s\n", StreamPool_GetStatistics(pool, buffer, sizeof(buffer)));
34 
35  Stream_Release(s[3]);
36  Stream_Release(s[4]);
37 
38  printf("%s\n", StreamPool_GetStatistics(pool, buffer, sizeof(buffer)));
39 
40  s[2] = StreamPool_Take(pool, 0);
41  s[3] = StreamPool_Take(pool, 0);
42  s[4] = StreamPool_Take(pool, 0);
43 
44  printf("%s\n", StreamPool_GetStatistics(pool, buffer, sizeof(buffer)));
45 
46  Stream_AddRef(s[2]);
47 
48  Stream_AddRef(s[3]);
49  Stream_AddRef(s[3]);
50 
51  Stream_AddRef(s[4]);
52  Stream_AddRef(s[4]);
53  Stream_AddRef(s[4]);
54 
55  Stream_Release(s[2]);
56  Stream_Release(s[2]);
57 
58  Stream_Release(s[3]);
59  Stream_Release(s[3]);
60  Stream_Release(s[3]);
61 
62  Stream_Release(s[4]);
63  Stream_Release(s[4]);
64  Stream_Release(s[4]);
65  Stream_Release(s[4]);
66 
67  printf("%s\n", StreamPool_GetStatistics(pool, buffer, sizeof(buffer)));
68 
69  s[2] = StreamPool_Take(pool, 0);
70  s[3] = StreamPool_Take(pool, 0);
71  s[4] = StreamPool_Take(pool, 0);
72 
73  printf("%s\n", StreamPool_GetStatistics(pool, buffer, sizeof(buffer)));
74 
75  StreamPool_Free(pool);
76 
77  return 0;
78 }