diff --git a/include/stream.h b/include/stream.h index 7be34df..0103078 100644 --- a/include/stream.h +++ b/include/stream.h @@ -81,8 +81,10 @@ 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 int stream_upgrade_to_tls(struct stream* self, void* context); diff --git a/src/stream.c b/src/stream.c index 598423a..d0ca3f2 100644 --- a/src/stream.c +++ b/src/stream.c @@ -304,8 +304,8 @@ failure: return NULL; } -int stream_write(struct stream* self, struct rcbuf* payload, - stream_req_fn on_done, void* userdata) +int stream_send(struct stream* self, struct rcbuf* payload, + stream_req_fn on_done, void* userdata) { if (self->state == STREAM_STATE_CLOSED) return -1; @@ -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);