| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- using Invercargill;
- using Invercargill.DataStructures;
- namespace Astralis {
- internal class ServerInput : Object, AsyncInput {
- private bool write_occurred;
- private Series<ByteBuffer> chunks = new Series<ByteBuffer>();
- private bool writes_complete;
- public BinaryData? peek() {
- return chunks.first_or_default();
- }
- public async BinaryData? read() {
- while (chunks.length == 0 && !writes_complete) {
- Idle.add(read.callback);
- yield;
- }
- if(chunks.length == 0) {
- return null;
- }
- return chunks.pop_start();
- }
- public async BinaryData read_all() {
- while (!writes_complete) {
- Idle.add(read_all.callback);
- yield;
- }
- var data = new ByteComposition();
- data.append_all(chunks);
- chunks.clear();
- return data;
- }
- internal void write(uint8[] data) {
- chunks.add(new ByteBuffer.from_byte_array(data));
- write_occurred = true;
- }
- internal void complete() {
- writes_complete = true;
- }
- }
- }
|