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_UDPConnection.h 27 UDPConnection interface 28 29 30 ****************************************************************************/ 31 32 #pragma once 33 34 #include "I_EventSystem.h" 35 #define INK_ETHERNET_MTU_SIZE 1472 36 class UDPPacket; 37 /** 38 UDP Connection endpoint 39 40 You can schedule packet to be sent immediately or for the future, 41 and set up a persistent receive() operation. 42 */ 43 44 class UDPConnection : public Continuation 45 { 46 public: ~UDPConnection()47 ~UDPConnection() override{}; 48 49 SOCKET getFd(); 50 void setBinding(struct sockaddr const *); 51 void setBinding(const IpAddr &, in_port_t); 52 inkcoreapi bool getBinding(struct sockaddr *); 53 54 void destroy(); 55 int shouldDestroy(); 56 /** 57 <p> 58 <b>Callbacks:</b><br> 59 cont->handleEvent(NET_EVENT_DATAGRAM_WRITE_ERROR, UDPPacket *) on error 60 <br> 61 no callback on success. 62 63 @return Action* send can't be cancelled via this Action 64 @param c continuation to be called back 65 @param p packet to be sent. 66 */ 67 Action *send(Continuation *c, UDPPacket *p); 68 69 /** 70 <p> 71 <b>Callbacks:</b><br> 72 cont->handleEvent(NET_EVENT_DATAGRAM_ERROR, UDPConnection *) on error 73 <br> 74 cont->handleEvent(NET_EVENT_DATAGRAM_READ_READY, Queue<UDPPacketInternal> *) on incoming packets. 75 76 @return Action* Always returns nullptr. Can't be 77 cancelled via this Action. 78 @param c continuation to be called back 79 */ 80 Action *recv(Continuation *c); 81 82 void Release(); 83 void AddRef(); 84 int GetRefCount(); 85 86 int getPortNum(); 87 88 int GetSendGenerationNumber(); // const 89 void setContinuation(Continuation *c); 90 91 /** 92 Put socket on net queue for read/write polling. 93 94 Not required for UDPConnections created with UDPNetProcessor::UDPBind 95 96 Required for and UDPNetProcessor::CreateUDPSocket. They don't do 97 bindToThread() automatically so that the sockets can be passed to 98 other Continuations. 99 */ 100 void bindToThread(Continuation *c); 101 102 virtual void UDPConnection_is_abstract() = 0; 103 }; 104 105 extern UDPConnection *new_UDPConnection(int fd); 106