Github user SolidWallOfCode commented on a diff in the pull request:
https://github.com/apache/trafficserver/pull/843#discussion_r75878885
--- Diff: plugins/experimental/carp/HttpFetch.cc ---
@@ -0,0 +1,439 @@
+/** @file
+
+ Limited URL fetcher..
+
+ @section license License
+
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ */
+
+#define __STDC_LIMIT_MACROS // need INT64_MAX definition
+#include <stdint.h>
+#include <sys/time.h>
+
+#include "HttpFetch.h"
+#include "UrlComponents.h"
+#include "Common.h"
+
+using std::string;
+
+/**********************************************************/
+// just 'pass through' and call object's handlEvent fn
+
+static int
+handleHttpFetchIOEvents(TSCont cont, TSEvent event, void *edata)
+{
+ HttpFetch *fetchObj = static_cast<HttpFetch *> (TSContDataGet(cont));
+ if (NULL == fetchObj) {
+ TSDebug(DEBUG_FETCH_TAG, "handleHttpFetchEvents continuation data
NULL");
+ TSAssert(fetchObj);
+ }
+ return fetchObj->handleIOEvent(cont, event, edata);
+}
+
+/**********************************************************/
+HttpFetch::HttpFetch(const std::string &url, HashAlgorithm *hashAlgo,
+ HashNode *hashNode,const char *method)
+{
+ TSMBuffer bufp;
+ _url = url;
+ _respInfo = NULL;
+ _reqInfo = NULL;
+ _hashAlgo = hashAlgo;
+ _hashNode = hashNode;
+ _hcTimeoutSecond = DEFAULT_HEALTH_CHECK_TIMEOUT;
+
+ bufp = TSMBufferCreate();
+
+ if (bufp != NULL) {
+ TSMLoc urlp;
+ if (TSUrlCreate(bufp, &urlp) == TS_SUCCESS) {
+ const char *start = url.data();
+ if (TSUrlParse(bufp, urlp, &start, start + url.length()) ==
TS_PARSE_DONE) {
+ UrlComponents reqUrl;
+ string sPath;
+ string sHost;
+ reqUrl.populate(bufp, urlp);
+ reqUrl.getCompletePathString(sPath);
+ reqUrl.getCompleteHostString(sHost);
+ _request = string(method) + " " + sPath + " HTTP/1.0\r\nHost: " +
sHost + "\r\n";
+ _request += CARP_ROUTED_HEADER + ": 1\r\n";
+ _request += "\r\n";
+ }
+ TSHandleMLocRelease(bufp, NULL, urlp);
+ }
+ }
+ TSMBufferDestroy(bufp);
+ TSDebug(DEBUG_FETCH_TAG, "HttpFetch assembled this request %s",
_request.c_str());
+ _responseStatus=TS_HTTP_STATUS_NONE;
+ _ready = true;
+}
+
+/**********************************************************/
+HttpFetch::~HttpFetch()
+{
+}
+/**********************************************************/
+void
+HttpFetch::setHealthcheckTimeout(int timeout) {
+ _hcTimeoutSecond = timeout;
+}
+/**********************************************************/
+void
+HttpFetch::makeAsyncRequest(struct sockaddr const* serverAddr)
+{
+ _ready = false;
+ __sync_synchronize();
+ _result = UNKNOWN;
+ TSCont fetchCont = TSContCreate(handleHttpFetchIOEvents,
TSMutexCreate());
+ //TSCont fetchCont = TSContCreate(handleHttpFetchIOEvents, NULL);
+ TSContDataSet(fetchCont, static_cast<void *> (this));
+
+ // save server addr
+ memmove((void *) &_serverAddr, (void *) serverAddr, sizeof (struct
sockaddr));
+
+ // initiate request
+ TSDebug(DEBUG_FETCH_TAG, "TSNetConnect()");
+
+ struct timeval tvStart;
+ gettimeofday(&tvStart, NULL);
+ _startTime = tvStart.tv_sec*1000 + tvStart.tv_usec/1000;
+
+ struct sockaddr_in tempServerAddr;
+ memmove((void *) &tempServerAddr, (void *) &_serverAddr, sizeof (struct
sockaddr));
--- End diff --
Type mismatch here too - `sockaddr` vs `sockaddr_in`. Further, why copy to
`tempServerAddr`?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---