Пример #1
0
static void
transform_destroy(TSCont contp)
{
  TransformData *data;

  data = TSContDataGet(contp);
  if (data != NULL) {
    if (data->input_buf) {
      TSIOBufferDestroy(data->input_buf);
    }

    if (data->output_buf) {
      TSIOBufferDestroy(data->output_buf);
    }

    if (data->pending_action) {
      TSActionCancel(data->pending_action);
    }

    if (data->server_vc) {
      TSVConnAbort(data->server_vc, 1);
    }

    TSfree(data);
  } else {
    TSError("[%s] Unable to get Continuation's Data. TSContDataGet returns NULL", PLUGIN_NAME);
  }

  TSContDestroy(contp);
}
Пример #2
0
/* When the handle is called, the net_vc is returned. */
static int
accept_handler(TSCont contp, TSEvent event, void *edata)
{
  TSCont txn_sm;
  TSMutex pmutex;

  switch (event) {
  case TS_EVENT_NET_ACCEPT:
    /* Create a new mutex for the TxnSM, which is going
       to handle the incoming request. */
    pmutex = (TSMutex)TSMutexCreate();
    txn_sm = (TSCont)TxnSMCreate(pmutex, (TSVConn)edata, server_port);

    /* This is no reason for not grabbing the lock.
       So skip the routine which handle LockTry failure case. */
    TSMutexLockTry(pmutex); // TODO: why should it not check if we got the lock??
    TSContCall(txn_sm, 0, NULL);
    TSMutexUnlock(pmutex);
    break;

  default:
    /* Something wrong with the network, if there are any
       pending NetAccept, cancel them. */
    if (pending_action && !TSActionDone(pending_action))
      TSActionCancel(pending_action);

    TSContDestroy(contp);
    break;
  }

  return TS_EVENT_NONE;
}
Пример #3
0
static void
ts_lua_release_cache_info(ts_lua_cache_info *info, int destroy)
{
    if (info == NULL)
        return;

    if (info->cache_action) {
        TSActionCancel(info->cache_action);
        info->cache_action = NULL;
    }

    if (info->cache_key) {
        TSCacheKeyDestroy(info->cache_key);
        info->cache_key = NULL;
    }

    if (info->cache_vc) {
        TSVConnClose(info->cache_vc);
        info->cache_vc = NULL;
    }

    TS_LUA_RELEASE_IO_HANDLE((&info->ioh));
    TS_LUA_RELEASE_IO_HANDLE((&info->reserved));

    if (destroy) {
        TSfree(info);
    }
}
Пример #4
0
void
ts_http_fetcher_destroy(http_fetcher *fch)
{
    if (fch->action) {
        TSActionCancel(fch->action);
        fch->action = NULL;
    }

    fch->deleted = 1;

    if (fch->ref)
        return;

    ts_http_fetcher_release(fch);
}
Пример #5
0
int
ts_http_fetcher_filter_body(http_fetcher *fch, int ev)
{
    int         ret;
    int64_t     resp_avail, body_avail, wavail, need;

    if (fch->action) {
        TSActionCancel(fch->action);
        fch->action = NULL;
    }

    need = 0;
    resp_avail = TSIOBufferReaderAvail(fch->resp_reader);

    if (ev != BODY_COMPLETE) {

        body_avail = TSIOBufferReaderAvail(fch->body_reader);
        wavail = TS_FETCH_MARK_BODY_HIGH_WATER - body_avail;

        if (wavail <= 0)
            return TS_FETCH_EVENT_BODY_QUIET;

        need = resp_avail > wavail ? wavail : resp_avail;

        TSIOBufferCopy(fch->flow_buffer, fch->resp_reader, need, 0);
        TSIOBufferReaderConsume(fch->resp_reader, need);

        if (TSIOBufferReaderAvail(fch->resp_reader) < TS_FETCH_MARK_RESP_LOW_WATER)
            TSVIOReenable(fch->read_vio);

    } else  {
        TSIOBufferCopy(fch->flow_buffer, fch->resp_reader, resp_avail, 0);
        TSIOBufferReaderConsume(fch->resp_reader, resp_avail);
        need = resp_avail;
    }

    if (fch->chunked) {
        ret = ts_http_fetcher_verify_chunked(fch, ev);

    } else if (fch->resp_cl >= 0) {
        ret = ts_http_fetcher_verify_cl(fch, ev);

    } else {
        ret = ts_http_fetcher_transfer(fch, ev);
    }

    switch (ret) {

        case BODY_READY:
            if (need == 0)
                return TS_FETCH_EVENT_BODY_QUIET;

            return TS_FETCH_EVENT_BODY_READY;

        case BODY_COMPLETE:
            fch->body_done = 1;
            return TS_FETCH_EVENT_BODY_COMPLETE;

        default:
            break;
    }

    fch->error = 1;
    return TS_FETCH_EVENT_ERROR;
}