… | |
… | |
191 | |
191 | |
192 | To access (and remove data from) the read buffer, use the C<< ->rbuf >> |
192 | To access (and remove data from) the read buffer, use the C<< ->rbuf >> |
193 | method or access the C<< $handle->{rbuf} >> member directly. Note that you |
193 | method or access the C<< $handle->{rbuf} >> member directly. Note that you |
194 | must not enlarge or modify the read buffer, you can only remove data at |
194 | must not enlarge or modify the read buffer, you can only remove data at |
195 | the beginning from it. |
195 | the beginning from it. |
|
|
196 | |
|
|
197 | You can also call C<< ->push_read (...) >> or any other function that |
|
|
198 | modifies the read queue. Or do both. Or ... |
196 | |
199 | |
197 | When an EOF condition is detected then AnyEvent::Handle will first try to |
200 | When an EOF condition is detected then AnyEvent::Handle will first try to |
198 | feed all the remaining data to the queued callbacks and C<on_read> before |
201 | feed all the remaining data to the queued callbacks and C<on_read> before |
199 | calling the C<on_eof> callback. If no progress can be made, then a fatal |
202 | calling the C<on_eof> callback. If no progress can be made, then a fatal |
200 | error will be raised (with C<$!> set to C<EPIPE>). |
203 | error will be raised (with C<$!> set to C<EPIPE>). |
… | |
… | |
933 | |
936 | |
934 | Instead of formatting your data yourself, you can also let this module |
937 | Instead of formatting your data yourself, you can also let this module |
935 | do the job by specifying a type and type-specific arguments. You |
938 | do the job by specifying a type and type-specific arguments. You |
936 | can also specify the (fully qualified) name of a package, in which |
939 | can also specify the (fully qualified) name of a package, in which |
937 | case AnyEvent tries to load the package and then expects to find the |
940 | case AnyEvent tries to load the package and then expects to find the |
938 | C<anyevent_read_type> function inside (see "custom write types", below). |
941 | C<anyevent_write_type> function inside (see "custom write types", below). |
939 | |
942 | |
940 | Predefined types are (if you have ideas for additional types, feel free to |
943 | Predefined types are (if you have ideas for additional types, feel free to |
941 | drop by and tell us): |
944 | drop by and tell us): |
942 | |
945 | |
943 | =over 4 |
946 | =over 4 |
… | |
… | |
1107 | ways, the "simple" way, using only C<on_read> and the "complex" way, using |
1110 | ways, the "simple" way, using only C<on_read> and the "complex" way, using |
1108 | a queue. |
1111 | a queue. |
1109 | |
1112 | |
1110 | In the simple case, you just install an C<on_read> callback and whenever |
1113 | In the simple case, you just install an C<on_read> callback and whenever |
1111 | new data arrives, it will be called. You can then remove some data (if |
1114 | new data arrives, it will be called. You can then remove some data (if |
1112 | enough is there) from the read buffer (C<< $handle->rbuf >>). Or you cna |
1115 | enough is there) from the read buffer (C<< $handle->rbuf >>). Or you can |
1113 | leave the data there if you want to accumulate more (e.g. when only a |
1116 | leave the data there if you want to accumulate more (e.g. when only a |
1114 | partial message has been received so far). |
1117 | partial message has been received so far), or change the read queue with |
|
|
1118 | e.g. C<push_read>. |
1115 | |
1119 | |
1116 | In the more complex case, you want to queue multiple callbacks. In this |
1120 | In the more complex case, you want to queue multiple callbacks. In this |
1117 | case, AnyEvent::Handle will call the first queued callback each time new |
1121 | case, AnyEvent::Handle will call the first queued callback each time new |
1118 | data arrives (also the first time it is queued) and removes it when it has |
1122 | data arrives (also the first time it is queued) and removes it when it has |
1119 | done its job (see C<push_read>, below). |
1123 | done its job (see C<push_read>, below). |