Lines Matching refs:reader

61 static bool has_byte(const eager_reader_t *reader);
118 void eager_reader_free(eager_reader_t *reader) { in eager_reader_free() argument
119 if (!reader) in eager_reader_free()
122 eager_reader_unregister(reader); in eager_reader_free()
125 if (reader->inbound_read_object) in eager_reader_free()
126 reactor_unregister(reader->inbound_read_object); in eager_reader_free()
128 if (reader->bytes_available_fd != INVALID_FD) in eager_reader_free()
129 close(reader->bytes_available_fd); in eager_reader_free()
133 if (reader->current_buffer) in eager_reader_free()
134 reader->allocator->free(reader->current_buffer); in eager_reader_free()
136 fixed_queue_free(reader->buffers, reader->allocator->free); in eager_reader_free()
137 thread_free(reader->inbound_read_thread); in eager_reader_free()
138 osi_free(reader); in eager_reader_free()
141 void eager_reader_register(eager_reader_t *reader, reactor_t *reactor, eager_reader_cb read_cb, voi… in eager_reader_register() argument
142 assert(reader != NULL); in eager_reader_register()
147 eager_reader_unregister(reader); in eager_reader_register()
149 reader->outbound_read_ready = read_cb; in eager_reader_register()
150 reader->outbound_context = context; in eager_reader_register()
151reader->outbound_registration = reactor_register(reactor, reader->bytes_available_fd, reader, inte… in eager_reader_register()
154 void eager_reader_unregister(eager_reader_t *reader) { in eager_reader_unregister() argument
155 assert(reader != NULL); in eager_reader_unregister()
157 if (reader->outbound_registration) { in eager_reader_unregister()
158 reactor_unregister(reader->outbound_registration); in eager_reader_unregister()
159 reader->outbound_registration = NULL; in eager_reader_unregister()
164 size_t eager_reader_read(eager_reader_t *reader, uint8_t *buffer, size_t max_size) { in eager_reader_read() argument
165 assert(reader != NULL); in eager_reader_read()
169 if (!has_byte(reader)) in eager_reader_read()
174 if (eventfd_read(reader->bytes_available_fd, &bytes_available) == -1) { in eager_reader_read()
184 if (!reader->current_buffer) in eager_reader_read()
185 reader->current_buffer = fixed_queue_dequeue(reader->buffers); in eager_reader_read()
187 size_t bytes_to_copy = reader->current_buffer->length - reader->current_buffer->offset; in eager_reader_read()
191 …memcpy(&buffer[bytes_consumed], &reader->current_buffer->data[reader->current_buffer->offset], byt… in eager_reader_read()
193 reader->current_buffer->offset += bytes_to_copy; in eager_reader_read()
195 if (reader->current_buffer->offset >= reader->current_buffer->length) { in eager_reader_read()
196 reader->allocator->free(reader->current_buffer); in eager_reader_read()
197 reader->current_buffer = NULL; in eager_reader_read()
202 if (eventfd_write(reader->bytes_available_fd, bytes_available) == -1) { in eager_reader_read()
209 thread_t* eager_reader_get_read_thread(const eager_reader_t *reader) { in eager_reader_get_read_thread() argument
210 assert(reader != NULL); in eager_reader_get_read_thread()
211 return reader->inbound_read_thread; in eager_reader_get_read_thread()
214 static bool has_byte(const eager_reader_t *reader) { in has_byte() argument
215 assert(reader != NULL); in has_byte()
221 FD_SET(reader->bytes_available_fd, &read_fds); in has_byte()
228 int ret = select(reader->bytes_available_fd + 1, &read_fds, NULL, NULL, in has_byte()
235 return FD_ISSET(reader->bytes_available_fd, &read_fds); in has_byte()
239 eager_reader_t *reader = (eager_reader_t *)context; in inbound_data_waiting() local
241 …data_buffer_t *buffer = (data_buffer_t *)reader->allocator->alloc(reader->buffer_size + sizeof(dat… in inbound_data_waiting()
251 OSI_NO_INTR(bytes_read = read(reader->inbound_fd, buffer->data, in inbound_data_waiting()
252 reader->buffer_size)); in inbound_data_waiting()
256 fixed_queue_enqueue(reader->buffers, buffer); in inbound_data_waiting()
260 eventfd_write(reader->bytes_available_fd, bytes_read); in inbound_data_waiting()
267 reader->allocator->free(buffer); in inbound_data_waiting()
274 eager_reader_t *reader = (eager_reader_t *)context; in internal_outbound_read_ready() local
275 reader->outbound_read_ready(reader, reader->outbound_context); in internal_outbound_read_ready()