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,8 +81,10 @@ struct stream* stream_new(int fd, stream_event_fn on_event, void* userdata);
int stream_close(struct stream* self); int stream_close(struct stream* self);
void stream_destroy(struct stream* self); void stream_destroy(struct stream* self);
ssize_t stream_read(struct stream* self, void* dst, size_t size); 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); 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 #ifdef ENABLE_TLS
int stream_upgrade_to_tls(struct stream* self, void* context); int stream_upgrade_to_tls(struct stream* self, void* context);

View File

@ -304,8 +304,8 @@ failure:
return NULL; 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) stream_req_fn on_done, void* userdata)
{ {
if (self->state == STREAM_STATE_CLOSED) if (self->state == STREAM_STATE_CLOSED)
return -1; return -1;
@ -323,6 +323,13 @@ int stream_write(struct stream* self, struct rcbuf* payload,
return stream__flush(self); 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) ssize_t stream__read_plain(struct stream* self, void* dst, size_t size)
{ {
return read(self->fd, dst, size); return read(self->fd, dst, size);