~ps10gel/ubuntu/xenial/trafficserver/6.2.0

« back to all changes in this revision

Viewing changes to iocore/net/P_NetAccept.h

  • 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
 
 
26
  NetAccept.h
 
27
 
 
28
 
 
29
   NetAccept is a generalized facility which allows
 
30
   Connections of different classes to be accepted either
 
31
   from a blockable thread or by adaptive polling.
 
32
 
 
33
   It is used by the NetProcessor and the ClusterProcessor
 
34
   and should be considered PRIVATE to processor implementations.
 
35
 
 
36
 
 
37
 
 
38
 ****************************************************************************/
 
39
#ifndef __P_NETACCEPT_H__
 
40
#define __P_NETACCEPT_H__
 
41
 
 
42
#include "libts.h"
 
43
#include "P_Connection.h"
 
44
 
 
45
 
 
46
struct NetAccept;
 
47
class Event;
 
48
//
 
49
// Default accept function
 
50
//   Accepts as many connections as possible, returning the number accepted
 
51
//   or -1 to stop accepting.
 
52
//
 
53
typedef int (AcceptFunction) (NetAccept * na, void *e, bool blockable);
 
54
typedef AcceptFunction *AcceptFunctionPtr;
 
55
AcceptFunction net_accept;
 
56
 
 
57
class UnixNetVConnection;
 
58
 
 
59
// TODO fix race between cancel accept and call back
 
60
struct NetAcceptAction:public Action, public RefCountObj
 
61
{
 
62
  Server *server;
 
63
 
 
64
  void cancel(Continuation * cont = NULL) {
 
65
    Action::cancel(cont);
 
66
    server->close();
 
67
  }
 
68
 
 
69
  Continuation *operator =(Continuation * acont)
 
70
  {
 
71
    return Action::operator=(acont);
 
72
  }
 
73
 
 
74
  ~NetAcceptAction() {
 
75
    Debug("net_accept", "NetAcceptAction dying\n");
 
76
  }
 
77
};
 
78
 
 
79
 
 
80
//
 
81
// NetAccept
 
82
// Handles accepting connections.
 
83
//
 
84
struct NetAccept:public Continuation
 
85
{
 
86
  int port;
 
87
  int domain;
 
88
  ink_hrtime period;
 
89
  Server server;
 
90
  void *alloc_cache;
 
91
  AcceptFunctionPtr accept_fn;
 
92
  int ifd;
 
93
  int ifd_seq_num;
 
94
  bool callback_on_open;
 
95
  Ptr<NetAcceptAction> action_;
 
96
  int recv_bufsize;
 
97
  int send_bufsize;
 
98
  uint32_t sockopt_flags;
 
99
  EventType etype;
 
100
  UnixNetVConnection *epoll_vc; // only storage for epoll events
 
101
  EventIO ep;
 
102
 
 
103
  // Functions all THREAD_FREE and THREAD_ALLOC to be performed
 
104
  // for both SSL and regular NetVConnection transparent to
 
105
  // accept functions.
 
106
  virtual UnixNetVConnection *allocateThread(EThread *t);
 
107
  virtual void freeThread(UnixNetVConnection *vc, EThread *t);
 
108
  virtual UnixNetVConnection *allocateGlobal();
 
109
  virtual EventType getEtype();
 
110
 
 
111
  void init_accept_loop();
 
112
  virtual void init_accept(EThread * t = NULL);
 
113
  virtual void init_accept_per_thread();
 
114
  // 0 == success
 
115
  int do_listen(bool non_blocking);
 
116
 
 
117
  int do_blocking_accept(NetAccept * master_na, EThread * t);
 
118
  virtual int acceptEvent(int event, void *e);
 
119
  virtual int acceptFastEvent(int event, void *e);
 
120
  int acceptLoopEvent(int event, Event * e);
 
121
  void cancel();
 
122
 
 
123
  NetAccept();
 
124
  virtual ~ NetAccept()
 
125
  {
 
126
    action_ = NULL;
 
127
  };
 
128
};
 
129
 
 
130
 
 
131
#endif