Skip to content

Commit

Permalink
fix(server): Fix connection bug (#695)
Browse files Browse the repository at this point in the history
  • Loading branch information
dranikpg authored Jan 16, 2023
1 parent 57e3ec9 commit daf5473
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/facade/dragonfly_connection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,18 @@ struct Connection::Request {
using MonitorMessage = std::string;

struct PipelineMsg {
absl::InlinedVector<MutableSlice, 6> args;

// I do not use mi_heap_t explicitly but mi_stl_allocator at the end does the same job
// of using the thread's heap.
// The capacity is chosen so that we allocate a fully utilized (256 bytes) block.
using StorageType = absl::InlinedVector<char, kReqStorageSize, mi_stl_allocator<char>>;

StorageType storage;

PipelineMsg(size_t nargs, size_t capacity) : args(nargs), storage(capacity) {
}

void Reset(size_t nargs, size_t capacity);

absl::InlinedVector<MutableSlice, 6> args;
StorageType storage;
};

static constexpr size_t kSizeOfPipelineMsg = sizeof(PipelineMsg);
Expand Down Expand Up @@ -207,15 +208,18 @@ void Connection::RequestDeleter::operator()(Request* req) const {
void Connection::Request::Emplace(const RespVec& args, size_t capacity) {
PipelineMsg* msg = get_if<PipelineMsg>(&payload);
if (msg) {
if (msg->storage.size() < capacity) {
msg->storage.resize(capacity);
}
msg->Reset(args.size(), capacity);
} else {
payload = PipelineMsg{args.size(), capacity};
}
SetArgs(args);
}

void Connection::Request::PipelineMsg::Reset(size_t nargs, size_t capacity) {
storage.resize(capacity);
args.resize(nargs);
}

Connection::Connection(Protocol protocol, util::HttpListenerBase* http_listener, SSL_CTX* ctx,
ServiceInterface* service)
: io_buf_(kMinReadSize), http_listener_(http_listener), ctx_(ctx), service_(service) {
Expand Down

0 comments on commit daf5473

Please sign in to comment.