stream: Change api for stream_write

vencrypt
Andri Yngvason 2020-01-25 15:46:52 +00:00
parent caf9fe0130
commit fef9ca1d7c
2 changed files with 12 additions and 3 deletions

View File

@ -81,7 +81,9 @@ struct stream* stream_new(int fd, stream_event_fn on_event, void* userdata);
int stream_close(struct stream* self);
void stream_destroy(struct stream* self);
ssize_t stream_read(struct stream* self, void* dst, size_t size);
int stream_write(struct stream* self, struct rcbuf* payload,
int stream_write(struct stream* self, const void* payload, size_t len,
stream_req_fn on_done, void* userdata);
int stream_send(struct stream* self, struct rcbuf* payload,
stream_req_fn on_done, void* userdata);
#ifdef ENABLE_TLS

View File

@ -304,7 +304,7 @@ failure:
return NULL;
}
int stream_write(struct stream* self, struct rcbuf* payload,
int stream_send(struct stream* self, struct rcbuf* payload,
stream_req_fn on_done, void* userdata)
{
if (self->state == STREAM_STATE_CLOSED)
@ -323,6 +323,13 @@ int stream_write(struct stream* self, struct rcbuf* payload,
return stream__flush(self);
}
int stream_write(struct stream* self, const void* payload, size_t len,
stream_req_fn on_done, void* userdata)
{
struct rcbuf* buf = rcbuf_from_mem(payload, len);
return buf ? stream_send(self, buf, on_done, userdata) : -1;
}
ssize_t stream__read_plain(struct stream* self, void* dst, size_t size)
{
return read(self->fd, dst, size);