Lines Matching refs:reader
62 static bool has_byte(const eager_reader_t *reader);
123 void eager_reader_free(eager_reader_t *reader) { in eager_reader_free() argument
124 if (!reader) in eager_reader_free()
127 eager_reader_unregister(reader); in eager_reader_free()
130 if (reader->inbound_read_object) in eager_reader_free()
131 reactor_unregister(reader->inbound_read_object); in eager_reader_free()
133 if (reader->bytes_available_fd != INVALID_FD) in eager_reader_free()
134 close(reader->bytes_available_fd); in eager_reader_free()
138 if (reader->current_buffer) in eager_reader_free()
139 reader->allocator->free(reader->current_buffer); in eager_reader_free()
141 fixed_queue_free(reader->buffers, reader->allocator->free); in eager_reader_free()
142 thread_free(reader->inbound_read_thread); in eager_reader_free()
143 osi_free(reader); in eager_reader_free()
146 void eager_reader_register(eager_reader_t *reader, reactor_t *reactor, eager_reader_cb read_cb, voi… in eager_reader_register() argument
147 assert(reader != NULL); in eager_reader_register()
152 eager_reader_unregister(reader); in eager_reader_register()
154 reader->outbound_read_ready = read_cb; in eager_reader_register()
155 reader->outbound_context = context; in eager_reader_register()
156 …reader->outbound_registration = reactor_register(reactor, reader->bytes_available_fd, reader, inte… in eager_reader_register()
159 void eager_reader_unregister(eager_reader_t *reader) { in eager_reader_unregister() argument
160 assert(reader != NULL); in eager_reader_unregister()
162 if (reader->outbound_registration) { in eager_reader_unregister()
163 reactor_unregister(reader->outbound_registration); in eager_reader_unregister()
164 reader->outbound_registration = NULL; in eager_reader_unregister()
169 size_t eager_reader_read(eager_reader_t *reader, uint8_t *buffer, size_t max_size, bool block) { in eager_reader_read() argument
170 assert(reader != NULL); in eager_reader_read()
175 if (!block && !has_byte(reader)) in eager_reader_read()
180 if (eventfd_read(reader->bytes_available_fd, &bytes_available) == -1) { in eager_reader_read()
190 if (!reader->current_buffer) in eager_reader_read()
191 reader->current_buffer = fixed_queue_dequeue(reader->buffers); in eager_reader_read()
193 size_t bytes_to_copy = reader->current_buffer->length - reader->current_buffer->offset; in eager_reader_read()
197 …memcpy(&buffer[bytes_consumed], &reader->current_buffer->data[reader->current_buffer->offset], byt… in eager_reader_read()
199 reader->current_buffer->offset += bytes_to_copy; in eager_reader_read()
201 if (reader->current_buffer->offset >= reader->current_buffer->length) { in eager_reader_read()
202 reader->allocator->free(reader->current_buffer); in eager_reader_read()
203 reader->current_buffer = NULL; in eager_reader_read()
208 if (eventfd_write(reader->bytes_available_fd, bytes_available) == -1) { in eager_reader_read()
215 static bool has_byte(const eager_reader_t *reader) { in has_byte() argument
216 assert(reader != NULL); in has_byte()
220 FD_SET(reader->bytes_available_fd, &read_fds); in has_byte()
227 select(reader->bytes_available_fd + 1, &read_fds, NULL, NULL, &timeout); in has_byte()
228 return FD_ISSET(reader->bytes_available_fd, &read_fds); in has_byte()
232 eager_reader_t *reader = (eager_reader_t *)context; in inbound_data_waiting() local
234 …data_buffer_t *buffer = (data_buffer_t *)reader->allocator->alloc(reader->buffer_size + sizeof(dat… in inbound_data_waiting()
243 int bytes_read = read(reader->inbound_fd, buffer->data, reader->buffer_size); in inbound_data_waiting()
247 fixed_queue_enqueue(reader->buffers, buffer); in inbound_data_waiting()
251 eventfd_write(reader->bytes_available_fd, bytes_read); in inbound_data_waiting()
258 reader->allocator->free(buffer); in inbound_data_waiting()
265 eager_reader_t *reader = (eager_reader_t *)context; in internal_outbound_read_ready() local
266 reader->outbound_read_ready(reader, reader->outbound_context); in internal_outbound_read_ready()