int mu_iostream_create (mu_stream_t *pref, mu_stream_t in, mu_stream_t out) { struct _mu_iostream *sp; sp = (struct _mu_iostream *) _mu_stream_create (sizeof (*sp), MU_STREAM_READ | MU_STREAM_WRITE); if (!sp) return ENOMEM; sp->stream.flags |= _MU_STR_OPEN; sp->stream.read = _iostream_read; if (in->readdelim) sp->stream.readdelim = _iostream_readdelim; sp->stream.write = _iostream_write; sp->stream.flush = _iostream_flush; sp->stream.open = _iostream_open; sp->stream.close = _iostream_close; sp->stream.done = _iostream_done; sp->stream.ctl = _iostream_ctl; sp->stream.wait = _iostream_wait; sp->stream.shutdown = _iostream_shutdown; sp->stream.error_string = _iostream_error_string; mu_stream_ref (in); sp->transport[_MU_STREAM_INPUT] = in; mu_stream_ref (out); sp->transport[_MU_STREAM_OUTPUT] = out; mu_stream_set_buffer ((mu_stream_t) sp, mu_buffer_line, 0); *pref = (mu_stream_t) sp; return 0; }
int mu_streamref_create_abridged (mu_stream_t *pref, mu_stream_t str, mu_off_t start, mu_off_t end) { int rc; mu_off_t off; int flags; struct _mu_streamref *sp; rc = mu_stream_seek (str, 0, MU_SEEK_SET, &off);/*FIXME: SEEK_CUR?*/ if (rc) return rc; mu_stream_get_flags (str, &flags); sp = (struct _mu_streamref *) _mu_stream_create (sizeof (*sp), flags | _MU_STR_OPEN); if (!sp) return ENOMEM; mu_stream_ref (str); sp->stream.read = _streamref_read; if (str->readdelim) sp->stream.readdelim = _streamref_readdelim; sp->stream.write = _streamref_write; sp->stream.flush = _streamref_flush; sp->stream.open = _streamref_open; sp->stream.close = _streamref_close; sp->stream.done = _streamref_done; sp->stream.seek = _streamref_seek; sp->stream.size = _streamref_size; sp->stream.ctl = _streamref_ctl; sp->stream.wait = _streamref_wait; sp->stream.truncate = _streamref_truncate; sp->stream.shutdown = _streamref_shutdown; sp->stream.error_string = _streamref_error_string; sp->transport = str; sp->start = start; sp->end = end; if (off < start || off > end) off = start; sp->offset = off; *pref = (mu_stream_t) sp; mu_stream_set_buffer (*pref, mu_buffer_full, 0); return 0; }
static struct _tcp_instance * _create_tcp_stream (int flags) { struct _tcp_instance *tcp = (struct _tcp_instance *)_mu_stream_create (sizeof (*tcp), flags); if (tcp) { tcp->stream.open = _tcp_open; tcp->stream.close = _tcp_close; tcp->stream.read = _tcp_read; tcp->stream.write = _tcp_write; tcp->stream.ctl = _tcp_ioctl; tcp->stream.done = _tcp_done; tcp->stream.wait = _tcp_wait; tcp->stream.shutdown = _tcp_shutdown; tcp->fd = -1; tcp->state = TCP_STATE_INIT; } return tcp; }