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

P_UDPConnection.h

Go to the documentation of this file.
00001 /** @file
00002 
00003   A brief file description
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 /****************************************************************************
00025 
00026   P_UDPConnection.h
00027   Internal UDPConnection holds data members and defines member functions
00028 
00029 
00030  ****************************************************************************/
00031 #ifndef __P_UDPCONNECTION_H_
00032 #define __P_UDPCONNECTION_H_
00033 
00034 #include "I_UDPNet.h"
00035 
00036 
00037 class UDPConnectionInternal:public UDPConnection
00038 {
00039 
00040 public:
00041   UDPConnectionInternal();
00042   virtual ~ UDPConnectionInternal();
00043 
00044   Continuation *continuation;
00045   int recvActive;               // interested in receiving
00046   int refcount;               // public for assertion
00047 
00048   SOCKET fd;
00049   IpEndpoint binding;
00050   int binding_valid;
00051   int tobedestroyed;
00052   int sendGenerationNum;
00053   int64_t lastSentPktTSSeqNum;
00054 
00055   // this is for doing packet scheduling: we keep two values so that we can
00056   // implement cancel.  The first value tracks the startTime of the last
00057   // packet that was sent on this connection; the second value tracks the
00058   // startTime of the last packet when we are doing scheduling;  whenever the
00059   // associated continuation cancels a packet, we rest lastPktStartTime to be
00060   // the same as the lastSentPktStartTime.
00061   uint64_t lastSentPktStartTime;
00062   uint64_t lastPktStartTime;
00063 };
00064 
00065 TS_INLINE
00066 UDPConnectionInternal::UDPConnectionInternal()
00067   : continuation(NULL), recvActive(0), refcount(0), fd(-1), binding_valid(0), tobedestroyed(0)
00068 {
00069   sendGenerationNum = 0;
00070   lastSentPktTSSeqNum = -1;
00071   lastSentPktStartTime = 0;
00072   lastPktStartTime = 0;
00073   memset(&binding, 0, sizeof binding);
00074 }
00075 
00076 TS_INLINE
00077 UDPConnectionInternal::~UDPConnectionInternal()
00078 {
00079   continuation = NULL;
00080   mutex = NULL;
00081 }
00082 
00083 
00084 TS_INLINE SOCKET
00085 UDPConnection::getFd()
00086 {
00087   return ((UDPConnectionInternal *) this)->fd;
00088 }
00089 
00090 TS_INLINE void
00091 UDPConnection::setBinding(struct sockaddr const* s)
00092 {
00093   UDPConnectionInternal *p = (UDPConnectionInternal *) this;
00094   ats_ip_copy(&p->binding, s);
00095   p->binding_valid = 1;
00096 }
00097 
00098 TS_INLINE int
00099 UDPConnection::getBinding(struct sockaddr *s)
00100 {
00101   UDPConnectionInternal *p = (UDPConnectionInternal *) this;
00102   ats_ip_copy(s, &p->binding);
00103   return p->binding_valid;
00104 }
00105 
00106 TS_INLINE void
00107 UDPConnection::destroy()
00108 {
00109   ((UDPConnectionInternal *) this)->tobedestroyed = 1;
00110 }
00111 
00112 TS_INLINE int
00113 UDPConnection::shouldDestroy()
00114 {
00115   return ((UDPConnectionInternal *) this)->tobedestroyed;
00116 }
00117 
00118 TS_INLINE void
00119 UDPConnection::AddRef()
00120 {
00121   ink_atomic_increment(&((UDPConnectionInternal *) this)->refcount, 1);
00122 }
00123 
00124 TS_INLINE int
00125 UDPConnection::GetRefCount()
00126 {
00127   return ((UDPConnectionInternal *) this)->refcount;
00128 }
00129 
00130 TS_INLINE int
00131 UDPConnection::GetSendGenerationNumber()
00132 {
00133   return ((UDPConnectionInternal *) this)->sendGenerationNum;
00134 }
00135 
00136 TS_INLINE int
00137 UDPConnection::getPortNum(void)
00138 {
00139   return ats_ip_port_host_order(&static_cast<UDPConnectionInternal *>(this)->binding);
00140 }
00141 
00142 TS_INLINE int64_t
00143 UDPConnection::cancel(void)
00144 {
00145   UDPConnectionInternal *p = (UDPConnectionInternal *) this;
00146 
00147   p->sendGenerationNum++;
00148   p->lastPktStartTime = p->lastSentPktStartTime;
00149   return p->lastSentPktTSSeqNum;
00150 }
00151 
00152 TS_INLINE void
00153 UDPConnection::SetLastSentPktTSSeqNum(int64_t sentSeqNum)
00154 {
00155   ((UDPConnectionInternal *) this)->lastSentPktTSSeqNum = sentSeqNum;
00156 }
00157 
00158 TS_INLINE void
00159 UDPConnection::setContinuation(Continuation * c)
00160 {
00161   // it is not safe to switch among continuations that don't share locks
00162   ink_assert(mutex == NULL || c->mutex == mutex);
00163   mutex = c->mutex;
00164   ((UDPConnectionInternal *) this)->continuation = c;
00165 }
00166 
00167 #endif //__P_UDPCONNECTION_H_

Generated by  doxygen 1.7.1