~ps10gel/ubuntu/xenial/trafficserver/6.2.0

« back to all changes in this revision

Viewing changes to iocore/net/I_UDPNet.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
  I_UDPNet.h
 
27
  This file provides UDP interface. To be included in I_Net.h
 
28
 
 
29
 
 
30
 ****************************************************************************/
 
31
 
 
32
#ifndef __UDPNET_H_
 
33
#define __UDPNET_H_
 
34
 
 
35
#include "I_Version.h"
 
36
#include "I_EventSystem.h"
 
37
/**
 
38
   UDP service
 
39
 
 
40
   You can create UDPConnections for asynchronous send/receive or call
 
41
   directly (inefficiently) into network layer.
 
42
 */
 
43
class UDPNetProcessor:public Processor
 
44
{
 
45
public:
 
46
  virtual int start(int n_upd_threads) = 0;
 
47
 
 
48
  //this function was interanal intially.. this is required for public and
 
49
  //interface probably should change.
 
50
  bool CreateUDPSocket(int *resfd, struct sockaddr_in *addr,
 
51
                       Action ** status,
 
52
                       int my_port, unsigned int my_ip = 0, int send_bufsize = 0, int recv_bufsize = 0);
 
53
 
 
54
  /**
 
55
     create UDPConnection
 
56
 
 
57
     Why was this implemented as an asynchronous call?  Just in case
 
58
     Windows requires it...
 
59
     <p>
 
60
     <b>Callbacks:</b><br>
 
61
     cont->handleEvent( NET_EVENT_DATAGRAM_OPEN, UDPConnection *) is
 
62
     called for new socket.
 
63
 
 
64
     @param c Continuation that is called back with newly created
 
65
     socket.
 
66
     @param my_port Local port to be bound (required)
 
67
     @param my_ip Local IP to be bound (optional).  Defaults to '0' (INADDR_ANY)
 
68
     @param send_bufsize (optional) Socket buffer size for sending.
 
69
     Limits how much outstanding data to OS before it is able to send
 
70
     to the NIC.
 
71
     @param recv_bufsize (optional) Socket buffer size for sending.
 
72
     Limits how much can be queued by OS before we read it.
 
73
     @return Action* Always returns ACTION_RESULT_DONE if socket was
 
74
     created successfuly, or ACTION_IO_ERROR if not.
 
75
  */
 
76
  inkcoreapi Action *UDPBind(Continuation * c, int my_port, int my_ip = 0, int send_bufsize = 0, int recv_bufsize = 0);
 
77
 
 
78
  // The mess again: the complier won't let me stick UDPConnection here.
 
79
  void UDPClassifyConnection(Continuation * udpConn, int destIP);
 
80
 
 
81
  // create pairs of UDPConnections in which the first connection is
 
82
  // on a even-#'ed port and the second connection is on the next
 
83
  // odd-#'ed port.  Create "nPairs" of such connections.
 
84
  Action *UDPCreatePortPairs(Continuation *, int nPairs,
 
85
                             unsigned int myIP = 0,
 
86
                             unsigned int destIP = 0, int send_bufsize = 0, int recv_bufsize = 0);
 
87
 
 
88
  // Regarding sendto_re, sendmsg_re, recvfrom_re:
 
89
  // * You may be called back on 'c' with completion or error status.
 
90
  // * 'token' is an opaque which can be used by caller to match up the I/O
 
91
  //   with the completion event.
 
92
  // * If IOBufferBlock * is passed in the interface, it is reference
 
93
  //   counted internally.
 
94
  // * For recvfrom_re, data is written beginning at IOBufferBlock::end() and
 
95
  //   the IOBufferBlock is not fill()'ed until I/O actually occurs.  This
 
96
  //   kind of implies that you can only have one outstanding I/O per
 
97
  //   IOBufferBlock
 
98
  // Callback:
 
99
  // * callback signature is: handleEvent(int event,CompletionEvent *cevent);
 
100
  //   where event is one of:
 
101
  //  NET_EVENT_DATAGRAM_WRITE_COMPLETE
 
102
  //  NET_EVENT_DATAGRAM_WRITE_ERROR
 
103
  // * You can get the value of 'token' that you passed in by calling
 
104
  //   completionUtil::getHandle(cevent);
 
105
  // * You can get other info about the completed operation through use
 
106
  //   of the completionUtil class.
 
107
  Action *sendto_re(Continuation * c, void *token, int fd,
 
108
                    struct sockaddr *toaddr, int toaddrlen, IOBufferBlock * buf, int len);
 
109
  // I/O buffers referenced by msg must be pinned by the caller until
 
110
  // continuation is called back.
 
111
  Action *sendmsg_re(Continuation * c, void *token, int fd, struct msghdr *msg);
 
112
 
 
113
  Action *recvfrom_re(Continuation * c, void *token, int fd,
 
114
                      struct sockaddr *fromaddr, socklen_t *fromaddrlen,
 
115
                      IOBufferBlock * buf, int len, bool useReadCont = true, int timeout = 0);
 
116
  // Continuation is really a UDPConnection; due to the include mess, we stick in the
 
117
  // base-class of UDPConnection.
 
118
  bool AllocBandwidth(Continuation * udpConn, double desiredMbps);
 
119
  bool ChangeBandwidth(Continuation * udpConn, double desiredMbps);
 
120
  void FreeBandwidth(Continuation * udpConn);
 
121
  double GetAvailableBandwidth();
 
122
 
 
123
  virtual void UDPNetProcessor_is_abstract() = 0;
 
124
 
 
125
};
 
126
 
 
127
inkcoreapi extern UDPNetProcessor & udpNet;
 
128
 
 
129
#include "I_UDPPacket.h"
 
130
#include "I_UDPConnection.h"
 
131
 
 
132
#endif //__UDPNET_H_