本文整理汇总了C++中TSContCreate函数的典型用法代码示例。如果您正苦于以下问题:C++ TSContCreate函数的具体用法?C++ TSContCreate怎么用?C++ TSContCreate使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了TSContCreate函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TSPluginInit
void TSPluginInit(int argc, const char *argv[]) {
TSPluginRegistrationInfo info;
TSCont main_cont, config_cont;
config_holder_t *config_holder;
info.plugin_name = PLUGIN_TAG;
info.vendor_name = "Comcast";
info.support_email = "[email protected]";
astatsLoad = time(NULL);
if (TSPluginRegister(TS_SDK_VERSION_2_0, &info) != TS_SUCCESS)
TSError("Plugin registration failed. \n");
if (!check_ts_version()) {
TSError("Plugin requires Traffic Server 2.0 or later\n");
return;
}
config_holder = new_config_holder(argc > 1 ? argv[1] : NULL);
main_cont = TSContCreate(astats_origin, NULL);
TSContDataSet(main_cont, (void *) config_holder);
TSHttpHookAdd(TS_HTTP_READ_REQUEST_HDR_HOOK, main_cont);
config_cont = TSContCreate(config_handler, TSMutexCreate());
TSContDataSet(config_cont, (void *) config_holder);
TSMgmtUpdateRegister(config_cont, PLUGIN_TAG);
/* Create a continuation with a mutex as there is a shared global structure
containing the headers to add */
TSDebug(PLUGIN_TAG, "astats module registered, path: '%s'", config_holder->config->stats_path);
}
示例2: TSPluginInit
void
TSPluginInit(int argc, const char *argv[])
{
int i;
TSPluginRegistrationInfo info;
info.plugin_name = "blacklist-0";
info.vendor_name = "MyCompany";
info.support_email = "[email protected]";
if (TSPluginRegister(&info) != TS_SUCCESS) {
TSError("[blacklist-0] Plugin registration failed.");
}
nsites = argc - 1;
if (nsites > 0) {
sites = (char **)TSmalloc(sizeof(char *) * nsites);
for (i = 0; i < nsites; i++) {
sites[i] = TSstrdup(argv[i + 1]);
}
TSHttpHookAdd(TS_HTTP_OS_DNS_HOOK, TSContCreate(blacklist_plugin, NULL));
}
}
示例3: TSRemapDoRemap
TSRemapStatus
TSRemapDoRemap(void* ih, TSHttpTxn rh, TSRemapRequestInfo *rri)
{
int ret;
uint64_t req_id;
TSCont contp;
lua_State *L;
ts_lua_main_ctx *main_ctx;
ts_lua_http_ctx *http_ctx;
ts_lua_cont_info *ci;
ts_lua_instance_conf *instance_conf;
instance_conf = (ts_lua_instance_conf*)ih;
req_id = __sync_fetch_and_add(&ts_lua_http_next_id, 1);
main_ctx = &ts_lua_main_ctx_array[req_id%TS_LUA_MAX_STATE_COUNT];
TSMutexLock(main_ctx->mutexp);
http_ctx = ts_lua_create_http_ctx(main_ctx, instance_conf);
http_ctx->txnp = rh;
http_ctx->client_request_bufp = rri->requestBufp;
http_ctx->client_request_hdrp = rri->requestHdrp;
http_ctx->client_request_url = rri->requestUrl;
http_ctx->rri = rri;
ci = &http_ctx->cinfo;
L = ci->routine.lua;
contp = TSContCreate(ts_lua_http_cont_handler, NULL);
TSContDataSet(contp, http_ctx);
ci->contp = contp;
ci->mutex = TSContMutexGet((TSCont)rh);
// push do_remap function on the stack, and no async operation should exist here.
lua_getglobal(L, TS_LUA_FUNCTION_REMAP);
if (lua_pcall(L, 0, 1, 0) != 0) {
ee("lua_pcall failed: %s", lua_tostring(L, -1));
ret = TSREMAP_NO_REMAP;
} else {
ret = lua_tointeger(L, -1);
}
lua_pop(L, 1); // pop the result
if (http_ctx->hooks > 0) {
TSMutexUnlock(main_ctx->mutexp);
TSHttpTxnHookAdd(rh, TS_HTTP_TXN_CLOSE_HOOK, contp);
} else {
ts_lua_destroy_http_ctx(http_ctx);
TSMutexUnlock(main_ctx->mutexp);
}
return ret;
}
示例4: ts_lua_http_server_intercept
static int
ts_lua_http_server_intercept(lua_State *L)
{
TSCont contp;
int type;
ts_lua_http_ctx *http_ctx;
http_ctx = ts_lua_get_http_ctx(L);
http_ctx->has_hook = 1;
type = lua_type(L, 1);
if (type != LUA_TFUNCTION) {
TSError("[%s] param in ts.http.server_intercept should be a function", __FUNCTION__);
return 0;
}
lua_pushvalue(L, 1);
lua_setglobal(L, TS_LUA_FUNCTION_HTTP_SERVER_INTERCEPT);
http_ctx->intercept_type = TS_LUA_TYPE_HTTP_SERVER_INTERCEPT;
contp = TSContCreate(ts_lua_http_intercept_entry, TSMutexCreate());
TSContDataSet(contp, http_ctx);
TSHttpTxnServerIntercept(contp, http_ctx->txnp);
return 0;
}
示例5: ts_http_fetcher_launch
void
ts_http_fetcher_launch(http_fetcher *fch)
{
int64_t hdr_len;
// post body , content-length
TSIOBufferWrite(fch->req_buffer, "\r\n", sizeof("\r\n")-1);
hdr_len = TSIOBufferReaderAvail(fch->req_reader);
fch->http_vc = TSHttpConnect(&(fch->aip));
fch->hdr_buffer = TSIOBufferSizedCreate(TS_IOBUFFER_SIZE_INDEX_8K);
fch->hdr_reader = TSIOBufferReaderAlloc(fch->hdr_buffer);
fch->hdr_bufp = TSMBufferCreate();
fch->hdr_loc = TSHttpHdrCreate(fch->hdr_bufp);
fch->resp_buffer = TSIOBufferCreate();
fch->resp_reader = TSIOBufferReaderAlloc(fch->resp_buffer);
fch->http_parser = TSHttpParserCreate();
fch->fetch_contp = TSContCreate(ts_http_fetch_handler, fch->mutexp);
TSContDataSet(fch->fetch_contp, fch);
fch->read_vio = TSVConnRead(fch->http_vc, fch->fetch_contp, fch->resp_buffer, INT64_MAX);
if (fch->method == TS_FETCH_METHOD_POST && fch->post_cl >= 0) {
fch->write_vio = TSVConnWrite(fch->http_vc, fch->fetch_contp, fch->req_reader, hdr_len + fch->post_cl);
} else {
fch->write_vio = TSVConnWrite(fch->http_vc, fch->fetch_contp, fch->req_reader, hdr_len);
}
fch->launched = 1;
}
示例6: protocol_init
static void
protocol_init(int accept_port, int server_port ATS_UNUSED)
{
TSCont contp;
int ret_val;
/* create customized log */
ret_val = TSTextLogObjectCreate("protocol", TS_LOG_MODE_ADD_TIMESTAMP, &protocol_plugin_log);
if (ret_val != TS_SUCCESS) {
TSError("[protocol] Failed to create log");
}
/* format of the log entries, for caching_status, 1 for HIT and 0 for MISS */
ret_val = TSTextLogObjectWrite(protocol_plugin_log, "timestamp filename servername caching_status\n\n");
if (ret_val != TS_SUCCESS) {
TSError("[protocol] Failed to write into log");
}
contp = TSContCreate(accept_handler, TSMutexCreate());
/* Accept network traffic from the accept_port.
When there are requests coming in, contp's handler
should be called, in this case, contp's handler
is accept_event, see AcceptSM.c */
pending_action = TSNetAccept(contp, accept_port, -1, 1);
}
示例7: ironbee_plugin_ssn_start
static void ironbee_plugin_ssn_start(TSCont contp, TSHttpSsn ssnp)
{
assert(contp != NULL);
assert(ssnp != NULL);
TSCont mycont;
tsib_ssn_ctx *ssndata;
/* start of connection */
/* But we can't initialize conn stuff here, because there's
* no API to get the connection stuff required by ironbee
* at this point. So instead, intercept the first TXN
*
* what we can and must do: create a new contp whose
* lifetime is our ssn
*/
mycont = TSContCreate(ironbee_plugin, NULL);
TSHttpSsnHookAdd (ssnp, TS_HTTP_TXN_START_HOOK, mycont);
ssndata = TSmalloc(sizeof(*ssndata));
memset(ssndata, 0, sizeof(*ssndata));
ssndata->contp = mycont;
TSContDataSet(mycont, ssndata);
TSHttpSsnHookAdd (ssnp, TS_HTTP_SSN_CLOSE_HOOK, mycont);
TSHttpSsnReenable (ssnp, TS_EVENT_HTTP_CONTINUE);
}
示例8: TSPluginInit
void
TSPluginInit(int argc, const char *argv[])
{
TSPluginRegistrationInfo info;
info.plugin_name = "null-transform";
info.vendor_name = "MyCompany";
info.support_email = "[email protected]";
if (TSPluginRegister(TS_SDK_VERSION_3_0, &info) != TS_SUCCESS) {
TSError("[null-transform] Plugin registration failed.\n");
goto Lerror;
}
if (!check_ts_version()) {
TSError("[null-transform] Plugin requires Traffic Server 3.0 " "or later\n");
goto Lerror;
}
TSHttpHookAdd(TS_HTTP_READ_RESPONSE_HDR_HOOK, TSContCreate(transform_plugin, NULL));
return;
Lerror:
TSError("[null-tranform] Unable to initialize plugin (disabled).\n");
}
示例9: TSPluginInit
void
TSPluginInit(int argc, const char *argv[])
{
TSPluginRegistrationInfo info;
TSCont cont;
info.plugin_name = "server-transform";
info.vendor_name = "MyCompany";
info.support_email = "[email protected]";
if (TSPluginRegister(TS_SDK_VERSION_3_0, &info) != TS_SUCCESS) {
TSError("Plugin registration failed.\n");
}
if (!check_ts_version()) {
TSError("Plugin requires Traffic Server 3.0 or later\n");
return;
}
/* connect to the echo port on localhost */
server_ip = (127 << 24) | (0 << 16) | (0 << 8) | (1);
server_ip = htonl(server_ip);
server_port = 7;
cont = TSContCreate(transform_plugin, NULL);
TSHttpHookAdd(TS_HTTP_READ_REQUEST_HDR_HOOK, cont);
}
示例10: TSPluginInit
void
TSPluginInit(int argc, const char *argv[])
{
const char prefix[] = "http://";
int uri_len;
TSPluginRegistrationInfo info;
info.plugin_name = "redirect-1";
info.vendor_name = "MyCompany";
info.support_email = "[email protected]";
if (TSPluginRegister(TS_SDK_VERSION_3_0, &info) != TS_SUCCESS) {
TSError("Plugin registration failed.\n");
}
if (!check_ts_version()) {
TSError("Plugin requires Traffic Server 3.0 or later\n");
return;
}
if (argc == 3) {
block_ip = TSstrdup(argv[1]);
/*
* The Location header must contain an absolute URI:
*/
url_redirect = TSstrdup(argv[2]);
uri_len = strlen(prefix) + strlen(url_redirect) + 1;
uri_redirect = TSmalloc(uri_len);
TSstrlcpy(uri_redirect, prefix, uri_len);
TSstrlcat(uri_redirect, url_redirect, uri_len);
} else {
TSError("Incorrect syntax in plugin.conf: correct usage is" "redirect-1.so ip_deny url_redirect");
return;
}
ip_deny = inet_addr(block_ip);
TSDebug("redirect_init", "initializing stats...");
init_stats();
TSHttpHookAdd(TS_HTTP_READ_REQUEST_HDR_HOOK, TSContCreate(redirect_plugin, NULL));
TSDebug("redirect_init", "block_ip is %s, url_redirect is %s, and uri_redirect is %s",
block_ip, url_redirect, uri_redirect);
// ToDo: Should figure out how to print IPs which are IPv4 / v6.
// TSDebug("redirect_init", "ip_deny is %ld\n", ip_deny);
/*
* Demonstrate another tracing function. This can be used to
* enable debug calculations and other work that should only
* be done in debug mode.
*/
if (TSIsDebugTagSet("redirect_demo"))
TSDebug("redirect_init", "The redirect_demo tag is set");
else
TSDebug("redirect_init", "The redirect_demo tag is not set");
}
示例11: ts_lua_sleep
static int
ts_lua_sleep(lua_State *L)
{
int sec;
TSAction action;
TSCont contp;
ts_lua_async_item *ai;
ts_lua_cont_info *ci;
ci = ts_lua_get_cont_info(L);
if (ci == NULL)
return 0;
sec = luaL_checknumber(L, 1);
if (sec < 1) {
sec = 1;
}
contp = TSContCreate(ts_lua_sleep_handler, ci->mutex);
action = TSContSchedule(contp, sec * 1000, TS_THREAD_POOL_DEFAULT);
ai = ts_lua_async_create_item(contp, ts_lua_sleep_cleanup, (void *)action, ci);
TSContDataSet(contp, ai);
return lua_yield(L, 0);
}
示例12: TSPluginInit
void
TSPluginInit(int argc, const char *argv[])
{
TSPluginRegistrationInfo info;
TSMutex mutex = TS_NULL_MUTEX;
info.plugin_name = "buffered-null-transform";
info.vendor_name = "MyCompany";
info.support_email = "[email protected]";
if (TSPluginRegister(TS_SDK_VERSION_3_0, &info) != TS_SUCCESS) {
TSError("[bnull-transform] Plugin registration failed.\n");
goto Lerror;
}
if (!check_ts_version()) {
TSError("[bnull-transform] Plugin requires Traffic Server 3.0" " or later\n");
goto Lerror;
}
/* This is call we could use if we need to protect global data */
/* TSReleaseAssert ((mutex = TSMutexCreate()) != TS_NULL_MUTEX); */
TSHttpHookAdd(TS_HTTP_READ_RESPONSE_HDR_HOOK, TSContCreate(transform_plugin, mutex));
return;
Lerror:
TSError("[bnull-transform] Plugin disabled\n");
}
示例13: TSPluginInit
void
TSPluginInit(int argc, const char *argv[])
{
TSCont contp;
TSPluginRegistrationInfo info;
info.plugin_name = "session-1";
info.vendor_name = "MyCompany";
info.support_email = "[email protected]";
if (TSPluginRegister(&info) != TS_SUCCESS) {
TSError("[session-1] Plugin registration failed.\n");
goto error;
}
transaction_count = INKStatCreate("transaction.count", INKSTAT_TYPE_INT64);
session_count = INKStatCreate("session.count", INKSTAT_TYPE_INT64);
av_transaction = INKStatCreate("avg.transactions", INKSTAT_TYPE_FLOAT);
contp = TSContCreate(ssn_handler, NULL);
TSHttpHookAdd(TS_HTTP_SSN_START_HOOK, contp);
error:
TSError("[session-1] Plugin not initialized");
}
示例14: tsib_pre_init
/** Create and return top-level cont with no transient data
* Sets up engine manager and kill-or-continue txn hook before launching
* potentially-slow mainconfiguration in separate thread.
*/
static ib_status_t tsib_pre_init(TSCont *contp)
{
int rv;
ib_status_t rc;
TSCont cont;
assert(contp != NULL);
/* create a cont to fend off traffic while we read config */
*contp = cont = TSContCreate(ironbee_plugin, NULL);
if (cont == NULL) {
TSError("[ironbee] failed to create initial continuation: disabled");
return IB_EUNKNOWN;
}
if (module_data.allow_at_startup) {
/* SSN_START doesn't use contdata; READ_REQUEST_HDR only needs non-null flag.
* Using &module_data might let us clean up some tsib_api stuff in future.
*/
TSContDataSet(cont, &module_data);
}
else {
/* NULL contdata signals the READ_REQUEST_HDR hook to reject requests */
TSContDataSet(cont, NULL);
}
TSHttpHookAdd(TS_HTTP_READ_REQUEST_HDR_HOOK, cont);
if (!module_data.log_disable) {
/* success is documented as TS_LOG_ERROR_NO_ERROR but that's undefined.
* It's actually a TS_SUCCESS (proxy/InkAPI.cc line 6641).
*/
printf("Logging to \"%s\"\n", module_data.log_file);
rv = TSTextLogObjectCreate(module_data.log_file,
TS_LOG_MODE_ADD_TIMESTAMP,
&module_data.logger);
if (rv != TS_SUCCESS) {
TSError("[ironbee] Error creating log file.");
return IB_EUNKNOWN;
}
}
/* Initialize IronBee (including util) */
rc = ib_initialize();
if (rc != IB_OK) {
TSError("[ironbee] Error initializing IronBee: %s",
ib_status_to_string(rc));
return rc;
}
/* Create the IronBee engine manager */
TSDebug("ironbee", "Creating IronBee engine manager");
rc = ib_manager_create(&(module_data.manager), /* Engine Manager */
&ibplugin, /* Server object */
module_data.max_engines); /* Default max */
if (rc != IB_OK) {
TSError("[ironbee] Error creating IronBee engine manager: %s",
ib_status_to_string(rc));
}
return rc;
}
示例15: TxnSMCreate
/* Create the Txn data structure and the continuation for the Txn. */
TSCont
TxnSMCreate(TSMutex pmutex, TSVConn client_vc, int server_port)
{
TSCont contp;
TxnSM *txn_sm;
txn_sm = (TxnSM *)TSmalloc(sizeof(TxnSM));
txn_sm->q_mutex = pmutex;
txn_sm->q_pending_action = NULL;
/* Txn will use this server port to connect to the origin server. */
txn_sm->q_server_port = server_port;
/* The client_vc is returned by TSNetAccept, refer to Protocol.c. */
txn_sm->q_client_vc = client_vc;
/* The server_vc will be created if Txn connects to the origin server. */
txn_sm->q_server_vc = NULL;
txn_sm->q_client_read_vio = NULL;
txn_sm->q_client_write_vio = NULL;
txn_sm->q_client_request_buffer = NULL;
txn_sm->q_client_response_buffer = NULL;
txn_sm->q_client_request_buffer_reader = NULL;
txn_sm->q_client_response_buffer_reader = NULL;
txn_sm->q_server_read_vio = NULL;
txn_sm->q_server_write_vio = NULL;
txn_sm->q_server_request_buffer = NULL;
txn_sm->q_server_response_buffer = NULL;
txn_sm->q_server_request_buffer_reader = NULL;
/* Char buffers to store client request and server response. */
txn_sm->q_client_request = (char *)TSmalloc(sizeof(char) * (MAX_REQUEST_LENGTH + 1));
memset(txn_sm->q_client_request, '\0', (sizeof(char) * (MAX_REQUEST_LENGTH + 1)));
txn_sm->q_server_response = NULL;
txn_sm->q_server_response_length = 0;
txn_sm->q_block_bytes_read = 0;
txn_sm->q_cache_vc = NULL;
txn_sm->q_cache_response_length = 0;
txn_sm->q_cache_read_buffer = NULL;
txn_sm->q_cache_read_buffer_reader = NULL;
txn_sm->q_server_name = (char *)TSmalloc(sizeof(char) * (MAX_SERVER_NAME_LENGTH + 1));
txn_sm->q_file_name = (char *)TSmalloc(sizeof(char) * (MAX_FILE_NAME_LENGTH + 1));
txn_sm->q_key = NULL;
txn_sm->q_magic = TXN_SM_ALIVE;
/* Set the current handler to be state_start. */
set_handler(txn_sm->q_current_handler, &state_start);
contp = TSContCreate(main_handler, txn_sm->q_mutex);
TSContDataSet(contp, txn_sm);
return contp;
}