-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Avoid excessive reply buffer copy in WinHTTP #2954
Conversation
} | ||
|
||
read = 0; | ||
while (writerFunc(dstBegin, dstSz, read) && read > 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of having two while loops they seem to have similar bodies, seems like we could use a do while here to avoid dry
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there are 1 while loop. While it is a bit ugly to have similar conditions, it looks to have a bit more clear logic.
410b24d
to
814f1a3
Compare
7c3111d
to
8c472e1
Compare
} | ||
} | ||
} | ||
return totalRead; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
under what conditions are you getting to this line? only way out of while is to return. is this expected or while is missing a break somewhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as dimitry also if the line is "unreachable in theory but we need to return something" we should assert use AWS_UNREACHABLE
as a invariant
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed to break + proper return
911c421
to
7e5292b
Compare
} | ||
} | ||
} | ||
return totalRead; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as dimitry also if the line is "unreachable in theory but we need to return something" we should assert use AWS_UNREACHABLE
as a invariant
if (ioStream.fail()) { | ||
AWS_LOGSTREAM_ERROR("StreamBufProtectedWriter", "Failed to write 1 byte (eof: " | ||
<< ioStream.eof() << ", bad: " << ioStream.bad() << ")"); | ||
return 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
np: please return false/true instead of int
@@ -10,6 +10,13 @@ | |||
#include <metric/CloudWatchMetrics.h> | |||
|
|||
int main(int argc, char *argv[]) { | |||
if (1 == argc || | |||
2 == argc && (std::string(argv[1]) == "-h" || std::string(argv[1]) == "--help" )) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NICE!
7e5292b
to
2e25d47
Compare
2e25d47
to
57521e6
Compare
return false; | ||
} | ||
|
||
static uint64_t WriteWithHelperBuffer(Aws::IOStream& ioStream, const WriterFunc& writerFunc, uint64_t& read) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: the return type should be bool
return false; | ||
} | ||
|
||
static uint64_t WriteDirectlyToPtr(StreamBufProtectedWriter* pBuffer, const WriterFunc& writerFunc, uint64_t& read) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: the return type should be bool
{ | ||
ioStream.write(tmpBuf, read); | ||
if (ioStream.fail()) { | ||
AWS_LOGSTREAM_ERROR("StreamBufProtectedWriter", "Failed to write " << tmpBufSz |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: shouldn't it be "Failed to write " << read
?
Issue #, if available:
Unlike in lib curl,
WinHTTP expects a pointer + size to where Windows is going to write us a reply:
https://learn.microsoft.com/en-us/windows/win32/api/winhttp/nf-winhttp-winhttpreaddata
while C++'s iostream (it the central point of requests/response handling in the SDK from the initial design) manipulates C++'s streams:
https://en.cppreference.com/w/cpp/io/basic_iostream
and can't provide raw pre-allocated buffer that WinHTTP wants.
Should WinHTTP provide std::iostream interface - this would not be an issue.
Description of changes:
Create a hack-y class to access raw pointers of the underlying buffer of the streambuffer to perform writes directly to the
pptr
pointer.Check all that applies:
Check which platforms you have built SDK on to verify the correctness of this PR.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.