traeak commented on a change in pull request #8204:
URL: https://github.com/apache/trafficserver/pull/8204#discussion_r687905888
##########
File path: example/plugins/c-api/txn_data_sink/txn_data_sink.cc
##########
@@ -28,45 +28,49 @@
limitations under the License.
*/
-#include <stdio.h>
-#include <unistd.h>
#include <ts/ts.h>
-// This gets the PRI*64 types
-#define __STDC_FORMAT_MACROS 1
-#include <inttypes.h>
+#include <string>
+#include <string_view>
-#define PLUGIN_NAME "txn_data_sink"
-#define PCP "[" PLUGIN_NAME "] "
-
-// Activate the data sink if this field is present in the request.
-static const char FLAG_MIME_FIELD[] = "TS-Agent";
-static size_t const FLAG_MIME_LEN = sizeof(FLAG_MIME_FIELD) - 1;
-
-typedef struct {
- int64_t total;
-} SinkData;
+namespace
+{
+constexpr char const *PLUGIN_NAME = "txn_data_sink";
+
+/** Activate the data sink if this header field is present in the request. */
+std::string_view FLAG_HEADER_FIELD = "TS-Agent";
+
+/** The sink data for a transaction. */
+struct SinkData {
+ /** The bytes for the response body streamed in from the sink.
+ *
+ * @note This example plugin buffers the body which is useful for the
+ * associated Autest. In most production scenarios the user will want to
+ * interact with the body as a stream rather than buffering the entire body
+ * for each transaction.
+ */
+ std::string body_bytes;
+};
// This serves to consume all the data that arrives. If it's not consumed the
tunnel gets stalled
// and the transaction doesn't complete. Other things could be done with the
data, accessible via
// the IO buffer @a reader, such as writing it to disk to make an externally
accessible copy.
-static int
+int
client_reader(TSCont contp, TSEvent event, void *edata)
{
- SinkData *data = TSContDataGet(contp);
+ SinkData *data = static_cast<SinkData *>(TSContDataGet(contp));
// If we got closed, we're done.
if (TSVConnClosedGet(contp)) {
- TSfree(data);
+ delete data;
TSContDestroy(contp);
return 0;
}
TSVIO input_vio = TSVConnWriteVIOGet(contp);
if (!data) {
Review comment:
check to ensure pointers are compared with nullptr
This should be
if (data == nullptr) (although I personally prefer nullptr == data)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]