/* * tnt_buf() * * create and initialize buffer stream; * * s - stream pointer, maybe NULL * * if stream pointer is NULL, then new stream will be created. * * returns stream pointer, or NULL on error. */ struct tnt_stream *tnt_buf(struct tnt_stream *s) { int allocated = s == NULL; s = tnt_stream_init(s); if (s == NULL) return NULL; /* allocating stream data */ s->data = tnt_mem_alloc(sizeof(struct tnt_stream_buf)); if (s->data == NULL) { if (allocated) tnt_stream_free(s); return NULL; } /* initializing interfaces */ s->read = tnt_buf_read; s->read_reply = tnt_buf_reply; s->read_request = tnt_buf_request; s->read_tuple = NULL; s->write = tnt_buf_write; s->writev = tnt_buf_writev; s->write_request = tnt_buf_write_request; s->free = tnt_buf_free; /* initializing internal data */ struct tnt_stream_buf *sb = TNT_SBUF_CAST(s); sb->rdoff = 0; sb->size = 0; sb->data = NULL; return s; }
/* * tnt_xlog() * * create and initialize xlog stream; * * s - stream pointer, maybe NULL * * if stream pointer is NULL, then new stream will be created. * * returns stream pointer, or NULL on error. */ struct tnt_stream *tnt_xlog(struct tnt_stream *s) { int allocated = s == NULL; s = tnt_stream_init(s); if (s == NULL) return NULL; /* allocating stream data */ s->data = tnt_mem_alloc(sizeof(struct tnt_stream_xlog)); if (s->data == NULL) { if (allocated) tnt_stream_free(s); return NULL; } memset(s->data, 0, sizeof(struct tnt_stream_xlog)); /* initializing interfaces */ s->read = NULL; s->read_request = tnt_xlog_request; s->read_reply = NULL; s->read_tuple = NULL; s->write = NULL; s->writev = NULL; s->free = tnt_xlog_free; /* initializing internal data */ return s; }
/* * tnt_net() * * create and initialize network stream; * * s - stream pointer, maybe NULL * * if stream pointer is NULL, then new stream will be created. * * returns stream pointer, or NULL on error. */ struct tnt_stream *tnt_net(struct tnt_stream *s) { int allocated = s == NULL; s = tnt_stream_init(s); if (s == NULL) return NULL; /* allocating stream data */ s->data = tnt_mem_alloc(sizeof(struct tnt_stream_net)); if (s->data == NULL) { if (allocated) tnt_stream_free(s); return NULL; } memset(s->data, 0, sizeof(struct tnt_stream_net)); /* initializing interfaces */ s->read = tnt_net_read; s->read_reply = tnt_net_reply; s->read_request = tnt_net_request; s->write = tnt_net_write; s->writev = tnt_net_writev; s->write_request = tnt_net_write_request; s->free = tnt_net_free; /* initializing internal data */ struct tnt_stream_net *sn = TNT_SNET_CAST(s); sn->fd = -1; tnt_opt_init(&sn->opt); return s; }
/* * tnt_rpl() * * create and initialize replication stream; * * s - stream pointer, maybe NULL * * if stream pointer is NULL, then new stream will be created. * * returns stream pointer, or NULL on error. */ struct tnt_stream *tnt_rpl(struct tnt_stream *s) { int allocated = s == NULL; s = tnt_stream_init(s); if (s == NULL) return NULL; /* allocating stream data */ s->data = tnt_mem_alloc(sizeof(struct tnt_stream_rpl)); if (s->data == NULL) goto error; memset(s->data, 0, sizeof(struct tnt_stream_rpl)); /* initializing interfaces */ s->read = NULL; s->read_request = tnt_rpl_request; s->read_reply = NULL; s->read_tuple = NULL; s->write = NULL; s->writev = NULL; s->free = tnt_rpl_free; /* initializing internal data */ struct tnt_stream_rpl *sr = TNT_RPL_CAST(s); sr->net = NULL; return s; error: if (s->data) { tnt_mem_free(s->data); s->data = NULL; } if (allocated) tnt_stream_free(s); return NULL; }