Take some from jarred
This commit is contained in:
@@ -1,7 +1,29 @@
|
||||
/* This is a simple yet efficient WebSocket server benchmark much like WRK */
|
||||
|
||||
#define _BSD_SOURCE
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include <libkern/OSByteOrder.h>
|
||||
|
||||
#define htobe16(x) OSSwapHostToBigInt16(x)
|
||||
#define htole16(x) OSSwapHostToLittleInt16(x)
|
||||
#define be16toh(x) OSSwapBigToHostInt16(x)
|
||||
#define le16toh(x) OSSwapLittleToHostInt16(x)
|
||||
|
||||
#define htobe32(x) OSSwapHostToBigInt32(x)
|
||||
#define htole32(x) OSSwapHostToLittleInt32(x)
|
||||
#define be32toh(x) OSSwapBigToHostInt32(x)
|
||||
#define le32toh(x) OSSwapLittleToHostInt32(x)
|
||||
|
||||
#define htobe64(x) OSSwapHostToBigInt64(x)
|
||||
#define htole64(x) OSSwapHostToLittleInt64(x)
|
||||
#define be64toh(x) OSSwapBigToHostInt64(x)
|
||||
#define le64toh(x) OSSwapLittleToHostInt64(x)
|
||||
#else
|
||||
#include <endian.h>
|
||||
#endif
|
||||
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <libusockets.h>
|
||||
|
||||
@@ -29,12 +29,12 @@
|
||||
|
||||
namespace uWS {
|
||||
|
||||
uint32_t STATE_HAS_SIZE = 0x80000000;
|
||||
uint32_t STATE_IS_CHUNKED = 0x40000000;
|
||||
uint32_t STATE_SIZE_MASK = 0x3FFFFFFF;
|
||||
constexpr uint32_t STATE_HAS_SIZE = 0x80000000;
|
||||
constexpr uint32_t STATE_IS_CHUNKED = 0x40000000;
|
||||
constexpr uint32_t STATE_SIZE_MASK = 0x3FFFFFFF;
|
||||
|
||||
/* Reads hex number until CR or out of data to consume. Updates state. Returns bytes consumed. */
|
||||
void consumeHexNumber(std::string_view &data, unsigned int &state) {
|
||||
inline void consumeHexNumber(std::string_view &data, unsigned int &state) {
|
||||
/* Consume everything higher than 32 */
|
||||
while (data.length() && data.data()[0] > 32) {
|
||||
|
||||
@@ -63,11 +63,11 @@ namespace uWS {
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int chunkSize(unsigned int state) {
|
||||
inline unsigned int chunkSize(unsigned int state) {
|
||||
return state & STATE_SIZE_MASK;
|
||||
}
|
||||
|
||||
void decChunkSize(unsigned int &state, unsigned int by) {
|
||||
inline void decChunkSize(unsigned int &state, unsigned int by) {
|
||||
|
||||
//unsigned int bits = state & STATE_IS_CHUNKED;
|
||||
|
||||
@@ -76,17 +76,17 @@ namespace uWS {
|
||||
//state |= bits;
|
||||
}
|
||||
|
||||
bool hasChunkSize(unsigned int state) {
|
||||
inline bool hasChunkSize(unsigned int state) {
|
||||
return state & STATE_HAS_SIZE;
|
||||
}
|
||||
|
||||
/* Are we in the middle of parsing chunked encoding? */
|
||||
bool isParsingChunkedEncoding(unsigned int state) {
|
||||
inline bool isParsingChunkedEncoding(unsigned int state) {
|
||||
return state & ~STATE_SIZE_MASK;
|
||||
}
|
||||
|
||||
/* Returns next chunk (empty or not), or if all data was consumed, nullopt is returned. */
|
||||
std::optional<std::string_view> getNextChunk(std::string_view &data, unsigned int &state, bool trailer = false) {
|
||||
static std::optional<std::string_view> getNextChunk(std::string_view &data, unsigned int &state, bool trailer = false) {
|
||||
|
||||
while (data.length()) {
|
||||
|
||||
|
||||
@@ -113,6 +113,10 @@ public:
|
||||
return std::string_view(headers->value.data(), querySeparator);
|
||||
}
|
||||
|
||||
std::string_view getFullUrl() {
|
||||
return std::string_view(headers->value.data(), headers->value.length());
|
||||
}
|
||||
|
||||
std::string_view getMethod() {
|
||||
return std::string_view(headers->key.data(), headers->key.length());
|
||||
}
|
||||
|
||||
+9
-2
@@ -401,8 +401,8 @@ public:
|
||||
|
||||
/* Try and end the response. Returns [true, true] on success.
|
||||
* Starts a timeout in some cases. Returns [ok, hasResponded] */
|
||||
std::pair<bool, bool> tryEnd(std::string_view data, uintmax_t totalSize = 0) {
|
||||
return {internalEnd(data, totalSize, true), hasResponded()};
|
||||
std::pair<bool, bool> tryEnd(std::string_view data, uintmax_t totalSize = 0, bool closeConnection = false) {
|
||||
return {internalEnd(data, totalSize, true, true, closeConnection), hasResponded()};
|
||||
}
|
||||
|
||||
/* Write parts of the response in chunking fashion. Starts timeout if failed. */
|
||||
@@ -445,6 +445,13 @@ public:
|
||||
return httpResponseData->offset;
|
||||
}
|
||||
|
||||
/* If you are messing around with sendfile you might want to override the offset. */
|
||||
void overrideWriteOffset(uintmax_t offset) {
|
||||
HttpResponseData<SSL> *httpResponseData = getHttpResponseData();
|
||||
|
||||
httpResponseData->offset = offset;
|
||||
}
|
||||
|
||||
/* Checking if we have fully responded and are ready for another request */
|
||||
bool hasResponded() {
|
||||
HttpResponseData<SSL> *httpResponseData = getHttpResponseData();
|
||||
|
||||
Reference in New Issue
Block a user