1 /** @file 2 3 Net subsystem 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 @section details Details 24 25 Net subsystem is a layer on top the operations system network apis. It 26 provides an interface for accepting/creating new connection oriented 27 (TCP) and connection less (UDP) connections and for reading/writing 28 data through these. The net system can manage 1000s of connections 29 very efficiently. Another advantage of using the net system is that 30 the SMs dont have be concerned about differences in the net apis of 31 various operations systems. 32 33 SMs use the netProcessor global object of the Net System to create new 34 connections or to accept incoming connections. When a new connection 35 is created the SM gets a NetVConnection which is a handle for the 36 underlying connections. The SM can then use the NetVConnection to get 37 properties of the connection, read and write data. Net system also 38 has socks and ssl support. 39 40 */ 41 #pragma once 42 43 #include "tscore/I_Version.h" 44 #include "I_EventSystem.h" 45 #include <netinet/in.h> 46 47 #ifndef UIO_MAXIOV 48 #define NET_MAX_IOV 16 // UIO_MAXIOV shall be at least 16 1003.1g (5.4.1.1) 49 #else 50 #define NET_MAX_IOV UIO_MAXIOV 51 #endif 52 53 static constexpr ts::ModuleVersion NET_SYSTEM_MODULE_PUBLIC_VERSION(1, 0, ts::ModuleVersion::PUBLIC); 54 55 static constexpr int NO_FD = -1; 56 57 // All in milli-seconds 58 extern int net_config_poll_timeout; 59 extern int net_event_period; 60 extern int net_accept_period; 61 extern int net_retry_delay; 62 extern int net_throttle_delay; 63 64 extern std::string_view net_ccp_in; 65 extern std::string_view net_ccp_out; 66 67 #define NET_EVENT_OPEN (NET_EVENT_EVENTS_START) 68 #define NET_EVENT_OPEN_FAILED (NET_EVENT_EVENTS_START + 1) 69 #define NET_EVENT_ACCEPT (NET_EVENT_EVENTS_START + 2) 70 #define NET_EVENT_ACCEPT_SUCCEED (NET_EVENT_EVENTS_START + 3) 71 #define NET_EVENT_ACCEPT_FAILED (NET_EVENT_EVENTS_START + 4) 72 #define NET_EVENT_CANCEL (NET_EVENT_EVENTS_START + 5) 73 #define NET_EVENT_DATAGRAM_READ_COMPLETE (NET_EVENT_EVENTS_START + 6) 74 #define NET_EVENT_DATAGRAM_READ_ERROR (NET_EVENT_EVENTS_START + 7) 75 #define NET_EVENT_DATAGRAM_WRITE_COMPLETE (NET_EVENT_EVENTS_START + 8) 76 #define NET_EVENT_DATAGRAM_WRITE_ERROR (NET_EVENT_EVENTS_START + 9) 77 #define NET_EVENT_DATAGRAM_READ_READY (NET_EVENT_EVENTS_START + 10) 78 #define NET_EVENT_DATAGRAM_OPEN (NET_EVENT_EVENTS_START + 11) 79 #define NET_EVENT_DATAGRAM_ERROR (NET_EVENT_EVENTS_START + 12) 80 #define NET_EVENT_ACCEPT_INTERNAL (NET_EVENT_EVENTS_START + 22) 81 #define NET_EVENT_CONNECT_INTERNAL (NET_EVENT_EVENTS_START + 23) 82 83 #define MAIN_ACCEPT_PORT -1 84 85 /* 86 * Net system uses event threads 87 * so, the net thread group id is the event thread group id 88 */ 89 90 #define ET_NET ET_CALL 91 92 #include "I_NetVConnection.h" 93 #include "I_NetProcessor.h" 94 #include "I_SessionAccept.h" 95 96 void ink_net_init(ts::ModuleVersion version); 97