Experimental: Fix all signed/unsigned warnings
This commit is contained in:
+17
-13
@@ -20,6 +20,10 @@
|
||||
|
||||
/* This class implements async socket memory management strategies */
|
||||
|
||||
/* NOTE: Many unsigned/signed conversion warnings could be solved by moving from int length
|
||||
* to unsigned length for everything to/from uSockets - this would however remove the opportunity
|
||||
* to signal error with -1 (which is how the entire UNIX syscalling is built). */
|
||||
|
||||
#include "LoopData.h"
|
||||
#include "AsyncSocketData.h"
|
||||
|
||||
@@ -87,7 +91,7 @@ protected:
|
||||
LoopData *loopData = getLoopData();
|
||||
if (loopData->corkedSocket == this && loopData->corkOffset + size < LoopData::CORK_BUFFER_SIZE) {
|
||||
char *sendBuffer = loopData->corkBuffer + loopData->corkOffset;
|
||||
loopData->corkOffset += (int) size;
|
||||
loopData->corkOffset += (unsigned int) size;
|
||||
return {sendBuffer, false};
|
||||
} else {
|
||||
/* Slow path for now, we want to always be corked if possible */
|
||||
@@ -127,7 +131,7 @@ protected:
|
||||
static thread_local char buf[16];
|
||||
int ipLength = 16;
|
||||
us_socket_remote_address(SSL, (us_socket_t *) this, buf, &ipLength);
|
||||
return std::string_view(buf, ipLength);
|
||||
return std::string_view(buf, (unsigned int) ipLength);
|
||||
}
|
||||
|
||||
/* Returns the text representation of IP */
|
||||
@@ -156,14 +160,14 @@ protected:
|
||||
if ((unsigned int) written < asyncSocketData->buffer.length()) {
|
||||
|
||||
/* Update buffering (todo: we can do better here if we keep track of what happens to this guy later on) */
|
||||
asyncSocketData->buffer = asyncSocketData->buffer.substr(written);
|
||||
asyncSocketData->buffer = asyncSocketData->buffer.substr((size_t) written);
|
||||
|
||||
if (optionally) {
|
||||
/* Thankfully we can exit early here */
|
||||
return {0, true};
|
||||
} else {
|
||||
/* This path is horrible and points towards erroneous usage */
|
||||
asyncSocketData->buffer.append(src, length);
|
||||
asyncSocketData->buffer.append(src, (unsigned int) length);
|
||||
|
||||
return {length, true};
|
||||
}
|
||||
@@ -176,21 +180,21 @@ protected:
|
||||
if (length) {
|
||||
if (loopData->corkedSocket == this) {
|
||||
/* We are corked */
|
||||
if (LoopData::CORK_BUFFER_SIZE - loopData->corkOffset >= length) {
|
||||
if (LoopData::CORK_BUFFER_SIZE - loopData->corkOffset >= (unsigned int) length) {
|
||||
/* If the entire chunk fits in cork buffer */
|
||||
memcpy(loopData->corkBuffer + loopData->corkOffset, src, length);
|
||||
loopData->corkOffset += length;
|
||||
memcpy(loopData->corkBuffer + loopData->corkOffset, src, (unsigned int) length);
|
||||
loopData->corkOffset += (unsigned int) length;
|
||||
/* Fall through to default return */
|
||||
} else {
|
||||
/* Strategy differences between SSL and non-SSL regarding syscall minimizing */
|
||||
if constexpr (SSL) {
|
||||
/* Cork up as much as we can */
|
||||
int stripped = LoopData::CORK_BUFFER_SIZE - loopData->corkOffset;
|
||||
unsigned int stripped = LoopData::CORK_BUFFER_SIZE - loopData->corkOffset;
|
||||
memcpy(loopData->corkBuffer + loopData->corkOffset, src, stripped);
|
||||
loopData->corkOffset = LoopData::CORK_BUFFER_SIZE;
|
||||
|
||||
auto [written, failed] = uncork(src + stripped, length - stripped, optionally);
|
||||
return {written + stripped, failed};
|
||||
auto [written, failed] = uncork(src + stripped, length - (int) stripped, optionally);
|
||||
return {written + (int) stripped, failed};
|
||||
}
|
||||
|
||||
/* For non-SSL we take the penalty of two syscalls */
|
||||
@@ -210,11 +214,11 @@ protected:
|
||||
/* Fall back to worst possible case (should be very rare for HTTP) */
|
||||
/* At least we can reserve room for next chunk if we know it up front */
|
||||
if (nextLength) {
|
||||
asyncSocketData->buffer.reserve(asyncSocketData->buffer.length() + length - written + nextLength);
|
||||
asyncSocketData->buffer.reserve(asyncSocketData->buffer.length() + (size_t) (length - written + nextLength));
|
||||
}
|
||||
|
||||
/* Buffer this chunk */
|
||||
asyncSocketData->buffer.append(src + written, length - written);
|
||||
asyncSocketData->buffer.append(src + written, (size_t) (length - written));
|
||||
|
||||
/* Return the failure */
|
||||
return {length, true};
|
||||
@@ -237,7 +241,7 @@ protected:
|
||||
|
||||
if (loopData->corkOffset) {
|
||||
/* Corked data is already accounted for via its write call */
|
||||
auto [written, failed] = write(loopData->corkBuffer, loopData->corkOffset, false, length);
|
||||
auto [written, failed] = write(loopData->corkBuffer, (int) loopData->corkOffset, false, length);
|
||||
loopData->corkOffset = 0;
|
||||
|
||||
if (failed) {
|
||||
|
||||
Reference in New Issue
Block a user