~ps10gel/ubuntu/xenial/trafficserver/6.2.0

« back to all changes in this revision

Viewing changes to iocore/net/test_P_Net.cc

  • 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
#include "P_Net.h"
 
25
 
 
26
Diags *diags;
 
27
struct NetTesterSM:public Continuation
 
28
{
 
29
  VIO *read_vio;
 
30
  IOBufferReader *reader;
 
31
  NetVConnection *vc;
 
32
  MIOBuffer *buf;
 
33
 
 
34
    NetTesterSM(ProxyMutex * _mutex, NetVConnection * _vc):Continuation(_mutex)
 
35
  {
 
36
    MUTEX_TRY_LOCK(lock, mutex, _vc->thread);
 
37
    ink_release_assert(lock);
 
38
    vc = _vc;
 
39
    SET_HANDLER(&NetTesterSM::handle_read);
 
40
    buf = new_MIOBuffer(8);
 
41
    reader = buf->alloc_reader();
 
42
    read_vio = vc->do_io_read(this, INT64_MAX, buf);
 
43
  }
 
44
 
 
45
 
 
46
  int handle_read(int event, void *data)
 
47
  {
 
48
    int r;
 
49
    char *str;
 
50
    switch (event) {
 
51
    case VC_EVENT_READ_READY:
 
52
      r = reader->read_avail();
 
53
      str = NEW(new char[r + 10]);
 
54
      reader->read(str, r);
 
55
      printf("%s", str);
 
56
      fflush(stdout);
 
57
      break;
 
58
    case VC_EVENT_READ_COMPLETE:
 
59
      /* FALLSTHROUGH */
 
60
    case VC_EVENT_EOS:
 
61
      r = reader->read_avail();
 
62
      str = NEW(new char[r + 10]);
 
63
      reader->read(str, r);
 
64
      printf("%s", str);
 
65
      fflush(stdout);
 
66
    case VC_EVENT_ERROR:
 
67
      vc->do_io_close();
 
68
      break;
 
69
    default:
 
70
      ink_release_assert(!"unknown event");
 
71
 
 
72
    }
 
73
    return EVENT_CONT;
 
74
  }
 
75
 
 
76
 
 
77
};
 
78
 
 
79
 
 
80
struct NetTesterAccept:public Continuation
 
81
{
 
82
 
 
83
  NetTesterAccept(ProxyMutex * _mutex):Continuation(_mutex)
 
84
  {
 
85
    SET_HANDLER(&NetTesterAccept::handle_accept);
 
86
  }
 
87
 
 
88
  int handle_accept(int event, void *data)
 
89
  {
 
90
    printf("Accepted a connection\n");
 
91
    fflush(stdout);
 
92
    NetVConnection *vc = (NetVConnection *) data;
 
93
    NEW(new NetTesterSM(new_ProxyMutex(), vc));
 
94
    return EVENT_CONT;
 
95
  }
 
96
 
 
97
 
 
98
};
 
99
 
 
100
 
 
101
 
 
102
 
 
103
int
 
104
main()
 
105
{
 
106
  ink_event_system_init(EVENT_SYSTEM_MODULE_VERSION);
 
107
  MIOBuffer *mbuf = new_MIOBuffer(5);
 
108
  eventProcessor.start(1);
 
109
  netProcessor.start();
 
110
  netProcessor.accept(NEW(new NetTesterAccept(new_ProxyMutex())), 8080, true);
 
111
  this_thread()->execute();
 
112
}