Skip to content

Commit

Permalink
Separate cork size per SSL
Browse files Browse the repository at this point in the history
  • Loading branch information
uNetworkingAB committed Oct 18, 2024
1 parent 600e7fe commit ca171d4
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/App.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ struct TemplatedApp {
* app has one conceptual Topic tree) */
bool publish(std::string_view topic, std::string_view message, OpCode opCode, bool compress = false) {
/* Anything big bypasses corking efforts */
if (message.length() >= LoopData::CORK_BUFFER_SIZE) {
if (message.length() >= LoopData::CORK_BUFFER_SIZE[SSL]) {
return topicTree->publishBig(nullptr, topic, {message, opCode, compress}, [](Subscriber *s, TopicTreeBigMessage &message) {
auto *ws = (WebSocket<SSL, true, int> *) s->user;

Expand Down
8 changes: 4 additions & 4 deletions src/AsyncSocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ struct AsyncSocket {
LoopData *loopData = getLoopData();
BackPressure &backPressure = getAsyncSocketData()->buffer;
size_t existingBackpressure = backPressure.length();
if ((!existingBackpressure) && (isCorked() || canCork()) && (loopData->corkOffset + size < LoopData::CORK_BUFFER_SIZE)) {
if ((!existingBackpressure) && (isCorked() || canCork()) && (loopData->corkOffset + size < LoopData::CORK_BUFFER_SIZE[SSL])) {
/* Cork automatically if we can */
if (isCorked()) {
char *sendBuffer = loopData->corkBuffer + loopData->corkOffset;
Expand Down Expand Up @@ -271,7 +271,7 @@ struct AsyncSocket {
if (length) {
if (loopData->corkedSocket == this) {
/* We are corked */
if (LoopData::CORK_BUFFER_SIZE - loopData->corkOffset >= (unsigned int) length) {
if (LoopData::CORK_BUFFER_SIZE[SSL] - loopData->corkOffset >= (unsigned int) length) {
/* If the entire chunk fits in cork buffer */
memcpy(loopData->corkBuffer + loopData->corkOffset, src, (unsigned int) length);
loopData->corkOffset += (unsigned int) length;
Expand All @@ -280,9 +280,9 @@ struct AsyncSocket {
/* Strategy differences between SSL and non-SSL regarding syscall minimizing */
if constexpr (false) {
/* Cork up as much as we can */
unsigned int stripped = LoopData::CORK_BUFFER_SIZE - loopData->corkOffset;
unsigned int stripped = LoopData::CORK_BUFFER_SIZE[SSL] - loopData->corkOffset;
memcpy(loopData->corkBuffer + loopData->corkOffset, src, stripped);
loopData->corkOffset = LoopData::CORK_BUFFER_SIZE;
loopData->corkOffset = LoopData::CORK_BUFFER_SIZE[SSL];

auto [written, failed] = uncork(src + stripped, length - (int) stripped, optionally);
return {written + (int) stripped, failed};
Expand Down
6 changes: 3 additions & 3 deletions src/LoopData.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ struct alignas(16) LoopData {
/* Be silent */
bool noMark = false;

/* Good 16k for SSL perf. */
static const unsigned int CORK_BUFFER_SIZE = 16 * 1024;
/* Good 16k for SSL perf. 32kb for TCP */
static const unsigned int CORK_BUFFER_SIZE[2] = {32 * 1024, 16 * 1024};

/* Cork data */
char *corkBuffer = new char[CORK_BUFFER_SIZE];
char *corkBuffer = new char[CORK_BUFFER_SIZE[0]];
unsigned int corkOffset = 0;
void *corkedSocket = nullptr;

Expand Down
2 changes: 1 addition & 1 deletion src/WebSocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ struct WebSocket : AsyncSocket<SSL> {
}

/* Publish as sender, does not receive its own messages even if subscribed to relevant topics */
if (message.length() >= LoopData::CORK_BUFFER_SIZE) {
if (message.length() >= LoopData::CORK_BUFFER_SIZE[SSL]) {
return webSocketContextData->topicTree->publishBig(webSocketData->subscriber, topic, {message, opCode, compress}, [](Subscriber *s, TopicTreeBigMessage &message) {
auto *ws = (WebSocket<SSL, true, int> *) s->user;

Expand Down

0 comments on commit ca171d4

Please sign in to comment.