-
Notifications
You must be signed in to change notification settings - Fork 621
Refactor Mgr::StringParam.str to be a SBuf [DRAFT] #2405
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -11,6 +11,7 @@ | |||||||||||||||||||||||||||||||||||||||||
| #include "squid.h" | ||||||||||||||||||||||||||||||||||||||||||
| #include "base/TextException.h" | ||||||||||||||||||||||||||||||||||||||||||
| #include "ipc/TypedMsgHdr.h" | ||||||||||||||||||||||||||||||||||||||||||
| #include "sbuf/SBuf.h" | ||||||||||||||||||||||||||||||||||||||||||
| #include "SquidString.h" | ||||||||||||||||||||||||||||||||||||||||||
| #include "tools.h" | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -147,6 +148,29 @@ Ipc::TypedMsgHdr::putString(const String &s) | |||||||||||||||||||||||||||||||||||||||||
| putRaw(s.rawBuf(), s.psize()); | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| void | ||||||||||||||||||||||||||||||||||||||||||
| Ipc::TypedMsgHdr::getSBuf(SBuf &s) const | ||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||
| const int length = getInt(); | ||||||||||||||||||||||||||||||||||||||||||
| Must(length >= 0); | ||||||||||||||||||||||||||||||||||||||||||
| // SBuf doesn't need special handling for empty | ||||||||||||||||||||||||||||||||||||||||||
| if (!length) { | ||||||||||||||||||||||||||||||||||||||||||
| s.clear(); | ||||||||||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+156
to
+160
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
Suggested change
or
Suggested change
or
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||
| Must(length <= maxSize); | ||||||||||||||||||||||||||||||||||||||||||
| s.assign(data.raw + offset, length); | ||||||||||||||||||||||||||||||||||||||||||
| offset += length; | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| void | ||||||||||||||||||||||||||||||||||||||||||
| Ipc::TypedMsgHdr::putSBuf(const SBuf &s) | ||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||
| Must(s.length() <= maxSize); | ||||||||||||||||||||||||||||||||||||||||||
| putInt(s.length()); | ||||||||||||||||||||||||||||||||||||||||||
| putRaw(s.rawContent(), s.length()); | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| void | ||||||||||||||||||||||||||||||||||||||||||
| Ipc::TypedMsgHdr::getFixed(void *rawBuf, size_t rawSize) const | ||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -25,6 +25,7 @@ | |||||||||
|
|
||||||||||
| #include <type_traits> | ||||||||||
|
|
||||||||||
| class SBuf; | ||||||||||
| class String; | ||||||||||
|
|
||||||||||
| namespace Ipc | ||||||||||
|
|
@@ -57,6 +58,8 @@ class TypedMsgHdr: public msghdr | |||||||||
| /* access to message parts for selected commonly-used part types */ | ||||||||||
| void getString(String &s) const; ///< load variable-length string | ||||||||||
| void putString(const String &s); ///< store variable-length string | ||||||||||
| void getSBuf(SBuf &s) const; ///< load variable-length SBuf | ||||||||||
| void putSBuf(const SBuf &s); ///< store variable-length SBuf | ||||||||||
|
Comment on lines
+61
to
+62
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I recommend overloading these methods. They are not about the exact storage type (which may change). They are about extracting a
Suggested change
Overloading would also reduce noise when callers are upgraded to use SBuf. |
||||||||||
| int getInt() const; ///< load an integer | ||||||||||
| void putInt(int n); ///< store an integer | ||||||||||
| void getFixed(void *raw, size_t size) const; ///< always load size bytes | ||||||||||
|
|
||||||||||
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.
Here and elsewhere, please avoid deprecated
Must()in new code. Throw a TextException instead.