http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/example/response-header-1/response-header-1.c ---------------------------------------------------------------------- diff --git a/example/response-header-1/response-header-1.c b/example/response-header-1/response-header-1.c index 814c2d2..2dd9abb 100644 --- a/example/response-header-1/response-header-1.c +++ b/example/response-header-1/response-header-1.c @@ -85,18 +85,17 @@ modify_header(TSHttpTxn txnp) int num_refreshes = 0; if (!init_buffer_status) - return; /* caller reenables */ + return; /* caller reenables */ if (TSHttpTxnServerRespGet(txnp, &resp_bufp, &resp_loc) != TS_SUCCESS) { TSError("couldn't retrieve server response header\n"); - return; /* caller reenables */ + return; /* caller reenables */ } /* TSqa06246/TSqa06144 */ resp_status = TSHttpHdrStatusGet(resp_bufp, resp_loc); if (TS_HTTP_STATUS_OK == resp_status) { - TSDebug("resphdr", "Processing 200 OK"); TSMimeHdrFieldCreate(resp_bufp, resp_loc, &new_field_loc); /* Probably should check for errors */ TSDebug("resphdr", "Created new resp field with loc %p", new_field_loc); @@ -106,7 +105,7 @@ modify_header(TSHttpTxn txnp) */ TSMimeHdrFieldCopy(resp_bufp, resp_loc, new_field_loc, hdr_bufp, hdr_loc, field_loc); - /*********** Unclear why this is needed **************/ + /*********** Unclear why this is needed **************/ TSMimeHdrFieldAppend(resp_bufp, resp_loc, new_field_loc); @@ -114,10 +113,8 @@ modify_header(TSHttpTxn txnp) TSMimeHdrFieldCreate(resp_bufp, resp_loc, &new_field_loc); /* Probably should check for errors */ TSDebug("resphdr", "Created new resp field with loc %p", new_field_loc); TSMimeHdrFieldAppend(resp_bufp, resp_loc, new_field_loc); - TSMimeHdrFieldNameSet(resp_bufp, resp_loc, new_field_loc, - TS_MIME_FIELD_CACHE_CONTROL, TS_MIME_LEN_CACHE_CONTROL); - TSMimeHdrFieldValueStringInsert(resp_bufp, resp_loc, new_field_loc, - -1, TS_HTTP_VALUE_PUBLIC, TS_HTTP_LEN_PUBLIC); + TSMimeHdrFieldNameSet(resp_bufp, resp_loc, new_field_loc, TS_MIME_FIELD_CACHE_CONTROL, TS_MIME_LEN_CACHE_CONTROL); + TSMimeHdrFieldValueStringInsert(resp_bufp, resp_loc, new_field_loc, -1, TS_HTTP_VALUE_PUBLIC, TS_HTTP_LEN_PUBLIC); /* * mimehdr2_name = TSstrdup( "x-date-200-recvd" ) : CurrentDateTime @@ -133,7 +130,6 @@ modify_header(TSHttpTxn txnp) TSHandleMLocRelease(resp_bufp, TS_NULL_MLOC, resp_loc); } else if (TS_HTTP_STATUS_NOT_MODIFIED == resp_status) { - TSDebug("resphdr", "Processing 304 Not Modified"); /* N.B.: Protect writes to data (hash on URL + mutex: (ies)) */ @@ -143,17 +139,16 @@ modify_header(TSHttpTxn txnp) TSError("STATUS 304, TSHttpTxnCachedRespGet():"); TSError("couldn't retrieve cached response header\n"); TSHandleMLocRelease(resp_bufp, TS_NULL_MLOC, resp_loc); - return; /* Caller reenables */ + return; /* Caller reenables */ } /* Get the cached MIME field name for this HTTP header */ - cached_field_loc = TSMimeHdrFieldFind(cached_bufp, cached_loc, - (const char *) mimehdr1_name, strlen(mimehdr1_name)); + cached_field_loc = TSMimeHdrFieldFind(cached_bufp, cached_loc, (const char *)mimehdr1_name, strlen(mimehdr1_name)); if (TS_NULL_MLOC == cached_field_loc) { TSError("Can't find header %s in cached document", mimehdr1_name); TSHandleMLocRelease(resp_bufp, TS_NULL_MLOC, resp_loc); TSHandleMLocRelease(cached_bufp, TS_NULL_MLOC, cached_loc); - return; /* Caller reenables */ + return; /* Caller reenables */ } /* Get the cached MIME value for this name in this HTTP header */ @@ -163,7 +158,7 @@ modify_header(TSHttpTxn txnp) TSHandleMLocRelease(resp_bufp, TS_NULL_MLOC, resp_loc); TSHandleMLocRelease(cached_bufp, TS_NULL_MLOC, cached_loc); TSHandleMLocRelease(cached_bufp, cached_loc, cached_field_loc); - return; /* Caller reenables */ + return; /* Caller reenables */ } TSDebug("resphdr", "Header field value is %s, with length %d", chkptr, chklength); @@ -177,17 +172,17 @@ modify_header(TSHttpTxn txnp) num_refreshes++ ; */ - /* txn origin server response for this transaction stored - * in resp_bufp, resp_loc - * - * Create a new MIME field/value. Cached value has been incremented. - * Insert new MIME field/value into the server response buffer, - * allow HTTP processing to continue. This will update - * (indirectly invalidates) the cached HTTP headers MIME field. - * It is apparently not necessary to update all of the MIME fields - * in the in-process response in order to have the cached response - * become invalid. - */ + /* txn origin server response for this transaction stored + * in resp_bufp, resp_loc + * + * Create a new MIME field/value. Cached value has been incremented. + * Insert new MIME field/value into the server response buffer, + * allow HTTP processing to continue. This will update + * (indirectly invalidates) the cached HTTP headers MIME field. + * It is apparently not necessary to update all of the MIME fields + * in the in-process response in order to have the cached response + * become invalid. + */ TSMimeHdrFieldCreate(resp_bufp, resp_loc, &new_field_loc); /* Probaby should check for errrors */ /* mimehdr1_name : TSstrdup( "x-num-served-from-cache" ) ; */ @@ -217,14 +212,14 @@ modify_header(TSHttpTxn txnp) static int modify_response_header_plugin(TSCont contp ATS_UNUSED, TSEvent event, void *edata) { - TSHttpTxn txnp = (TSHttpTxn) edata; + TSHttpTxn txnp = (TSHttpTxn)edata; switch (event) { case TS_EVENT_HTTP_READ_RESPONSE_HDR: TSDebug("resphdr", "Called back with TS_EVENT_HTTP_READ_RESPONSE_HDR"); modify_header(txnp); TSHttpTxnReenable(txnp, TS_EVENT_HTTP_CONTINUE); - /* fall through */ + /* fall through */ default: break;
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/example/secure-link/secure-link.c ---------------------------------------------------------------------- diff --git a/example/secure-link/secure-link.c b/example/secure-link/secure-link.c index 9f55e18..04da8b3 100644 --- a/example/secure-link/secure-link.c +++ b/example/secure-link/secure-link.c @@ -41,7 +41,7 @@ typedef struct { } secure_link_info; TSRemapStatus -TSRemapDoRemap(void *ih, TSHttpTxn rh, TSRemapRequestInfo* rri) +TSRemapDoRemap(void *ih, TSHttpTxn rh, TSRemapRequestInfo *rri) { int i, len; time_t t, e; @@ -60,22 +60,22 @@ TSRemapDoRemap(void *ih, TSHttpTxn rh, TSRemapRequestInfo* rri) TSfree(s); qh = TSUrlHttpQueryGet(rri->requestBufp, rri->requestUrl, &len); - if(qh && len > 0) { + if (qh && len > 0) { s = (char *)TSstrndup(qh, len); - if((ptr = strtok_r(s, "&", &saveptr)) != NULL) { + if ((ptr = strtok_r(s, "&", &saveptr)) != NULL) { do { - if((val = strchr(ptr, '=')) != NULL) { + if ((val = strchr(ptr, '=')) != NULL) { *val++ = '\0'; - if(strcmp(ptr, "st") == 0) { + if (strcmp(ptr, "st") == 0) { token = TSstrdup(val); - } else if(strcmp(ptr, "ex") == 0) { + } else if (strcmp(ptr, "ex") == 0) { expire = TSstrdup(val); } } else { TSError("Invalid parameter [%s]", ptr); break; } - } while((ptr = strtok_r(NULL, "&", &saveptr)) != NULL); + } while ((ptr = strtok_r(NULL, "&", &saveptr)) != NULL); } else { TSError("strtok didn't find a & in the query string"); /* this is just example, so set fake params to prevent plugin crash */ @@ -88,9 +88,9 @@ TSRemapDoRemap(void *ih, TSHttpTxn rh, TSRemapRequestInfo* rri) } ph = TSUrlPathGet(rri->requestBufp, rri->requestUrl, &len); - if(ph && len > 0) { + if (ph && len > 0) { s = TSstrndup(ph, len); - if((ptr = strrchr(s, '/')) != NULL) { + if ((ptr = strrchr(s, '/')) != NULL) { *++ptr = '\0'; } path = TSstrdup(s); @@ -108,19 +108,19 @@ TSRemapDoRemap(void *ih, TSHttpTxn rh, TSRemapRequestInfo* rri) if (expire) MD5_Update(&ctx, expire, strlen(expire)); MD5_Final(md, &ctx); - for(i = 0; i < MD5_DIGEST_LENGTH; i++) { + for (i = 0; i < MD5_DIGEST_LENGTH; i++) { sprintf(&hash[i * 2], "%02x", md[i]); } time(&t); e = strtol(expire, NULL, 16); i = TSREMAP_DID_REMAP; - if(e < t || strcmp(hash, token) != 0) { - if(e < t) { + if (e < t || strcmp(hash, token) != 0) { + if (e < t) { TSDebug(PLUGIN_NAME, "link expired: [%lu] vs [%lu]", t, e); } else { TSDebug(PLUGIN_NAME, "tokens mismatch: [%s] vs [%s]", hash, token); } - if(sli->strict) { + if (sli->strict) { TSDebug(PLUGIN_NAME, "request is DENY"); TSHttpTxnSetHttpRetStatus(rh, TS_HTTP_STATUS_FORBIDDEN); i = TSREMAP_NO_REMAP; @@ -128,8 +128,8 @@ TSRemapDoRemap(void *ih, TSHttpTxn rh, TSRemapRequestInfo* rri) TSDebug(PLUGIN_NAME, "request is PASS"); } } - if(i == TSREMAP_DID_REMAP) { - if(TSUrlHttpQuerySet(rri->requestBufp, rri->requestUrl, "", -1) == TS_SUCCESS) { + if (i == TSREMAP_DID_REMAP) { + if (TSUrlHttpQuerySet(rri->requestBufp, rri->requestUrl, "", -1) == TS_SUCCESS) { s = TSUrlStringGet(rri->requestBufp, rri->requestUrl, &len); TSDebug(PLUGIN_NAME, "new request string is [%.*s]", len, s); TSfree(s); @@ -158,15 +158,15 @@ TSRemapNewInstance(int argc, char **argv, void **ih, char *errbuf, int errbuf_si sli->secret = NULL; sli->strict = 0; - for(i = 2; i < argc; i++) { - if((ptr = strchr(argv[i], ':')) != NULL) { + for (i = 2; i < argc; i++) { + if ((ptr = strchr(argv[i], ':')) != NULL) { *ptr++ = '\0'; - if(strcmp(argv[i], "secret") == 0) { - if(sli->secret != NULL) { + if (strcmp(argv[i], "secret") == 0) { + if (sli->secret != NULL) { TSfree(sli->secret); } sli->secret = TSstrdup(ptr); - } else if(strcmp(argv[i], "policy") == 0) { + } else if (strcmp(argv[i], "policy") == 0) { sli->strict = !strcasecmp(ptr, "strict"); } else { TSDebug(PLUGIN_NAME, "Unknown parameter [%s]", argv[i]); @@ -176,7 +176,7 @@ TSRemapNewInstance(int argc, char **argv, void **ih, char *errbuf, int errbuf_si } } - if(sli->secret == NULL) { + if (sli->secret == NULL) { sli->secret = TSstrdup(""); } http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/example/server-transform/server-transform.c ---------------------------------------------------------------------- diff --git a/example/server-transform/server-transform.c b/example/server-transform/server-transform.c index 4a2df81..a5c9573 100644 --- a/example/server-transform/server-transform.c +++ b/example/server-transform/server-transform.c @@ -59,15 +59,14 @@ #include "ts/ts.h" #include "ink_defs.h" -#define STATE_BUFFER 1 -#define STATE_CONNECT 2 -#define STATE_WRITE 3 -#define STATE_READ_STATUS 4 -#define STATE_READ 5 -#define STATE_BYPASS 6 - -typedef struct -{ +#define STATE_BUFFER 1 +#define STATE_CONNECT 2 +#define STATE_WRITE 3 +#define STATE_READ_STATUS 4 +#define STATE_READ 5 +#define STATE_BYPASS 6 + +typedef struct { int state; TSHttpTxn txn; @@ -99,7 +98,7 @@ transform_create(TSHttpTxn txnp) contp = TSTransformCreate(transform_handler, txnp); - data = (TransformData *) TSmalloc(sizeof(TransformData)); + data = (TransformData *)TSmalloc(sizeof(TransformData)); data->state = STATE_BUFFER; data->txn = txnp; data->input_buf = NULL; @@ -145,7 +144,7 @@ transform_destroy(TSCont contp) } static int -transform_connect(TSCont contp, TransformData * data) +transform_connect(TSCont contp, TransformData *data) { TSAction action; int content_length; @@ -171,7 +170,7 @@ transform_connect(TSCont contp, TransformData * data) temp = TSIOBufferCreate(); tempReader = TSIOBufferReaderAlloc(temp); - TSIOBufferWrite(temp, (const char *) &content_length, sizeof(int)); + TSIOBufferWrite(temp, (const char *)&content_length, sizeof(int)); TSIOBufferCopy(temp, data->input_reader, content_length, 0); TSIOBufferReaderFree(data->input_reader); @@ -191,7 +190,7 @@ transform_connect(TSCont contp, TransformData * data) ip_addr.sin_addr.s_addr = server_ip; /* Should be in network byte order */ ip_addr.sin_port = server_port; TSDebug("strans", "net connect.."); - action = TSNetConnect(contp, (struct sockaddr const*)&ip_addr); + action = TSNetConnect(contp, (struct sockaddr const *)&ip_addr); if (!TSActionDone(action)) { data->pending_action = action; @@ -201,7 +200,7 @@ transform_connect(TSCont contp, TransformData * data) } static int -transform_write(TSCont contp, TransformData * data) +transform_write(TSCont contp, TransformData *data) { int content_length; @@ -217,7 +216,7 @@ transform_write(TSCont contp, TransformData * data) } static int -transform_read_status(TSCont contp, TransformData * data) +transform_read_status(TSCont contp, TransformData *data) { data->state = STATE_READ_STATUS; @@ -233,7 +232,7 @@ transform_read_status(TSCont contp, TransformData * data) } static int -transform_read(TSCont contp, TransformData * data) +transform_read(TSCont contp, TransformData *data) { data->state = STATE_READ; @@ -242,7 +241,7 @@ transform_read(TSCont contp, TransformData * data) data->input_reader = NULL; data->server_vio = TSVConnRead(data->server_vc, contp, data->output_buf, data->content_length); - data->output_vc = TSTransformOutputVConnGet((TSVConn) contp); + data->output_vc = TSTransformOutputVConnGet((TSVConn)contp); if (data->output_vc == NULL) { TSError("TSTransformOutputVConnGet returns NULL"); } else { @@ -256,7 +255,7 @@ transform_read(TSCont contp, TransformData * data) } static int -transform_bypass(TSCont contp, TransformData * data) +transform_bypass(TSCont contp, TransformData *data) { data->state = STATE_BYPASS; @@ -273,12 +272,11 @@ transform_bypass(TSCont contp, TransformData * data) } TSIOBufferReaderConsume(data->input_reader, sizeof(int)); - data->output_vc = TSTransformOutputVConnGet((TSVConn) contp); + data->output_vc = TSTransformOutputVConnGet((TSVConn)contp); if (data->output_vc == NULL) { TSError("TSTransformOutputVConnGet returns NULL"); } else { - data->output_vio = - TSVConnWrite(data->output_vc, contp, data->input_reader, TSIOBufferReaderAvail(data->input_reader)); + data->output_vio = TSVConnWrite(data->output_vc, contp, data->input_reader, TSIOBufferReaderAvail(data->input_reader)); if (data->output_vio == NULL) { TSError("TSVConnWrite returns NULL"); } @@ -287,7 +285,7 @@ transform_bypass(TSCont contp, TransformData * data) } static int -transform_buffer_event(TSCont contp, TransformData * data, TSEvent event ATS_UNUSED, void *edata ATS_UNUSED) +transform_buffer_event(TSCont contp, TransformData *data, TSEvent event ATS_UNUSED, void *edata ATS_UNUSED) { TSVIO write_vio; int towrite; @@ -358,14 +356,14 @@ transform_buffer_event(TSCont contp, TransformData * data, TSEvent event ATS_UNU } static int -transform_connect_event(TSCont contp, TransformData * data, TSEvent event, void *edata) +transform_connect_event(TSCont contp, TransformData *data, TSEvent event, void *edata) { switch (event) { case TS_EVENT_NET_CONNECT: TSDebug("strans", "connected"); data->pending_action = NULL; - data->server_vc = (TSVConn) edata; + data->server_vc = (TSVConn)edata; return transform_write(contp, data); case TS_EVENT_NET_CONNECT_FAILED: TSDebug("strans", "connect failed"); @@ -379,7 +377,7 @@ transform_connect_event(TSCont contp, TransformData * data, TSEvent event, void } static int -transform_write_event(TSCont contp, TransformData * data, TSEvent event, void *edata ATS_UNUSED) +transform_write_event(TSCont contp, TransformData *data, TSEvent event, void *edata ATS_UNUSED) { switch (event) { case TS_EVENT_VCONN_WRITE_READY: @@ -402,7 +400,7 @@ transform_write_event(TSCont contp, TransformData * data, TSEvent event, void *e } static int -transform_read_status_event(TSCont contp, TransformData * data, TSEvent event, void *edata ATS_UNUSED) +transform_read_status_event(TSCont contp, TransformData *data, TSEvent event, void *edata ATS_UNUSED) { switch (event) { case TS_EVENT_ERROR: @@ -420,17 +418,17 @@ transform_read_status_event(TSCont contp, TransformData * data, TSEvent event, v buf_ptr = &data->content_length; while (read_nbytes > 0) { blk = TSIOBufferReaderStart(data->output_reader); - buf = (char *) TSIOBufferBlockReadStart(blk, data->output_reader, &avail); + buf = (char *)TSIOBufferBlockReadStart(blk, data->output_reader, &avail); read_ndone = (avail >= read_nbytes) ? read_nbytes : avail; memcpy(buf_ptr, buf, read_ndone); if (read_ndone > 0) { TSIOBufferReaderConsume(data->output_reader, read_ndone); read_nbytes -= read_ndone; /* move ptr frwd by read_ndone bytes */ - buf_ptr = (char *) buf_ptr + read_ndone; + buf_ptr = (char *)buf_ptr + read_ndone; } } - //data->content_length = ntohl(data->content_length); + // data->content_length = ntohl(data->content_length); return transform_read(contp, data); } return transform_bypass(contp, data); @@ -442,7 +440,7 @@ transform_read_status_event(TSCont contp, TransformData * data, TSEvent event, v } static int -transform_read_event(TSCont contp ATS_UNUSED, TransformData * data, TSEvent event, void *edata ATS_UNUSED) +transform_read_event(TSCont contp ATS_UNUSED, TransformData *data, TSEvent event, void *edata ATS_UNUSED) { switch (event) { case TS_EVENT_ERROR: @@ -487,7 +485,7 @@ transform_read_event(TSCont contp ATS_UNUSED, TransformData * data, TSEvent even } static int -transform_bypass_event(TSCont contp ATS_UNUSED, TransformData * data, TSEvent event, void *edata ATS_UNUSED) +transform_bypass_event(TSCont contp ATS_UNUSED, TransformData *data, TSEvent event, void *edata ATS_UNUSED) { switch (event) { case TS_EVENT_VCONN_WRITE_COMPLETE: @@ -520,8 +518,7 @@ transform_handler(TSCont contp, TSEvent event, void *edata) TSError("Didn't get Continuation's Data. Ignoring Event.."); return 0; } - TSDebug("strans", "transform handler event [%d], data->state = [%d]", - event, data->state); + TSDebug("strans", "transform handler event [%d], data->state = [%d]", event, data->state); do { switch (data->state) { @@ -607,7 +604,7 @@ server_response_ok(TSHttpTxn txnp) static int transform_plugin(TSCont contp, TSEvent event, void *edata) { - TSHttpTxn txnp = (TSHttpTxn) edata; + TSHttpTxn txnp = (TSHttpTxn)edata; switch (event) { case TS_EVENT_HTTP_READ_REQUEST_HDR: http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/example/session-1/session-1.c ---------------------------------------------------------------------- diff --git a/example/session-1/session-1.c b/example/session-1/session-1.c index 8547649..1dde8c7 100644 --- a/example/session-1/session-1.c +++ b/example/session-1/session-1.c @@ -69,13 +69,13 @@ ssn_handler(TSCont contp, TSEvent event, void *edata) switch (event) { case TS_EVENT_HTTP_SSN_START: - ssnp = (TSHttpSsn) edata; + ssnp = (TSHttpSsn)edata; handle_session(ssnp, contp); TSHttpSsnReenable(ssnp, TS_EVENT_HTTP_CONTINUE); return 0; case TS_EVENT_HTTP_TXN_START: - txnp = (TSHttpTxn) edata; + txnp = (TSHttpTxn)edata; txn_handler(txnp, contp); TSHttpTxnReenable(txnp, TS_EVENT_HTTP_CONTINUE); return 0; http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/example/ssl-preaccept/ats-util.h ---------------------------------------------------------------------- diff --git a/example/ssl-preaccept/ats-util.h b/example/ssl-preaccept/ats-util.h index e8f0aef..8973b14 100644 --- a/example/ssl-preaccept/ats-util.h +++ b/example/ssl-preaccept/ats-util.h @@ -21,10 +21,10 @@ limitations under the License. */ -# if !defined(_ats_util_h) -# define _ats_util_h +#if !defined(_ats_util_h) +#define _ats_util_h -# if defined(__cplusplus) +#if defined(__cplusplus) /** Set data to zero. Calls @c memset on @a t with a value of zero and a length of @c @@ -52,12 +52,13 @@ @endcode */ -template < typename T > inline void -ink_zero( - T& t ///< Object to zero. - ) { +template <typename T> +inline void +ink_zero(T &t ///< Object to zero. + ) +{ memset(&t, 0, sizeof(t)); } -# endif /* __cplusplus */ +#endif /* __cplusplus */ -# endif // ats-util.h +#endif // ats-util.h http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/example/ssl-preaccept/ssl-preaccept.cc ---------------------------------------------------------------------- diff --git a/example/ssl-preaccept/ssl-preaccept.cc b/example/ssl-preaccept/ssl-preaccept.cc index aa1431d..59b18dc 100644 --- a/example/ssl-preaccept/ssl-preaccept.cc +++ b/example/ssl-preaccept/ssl-preaccept.cc @@ -25,28 +25,28 @@ limitations under the License. */ -# include <stdio.h> -# include <memory.h> -# include <inttypes.h> -# include <ts/ts.h> -# include <tsconfig/TsValue.h> -# include <ts/ink_inet.h> -# include <getopt.h> +#include <stdio.h> +#include <memory.h> +#include <inttypes.h> +#include <ts/ts.h> +#include <tsconfig/TsValue.h> +#include <ts/ink_inet.h> +#include <getopt.h> using ts::config::Configuration; using ts::config::Value; -# define PN "ssl-preaccept" -# define PCP "[" PN " Plugin] " - -namespace { +#define PN "ssl-preaccept" +#define PCP "[" PN " Plugin] " +namespace +{ std::string ConfigPath; typedef std::pair<IpAddr, IpAddr> IpRange; typedef std::deque<IpRange> IpRangeQueue; IpRangeQueue ClientBlindTunnelIp; -Configuration Config; // global configuration +Configuration Config; // global configuration void Parse_Addr_String(ts::ConstBuffer const &text, IpRange &range) @@ -57,11 +57,10 @@ Parse_Addr_String(ts::ConstBuffer const &text, IpRange &range) size_t hyphen_pos = textstr.find("-"); if (hyphen_pos != std::string::npos) { std::string addr1 = textstr.substr(0, hyphen_pos); - std::string addr2 = textstr.substr(hyphen_pos+1); + std::string addr2 = textstr.substr(hyphen_pos + 1); range.first.load(ts::ConstBuffer(addr1.c_str(), addr1.length())); range.second.load(ts::ConstBuffer(addr2.c_str(), addr2.length())); - } - else { // Assume it is a single address + } else { // Assume it is a single address newAddr.load(text); range.first = newAddr; range.second = newAddr; @@ -69,7 +68,8 @@ Parse_Addr_String(ts::ConstBuffer const &text, IpRange &range) } /// Get a string value from a config node. -void Load_Config_Value(Value const& parent, char const* name, IpRangeQueue &addrs) +void +Load_Config_Value(Value const &parent, char const *name, IpRangeQueue &addrs) { Value v = parent[name]; std::string zret; @@ -124,12 +124,9 @@ CB_Pre_Accept(TSCont, TSEvent event, void *edata) IpAddr ip_client(TSNetVConnRemoteAddrGet(ssl_vc)); char buff2[INET6_ADDRSTRLEN]; - TSDebug("skh", "Pre accept callback %p - event is %s, target address %s, client address %s" - , ssl_vc - , event == TS_EVENT_VCONN_PRE_ACCEPT ? "good" : "bad" - , ip.toString(buff, sizeof(buff)) - , ip_client.toString(buff2, sizeof(buff2)) - ); + TSDebug("skh", "Pre accept callback %p - event is %s, target address %s, client address %s", ssl_vc, + event == TS_EVENT_VCONN_PRE_ACCEPT ? "good" : "bad", ip.toString(buff, sizeof(buff)), + ip_client.toString(buff2, sizeof(buff2))); // Not the worlds most efficient address comparison. For short lists // shouldn't be too bad. If the client IP is in any of the ranges, @@ -163,18 +160,16 @@ TSPluginInit(int argc, const char *argv[]) bool success = false; TSPluginRegistrationInfo info; TSCont cb_pa = 0; // pre-accept callback continuation - static const struct option longopt[] = { - { const_cast<char *>("config"), required_argument, NULL, 'c' }, - { NULL, no_argument, NULL, '\0' } - }; + static const struct option longopt[] = {{const_cast<char *>("config"), required_argument, NULL, 'c'}, + {NULL, no_argument, NULL, '\0'}}; - info.plugin_name = const_cast<char*>("SSL Preaccept test"); - info.vendor_name = const_cast<char*>("Network Geographics"); - info.support_email = const_cast<char*>("[email protected]"); + info.plugin_name = const_cast<char *>("SSL Preaccept test"); + info.vendor_name = const_cast<char *>("Network Geographics"); + info.support_email = const_cast<char *>("[email protected]"); int opt = 0; while (opt >= 0) { - opt = getopt_long(argc, (char * const *)argv, "c:", longopt, NULL); + opt = getopt_long(argc, (char *const *)argv, "c:", longopt, NULL); switch (opt) { case 'c': ConfigPath = optarg; @@ -183,7 +178,7 @@ TSPluginInit(int argc, const char *argv[]) } } if (ConfigPath.length() == 0) { - static char const * const DEFAULT_CONFIG_PATH = "ssl_preaccept.config"; + static char const *const DEFAULT_CONFIG_PATH = "ssl_preaccept.config"; ConfigPath = std::string(TSConfigDirGet()) + '/' + std::string(DEFAULT_CONFIG_PATH); TSDebug(PN, "No config path set in arguments, using default: %s", DEFAULT_CONFIG_PATH); } @@ -208,4 +203,3 @@ TSPluginInit(int argc, const char *argv[]) return; } - http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/example/ssl-sni-whitelist/ssl-sni-whitelist.cc ---------------------------------------------------------------------- diff --git a/example/ssl-sni-whitelist/ssl-sni-whitelist.cc b/example/ssl-sni-whitelist/ssl-sni-whitelist.cc index b213e8a..f7f0115 100644 --- a/example/ssl-sni-whitelist/ssl-sni-whitelist.cc +++ b/example/ssl-sni-whitelist/ssl-sni-whitelist.cc @@ -23,28 +23,28 @@ limitations under the License. */ -# include <stdio.h> -# include <memory.h> -# include <inttypes.h> -# include <ts/ts.h> -# include <ink_config.h> -# include <tsconfig/TsValue.h> -# include <openssl/ssl.h> -# include <getopt.h> +#include <stdio.h> +#include <memory.h> +#include <inttypes.h> +#include <ts/ts.h> +#include <ink_config.h> +#include <tsconfig/TsValue.h> +#include <openssl/ssl.h> +#include <getopt.h> using ts::config::Configuration; using ts::config::Value; -# define PN "ssl-sni-whitelist" -# define PCP "[" PN " Plugin] " +#define PN "ssl-sni-whitelist" +#define PCP "[" PN " Plugin] " -# if TS_USE_TLS_SNI - -namespace { +#if TS_USE_TLS_SNI +namespace +{ std::string ConfigPath; -Configuration Config; // global configuration +Configuration Config; // global configuration int Load_Config_File() @@ -108,18 +108,16 @@ TSPluginInit(int argc, const char *argv[]) bool success = false; TSPluginRegistrationInfo info; TSCont cb_sni = 0; // sni callback continuation - static const struct option longopt[] = { - { const_cast<char *>("config"), required_argument, NULL, 'c' }, - { NULL, no_argument, NULL, '\0' } - }; + static const struct option longopt[] = {{const_cast<char *>("config"), required_argument, NULL, 'c'}, + {NULL, no_argument, NULL, '\0'}}; - info.plugin_name = const_cast<char*>("SSL SNI whitelist"); - info.vendor_name = const_cast<char*>("Network Geographics"); - info.support_email = const_cast<char*>("[email protected]"); + info.plugin_name = const_cast<char *>("SSL SNI whitelist"); + info.vendor_name = const_cast<char *>("Network Geographics"); + info.support_email = const_cast<char *>("[email protected]"); int opt = 0; while (opt >= 0) { - opt = getopt_long(argc, (char * const *)argv, "c:", longopt, NULL); + opt = getopt_long(argc, (char *const *)argv, "c:", longopt, NULL); switch (opt) { case 'c': ConfigPath = optarg; @@ -128,7 +126,7 @@ TSPluginInit(int argc, const char *argv[]) } } if (ConfigPath.length() == 0) { - static char const * const DEFAULT_CONFIG_PATH = "ssl_sni_whitelist.config"; + static char const *const DEFAULT_CONFIG_PATH = "ssl_sni_whitelist.config"; ConfigPath = std::string(TSConfigDirGet()) + '/' + std::string(DEFAULT_CONFIG_PATH); TSDebug(PN, "No config path set in arguments, using default: %s", DEFAULT_CONFIG_PATH); } @@ -154,12 +152,12 @@ TSPluginInit(int argc, const char *argv[]) return; } -# else // ! TS_USE_TLS_SNI +#else // ! TS_USE_TLS_SNI void TSPluginInit(int, const char *[]) { - TSError(PCP "requires TLS SNI which is not available."); + TSError(PCP "requires TLS SNI which is not available."); } -# endif // TS_USE_TLS_SNI +#endif // TS_USE_TLS_SNI http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/example/ssl-sni/ssl-sni.cc ---------------------------------------------------------------------- diff --git a/example/ssl-sni/ssl-sni.cc b/example/ssl-sni/ssl-sni.cc index df9d840..1c47921 100644 --- a/example/ssl-sni/ssl-sni.cc +++ b/example/ssl-sni/ssl-sni.cc @@ -26,28 +26,28 @@ */ -# include <stdio.h> -# include <memory.h> -# include <inttypes.h> -# include <ts/ts.h> -# include <ink_config.h> -# include <tsconfig/TsValue.h> -# include <openssl/ssl.h> -# include <getopt.h> +#include <stdio.h> +#include <memory.h> +#include <inttypes.h> +#include <ts/ts.h> +#include <ink_config.h> +#include <tsconfig/TsValue.h> +#include <openssl/ssl.h> +#include <getopt.h> using ts::config::Configuration; using ts::config::Value; -# define PN "ssl-sni-test" -# define PCP "[" PN " Plugin] " +#define PN "ssl-sni-test" +#define PCP "[" PN " Plugin] " -# if TS_USE_TLS_SNI - -namespace { +#if TS_USE_TLS_SNI +namespace +{ std::string ConfigPath; -Configuration Config; // global configuration +Configuration Config; // global configuration int Load_Config_File() @@ -131,18 +131,16 @@ TSPluginInit(int argc, const char *argv[]) bool success = false; TSPluginRegistrationInfo info; TSCont cb_cert = 0; // Certificate callback continuation - static const struct option longopt[] = { - { const_cast<char *>("config"), required_argument, NULL, 'c' }, - { NULL, no_argument, NULL, '\0' } - }; + static const struct option longopt[] = {{const_cast<char *>("config"), required_argument, NULL, 'c'}, + {NULL, no_argument, NULL, '\0'}}; - info.plugin_name = const_cast<char*>("SSL SNI callback test"); - info.vendor_name = const_cast<char*>("Network Geographics"); - info.support_email = const_cast<char*>("[email protected]"); + info.plugin_name = const_cast<char *>("SSL SNI callback test"); + info.vendor_name = const_cast<char *>("Network Geographics"); + info.support_email = const_cast<char *>("[email protected]"); int opt = 0; while (opt >= 0) { - opt = getopt_long(argc, (char * const *)argv, "c:", longopt, NULL); + opt = getopt_long(argc, (char *const *)argv, "c:", longopt, NULL); switch (opt) { case 'c': ConfigPath = optarg; @@ -151,7 +149,7 @@ TSPluginInit(int argc, const char *argv[]) } } if (ConfigPath.length() == 0) { - static char const * const DEFAULT_CONFIG_PATH = "ssl_sni.config"; + static char const *const DEFAULT_CONFIG_PATH = "ssl_sni.config"; ConfigPath = std::string(TSConfigDirGet()) + '/' + std::string(DEFAULT_CONFIG_PATH); TSDebug(PN, "No config path set in arguments, using default: %s", DEFAULT_CONFIG_PATH); } @@ -177,12 +175,12 @@ TSPluginInit(int argc, const char *argv[]) return; } -# else // ! TS_USE_TLS_SNI +#else // ! TS_USE_TLS_SNI void TSPluginInit(int, const char *[]) { - TSError(PCP "requires TLS SNI which is not available."); + TSError(PCP "requires TLS SNI which is not available."); } -# endif // TS_USE_TLS_SNI +#endif // TS_USE_TLS_SNI http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/example/thread-1/thread-1.c ---------------------------------------------------------------------- diff --git a/example/thread-1/thread-1.c b/example/thread-1/thread-1.c index 5af7531..a504acf 100644 --- a/example/thread-1/thread-1.c +++ b/example/thread-1/thread-1.c @@ -40,7 +40,7 @@ static void * reenable_txn(void *data) { - TSHttpTxn txnp = (TSHttpTxn) data; + TSHttpTxn txnp = (TSHttpTxn)data; TSHttpTxnReenable(txnp, TS_EVENT_HTTP_CONTINUE); return NULL; } @@ -50,10 +50,10 @@ thread_plugin(TSCont contp ATS_UNUSED, TSEvent event, void *edata) { switch (event) { case TS_EVENT_HTTP_OS_DNS: - /** - * Check if the thread has been created successfully or not. - * If the thread has not been created successfully, assert. - */ + /** + * Check if the thread has been created successfully or not. + * If the thread has not been created successfully, assert. + */ if (!TSThreadCreate(reenable_txn, edata)) { TSReleaseAssert(!"Failure in thread creation"); } http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/example/thread-pool/include/gen.c ---------------------------------------------------------------------- diff --git a/example/thread-pool/include/gen.c b/example/thread-pool/include/gen.c index a4ec4e5..c4df4c4 100644 --- a/example/thread-pool/include/gen.c +++ b/example/thread-pool/include/gen.c @@ -36,5 +36,4 @@ main(int argc, char *argv[]) for (i = 0; i < atoi(argv[1]); i++) { printf("%d", i % 10); } - } http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/example/thread-pool/psi.c ---------------------------------------------------------------------- diff --git a/example/thread-pool/psi.c b/example/thread-pool/psi.c index 4d115c4..4601297 100644 --- a/example/thread-pool/psi.c +++ b/example/thread-pool/psi.c @@ -63,33 +63,30 @@ #define PSI_FILENAME_MAX_SIZE 512 -#define PSI_PATH_MAX_SIZE 256 +#define PSI_PATH_MAX_SIZE 256 #define PSI_PATH "include" -#define PSI_START_TAG "<!--include=" -#define PSI_START_TAG_LEN 12 +#define PSI_START_TAG "<!--include=" +#define PSI_START_TAG_LEN 12 -#define PSI_END_TAG "-->" -#define PSI_END_TAG_LEN 3 +#define PSI_END_TAG "-->" +#define PSI_END_TAG_LEN 3 #define MIME_FIELD_XPSI "X-Psi" -typedef enum -{ +typedef enum { STATE_READ_DATA = 1, STATE_READ_PSI = 2, - STATE_DUMP_PSI = 3 + STATE_DUMP_PSI = 3, } PluginState; -typedef enum -{ +typedef enum { PARSE_SEARCH, PARSE_EXTRACT, } ParseState; -typedef struct -{ +typedef struct { unsigned int magic; TSVIO output_vio; TSIOBuffer output_buffer; @@ -108,18 +105,16 @@ typedef struct } ContData; -typedef struct -{ +typedef struct { TSCont contp; TSEvent event; } TryLockData; -typedef enum -{ +typedef enum { STR_SUCCESS, STR_PARTIAL, - STR_FAIL + STR_FAIL, } StrOperationResult; @@ -145,7 +140,7 @@ cont_data_alloc() { ContData *data; - data = (ContData *) TSmalloc(sizeof(ContData)); + data = (ContData *)TSmalloc(sizeof(ContData)); data->magic = MAGIC_ALIVE; data->output_vio = NULL; data->output_buffer = NULL; @@ -177,7 +172,7 @@ cont_data_alloc() none -------------------------------------------------------------------------*/ static void -cont_data_destroy(ContData * data) +cont_data_destroy(ContData *data) { TSDebug(DBG_TAG, "Destroying continuation data"); if (data) { @@ -253,7 +248,7 @@ strsearch_ioreader(TSIOBufferReader reader, const char *pattern, int *nparse) block = TSIOBufferBlockNext(block); } - *nparse -= index; /* Adjust nparse so it doesn't include matching chars */ + *nparse -= index; /* Adjust nparse so it doesn't include matching chars */ if (index == slen) { TSDebug(DBG_TAG, "strfind: match for %s at position %d", pattern, *nparse); return STR_SUCCESS; @@ -306,7 +301,6 @@ strextract_ioreader(TSIOBufferReader reader, int offset, const char *end_pattern for (ptr = blockptr; ptr < blockptr + blocklen; ptr++, nbytes_so_far++) { if (nbytes_so_far >= offset) { - /* Add a new character to the filename */ buffer[buf_idx++] = *ptr; @@ -381,7 +375,6 @@ parse_data(TSCont contp, TSIOBufferReader input_reader, int avail, int *toconsum TSAssert(data->magic == MAGIC_ALIVE); if (data->parse_state == PARSE_SEARCH) { - /* Search for the start pattern */ status = strsearch_ioreader(input_reader, PSI_START_TAG, &nparse); switch (status) { @@ -410,8 +403,7 @@ parse_data(TSCont contp, TSIOBufferReader input_reader, int avail, int *toconsum /* And now let's extract the filename */ - status = strextract_ioreader(input_reader, nparse + PSI_START_TAG_LEN, - PSI_END_TAG, data->psi_filename, &data->psi_filename_len); + status = strextract_ioreader(input_reader, nparse + PSI_START_TAG_LEN, PSI_END_TAG, data->psi_filename, &data->psi_filename_len); switch (status) { case STR_FAIL: /* We couldn't extract a valid filename */ @@ -438,7 +430,7 @@ parse_data(TSCont contp, TSIOBufferReader input_reader, int avail, int *toconsum return 0; } -//TODO: Use libc basename function +// TODO: Use libc basename function // /*------------------------------------------------------------------------- strip_path @@ -456,7 +448,7 @@ _basename(const char *filename) char *cptr; const char *ptr = filename; - while ((cptr = strchr(ptr, (int) '/')) != NULL) { + while ((cptr = strchr(ptr, (int)'/')) != NULL) { ptr = cptr + 1; } return ptr; @@ -650,7 +642,6 @@ handle_transform(TSCont contp) /* There are some data available for reading. Let's parse it */ if (avail > 0) { - /* No need to parse data if there are too few bytes left to contain an include command... */ if (toread > (PSI_START_TAG_LEN + PSI_END_TAG_LEN)) { @@ -724,7 +715,7 @@ dump_psi(TSCont contp) ContData *data; int psi_output_len; - /* TODO: This is odd, do we need to get the input_vio, but never use it ?? */ +/* TODO: This is odd, do we need to get the input_vio, but never use it ?? */ #if 0 TSVIO input_vio; input_vio = TSVConnWriteVIOGet(contp); @@ -967,7 +958,7 @@ transform_add(TSHttpTxn txnp) static int read_response_handler(TSCont contp ATS_UNUSED, TSEvent event, void *edata) { - TSHttpTxn txnp = (TSHttpTxn) edata; + TSHttpTxn txnp = (TSHttpTxn)edata; switch (event) { case TS_EVENT_HTTP_READ_RESPONSE_HDR: @@ -1025,9 +1016,9 @@ TSPluginInit(int argc ATS_UNUSED, const char *argv[] ATS_UNUSED) init_queue(&job_queue); for (i = 0; i < NB_THREADS; i++) { - char *thread_name = (char *) TSmalloc(64); + char *thread_name = (char *)TSmalloc(64); sprintf(thread_name, "Thread[%d]", i); - if (!TSThreadCreate((TSThreadFunc) thread_loop, thread_name)) { + if (!TSThreadCreate((TSThreadFunc)thread_loop, thread_name)) { TSError("[TSPluginInit] Error while creating threads"); return; } http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/example/thread-pool/test/SDKTest/psi_server.c ---------------------------------------------------------------------- diff --git a/example/thread-pool/test/SDKTest/psi_server.c b/example/thread-pool/test/SDKTest/psi_server.c index e2b06d6..15f4c6b 100644 --- a/example/thread-pool/test/SDKTest/psi_server.c +++ b/example/thread-pool/test/SDKTest/psi_server.c @@ -40,7 +40,7 @@ #include <stdlib.h> #include "ServerAPI.h" -#define PSI_TAG_FORMAT "<!--include=file%d.txt-->" +#define PSI_TAG_FORMAT "<!--include=file%d.txt-->" #define PSI_TAG_MAX_SIZE 128 #define PSI_MIME_HEADER "X-Psi: true" @@ -48,19 +48,17 @@ #define TRUE 1 #define FALSE 0 -typedef struct -{ +typedef struct { int status_code; long request_length; long bytes_not_sent; char header_response[MAX_HEADER_RESPONSE]; - int done_sent_header; /* flag to see if header has been sent or not */ + int done_sent_header; /* flag to see if header has been sent or not */ int psi; } RequestInfo; -typedef struct -{ - double psi_ratio; /* for psi_ratio */ +typedef struct { + double psi_ratio; /* for psi_ratio */ } SCPlugin; SCPlugin my_plugin; @@ -84,7 +82,7 @@ TSOptionsProcess(char *option, char *value) { if (strcmp(option, "psi_ratio") == 0) { fprintf(stderr, "psi ratio set to %d %%\n", atoi(value)); - my_plugin.psi_ratio = (double) (atoi(value)) / 100.0; + my_plugin.psi_ratio = (double)(atoi(value)) / 100.0; } } @@ -103,7 +101,7 @@ int TSResponsePrepare(char *req_hdr, int req_len, void **response_id) { char *len_string; - RequestInfo *resp_id = (RequestInfo *) malloc(sizeof(RequestInfo)); + RequestInfo *resp_id = (RequestInfo *)malloc(sizeof(RequestInfo)); resp_id->psi = generate_psibility(); @@ -115,12 +113,11 @@ TSResponsePrepare(char *req_hdr, int req_len, void **response_id) resp_id->status_code = 200; if (resp_id->psi) { - sprintf(resp_id->header_response, "%s\r\n%s\r\n%s%ld\r\n%s\r\n\r\n", - "HTTP/1.0 200 OK", - "Content-type: text/plain", "Content-length: ", resp_id->request_length, PSI_MIME_HEADER); + sprintf(resp_id->header_response, "%s\r\n%s\r\n%s%ld\r\n%s\r\n\r\n", "HTTP/1.0 200 OK", "Content-type: text/plain", + "Content-length: ", resp_id->request_length, PSI_MIME_HEADER); } else { - sprintf(resp_id->header_response, "%s\r\n%s\r\n%s%ld\r\n\r\n", - "HTTP/1.0 200 OK", "Content-type: text/plain", "Content-length: ", resp_id->request_length); + sprintf(resp_id->header_response, "%s\r\n%s\r\n%s%ld\r\n\r\n", "HTTP/1.0 200 OK", "Content-type: text/plain", + "Content-length: ", resp_id->request_length); } } else { resp_id->request_length = -1; @@ -134,20 +131,18 @@ TSResponsePrepare(char *req_hdr, int req_len, void **response_id) /* put response (response header + response document) into buffer */ void -TSResponsePut(void **resp_id /* return */ , - void *resp_buffer /* return */ , - int *resp_bytes /* return */ , - int resp_buffer_size, int bytes_last_response) +TSResponsePut(void **resp_id /* return */, void *resp_buffer /* return */, int *resp_bytes /* return */, int resp_buffer_size, + int bytes_last_response) { int i = 0; - RequestInfo *rid = *((RequestInfo **) resp_id); + RequestInfo *rid = *((RequestInfo **)resp_id); int psi = 0; int len; char psi_tag[PSI_TAG_MAX_SIZE]; /* copy the header into the response buffer */ if (!rid->done_sent_header) { - i = sprintf((char *) resp_buffer, "%s", rid->header_response); + i = sprintf((char *)resp_buffer, "%s", rid->header_response); rid->done_sent_header = TRUE; } @@ -162,7 +157,7 @@ TSResponsePut(void **resp_id /* return */ , if (rid->status_code == 200) { /* buffer is not large enough to handle all content */ if (rid->bytes_not_sent + i > resp_buffer_size) { - memset((void *) ((char *) resp_buffer + i), 'X', resp_buffer_size - i); + memset((void *)((char *)resp_buffer + i), 'X', resp_buffer_size - i); *resp_bytes = resp_buffer_size; rid->bytes_not_sent -= (resp_buffer_size - i); } @@ -174,22 +169,21 @@ TSResponsePut(void **resp_id /* return */ , /* hopefully enough space for our include command */ if (rid->bytes_not_sent >= len) { - memcpy((void *) ((char *) resp_buffer + i), psi_tag, len); + memcpy((void *)((char *)resp_buffer + i), psi_tag, len); rid->bytes_not_sent -= len; i += len; } } - memset((void *) ((char *) resp_buffer + i), 'X', rid->bytes_not_sent); - memset((void *) ((char *) resp_buffer + i + rid->bytes_not_sent - 1), 'E', 1); + memset((void *)((char *)resp_buffer + i), 'X', rid->bytes_not_sent); + memset((void *)((char *)resp_buffer + i + rid->bytes_not_sent - 1), 'E', 1); *resp_bytes = rid->bytes_not_sent + i; rid->bytes_not_sent = 0; - } } /* return NULL as the resp_id to indicate * if it is the last TSResponsePut call */ if (rid->bytes_not_sent <= 0 || rid->status_code != 200) { free(rid); - *((RequestInfo **) resp_id) = NULL; + *((RequestInfo **)resp_id) = NULL; } } http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/example/thread-pool/thread.c ---------------------------------------------------------------------- diff --git a/example/thread-pool/thread.c b/example/thread-pool/thread.c index 9e49002..702676f 100644 --- a/example/thread-pool/thread.c +++ b/example/thread-pool/thread.c @@ -22,7 +22,6 @@ */ - #include <stdio.h> #include <pthread.h> #include "ts/ts.h" @@ -30,7 +29,7 @@ #include "thread.h" #include "ink_defs.h" -#define DBGTAG "xthread" +#define DBGTAG "xthread" struct timespec tp1; struct timespec tp2; @@ -42,16 +41,16 @@ static pthread_mutex_t cond_mutex; void -init_queue(Queue * q) +init_queue(Queue *q) { - q->head = NULL; /* Pointer on head cell */ - q->tail = NULL; /* Pointer on tail cell */ - q->nb_elem = 0; /* Nb elem in the queue */ + q->head = NULL; /* Pointer on head cell */ + q->tail = NULL; /* Pointer on tail cell */ + q->nb_elem = 0; /* Nb elem in the queue */ q->mutex = TSMutexCreate(); } void -add_to_queue(Queue * q, void *data) +add_to_queue(Queue *q, void *data) { Cell *new_cell; int n; @@ -86,14 +85,13 @@ add_to_queue(Queue * q, void *data) } void * -remove_from_queue(Queue * q) +remove_from_queue(Queue *q) { void *data = NULL; Cell *remove_cell; TSMutexLock(q->mutex); if (q->nb_elem > 0) { - remove_cell = q->head; TSAssert(remove_cell->magic == MAGIC_ALIVE); @@ -110,14 +108,13 @@ remove_from_queue(Queue * q) remove_cell->magic = MAGIC_DEAD; TSfree(remove_cell); q->nb_elem--; - } TSMutexUnlock(q->mutex); return data; } int -get_nbelem_queue(Queue * q) +get_nbelem_queue(Queue *q) { int nb; TSMutexLock(q->mutex); @@ -141,7 +138,7 @@ job_create(TSCont contp, ExecFunc func, void *data) } void -job_delete(Job * job) +job_delete(Job *job) { job->magic = MAGIC_DEAD; TSfree(job); @@ -187,4 +184,3 @@ thread_loop(void *arg ATS_UNUSED) } } } - http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/example/thread-pool/thread.h ---------------------------------------------------------------------- diff --git a/example/thread-pool/thread.h b/example/thread-pool/thread.h index b6f5900..fe127a8 100644 --- a/example/thread-pool/thread.h +++ b/example/thread-pool/thread.h @@ -22,31 +22,28 @@ */ - #ifndef _THREAD_H_ #define _THREAD_H_ #define MAGIC_ALIVE 0xfeedbabe -#define MAGIC_DEAD 0xdeadbeef +#define MAGIC_DEAD 0xdeadbeef /* If more than MAX_JOBS_ALARM are present in queue, the plugin will log error messages. This should be tuned based on your application */ #define MAX_JOBS_ALARM 1000 -typedef int (*ExecFunc) (TSCont, void *); +typedef int (*ExecFunc)(TSCont, void *); /* Structure that contains all information for a job execution */ -typedef struct -{ +typedef struct { unsigned int magic; - TSCont cont; /* Continuation to call once job is done */ - ExecFunc func; /* Job function */ - void *data; /* Any data to pass to the job function */ + TSCont cont; /* Continuation to call once job is done */ + ExecFunc func; /* Job function */ + void *data; /* Any data to pass to the job function */ } Job; /* Implementation of the queue for jobs */ -struct cell_rec -{ +struct cell_rec { unsigned int magic; void *ptr_data; struct cell_rec *ptr_next; @@ -54,8 +51,7 @@ struct cell_rec }; typedef struct cell_rec Cell; -typedef struct -{ +typedef struct { Cell *head; Cell *tail; int nb_elem; @@ -64,19 +60,19 @@ typedef struct /* queue manipulation functions */ -void init_queue(Queue * q); +void init_queue(Queue *q); -void add_to_queue(Queue * q, void *data); +void add_to_queue(Queue *q, void *data); -void *remove_from_queue(Queue * q); +void *remove_from_queue(Queue *q); -int get_nbelem_queue(Queue * q); +int get_nbelem_queue(Queue *q); /* Job functions */ Job *job_create(TSCont contp, ExecFunc func, void *data); -void job_delete(Job * job); +void job_delete(Job *job); /* thread functions */ http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/example/version/version.c ---------------------------------------------------------------------- diff --git a/example/version/version.c b/example/version/version.c index 71aa15e..77c824b 100644 --- a/example/version/version.c +++ b/example/version/version.c @@ -53,7 +53,7 @@ TSPluginInit(int argc ATS_UNUSED, const char *argv[] ATS_UNUSED) info.vendor_name = "MyCompany"; info.support_email = "[email protected]"; - // partial compilation +// partial compilation #if (TS_VERSION_NUMBER < 3000000) if (TSPluginRegister(TS_SDK_VERSION_2_0, &info) != TS_SUCCESS) { #else @@ -62,6 +62,6 @@ TSPluginInit(int argc ATS_UNUSED, const char *argv[] ATS_UNUSED) TSError("Plugin registration failed. \n"); } - TSDebug("debug-version-plugin", "Running in Apache Traffic Server: v%d.%d.%d\n", major_ts_version, minor_ts_version, patch_ts_version); + TSDebug("debug-version-plugin", "Running in Apache Traffic Server: v%d.%d.%d\n", major_ts_version, minor_ts_version, + patch_ts_version); } - http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/iocore/aio/AIO.cc ---------------------------------------------------------------------- diff --git a/iocore/aio/AIO.cc b/iocore/aio/AIO.cc index 877bc61..4dd1842 100644 --- a/iocore/aio/AIO.cc +++ b/iocore/aio/AIO.cc @@ -28,7 +28,7 @@ #include "P_AIO.h" #if AIO_MODE == AIO_MODE_NATIVE -#define AIO_PERIOD -HRTIME_MSECONDS(10) +#define AIO_PERIOD -HRTIME_MSECONDS(10) #else #define MAX_DISKS_POSSIBLE 100 @@ -65,8 +65,8 @@ uint64_t aio_bytes_written = 0; static int aio_stats_cb(const char * /* name ATS_UNUSED */, RecDataT data_type, RecData *data, RecRawStatBlock *rsb, int id) { - (void) data_type; - (void) rsb; + (void)data_type; + (void)rsb; int64_t new_val = 0; int64_t diff = 0; int64_t count, sum; @@ -102,7 +102,7 @@ aio_stats_cb(const char * /* name ATS_UNUSED */, RecDataT data_type, RecData *da diff = new_val - sum; RecSetGlobalRawStatSum(aio_rsb, id, new_val); RecSetGlobalRawStatCount(aio_rsb, id, now); - data->rec_float = (float) diff *1000.00 / (float) time_diff; + data->rec_float = (float)diff * 1000.00 / (float)time_diff; return 0; } @@ -117,8 +117,8 @@ int AIOTestData::ink_aio_stats(int event, void *d) { ink_hrtime now = ink_get_hrtime(); - double time_msec = (double) (now - start) / (double) HRTIME_MSECOND; - int i = (aio_reqs[0] == NULL)? 1 : 0; + double time_msec = (double)(now - start) / (double)HRTIME_MSECOND; + int i = (aio_reqs[0] == NULL) ? 1 : 0; for (; i < num_filedes; ++i) printf("%0.2f\t%i\t%i\t%i\n", time_msec, aio_reqs[i]->filedes, aio_reqs[i]->pending, aio_reqs[i]->queued); printf("Num Requests: %i Num Queued: %i num Moved: %i\n\n", data->num_req, data->num_queue, data->num_temp); @@ -148,17 +148,15 @@ ink_aio_init(ModuleVersion v) { ink_release_assert(!checkModuleVersion(v, AIO_MODULE_VERSION)); - aio_rsb = RecAllocateRawStatBlock((int) AIO_STAT_COUNT); - RecRegisterRawStat(aio_rsb, RECT_PROCESS, "proxy.process.cache.read_per_sec", - RECD_FLOAT, RECP_PERSISTENT, (int) AIO_STAT_READ_PER_SEC, aio_stats_cb); - RecRegisterRawStat(aio_rsb, RECT_PROCESS, "proxy.process.cache.write_per_sec", - RECD_FLOAT, RECP_PERSISTENT, (int) AIO_STAT_WRITE_PER_SEC, aio_stats_cb); - RecRegisterRawStat(aio_rsb, RECT_PROCESS, - "proxy.process.cache.KB_read_per_sec", - RECD_FLOAT, RECP_PERSISTENT, (int) AIO_STAT_KB_READ_PER_SEC, aio_stats_cb); - RecRegisterRawStat(aio_rsb, RECT_PROCESS, - "proxy.process.cache.KB_write_per_sec", - RECD_FLOAT, RECP_PERSISTENT, (int) AIO_STAT_KB_WRITE_PER_SEC, aio_stats_cb); + aio_rsb = RecAllocateRawStatBlock((int)AIO_STAT_COUNT); + RecRegisterRawStat(aio_rsb, RECT_PROCESS, "proxy.process.cache.read_per_sec", RECD_FLOAT, RECP_PERSISTENT, + (int)AIO_STAT_READ_PER_SEC, aio_stats_cb); + RecRegisterRawStat(aio_rsb, RECT_PROCESS, "proxy.process.cache.write_per_sec", RECD_FLOAT, RECP_PERSISTENT, + (int)AIO_STAT_WRITE_PER_SEC, aio_stats_cb); + RecRegisterRawStat(aio_rsb, RECT_PROCESS, "proxy.process.cache.KB_read_per_sec", RECD_FLOAT, RECP_PERSISTENT, + (int)AIO_STAT_KB_READ_PER_SEC, aio_stats_cb); + RecRegisterRawStat(aio_rsb, RECT_PROCESS, "proxy.process.cache.KB_write_per_sec", RECD_FLOAT, RECP_PERSISTENT, + (int)AIO_STAT_KB_WRITE_PER_SEC, aio_stats_cb); #if AIO_MODE != AIO_MODE_NATIVE memset(&aio_reqs, 0, MAX_DISKS_POSSIBLE * sizeof(AIO_Reqs *)); ink_mutex_init(&insert_mutex, NULL); @@ -176,29 +174,27 @@ ink_aio_start() return 0; } -#if AIO_MODE != AIO_MODE_NATIVE +#if AIO_MODE != AIO_MODE_NATIVE static void *aio_thread_main(void *arg); -struct AIOThreadInfo:public Continuation -{ - +struct AIOThreadInfo : public Continuation { AIO_Reqs *req; int sleep_wait; - int start(int event, Event *e) + int + start(int event, Event *e) { - (void) event; - (void) e; + (void)event; + (void)e; aio_thread_main(this); return EVENT_DONE; } - AIOThreadInfo(AIO_Reqs *thr_req, int sleep):Continuation(new_ProxyMutex()), req(thr_req), sleep_wait(sleep) + AIOThreadInfo(AIO_Reqs *thr_req, int sleep) : Continuation(new_ProxyMutex()), req(thr_req), sleep_wait(sleep) { SET_HANDLER(&AIOThreadInfo::start); } - }; /* priority scheduling */ @@ -227,7 +223,7 @@ aio_init_fildes(int fildes, int fromAPI = 0) ink_cond_init(&request->aio_cond); ink_mutex_init(&request->aio_mutex, NULL); - ink_atomiclist_init(&request->aio_temp_list, "temp_list", (uintptr_t) &((AIOCallback *) 0)->link); + ink_atomiclist_init(&request->aio_temp_list, "temp_list", (uintptr_t) & ((AIOCallback *)0)->link); RecInt thread_num; @@ -275,18 +271,17 @@ aio_insert(AIOCallback *op, AIO_Reqs *req) num_requests++; req->queued++; #endif - if (op->aiocb.aio_reqprio == AIO_LOWEST_PRIORITY) // http request + if (op->aiocb.aio_reqprio == AIO_LOWEST_PRIORITY) // http request { - AIOCallback *cb = (AIOCallback *) req->http_aio_todo.tail; + AIOCallback *cb = (AIOCallback *)req->http_aio_todo.tail; if (!cb) req->http_aio_todo.push(op); else req->http_aio_todo.insert(op, cb); } else { + AIOCallback *cb = (AIOCallback *)req->aio_todo.tail; - AIOCallback *cb = (AIOCallback *) req->aio_todo.tail; - - for (; cb; cb = (AIOCallback *) cb->link.prev) { + for (; cb; cb = (AIOCallback *)cb->link.prev) { if (cb->aiocb.aio_reqprio >= op->aiocb.aio_reqprio) { req->aio_todo.insert(op, cb); return; @@ -302,12 +297,12 @@ aio_insert(AIOCallback *op, AIO_Reqs *req) static void aio_move(AIO_Reqs *req) { - AIOCallback *next = NULL, *prev = NULL, *cb = (AIOCallback *) ink_atomiclist_popall(&req->aio_temp_list); + AIOCallback *next = NULL, *prev = NULL, *cb = (AIOCallback *)ink_atomiclist_popall(&req->aio_temp_list); /* flip the list */ if (!cb) return; while (cb->link.next) { - next = (AIOCallback *) cb->link.next; + next = (AIOCallback *)cb->link.next; cb->link.next = prev; prev = cb; cb = next; @@ -315,7 +310,7 @@ aio_move(AIO_Reqs *req) /* fix the last pointer */ cb->link.next = prev; for (; cb; cb = next) { - next = (AIOCallback *) cb->link.next; + next = (AIOCallback *)cb->link.next; cb->link.next = NULL; cb->link.prev = NULL; aio_insert(cb, req); @@ -328,10 +323,11 @@ aio_queue_req(AIOCallbackInternal *op, int fromAPI = 0) { int thread_ndx = 1; AIO_Reqs *req = op->aio_req; - op->link.next = NULL;; + op->link.next = NULL; + ; op->link.prev = NULL; #ifdef AIO_STATS - ink_atomic_increment((int *) &data->num_req, 1); + ink_atomic_increment((int *)&data->num_req, 1); #endif if (!fromAPI && (!req || req->filedes != op->aiocb.aio_fildes)) { /* search for the matching file descriptor */ @@ -382,7 +378,7 @@ aio_queue_req(AIOCallbackInternal *op, int fromAPI = 0) #endif ink_atomiclist_push(&req->aio_temp_list, op); } else { - /* check if any pending requests on the atomic list */ +/* check if any pending requests on the atomic list */ #ifdef AIO_STATS ink_atomic_increment(&data->num_queue, 1); #endif @@ -399,27 +395,26 @@ static inline int cache_op(AIOCallbackInternal *op) { bool read = (op->aiocb.aio_lio_opcode == LIO_READ) ? 1 : 0; - for (; op; op = (AIOCallbackInternal *) op->then) { + for (; op; op = (AIOCallbackInternal *)op->then) { ink_aiocb_t *a = &op->aiocb; ssize_t err, res = 0; while (a->aio_nbytes - res > 0) { do { if (read) - err = pread(a->aio_fildes, ((char *) a->aio_buf) + res, a->aio_nbytes - res, a->aio_offset + res); + err = pread(a->aio_fildes, ((char *)a->aio_buf) + res, a->aio_nbytes - res, a->aio_offset + res); else - err = pwrite(a->aio_fildes, ((char *) a->aio_buf) + res, a->aio_nbytes - res, a->aio_offset + res); + err = pwrite(a->aio_fildes, ((char *)a->aio_buf) + res, a->aio_nbytes - res, a->aio_offset + res); } while ((err < 0) && (errno == EINTR || errno == ENOBUFS || errno == ENOMEM)); if (err <= 0) { - Warning("cache disk operation failed %s %zd %d\n", - (a->aio_lio_opcode == LIO_READ) ? "READ" : "WRITE", err, errno); + Warning("cache disk operation failed %s %zd %d\n", (a->aio_lio_opcode == LIO_READ) ? "READ" : "WRITE", err, errno); op->aio_result = -errno; return (err); } res += err; } op->aio_result = res; - ink_assert(op->aio_result == (int64_t) a->aio_nbytes); + ink_assert(op->aio_result == (int64_t)a->aio_nbytes); } return 1; } @@ -428,7 +423,7 @@ int ink_aio_read(AIOCallback *op, int fromAPI) { op->aiocb.aio_lio_opcode = LIO_READ; - aio_queue_req((AIOCallbackInternal *) op, fromAPI); + aio_queue_req((AIOCallbackInternal *)op, fromAPI); return 1; } @@ -437,7 +432,7 @@ int ink_aio_write(AIOCallback *op, int fromAPI) { op->aiocb.aio_lio_opcode = LIO_WRITE; - aio_queue_req((AIOCallbackInternal *) op, fromAPI); + aio_queue_req((AIOCallbackInternal *)op, fromAPI); return 1; } @@ -456,8 +451,8 @@ ink_aio_thread_num_set(int thread_num) void * aio_thread_main(void *arg) { - AIOThreadInfo *thr_info = (AIOThreadInfo *) arg; - AIO_Reqs *my_aio_req = (AIO_Reqs *) thr_info->req; + AIOThreadInfo *thr_info = (AIOThreadInfo *)arg; + AIO_Reqs *my_aio_req = (AIO_Reqs *)thr_info->req; AIO_Reqs *current_req = NULL; AIOCallback *op = NULL; ink_mutex_acquire(&my_aio_req->aio_mutex); @@ -472,7 +467,7 @@ aio_thread_main(void *arg) #ifdef AIO_STATS num_requests--; current_req->queued--; - ink_atomic_increment((int *) ¤t_req->pending, 1); + ink_atomic_increment((int *)¤t_req->pending, 1); #endif // update the stats; if (op->aiocb.aio_lio_opcode == LIO_WRITE) { @@ -483,7 +478,7 @@ aio_thread_main(void *arg) aio_bytes_read += op->aiocb.aio_nbytes; } ink_mutex_release(¤t_req->aio_mutex); - if (cache_op((AIOCallbackInternal *) op) <= 0) { + if (cache_op((AIOCallbackInternal *)op) <= 0) { if (aio_err_callbck) { AIOCallback *callback_op = new AIOCallbackInternal(); callback_op->aiocb.aio_fildes = op->aiocb.aio_fildes; @@ -492,9 +487,9 @@ aio_thread_main(void *arg) eventProcessor.schedule_imm(callback_op); } } - ink_atomic_increment((int *) ¤t_req->requests_queued, -1); + ink_atomic_increment((int *)¤t_req->requests_queued, -1); #ifdef AIO_STATS - ink_atomic_increment((int *) ¤t_req->pending, -1); + ink_atomic_increment((int *)¤t_req->pending, -1); #endif op->link.prev = NULL; op->link.next = NULL; @@ -516,7 +511,8 @@ aio_thread_main(void *arg) } #else int -DiskHandler::startAIOEvent(int /* event ATS_UNUSED */, Event *e) { +DiskHandler::startAIOEvent(int /* event ATS_UNUSED */, Event *e) +{ SET_HANDLER(&DiskHandler::mainAIOEvent); e->schedule_every(AIO_PERIOD); trigger_event = e; @@ -524,12 +520,13 @@ DiskHandler::startAIOEvent(int /* event ATS_UNUSED */, Event *e) { } int -DiskHandler::mainAIOEvent(int event, Event *e) { +DiskHandler::mainAIOEvent(int event, Event *e) +{ AIOCallback *op = NULL; Lagain: int ret = io_getevents(ctx, 0, MAX_AIO_EVENTS, events, NULL); for (int i = 0; i < ret; i++) { - op = (AIOCallback *) events[i].data; + op = (AIOCallback *)events[i].data; op->aio_result = events[i].res; ink_assert(op->action.continuation); complete_list.enqueue(op); @@ -576,7 +573,8 @@ Lagain: } int -ink_aio_read(AIOCallback *op, int /* fromAPI ATS_UNUSED */) { +ink_aio_read(AIOCallback *op, int /* fromAPI ATS_UNUSED */) +{ op->aiocb.aio_reqprio = AIO_DEFAULT_PRIORITY; op->aiocb.aio_lio_opcode = IO_CMD_PREAD; op->aiocb.data = op; @@ -590,7 +588,8 @@ ink_aio_read(AIOCallback *op, int /* fromAPI ATS_UNUSED */) { } int -ink_aio_write(AIOCallback *op, int /* fromAPI ATS_UNUSED */) { +ink_aio_write(AIOCallback *op, int /* fromAPI ATS_UNUSED */) +{ op->aiocb.aio_reqprio = AIO_DEFAULT_PRIORITY; op->aiocb.aio_lio_opcode = IO_CMD_PWRITE; op->aiocb.data = op; @@ -604,7 +603,8 @@ ink_aio_write(AIOCallback *op, int /* fromAPI ATS_UNUSED */) { } int -ink_aio_readv(AIOCallback *op, int /* fromAPI ATS_UNUSED */) { +ink_aio_readv(AIOCallback *op, int /* fromAPI ATS_UNUSED */) +{ EThread *t = this_ethread(); DiskHandler *dh = t->diskHandler; AIOCallback *io = op; @@ -634,7 +634,8 @@ ink_aio_readv(AIOCallback *op, int /* fromAPI ATS_UNUSED */) { } int -ink_aio_writev(AIOCallback *op, int /* fromAPI ATS_UNUSED */) { +ink_aio_writev(AIOCallback *op, int /* fromAPI ATS_UNUSED */) +{ EThread *t = this_ethread(); DiskHandler *dh = t->diskHandler; AIOCallback *io = op; http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/iocore/aio/I_AIO.h ---------------------------------------------------------------------- diff --git a/iocore/aio/I_AIO.h b/iocore/aio/I_AIO.h index 2dc864b..806962d 100644 --- a/iocore/aio/I_AIO.h +++ b/iocore/aio/I_AIO.h @@ -28,7 +28,7 @@ ****************************************************************************/ -#if !defined (_I_AIO_h_) +#if !defined(_I_AIO_h_) #define _I_AIO_h_ #include "libts.h" @@ -37,23 +37,21 @@ #define AIO_MODULE_MAJOR_VERSION 1 #define AIO_MODULE_MINOR_VERSION 0 -#define AIO_MODULE_VERSION makeModuleVersion(AIO_MODULE_MAJOR_VERSION,\ - AIO_MODULE_MINOR_VERSION,\ - PUBLIC_MODULE_HEADER) +#define AIO_MODULE_VERSION makeModuleVersion(AIO_MODULE_MAJOR_VERSION, AIO_MODULE_MINOR_VERSION, PUBLIC_MODULE_HEADER) -#define AIO_EVENT_DONE (AIO_EVENT_EVENTS_START+0) +#define AIO_EVENT_DONE (AIO_EVENT_EVENTS_START + 0) -#define AIO_MODE_THREAD 0 -#define AIO_MODE_NATIVE 1 +#define AIO_MODE_THREAD 0 +#define AIO_MODE_NATIVE 1 #if TS_USE_LINUX_NATIVE_AIO -#define AIO_MODE AIO_MODE_NATIVE +#define AIO_MODE AIO_MODE_NATIVE #else -#define AIO_MODE AIO_MODE_THREAD +#define AIO_MODE AIO_MODE_THREAD #endif -#define LIO_READ 0x1 -#define LIO_WRITE 0x2 +#define LIO_READ 0x1 +#define LIO_WRITE 0x2 #if AIO_MODE == AIO_MODE_NATIVE @@ -65,23 +63,22 @@ typedef struct iocb ink_aiocb_t; typedef struct io_event ink_io_event_t; // XXX hokey old-school compatibility with ink_aiocb.h ... -#define aio_nbytes u.c.nbytes -#define aio_offset u.c.offset -#define aio_buf u.c.buf +#define aio_nbytes u.c.nbytes +#define aio_offset u.c.offset +#define aio_buf u.c.buf #else -typedef struct ink_aiocb -{ +typedef struct ink_aiocb { int aio_fildes; - volatile void *aio_buf; /* buffer location */ - size_t aio_nbytes; /* length of transfer */ - off_t aio_offset; /* file offset */ - - int aio_reqprio; /* request priority offset */ - int aio_lio_opcode; /* listio operation */ - int aio_state; /* state flag for List I/O */ - int aio__pad[1]; /* extension padding */ + volatile void *aio_buf; /* buffer location */ + size_t aio_nbytes; /* length of transfer */ + off_t aio_offset; /* file offset */ + + int aio_reqprio; /* request priority offset */ + int aio_lio_opcode; /* listio operation */ + int aio_state; /* state flag for List I/O */ + int aio__pad[1]; /* extension padding */ } ink_aiocb_t; bool ink_aio_thread_num_set(int thread_num); @@ -89,14 +86,13 @@ bool ink_aio_thread_num_set(int thread_num); #endif // AIOCallback::thread special values -#define AIO_CALLBACK_THREAD_ANY ((EThread*)0) // any regular event thread -#define AIO_CALLBACK_THREAD_AIO ((EThread*)-1) +#define AIO_CALLBACK_THREAD_ANY ((EThread *)0) // any regular event thread +#define AIO_CALLBACK_THREAD_AIO ((EThread *)-1) -#define AIO_LOWEST_PRIORITY 0 -#define AIO_DEFAULT_PRIORITY AIO_LOWEST_PRIORITY +#define AIO_LOWEST_PRIORITY 0 +#define AIO_DEFAULT_PRIORITY AIO_LOWEST_PRIORITY -struct AIOCallback: public Continuation -{ +struct AIOCallback : public Continuation { // set before calling aio_read/aio_write ink_aiocb_t aiocb; Action action; @@ -106,21 +102,18 @@ struct AIOCallback: public Continuation int64_t aio_result; int ok(); - AIOCallback() : thread(AIO_CALLBACK_THREAD_ANY), then(0) { - aiocb.aio_reqprio = AIO_DEFAULT_PRIORITY; - } + AIOCallback() : thread(AIO_CALLBACK_THREAD_ANY), then(0) { aiocb.aio_reqprio = AIO_DEFAULT_PRIORITY; } }; #if AIO_MODE == AIO_MODE_NATIVE -struct AIOVec: public Continuation -{ +struct AIOVec : public Continuation { Action action; int size; int completed; AIOCallback *first; - AIOVec(int sz, AIOCallback *c): Continuation(new_ProxyMutex()), size(sz), completed(0), first(c) + AIOVec(int sz, AIOCallback *c) : Continuation(new_ProxyMutex()), size(sz), completed(0), first(c) { action = c->action; SET_HANDLER(&AIOVec::mainEvent); @@ -129,8 +122,7 @@ struct AIOVec: public Continuation int mainEvent(int event, Event *e); }; -struct DiskHandler: public Continuation -{ +struct DiskHandler : public Continuation { Event *trigger_event; io_context_t ctx; ink_io_event_t events[MAX_AIO_EVENTS]; @@ -138,7 +130,8 @@ struct DiskHandler: public Continuation Que(AIOCallback, link) complete_list; int startAIOEvent(int event, Event *e); int mainAIOEvent(int event, Event *e); - DiskHandler() { + DiskHandler() + { SET_HANDLER(&DiskHandler::startAIOEvent); memset(&ctx, 0, sizeof(ctx)); int ret = io_setup(MAX_AIO_EVENTS, &ctx); @@ -151,11 +144,13 @@ struct DiskHandler: public Continuation void ink_aio_init(ModuleVersion version); int ink_aio_start(); -void ink_aio_set_callback(Continuation * error_callback); +void ink_aio_set_callback(Continuation *error_callback); -int ink_aio_read(AIOCallback *op, int fromAPI = 0); // fromAPI is a boolean to indicate if this is from a API call such as upload proxy feature +int ink_aio_read(AIOCallback *op, + int fromAPI = 0); // fromAPI is a boolean to indicate if this is from a API call such as upload proxy feature int ink_aio_write(AIOCallback *op, int fromAPI = 0); -int ink_aio_readv(AIOCallback *op, int fromAPI = 0); // fromAPI is a boolean to indicate if this is from a API call such as upload proxy feature +int ink_aio_readv(AIOCallback *op, + int fromAPI = 0); // fromAPI is a boolean to indicate if this is from a API call such as upload proxy feature int ink_aio_writev(AIOCallback *op, int fromAPI = 0); AIOCallback *new_AIOCallback(void); #endif http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/iocore/aio/P_AIO.h ---------------------------------------------------------------------- diff --git a/iocore/aio/P_AIO.h b/iocore/aio/P_AIO.h index d1ce7b2..2e6427a 100644 --- a/iocore/aio/P_AIO.h +++ b/iocore/aio/P_AIO.h @@ -37,27 +37,24 @@ // for debugging // #define AIO_STATS 1 -#undef AIO_MODULE_VERSION -#define AIO_MODULE_VERSION makeModuleVersion(AIO_MODULE_MAJOR_VERSION,\ - AIO_MODULE_MINOR_VERSION,\ - PRIVATE_MODULE_HEADER) +#undef AIO_MODULE_VERSION +#define AIO_MODULE_VERSION makeModuleVersion(AIO_MODULE_MAJOR_VERSION, AIO_MODULE_MINOR_VERSION, PRIVATE_MODULE_HEADER) TS_INLINE int AIOCallback::ok() { - return (off_t) aiocb.aio_nbytes == (off_t) aio_result; + return (off_t)aiocb.aio_nbytes == (off_t)aio_result; } #if AIO_MODE == AIO_MODE_NATIVE extern Continuation *aio_err_callbck; -struct AIOCallbackInternal: public AIOCallback -{ +struct AIOCallbackInternal : public AIOCallback { int io_complete(int event, void *data); AIOCallbackInternal() { - memset ((char *) &(this->aiocb), 0, sizeof(this->aiocb)); + memset((char *)&(this->aiocb), 0, sizeof(this->aiocb)); SET_HANDLER(&AIOCallbackInternal::io_complete); } }; @@ -65,8 +62,8 @@ struct AIOCallbackInternal: public AIOCallback TS_INLINE int AIOCallbackInternal::io_complete(int event, void *data) { - (void) event; - (void) data; + (void)event; + (void)data; if (!ok() && aio_err_callbck) eventProcessor.schedule_imm(aio_err_callbck, ET_CALL, AIO_EVENT_DONE); @@ -78,7 +75,8 @@ AIOCallbackInternal::io_complete(int event, void *data) } TS_INLINE int -AIOVec::mainEvent(int /* event */, Event *) { +AIOVec::mainEvent(int /* event */, Event *) +{ ++completed; if (completed < size) return EVENT_CONT; @@ -97,16 +95,15 @@ AIOVec::mainEvent(int /* event */, Event *) { struct AIO_Reqs; -struct AIOCallbackInternal: public AIOCallback -{ +struct AIOCallbackInternal : public AIOCallback { AIOCallback *first; AIO_Reqs *aio_req; ink_hrtime sleep_time; int io_complete(int event, void *data); AIOCallbackInternal() { - const size_t to_zero = sizeof(AIOCallbackInternal) - (size_t) & (((AIOCallbackInternal *) 0)->aiocb); - memset((char *) &(this->aiocb), 0, to_zero); + const size_t to_zero = sizeof(AIOCallbackInternal) - (size_t) & (((AIOCallbackInternal *)0)->aiocb); + memset((char *)&(this->aiocb), 0, to_zero); SET_HANDLER(&AIOCallbackInternal::io_complete); } }; @@ -114,32 +111,31 @@ struct AIOCallbackInternal: public AIOCallback TS_INLINE int AIOCallbackInternal::io_complete(int event, void *data) { - (void) event; - (void) data; + (void)event; + (void)data; if (!action.cancelled) action.continuation->handleEvent(AIO_EVENT_DONE, this); return EVENT_DONE; } -struct AIO_Reqs -{ - Que(AIOCallback, link) aio_todo; /* queue for holding non-http requests */ - Que(AIOCallback, link) http_aio_todo; /* queue for http requests */ - /* Atomic list to temporarily hold the request if the - lock for a particular queue cannot be acquired */ +struct AIO_Reqs { + Que(AIOCallback, link) aio_todo; /* queue for holding non-http requests */ + Que(AIOCallback, link) http_aio_todo; /* queue for http requests */ + /* Atomic list to temporarily hold the request if the + lock for a particular queue cannot be acquired */ InkAtomicList aio_temp_list; ink_mutex aio_mutex; ink_cond aio_cond; - int index; /* position of this struct in the aio_reqs array */ - volatile int pending; /* number of outstanding requests on the disk */ - volatile int queued; /* total number of aio_todo and http_todo requests */ - volatile int filedes; /* the file descriptor for the requests */ + int index; /* position of this struct in the aio_reqs array */ + volatile int pending; /* number of outstanding requests on the disk */ + volatile int queued; /* total number of aio_todo and http_todo requests */ + volatile int filedes; /* the file descriptor for the requests */ volatile int requests_queued; }; #endif // AIO_MODE == AIO_MODE_NATIVE #ifdef AIO_STATS -class AIOTestData:public Continuation +class AIOTestData : public Continuation { public: int num_req; @@ -149,7 +145,7 @@ public: int ink_aio_stats(int event, void *data); - AIOTestData():Continuation(new_ProxyMutex()), num_req(0), num_temp(0), num_queue(0) + AIOTestData() : Continuation(new_ProxyMutex()), num_req(0), num_temp(0), num_queue(0) { start = ink_get_hrtime(); SET_HANDLER(&AIOTestData::ink_aio_stats); @@ -157,8 +153,7 @@ public: }; #endif -enum aio_stat_enum -{ +enum aio_stat_enum { AIO_STAT_READ_PER_SEC, AIO_STAT_KB_READ_PER_SEC, AIO_STAT_WRITE_PER_SEC, http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/iocore/aio/test_AIO.cc ---------------------------------------------------------------------- diff --git a/iocore/aio/test_AIO.cc b/iocore/aio/test_AIO.cc index c9d7a9c..eb8691f 100644 --- a/iocore/aio/test_AIO.cc +++ b/iocore/aio/test_AIO.cc @@ -66,7 +66,6 @@ reconfigure_diags() // read output routing values for (i = 0; i < DiagsLevel_Count; i++) { - c.outputs[i].to_stdout = 0; c.outputs[i].to_stderr = 1; c.outputs[i].to_syslog = 1; @@ -89,15 +88,14 @@ reconfigure_diags() if (diags->base_action_tags) diags->activate_taglist(diags->base_action_tags, DiagsTagType_Action); - //////////////////////////////////// - // change the diags config values // - //////////////////////////////////// +//////////////////////////////////// +// change the diags config values // +//////////////////////////////////// #if !defined(__GNUC__) && !defined(hpux) diags->config = c; #else - memcpy(((void *) &diags->config), ((void *) &c), sizeof(DiagsConfigState)); + memcpy(((void *)&diags->config), ((void *)&c), sizeof(DiagsConfigState)); #endif - } static void @@ -120,22 +118,26 @@ init_diags(const char *bdt, const char *bat) diags = new Diags(bdt, bat, diags_log_fp); if (diags_log_fp == NULL) { - Warning("couldn't open diags log file '%s', " "will not log to this file", diags_logpath); + Warning("couldn't open diags log file '%s', " + "will not log to this file", + diags_logpath); } Status("opened %s", diags_logpath); reconfigure_diags(); - } #define MAX_DISK_THREADS 200 #ifdef DISK_ALIGN -#define MIN_OFFSET (32*1024) +#define MIN_OFFSET (32 * 1024) #else -#define MIN_OFFSET (8*1024) +#define MIN_OFFSET (8 * 1024) #endif -enum -{ READ_MODE, WRITE_MODE, RANDOM_READ_MODE }; +enum { + READ_MODE, + WRITE_MODE, + RANDOM_READ_MODE, +}; struct AIO_Device; volatile int n_accessors = 0; @@ -170,8 +172,7 @@ int seq_read_size = 0; int seq_write_size = 0; int rand_read_size = 0; -struct AIO_Device:public Continuation -{ +struct AIO_Device : public Continuation { char *path; int fd; int id; @@ -183,14 +184,15 @@ struct AIO_Device:public Continuation int hotset_idx; int mode; AIOCallback *io; - AIO_Device(ProxyMutex * m):Continuation(m) + AIO_Device(ProxyMutex *m) : Continuation(m) { hotset_idx = 0; io = new_AIOCallback(); time_start = 0; SET_HANDLER(&AIO_Device::do_hotset); } - int select_mode(double p) + int + select_mode(double p) { if (p < real_seq_read_percent) return READ_MODE; @@ -199,28 +201,30 @@ struct AIO_Device:public Continuation else return RANDOM_READ_MODE; }; - void do_touch_data(off_t orig_len, off_t orig_offset) + void + do_touch_data(off_t orig_len, off_t orig_offset) { if (!touch_data) return; - unsigned int len = (unsigned int) orig_len; - unsigned int offset = (unsigned int) orig_offset; + unsigned int len = (unsigned int)orig_len; + unsigned int offset = (unsigned int)orig_offset; offset = offset % 1024; char *b = buf; - unsigned *x = (unsigned *) b; + unsigned *x = (unsigned *)b; for (unsigned j = 0; j < (len / sizeof(int)); j++) { x[j] = offset; offset = (offset + 1) % 1024; } }; - int do_check_data(off_t orig_len, off_t orig_offset) + int + do_check_data(off_t orig_len, off_t orig_offset) { if (!touch_data) return 0; - unsigned int len = (unsigned int) orig_len; - unsigned int offset = (unsigned int) orig_offset; + unsigned int len = (unsigned int)orig_len; + unsigned int offset = (unsigned int)orig_offset; offset = offset % 1024; - unsigned *x = (unsigned *) buf; + unsigned *x = (unsigned *)buf; for (unsigned j = 0; j < (len / sizeof(int)); j++) { if (x[j] != offset) return 1; @@ -228,9 +232,8 @@ struct AIO_Device:public Continuation } return 0; } - int do_hotset(int event, Event * e); - int do_fd(int event, Event * e); - + int do_hotset(int event, Event *e); + int do_fd(int event, Event *e); }; void @@ -266,8 +269,8 @@ dump_summary(void) for (int i = 0; i < orig_n_accessors; i++) { double secs = (dev[i]->time_end - dev[i]->time_start) / 1000000000.0; double ops_sec = (dev[i]->seq_reads + dev[i]->seq_writes + dev[i]->rand_reads) / secs; - printf("%s: #sr:%d #sw:%d #rr:%d %0.1f secs %0.1f ops/sec\n", - dev[i]->path, dev[i]->seq_reads, dev[i]->seq_writes, dev[i]->rand_reads, secs, ops_sec); + printf("%s: #sr:%d #sw:%d #rr:%d %0.1f secs %0.1f ops/sec\n", dev[i]->path, dev[i]->seq_reads, dev[i]->seq_writes, + dev[i]->rand_reads, secs, ops_sec); total_secs += secs; total_seq_reads += dev[i]->seq_reads; total_seq_writes += dev[i]->seq_writes; @@ -283,12 +286,12 @@ dump_summary(void) sw /= 1024.0 * 1024.0; float rr = (total_rand_reads * rand_read_size) / total_secs; rr /= 1024.0 * 1024.0; - printf("%f ops %0.2f mbytes/sec %0.1f ops/sec %0.1f ops/sec/disk seq_read\n", - total_seq_reads, sr, total_seq_reads / total_secs, total_seq_reads / total_secs / n_disk_path); - printf("%f ops %0.2f mbytes/sec %0.1f ops/sec %0.1f ops/sec/disk seq_write\n", - total_seq_writes, sw, total_seq_writes / total_secs, total_seq_writes / total_secs / n_disk_path); - printf("%f ops %0.2f mbytes/sec %0.1f ops/sec %0.1f ops/sec/disk rand_read\n", - total_rand_reads, rr, total_rand_reads / total_secs, total_rand_reads / total_secs / n_disk_path); + printf("%f ops %0.2f mbytes/sec %0.1f ops/sec %0.1f ops/sec/disk seq_read\n", total_seq_reads, sr, total_seq_reads / total_secs, + total_seq_reads / total_secs / n_disk_path); + printf("%f ops %0.2f mbytes/sec %0.1f ops/sec %0.1f ops/sec/disk seq_write\n", total_seq_writes, sw, + total_seq_writes / total_secs, total_seq_writes / total_secs / n_disk_path); + printf("%f ops %0.2f mbytes/sec %0.1f ops/sec %0.1f ops/sec/disk rand_read\n", total_rand_reads, rr, + total_rand_reads / total_secs, total_rand_reads / total_secs / n_disk_path); printf("%0.2f total mbytes/sec\n", sr + sw + rr); printf("----------------------------------------------------------\n"); @@ -301,7 +304,7 @@ dump_summary(void) int AIO_Device::do_hotset(int /* event ATS_UNUSED */, Event * /* e ATS_UNUSED */) { - off_t max_offset = ((off_t) disk_size) * 1024 * 1024; + off_t max_offset = ((off_t)disk_size) * 1024 * 1024; io->aiocb.aio_lio_opcode = LIO_WRITE; io->aiocb.aio_fildes = fd; io->aiocb.aio_offset = MIN_OFFSET + hotset_idx * max_size; @@ -310,9 +313,8 @@ AIO_Device::do_hotset(int /* event ATS_UNUSED */, Event * /* e ATS_UNUSED */) if (!hotset_idx) fprintf(stderr, "Starting hotset document writing \n"); if (io->aiocb.aio_offset > max_offset) { - fprintf(stderr, - "Finished hotset documents [%d] offset [%6.0f] size [%6.0f]\n", - hotset_idx, (float) MIN_OFFSET, (float) max_size); + fprintf(stderr, "Finished hotset documents [%d] offset [%6.0f] size [%6.0f]\n", hotset_idx, (float)MIN_OFFSET, + (float)max_size); SET_HANDLER(&AIO_Device::do_fd); eventProcessor.schedule_imm(this); return (0); @@ -341,10 +343,10 @@ AIO_Device::do_fd(int /* event ATS_UNUSED */, Event * /* e ATS_UNUSED */) return 0; } - off_t max_offset = ((off_t) disk_size) * 1024 * 1024; // MB-GB - off_t max_hotset_offset = ((off_t) hotset_size) * 1024 * 1024; // MB-GB - off_t seq_read_point = ((off_t) MIN_OFFSET); - off_t seq_write_point = ((off_t) MIN_OFFSET) + max_offset / 2 + write_after * 1024 * 1024; + off_t max_offset = ((off_t)disk_size) * 1024 * 1024; // MB-GB + off_t max_hotset_offset = ((off_t)hotset_size) * 1024 * 1024; // MB-GB + off_t seq_read_point = ((off_t)MIN_OFFSET); + off_t seq_write_point = ((off_t)MIN_OFFSET) + max_offset / 2 + write_after * 1024 * 1024; seq_write_point += (id % n_disk_path) * (max_offset / (threads_per_disk * 4)); if (seq_write_point > max_offset) seq_write_point = MIN_OFFSET; @@ -352,7 +354,7 @@ AIO_Device::do_fd(int /* event ATS_UNUSED */, Event * /* e ATS_UNUSED */) if (io->aiocb.aio_lio_opcode == LIO_READ) { ink_assert(!do_check_data(io->aiocb.aio_nbytes, io->aiocb.aio_offset)); } - memset((void *) buf, 0, max_size); + memset((void *)buf, 0, max_size); io->aiocb.aio_fildes = fd; io->aiocb.aio_buf = buf; io->action = this; @@ -373,7 +375,7 @@ AIO_Device::do_fd(int /* event ATS_UNUSED */, Event * /* e ATS_UNUSED */) io->aiocb.aio_offset = seq_write_point; io->aiocb.aio_nbytes = seq_write_size; io->aiocb.aio_lio_opcode = LIO_WRITE; - do_touch_data(seq_write_size, ((int) seq_write_point) % 1024); + do_touch_data(seq_write_size, ((int)seq_write_point) % 1024); ink_assert(ink_aio_write(io) >= 0); seq_write_point += seq_write_size; seq_write_point += write_skip; @@ -382,36 +384,36 @@ AIO_Device::do_fd(int /* event ATS_UNUSED */, Event * /* e ATS_UNUSED */) seq_writes++; break; - case RANDOM_READ_MODE:{ - // fprintf(stderr, "random read started \n"); - double p, f; - p = drand48(); - f = drand48(); - off_t o = 0; - if (f < hotset_frequency) - o = (off_t) p *max_hotset_offset; - else - o = (off_t) p *(max_offset - rand_read_size); - if (o < MIN_OFFSET) - o = MIN_OFFSET; - o = (o + (seq_read_size - 1)) & (~(seq_read_size - 1)); - io->aiocb.aio_offset = o; - io->aiocb.aio_nbytes = rand_read_size; - io->aiocb.aio_lio_opcode = LIO_READ; - ink_assert(ink_aio_read(io) >= 0); - rand_reads++; - break; - } + case RANDOM_READ_MODE: { + // fprintf(stderr, "random read started \n"); + double p, f; + p = drand48(); + f = drand48(); + off_t o = 0; + if (f < hotset_frequency) + o = (off_t)p * max_hotset_offset; + else + o = (off_t)p * (max_offset - rand_read_size); + if (o < MIN_OFFSET) + o = MIN_OFFSET; + o = (o + (seq_read_size - 1)) & (~(seq_read_size - 1)); + io->aiocb.aio_offset = o; + io->aiocb.aio_nbytes = rand_read_size; + io->aiocb.aio_lio_opcode = LIO_READ; + ink_assert(ink_aio_read(io) >= 0); + rand_reads++; + break; + } } return 0; } -#define PARAM(_s) \ - else if (strcmp(field_name, #_s) == 0) { \ - fin >> _s; \ - cout << "reading " #_s " = " \ - << _s << endl; \ - } +#define PARAM(_s) \ + else if (strcmp(field_name, #_s) == 0) \ + { \ + fin >> _s; \ + cout << "reading " #_s " = " << _s << endl; \ + } int read_config(const char *config_filename) @@ -433,23 +435,24 @@ read_config(const char *config_filename) if (0) { } PARAM(hotset_size) - PARAM(hotset_frequency) - PARAM(touch_data) - PARAM(use_lseek) - PARAM(write_after) - PARAM(write_skip) - PARAM(disk_size) - PARAM(seq_read_percent) - PARAM(seq_write_percent) - PARAM(rand_read_percent) - PARAM(seq_read_size) - PARAM(seq_write_size) - PARAM(rand_read_size) - PARAM(run_time) - PARAM(chains) - PARAM(threads_per_disk) - PARAM(delete_disks) - else if (strcmp(field_name, "disk_path") == 0) { + PARAM(hotset_frequency) + PARAM(touch_data) + PARAM(use_lseek) + PARAM(write_after) + PARAM(write_skip) + PARAM(disk_size) + PARAM(seq_read_percent) + PARAM(seq_write_percent) + PARAM(rand_read_percent) + PARAM(seq_read_size) + PARAM(seq_write_size) + PARAM(rand_read_size) + PARAM(run_time) + PARAM(chains) + PARAM(threads_per_disk) + PARAM(delete_disks) + else if (strcmp(field_name, "disk_path") == 0) + { assert(n_disk_path < MAX_DISK_THREADS); fin >> field_value; disk_path[n_disk_path] = strdup(field_value); @@ -525,7 +528,7 @@ main(int /* argc ATS_UNUSED */, char *argv[]) perror(disk_path[i]); exit(1); } - dev[n_accessors]->buf = (char *) valloc(max_size); + dev[n_accessors]->buf = (char *)valloc(max_size); eventProcessor.schedule_imm(dev[n_accessors]); n_accessors++; }
