int kr_io2_sync (kr_io2_t *io) { int bytes; int ret; int len; uint8_t *buffer; buffer = io->buffer; len = io->len; ret = 0; bytes = 0; if (!kr_io2_want_out (io)) { return 0; } while (bytes != len) { ret += write (io->fd, buffer + bytes, len - bytes); if (ret <= 0) { break; } else { bytes += ret; } } kr_io2_restart (io); return bytes; }
int kr_io2_output(kr_io2_t *io) { ssize_t ret; if (!kr_io2_want_out(io)) { return 0; } ret = kr_io2_write(io); //printk("kr_io2_output wrote: %zu old len: %zu new len: %zu", // ret, io->len, io->len - ret); if (ret != io->len) { if (ret < 1) { printke("its bad we should certainly fail, ret %zu len %zu", ret, io->len); return ret; } else { io->len -= ret; io->wr_buf += ret; } return 0; } kr_io2_restart(io); return 0; }
void kr_io2_pulled(kr_io2_t *io, size_t bytes) { io->len -= bytes; io->rd_buf += bytes; if (io->len == 0) { kr_io2_restart (io); } }
kr_io2_t *kr_io2_create_size(size_t size) { kr_io2_t *io; io = malloc (sizeof(kr_io2_t)); io->size = size; io->buffer = malloc (io->size); io->fd = -1; kr_io2_restart (io); return io; }
int kr_io2_sync(kr_io2_t *io) { // FILES ONLY blocking or failing! ssize_t ret; if (!kr_io2_want_out(io)) { return 0; } ret = kr_io2_write (io); if (ret != io->len) { printk ("Could not write all we wanted to: %zd of %zu", ret, io->len); printke ("Failing here a, this should not happen as a file only func"); exit (77); } kr_io2_restart (io); return 0; }
static int kr_ogg_io_push_internal (kr_ogg_io *ogg_io) { ssize_t ret; ssize_t sent; ssize_t bytes; uint8_t *buffer; if (ogg_io->stream != NULL) { sent = 0; buffer = ogg_io->io->buffer; bytes = ogg_io->io->len; while (sent != bytes) { kr_stream_i_am_a_blocking_subscripter (ogg_io->stream); ret = kr_stream_send (ogg_io->stream, buffer + sent, bytes - sent); if (ret > 0) { sent += ret; } if (sent != bytes) { //printf ("\nSent to few bytes: ret %zd - sent %zd - total %zd\n", // ret, sent, bytes); //fflush (stdout); } if (ogg_io->stream->connected == 0) { printke ("Failed!: %s\n", ogg_io->stream->error_str); return -1; } } if (ogg_io->stream->connected == 1) { kr_io2_restart (ogg_io->io); } } else { kr_io2_sync (ogg_io->io); } return 0; }
int kr_io2_flush (kr_io2_t *io) { int ret; int len; if (!kr_io2_want_out (io)) { return 0; } len = io->len; ret = kr_io2_write (io); if (ret != len) { printk ("Could not write all we wanted to: %d of %d", ret, len); printke ("Failing here a temporary test"); exit (77); } kr_io2_restart (io); return 0; }