Begin restoring WebSocket performance
This commit is contained in:
@@ -71,6 +71,24 @@ protected:
|
|||||||
getLoopData()->corked = true;
|
getLoopData()->corked = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// this is highly broken right now, should properly make use of secondary buffer if needed
|
||||||
|
std::pair<char *, bool> getSendBuffer(size_t size) {
|
||||||
|
|
||||||
|
// for now, just return this straight up
|
||||||
|
|
||||||
|
LoopData *loopData = getLoopData();
|
||||||
|
|
||||||
|
char *sendBuffer = loopData->corkBuffer + loopData->corkOffset;
|
||||||
|
|
||||||
|
|
||||||
|
// very broken
|
||||||
|
loopData->corkOffset += size;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return {sendBuffer, false};
|
||||||
|
}
|
||||||
|
|
||||||
/* Write in three levels of prioritization: cork-buffer, syscall, socket-buffer. Always drain if possible.
|
/* Write in three levels of prioritization: cork-buffer, syscall, socket-buffer. Always drain if possible.
|
||||||
* Returns pair of bytes written (anywhere) and wheter or not this call resulted in the polling for
|
* Returns pair of bytes written (anywhere) and wheter or not this call resulted in the polling for
|
||||||
* writable (or we are in a state that implies polling for writable). */
|
* writable (or we are in a state that implies polling for writable). */
|
||||||
|
|||||||
+17
-12
@@ -40,20 +40,25 @@ private:
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
// this function need clean-ups and perf. fixes
|
// this function need clean-ups and perf. fixes
|
||||||
void send(std::string_view message, uWS::OpCode opCode) {
|
bool send(std::string_view message, uWS::OpCode opCode = uWS::OpCode::BINARY, bool compress = false) {
|
||||||
|
/* Transform the message to compressed domain if requested */
|
||||||
|
if (compress) {
|
||||||
|
//message = ;
|
||||||
|
std::cout << "send compression ignored!" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
// if corkAllocate(size) then corkFree(unused)
|
/* Get size, alloate size, write if needed */
|
||||||
|
size_t messageFrameSize = WebSocketProtocol<isServer, WebSocket<SSL, isServer>>::messageFrameSize(message.length());
|
||||||
// format the response
|
auto[sendBuffer, requiresWrite] = Super::getSendBuffer(messageFrameSize);
|
||||||
char *buf = (char *) malloc(message.length() + 100);
|
WebSocketProtocol<isServer, WebSocket<SSL, isServer>>::formatMessage(sendBuffer, message.data(), message.length(), opCode, message.length(), false);
|
||||||
int writeLength = WebSocketProtocol<isServer, WebSocket<SSL, isServer>>::formatMessage(buf, message.data(), message.length(), opCode, message.length(), false);
|
if (requiresWrite) {
|
||||||
|
auto[written, failed] = Super::write(sendBuffer, messageFrameSize);
|
||||||
|
/* Return true for success */
|
||||||
|
return !failed;
|
||||||
Super::write(buf, writeLength);
|
}
|
||||||
|
|
||||||
free(buf);
|
|
||||||
|
|
||||||
|
/* Return success */
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Emit close event, stat passive timeout */
|
/* Emit close event, stat passive timeout */
|
||||||
|
|||||||
@@ -309,6 +309,15 @@ public:
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline size_t messageFrameSize(size_t messageSize) {
|
||||||
|
if (messageSize < 126) {
|
||||||
|
return 2 + messageSize;
|
||||||
|
} else if (messageSize <= UINT16_MAX) {
|
||||||
|
return 4 + messageSize;
|
||||||
|
}
|
||||||
|
return 10 + messageSize;
|
||||||
|
}
|
||||||
|
|
||||||
static inline size_t formatMessage(char *dst, const char *src, size_t length, OpCode opCode, size_t reportedLength, bool compressed) {
|
static inline size_t formatMessage(char *dst, const char *src, size_t length, OpCode opCode, size_t reportedLength, bool compressed) {
|
||||||
size_t messageLength;
|
size_t messageLength;
|
||||||
size_t headerLength;
|
size_t headerLength;
|
||||||
|
|||||||
Reference in New Issue
Block a user