Sys/Poll/PollfdArray.pm untested

filter: Statementstmt n/a Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a SCAR -
1 package SPVM::Sys::Poll::PollfdArray;
2  
3 1;
4  
5 =head1 Name
6  
7 SPVM::Sys::Poll::PollfdArray - Array of C<struct pollfd> in the C language
8  
9 =head1 Description
10  
11 Sys::Poll::PollfdArray class in L<SPVM> represents the array of C<struct pollfd> in the C language.
12  
13 =head1 Usage
14  
15 use Sys::Poll::PollfdArray;
16 use Sys::Poll::Constant as POLL;
17
18 my $pollfds = Sys::Poll::PollfdArray->new;
19
20 # Add
21 my $fd = 1;
22 $pollfds->push($fd);
23
24 # Get
25 my $fd = $pollfds->fd($index);
26 my $event = $pollfds->events($index);
27 my $revent = $pollfds->revents($index);
28
29 # Event Constant Values
30 my $event = POLL->POLLIN;
31 my $event = POLL->POLLOUT;
32
33 # Set
34 $pollfds->set_fd($index, $fd);
35 $pollfds->set_events($index, $event);
36 $pollfds->set_revents($index, $revent);
37
38 # Remove
39 $pollfds->remove($index);
40
41 # Length
42 my $length = $pollfds->length;
43  
44 =head1 Details
45  
46 This class is a pointer class. The pointer is set to an C<struct pollfd> array.
47  
48 =head1 Fields
49  
50 =head2 length
51  
52 C<has length : ro int;>
53  
54 The length of the array of C<struct pollfd> data.
55  
56 =head2 capacity
57  
58 C<has capacity : ro int;>
59  
60 The capacity of the array of C<struct pollfd> data.
61  
62 =head1 Class Methods
63  
64 =head2 new
65  
66 C<static method new : L<Sys::Poll::PollfdArray|SPVM::Sys::Poll::PollfdArray> ($length : int = 0, $capacity : int = -1);>
67  
68 Creates a new L<Sys::Poll::PollfdArray|SPVM::Sys::Poll::PollfdArray> object given the length $lenth and the capacity $capacity.
69  
70 If $capacity is a negative value, $capacity is set to $length. And if $capacity is 0, $capacity is set to 1.
71  
72 A C<struct pollfd> array is created and the pointer is set to it.
73  
74 =head1 Instance Methods
75  
76 =head2 DESTROY
77  
78 C<method DESTROY : void ();>
79  
80 The destructor. The C<struct pollfd> array is released.
81  
82 =head2 fd
83  
84 C<method fd : int ($index : int);>
85  
86 Returns C<fd> of the array of C<struct pollfd> data at the index $index.
87  
88 Excetpions:
89  
90 $index must be greater than or equal to 0. Otherwise an exception is thrown.
91  
92 $index must be less than the length of the file descripters. Otherwise an exception is thrown.
93  
94 =head2 set_fd
95  
96 C<method set_fd : void ($index : int, $fd : int);>
97  
98 Sets C<fd> of the array of C<struct pollfd> data at the index $index.
99  
100 Excetpions:
101  
102 $index must be greater than or equal to 0. Otherwise an exception is thrown.
103  
104 $index must be less than the length of the file descripters. Otherwise an exception is thrown.
105  
106 =head2 events
107  
108 C<method events : int ($index : int);>
109  
110 Returns C<events> of the array of C<struct pollfd> data at the index $index.
111  
112 Excetpions:
113  
114 $index must be greater than or equal to 0. Otherwise an exception is thrown.
115  
116 $index must be less than the length of the file descripters. Otherwise an exception is thrown.
117  
118 =head2 set_events
119  
120 C<method set_events : void ($index : int, $events : int);>
121  
122 Sets C<events> of the array of C<struct pollfd> data at the index $index.
123  
124 Excetpions:
125  
126 $index must be greater than or equal to 0. Otherwise an exception is thrown.
127  
128 $index must be less than the length of the file descripters. Otherwise an exception is thrown.
129  
130 See L<Sys::Poll::Constant|SPVM::Sys::Poll::Constant> about constant values given to $revents.
131  
132 =head2 events
133  
134 C<method revents : int ($index : int);>
135  
136 Returns C<revents> of the array of C<struct pollfd> data at the index $index.
137  
138 Excetpions:
139  
140 $index must be greater than or equal to 0. Otherwise an exception is thrown.
141  
142 $index must be less than the length of the file descripters. Otherwise an exception is thrown.
143  
144 =head2 set_revents
145  
146 C<method set_revents : void ($index : int, $revents : int);>
147  
148 Sets C<revents> of the array of C<struct pollfd> data at the index $index.
149  
150 Excetpions:
151  
152 $index must be greater than or equal to 0. Otherwise an exception is thrown.
153  
154 $index must be less than the length of the file descripters. Otherwise an exception is thrown.
155  
156 See L<Sys::Poll::Constant|SPVM::Sys::Poll::Constant> about constant values given to $revents.
157  
158 =head2 push
159  
160 C<method push : void ($fd : int);>
161  
162 Adds an C<struct pollfd> data with the file descriptoer $fd to the end of the C<struct pollfd> array.
163  
164 If the capacity stored in L</"capacity"> fields is not enough, it is extended to about twice its capacity.
165  
166 =head2 remove
167  
168 C<method remove : void ($index : int);>
169  
170 Removes an C<struct pollfd> data at the index $index.
171  
172 =head1 See Also
173  
174 =over 2
175  
176 =item * L<Sys|SPVM::Sys>
177  
178 =back
179  
180 =head1 Copyright & License
181  
182 Copyright (c) 2023 Yuki Kimoto
183  
184 MIT License
185