Skip to content

Commit 3debf7a

Browse files
committed
UPD | chunked #3
1 parent 5107836 commit 3debf7a

File tree

12 files changed

+176
-92
lines changed

12 files changed

+176
-92
lines changed

include/ManapiUtils.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ namespace manapi::sockets {
4040
namespace manapi::memory {
4141
template<typename T>
4242
constexpr T *alloc (std::size_t size) {
43+
printf("alloc()\n");
4344
auto p = static_cast<T *> (::malloc(size));
4445
if (!p) { throw std::bad_alloc(); }
4546
return p;
@@ -51,6 +52,7 @@ namespace manapi::memory {
5152

5253
template<typename T>
5354
constexpr T *realloc (T *n, std::size_t size) {
55+
printf("realloc()\n");
5456
auto p = static_cast<T *> (::realloc(n, size));
5557
if (!p) { throw std::bad_alloc(); }
5658
return p;

include/http/HTTPv2.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ namespace manapi::net::http {
138138
int http_v2_on_write (http_v2_t *ctx);
139139
int http_v2_on_read_stream (const worker::shared_conn &conn, http_v2_stream_t *s);
140140
int http_v2_work (http_v2_t *ctx, http::config *config, const char **nbuffer, ssize_t *nsize);
141-
ssize_t http_v2_write (http_v2_stream_t *s, const void *buffer, ssize_t size, bool finish);
141+
ssize_t http_v2_write (const worker::shared_conn &conn, http_v2_stream_t *s, const void *buffer, ssize_t size, bool finish);
142142
int http_v2_rst_stream (http_v2_stream_t *s, int errcode);
143143
manapi::future<ssize_t> http_v2_response (worker::base *worker, const worker::shared_conn &connection, http_v2_stream_t *s, int status, std::map<std::string, std::string> headers, bool finish);
144144
}

include/worker/TCP.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ namespace manapi::net::worker {
9696

9797
bool is_writable(const shared_conn &conn) override;
9898

99-
virtual void http_work_ (http::http_v1_1_t *http_v1_1_ctx, const worker::shared_conn &conn, int flags, const char *buffer, ssize_t nsize);
99+
virtual void http_work_ (http::http_v1_1_t *http_v1_1_ctx, const worker::shared_conn &conn, int flags, const char *buffer, ssize_t nsize, ibuffpool_t *p);
100100

101101
virtual void onaccept_event_ (const worker::shared_conn &conn);
102102

include/worker/base_worker.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ namespace manapi::net::worker {
144144

145145
static ssize_t connection_io_send (struct connection_io_part *top, const char *buffer, ssize_t size, object_pool *bufferpool, int buffer_size, int *cnt, int max_cnt);
146146

147+
static void connection_io_send_start (struct connection_io_part *top, ibuffpool_t buff, int *cnt);
148+
147149
static void connection_io_trim (struct connection_io_part *top, buffer_deque *parent, int *cnt);
148150
protected:
149151

main.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,10 +230,13 @@ int main () {
230230
-> manapi::future<> {
231231
resp.header(manapi::net::http::HEADER.CONTENT_LENGTH, req.header(manapi::net::http::HEADER.CONTENT_LENGTH));
232232
co_return resp.callback_stream([&req] (manapi::net::http::response::resp_stream_cb cb) -> manapi::future<> {
233-
co_await req.callback_async([cb = std::move(cb)] (const char *buffer, ssize_t size, bool fin) mutable
233+
ssize_t rhs = 0;
234+
co_await req.callback_async([&rhs, cb = std::move(cb)] (const char *buffer, ssize_t size, bool fin) mutable
234235
-> manapi::future<ssize_t> {
235-
co_return co_await cb (buffer, size, fin);
236+
rhs += size;
237+
co_return size;
236238
});
239+
std::cout << rhs << "\n";
237240
});
238241
});
239242

src/ManapiHttpRequest.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ manapi::future<> manapi::net::http::request::read_async_body_(worker::base *work
419419
assert(!(p->empty()));
420420

421421
ctx_cb.worker->waiting(conn, false);
422-
ctx_cb.worker->event_flags(conn, 0);
422+
ctx_cb.worker->event_toggle(conn, false, ev::READ);
423423
ctx_cb.cnt++;
424424
manapi::async::run (manapi::async::invoke(
425425
[] (const worker::shared_conn & conn, worker::ibuffpool_t p, const char * buffer, ssize_t nsize, ctx_cb_t_ *ctx_cb, int flags) -> manapi::future<> {
@@ -476,7 +476,6 @@ manapi::future<> manapi::net::http::request::read_async_body_(worker::base *work
476476
goto finish;
477477
}
478478

479-
480479
if (!ctx_cb->req->body_size) {
481480
auto const copy = static_cast<int>(size - rhs);
482481
if (copy) {
@@ -495,7 +494,8 @@ manapi::future<> manapi::net::http::request::read_async_body_(worker::base *work
495494
goto finish;
496495
}
497496

498-
ctx_cb->worker->event_flags(conn, ev::READ);
497+
ctx_cb->worker->waiting(conn, true);
498+
ctx_cb->worker->event_toggle(conn, true, ev::READ);
499499
ctx_cb->cnt--;
500500
ctx_cb->mx.unlock();
501501

src/components/Buffer.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,9 @@ void manapi::bytebuffer::clear() {
159159
this->src = nullptr;
160160
}
161161
else {
162-
manapi::memory::free(std::exchange(this->src, nullptr));
162+
if (this->src) {
163+
manapi::memory::free(std::exchange(this->src, nullptr));
164+
}
163165
this->s = 0;
164166
this->reserved = 0;
165167
}

0 commit comments

Comments
 (0)