Skip to content

Commit

Permalink
small stuff + merge first fio_io_write call for HTTP responses
Browse files Browse the repository at this point in the history
  • Loading branch information
boazsegev committed Nov 25, 2024
1 parent ff7c07a commit b422dee
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 4 deletions.
32 changes: 31 additions & 1 deletion fio-stl.h
Original file line number Diff line number Diff line change
Expand Up @@ -45169,6 +45169,7 @@ struct fio___http_connection_http_s {
void (*on_http)(fio_http_s *h);
void (*on_finish)(fio_http_s *h);
fio_http1_parser_s parser;
fio_str_info_s buf;
uint32_t max_header;
};
struct fio___http_connection_ws_s {
Expand Down Expand Up @@ -46118,7 +46119,9 @@ FIO_SFUNC void fio___http_controller_http1_send_headers(fio_http_s *h) {
"transfer-encoding: chunked\r\n",
28);
fio_string_write(&buf, FIO_STRING_REALLOC, "\r\n", 2);
/* send data (move memory ownership) */
/* send data (move memory ownership)? */
c->state.http.buf = buf;
return;
fio_io_write2(c->io,
.buf = buf.buf,
.len = buf.len,
Expand All @@ -46134,6 +46137,21 @@ FIO_SFUNC void fio___http_controller_http1_write_body(
goto no_write_err;
if (fio_http_is_streaming(h))
goto stream_chunk;
if (c->state.http.buf.len && args.buf && args.len) {
fio_string_write(&c->state.http.buf,
FIO_STRING_REALLOC,
(char *)args.buf + args.offset,
args.len);
if (args.dealloc)
args.dealloc((void *)args.buf);
fio_io_write2(c->io,
.buf = (void *)c->state.http.buf.buf,
.len = c->state.http.buf.len,
.dealloc = FIO_STRING_FREE);
c->state.http.buf = FIO_STR_INFO0;
return;
}

fio_io_write2(c->io,
.buf = (void *)args.buf,
.fd = args.fd,
Expand Down Expand Up @@ -46180,6 +46198,14 @@ FIO_SFUNC void fio___http_controller_http1_on_finish_task(void *c_,
void *upgraded) {
fio___http_connection_s *c = (fio___http_connection_s *)c_;
c->suspend = 0;
if (c->state.http.buf.len) {
fio_io_write2(c->io,
.buf = (void *)c->state.http.buf.buf,
.len = c->state.http.buf.len,
.dealloc = FIO_STRING_FREE);
c->state.http.buf = FIO_STR_INFO0;
}

if (upgraded)
goto upgraded;

Expand Down Expand Up @@ -46938,6 +46964,10 @@ FIO_SFUNC void fio__http_controller_on_destroyed(fio_http_s *h) {
fio_http_write_args_s args = {.finish = 1}; /* never sets upgrade flag */
fio_http_write FIO_NOOP(h, args);
}
fio___http_connection_s *c = (fio___http_connection_s *)fio_http_cdata(h);
if (c->state.http.buf.buf)
FIO_STRING_FREE2(c->state.http.buf);
c->state.http.buf = FIO_STR_INFO0;
fio_queue_push(fio_io_queue(),
fio___http_controller_on_destroyed_task,
fio_http_cdata(h));
Expand Down
2 changes: 1 addition & 1 deletion fio-stl/249 reference counter.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ IFUNC FIO_REF_TYPE_PTR FIO_NAME(FIO_REF_NAME, FIO_REF_CONSTRUCTOR)(void) {
FIO_LEAK_COUNTER_ON_ALLOC(FIO_REF_NAME);
o->ref = 1;
#ifdef FIO_REF_FLEX_TYPE
o->flx_size = members;
o->flx_size = (uint32_t)members;
#endif
FIO_REF_METADATA_INIT((o->metadata));
FIO_REF_TYPE *ret = (FIO_REF_TYPE *)(o + 1);
Expand Down
2 changes: 1 addition & 1 deletion fio-stl/431 http handle.h
Original file line number Diff line number Diff line change
Expand Up @@ -1119,7 +1119,7 @@ static void fio___http_str_cached_init(void) {
FIO___HTTP_STATIC_CACHE_IMAP,
FIO___HTTP_STATIC_CACHE_CAPA_BITS,
(void *)&obj,
hash,
(uint32_t)hash,
fio___http_str_cached_cmp,
FIO___HTTP_STATIC_CACHE_STEP_LIMIT);
FIO_ASSERT(!pos.is_valid && pos.ipos < FIO___HTTP_STATIC_CACHE_CAPA &&
Expand Down
32 changes: 31 additions & 1 deletion fio-stl/439 http.h
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ struct fio___http_connection_http_s {
void (*on_http)(fio_http_s *h);
void (*on_finish)(fio_http_s *h);
fio_http1_parser_s parser;
fio_str_info_s buf;
uint32_t max_header;
};
struct fio___http_connection_ws_s {
Expand Down Expand Up @@ -1393,7 +1394,9 @@ FIO_SFUNC void fio___http_controller_http1_send_headers(fio_http_s *h) {
"transfer-encoding: chunked\r\n",
28);
fio_string_write(&buf, FIO_STRING_REALLOC, "\r\n", 2);
/* send data (move memory ownership) */
/* send data (move memory ownership)? */
c->state.http.buf = buf;
return;
fio_io_write2(c->io,
.buf = buf.buf,
.len = buf.len,
Expand All @@ -1409,6 +1412,21 @@ FIO_SFUNC void fio___http_controller_http1_write_body(
goto no_write_err;
if (fio_http_is_streaming(h))
goto stream_chunk;
if (c->state.http.buf.len && args.buf && args.len) {
fio_string_write(&c->state.http.buf,
FIO_STRING_REALLOC,
(char *)args.buf + args.offset,
args.len);
if (args.dealloc)
args.dealloc((void *)args.buf);
fio_io_write2(c->io,
.buf = (void *)c->state.http.buf.buf,
.len = c->state.http.buf.len,
.dealloc = FIO_STRING_FREE);
c->state.http.buf = FIO_STR_INFO0;
return;
}

fio_io_write2(c->io,
.buf = (void *)args.buf,
.fd = args.fd,
Expand Down Expand Up @@ -1455,6 +1473,14 @@ FIO_SFUNC void fio___http_controller_http1_on_finish_task(void *c_,
void *upgraded) {
fio___http_connection_s *c = (fio___http_connection_s *)c_;
c->suspend = 0;
if (c->state.http.buf.len) {
fio_io_write2(c->io,
.buf = (void *)c->state.http.buf.buf,
.len = c->state.http.buf.len,
.dealloc = FIO_STRING_FREE);
c->state.http.buf = FIO_STR_INFO0;
}

if (upgraded)
goto upgraded;

Expand Down Expand Up @@ -2213,6 +2239,10 @@ FIO_SFUNC void fio__http_controller_on_destroyed(fio_http_s *h) {
fio_http_write_args_s args = {.finish = 1}; /* never sets upgrade flag */
fio_http_write FIO_NOOP(h, args);
}
fio___http_connection_s *c = (fio___http_connection_s *)fio_http_cdata(h);
if (c->state.http.buf.buf)
FIO_STRING_FREE2(c->state.http.buf);
c->state.http.buf = FIO_STR_INFO0;
fio_queue_push(fio_io_queue(),
fio___http_controller_on_destroyed_task,
fio_http_cdata(h));
Expand Down

0 comments on commit b422dee

Please sign in to comment.