• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

HttpUpdateTester.cc

Go to the documentation of this file.
00001 /** @file
00002 
00003         Tests http scheduled functionality by requesting URLs out of a file
00004 
00005   @section license License
00006 
00007   Licensed to the Apache Software Foundation (ASF) under one
00008   or more contributor license agreements.  See the NOTICE file
00009   distributed with this work for additional information
00010   regarding copyright ownership.  The ASF licenses this file
00011   to you under the Apache License, Version 2.0 (the
00012   "License"); you may not use this file except in compliance
00013   with the License.  You may obtain a copy of the License at
00014 
00015       http://www.apache.org/licenses/LICENSE-2.0
00016 
00017   Unless required by applicable law or agreed to in writing, software
00018   distributed under the License is distributed on an "AS IS" BASIS,
00019   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00020   See the License for the specific language governing permissions and
00021   limitations under the License.
00022  */
00023 
00024 #include "HttpUpdateSM.h"
00025 #include "HttpDebugNames.h"
00026 #include "Diags.h"
00027 #include "ink_platform.h"
00028 
00029 #define MAX_ACTIVE_REQUESTS 5
00030 #define MAX_TOTAL_REQUESTS 100
00031 
00032 class UpTest:public Continuation
00033 {
00034 public:
00035   UpTest(FILE * f, ProxyMutex * amutex);
00036   int main_handler(int event, void *data);
00037 private:
00038   void make_requests();
00039   int active_req;
00040 #ifdef GO_AWAY
00041   int total_req;
00042   FILE *file;
00043 #endif
00044 };
00045 
00046 UpTest::UpTest(FILE * /* f ATS_UNUSED */, ProxyMutex * amutex)
00047   : Continuation(amutex), active_req(0)
00048 #ifdef GO_AWAY
00049   , total_req(0), file(f)
00050 #endif
00051 {
00052   SET_HANDLER(&UpTest::main_handler);
00053 }
00054 
00055 void
00056 UpTest::make_requests()
00057 {
00058   ink_release_assert(0);
00059   // HDR FIX ME
00060 #ifdef GO_AWAY
00061   while (active_req < MAX_ACTIVE_REQUESTS && file != NULL && total_req < MAX_TOTAL_REQUESTS) {
00062 
00063     char url_buf[2048];
00064     char req_buf[4096];
00065 
00066     if (!fgets(url_buf, 2047, file)) {
00067       Note("[Http Update Tester] url file exhausted");
00068       fclose(file);
00069       file = NULL;
00070       return;
00071     }
00072     url_buf[strlen(url_buf) - 1] = '\0';
00073 
00074     Debug("http_sch", "Firing off request for %s", url_buf);
00075 
00076     sprintf(req_buf, "GET %s HTTP/1.0\r\nCache-Control: max-age=0\r\n\r\n", url_buf);
00077     const char *req = req_buf;
00078 
00079     HTTPHdr test_req;
00080     HTTPParser http_parser;
00081     http_parser_init(&http_parser);
00082     test_req.create();
00083 
00084     test_req.parse_req(&http_parser, &req, req + strlen(req), false);
00085     http_parser_clear(&http_parser);
00086 
00087     HttpUpdateSM *current_reader = HttpUpdateSM::allocate();
00088     current_reader->init();
00089     Action *a = current_reader->start_scheduled_update(this, test_req);
00090     (void) a;
00091 
00092     active_req++;
00093     total_req++;
00094   }
00095 #endif
00096 }
00097 
00098 int
00099 UpTest::main_handler(int event, void * /* data ATS_UNUSED */)
00100 {
00101   Debug("http_sch", "Received Event %s", HttpDebugNames::get_event_name(event));
00102 
00103   if (event != EVENT_NONE && event != VC_EVENT_IMMEDIATE) {
00104     active_req--;
00105   }
00106 
00107   make_requests();
00108 
00109   return EVENT_DONE;
00110 
00111 }
00112 
00113 void
00114 init_http_update_test()
00115 {
00116 
00117   FILE *f = fopen("urls", "r");
00118 
00119   if (f == NULL) {
00120     Warning("[Http Update Tester] could not open URL file");
00121     return;
00122   }
00123 
00124   UpTest *u = new UpTest(f, new_ProxyMutex());
00125   fclose(f); // UpTest doesn't take ownership of f.
00126   eventProcessor.schedule_imm(u);
00127 }

Generated by  doxygen 1.7.1