~ps10gel/ubuntu/xenial/trafficserver/6.2.0

« back to all changes in this revision

Viewing changes to test/plugin/INKContinuations/mod.Sched

  • Committer: Bazaar Package Importer
  • Author(s): Arno Toell
  • Date: 2011-01-13 11:49:18 UTC
  • Revision ID: james.westby@ubuntu.com-20110113114918-vu422h8dknrgkj15
Tags: upstream-2.1.5-unstable
ImportĀ upstreamĀ versionĀ 2.1.5-unstable

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/** @file
 
2
 
 
3
  A brief file description
 
4
 
 
5
  @section license License
 
6
 
 
7
  Licensed to the Apache Software Foundation (ASF) under one
 
8
  or more contributor license agreements.  See the NOTICE file
 
9
  distributed with this work for additional information
 
10
  regarding copyright ownership.  The ASF licenses this file
 
11
  to you under the Apache License, Version 2.0 (the
 
12
  "License"); you may not use this file except in compliance
 
13
  with the License.  You may obtain a copy of the License at
 
14
 
 
15
      http://www.apache.org/licenses/LICENSE-2.0
 
16
 
 
17
  Unless required by applicable law or agreed to in writing, software
 
18
  distributed under the License is distributed on an "AS IS" BASIS,
 
19
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
20
  See the License for the specific language governing permissions and
 
21
  limitations under the License.
 
22
 */
 
23
 
 
24
/**************************************************************************
 
25
Verification of INKqa06643
 
26
 
 
27
Schedule a continuation that is simply called back with a later timeout
 
28
value. Explicitly call TSContSchedule() without a mutex, the mutex should
 
29
be created in InkAPI.cc/TSContSchedule. 
 
30
 
 
31
This plug-in will not complete the client request (request times-out), 
 
32
since the event routine calls TSContSchedule() in the event handler.  
 
33
A simple change to the event routine can be made so that TSHttpTxnReenable() 
 
34
is called in place of TSContSchedule().
 
35
 
 
36
Entry points to the core now use either 
 
37
        FORCE_PLUGIN_MUTEX 
 
38
or
 
39
        new_ProxyMutex() 
 
40
 
 
41
to create/init a mutex. 
 
42
 
 
43
**************************************************************************/
 
44
 
 
45
 
 
46
#include <sys/types.h>
 
47
#include <time.h>
 
48
 
 
49
#include <ts/ts.h> 
 
50
 
 
51
/* Verification code for: TSqa06643 */
 
52
static int
 
53
EventHandler(TSCont contp, TSEvent event, void *eData) 
 
54
{
 
55
        TSHttpTxn txn = (TSHttpTxn)eData; 
 
56
        int iVal; 
 
57
        time_t tVal ;
 
58
 
 
59
        if (time(&tVal) != (time_t)(-1)) {
 
60
                TSDebug("tag_sched6643",
 
61
                        "TSContSchedule: EventHandler: called at %s\n",
 
62
                        ctime(&tVal));
 
63
        }
 
64
 
 
65
        iVal = (int)TSContDataGet(contp);
 
66
 
 
67
        TSDebug("tag_sched6643",
 
68
        "TSContSchedule: handler called with value %d\n",iVal); 
 
69
        
 
70
        switch (event) {
 
71
 
 
72
        case TS_EVENT_HTTP_OS_DNS:
 
73
                TSDebug("tag_sched6643", 
 
74
                "TSContSchedule: Seed event %s\n", "TS_EVENT_HTTP_OS_DNS");
 
75
                break;
 
76
 
 
77
        case TS_EVENT_TIMEOUT:
 
78
                TSDebug("tag_sched6643",
 
79
                "TSContSchedule: TIMEOUT event\n");
 
80
                break;
 
81
 
 
82
        default: 
 
83
                TSDebug("tag_sched6643",
 
84
                "TSContSchedule: Error: default event\n");
 
85
                break;
 
86
        }
 
87
        
 
88
        iVal += 100;     /* seed + timeout val */
 
89
        TSContDataSet(contp, (void*)iVal); 
 
90
        TSContSchedule(contp,iVal); 
 
91
 
 
92
        /* TSHttpTxnReenable(txn, TS_EVENT_HTTP_CONTINUE); */
 
93
}
 
94
 
 
95
static int
 
96
EventHandler2(TSCont contp, TSEvent event, void *eData) 
 
97
{
 
98
}
 
99
 
 
100
void
 
101
TSPluginInit(int argc, const char* argv[])
 
102
{
 
103
        TSCont  contp, contp2;
 
104
        int     timeOut = 10 ;  
 
105
 
 
106
        TSDebug("tag_sched6643",
 
107
        "TSContSchedule: Initial data value for contp is %d\n",timeOut); 
 
108
 
 
109
        /* contp = TSContCreate(EventHandler, TSMutexCreate() ); */
 
110
        mymUtex = TSMutexCreate() ;
 
111
 
 
112
        contp = TSContCreate(EventHandler, myMutex);
 
113
        TSContDataSet(contp, (void*)timeOut); 
 
114
 
 
115
        contp2 = TSContCreate(EventHandler2, myMutex);
 
116
        TSContDataSet(contp2, (void*)contp); 
 
117
 
 
118
        /* TSHttpHookAdd(TS_HTTP_OS_DNS_HOOK, contp); */
 
119
        TSHttpHookAdd(TS_HTTP_OS_DNS_HOOK, contp2);
 
120
}