├── .gitignore ├── Config ├── DefaultEditor.ini ├── DefaultEngine.ini └── DefaultGame.ini ├── Content └── StarterContent │ ├── Materials │ └── M_Basic_Wall.uasset │ ├── Shapes │ ├── Shape_Cone.uasset │ ├── Shape_Cube.uasset │ ├── Shape_Cylinder.uasset │ ├── Shape_NarrowCapsule.uasset │ ├── Shape_Pipe.uasset │ ├── Shape_Pipe_180.uasset │ ├── Shape_Pipe_90.uasset │ ├── Shape_Plane.uasset │ ├── Shape_QuadPyramid.uasset │ ├── Shape_Sphere.uasset │ ├── Shape_Torus.uasset │ ├── Shape_TriPyramid.uasset │ ├── Shape_Trim.uasset │ ├── Shape_Trim_90_In.uasset │ ├── Shape_Trim_90_Out.uasset │ ├── Shape_Tube.uasset │ ├── Shape_Wedge_A.uasset │ ├── Shape_Wedge_B.uasset │ └── Shape_WideCapsule.uasset │ └── YAsioTest.umap ├── LICENSE ├── Plugins ├── yasio │ ├── Source │ │ └── yasio │ │ │ ├── Private │ │ │ └── yasio │ │ │ │ ├── io_service.cpp │ │ │ │ ├── platform │ │ │ │ ├── java │ │ │ │ │ └── org │ │ │ │ │ │ └── yasio │ │ │ │ │ │ └── AppGlobals.java │ │ │ │ ├── yasio_jni.cpp │ │ │ │ └── yasio_unreal.cpp │ │ │ │ └── xxsocket.cpp │ │ │ ├── Public │ │ │ └── yasio │ │ │ │ ├── .clang-format │ │ │ │ ├── buffer_alloc.hpp │ │ │ │ ├── byte_buffer.hpp │ │ │ │ ├── compiler │ │ │ │ └── feature_test.hpp │ │ │ │ ├── config.hpp │ │ │ │ ├── endian_portable.hpp │ │ │ │ ├── errc.hpp │ │ │ │ ├── fsutils.hpp │ │ │ │ ├── ibstream.hpp │ │ │ │ ├── impl │ │ │ │ ├── ares.hpp │ │ │ │ ├── char_traits.hpp │ │ │ │ ├── concurrent_queue.hpp │ │ │ │ ├── epoll_io_watcher.hpp │ │ │ │ ├── eventfd_select_interrupter.hpp │ │ │ │ ├── evport_io_watcher.hpp │ │ │ │ ├── fp16.hpp │ │ │ │ ├── ifaddrs.hpp │ │ │ │ ├── inet_ntop.hpp │ │ │ │ ├── kqueue_io_watcher.hpp │ │ │ │ ├── mbedtls.hpp │ │ │ │ ├── object_pool.hpp │ │ │ │ ├── openssl.hpp │ │ │ │ ├── pipe_select_interrupter.hpp │ │ │ │ ├── poll_io_watcher.hpp │ │ │ │ ├── select_interrupter.hpp │ │ │ │ ├── select_io_watcher.hpp │ │ │ │ ├── socket.hpp │ │ │ │ └── socket_select_interrupter.hpp │ │ │ │ ├── io_service.hpp │ │ │ │ ├── io_watcher.hpp │ │ │ │ ├── logging.hpp │ │ │ │ ├── memory.hpp │ │ │ │ ├── object_pool.hpp │ │ │ │ ├── object_pool_alloc.hpp │ │ │ │ ├── obstream.hpp │ │ │ │ ├── platform │ │ │ │ ├── yasio_jni.hpp │ │ │ │ └── yasio_unreal.hpp │ │ │ │ ├── pod_vector.hpp │ │ │ │ ├── ref_ptr.hpp │ │ │ │ ├── shared_mutex.hpp │ │ │ │ ├── singleton.hpp │ │ │ │ ├── split.hpp │ │ │ │ ├── ssl.hpp │ │ │ │ ├── strfmt.hpp │ │ │ │ ├── string.hpp │ │ │ │ ├── string_view.hpp │ │ │ │ ├── sz.hpp │ │ │ │ ├── thread_name.hpp │ │ │ │ ├── type_traits.hpp │ │ │ │ ├── utils.hpp │ │ │ │ ├── wtimer_hres.hpp │ │ │ │ ├── xxsocket.hpp │ │ │ │ ├── yasio.hpp │ │ │ │ ├── yasio.natvis │ │ │ │ └── yasio_fwd.hpp │ │ │ └── yasio.Build.cs │ └── yasio.uplugin └── yasio_http │ ├── .clang-format │ ├── Source │ └── yasio_http │ │ ├── Private │ │ └── yasio_http │ │ │ ├── HttpClient.cpp │ │ │ ├── HttpCookie.cpp │ │ │ ├── Uri.cpp │ │ │ ├── llhttp │ │ │ ├── api.c │ │ │ ├── http.c │ │ │ └── llhttp.c │ │ │ └── yasio_http.cpp │ │ ├── Public │ │ └── yasio_http │ │ │ ├── HttpClient.h │ │ │ ├── HttpCookie.h │ │ │ ├── HttpRequest.h │ │ │ ├── HttpResponse.h │ │ │ ├── Uri.h │ │ │ ├── llhttp │ │ │ └── llhttp.h │ │ │ └── utils │ │ │ └── concurrent_deque.h │ │ └── yasio_http.Build.cs │ └── yasio_http.uplugin ├── README.md ├── Source ├── YAsioSample.Target.cs ├── YAsioSample │ ├── YAsioSample.Build.cs │ ├── YAsioSample.cpp │ ├── YAsioSample.h │ ├── YAsioSampleActor.cpp │ ├── YAsioSampleActor.h │ ├── YAsioSampleGameModeBase.cpp │ └── YAsioSampleGameModeBase.h └── YAsioSampleEditor.Target.cs └── yasio_unreal.uproject /.gitignore: -------------------------------------------------------------------------------- 1 | # Visual Studio 2015 user specific files 2 | .vs/ 3 | 4 | # Compiled Object files 5 | *.slo 6 | *.lo 7 | *.o 8 | *.obj 9 | 10 | # Precompiled Headers 11 | *.gch 12 | *.pch 13 | 14 | # Compiled Dynamic libraries 15 | *.so 16 | *.dylib 17 | *.dll 18 | 19 | # Fortran module files 20 | *.mod 21 | 22 | # Compiled Static libraries 23 | *.lai 24 | *.la 25 | *.a 26 | *.lib 27 | 28 | # Executables 29 | *.exe 30 | *.out 31 | *.app 32 | *.ipa 33 | 34 | # These project files can be generated by the engine 35 | *.xcodeproj 36 | *.xcworkspace 37 | *.sln 38 | *.suo 39 | *.opensdf 40 | *.sdf 41 | *.VC.db 42 | *.VC.opendb 43 | 44 | # Precompiled Assets 45 | SourceArt/**/*.png 46 | SourceArt/**/*.tga 47 | 48 | # Binary Files 49 | Binaries/* 50 | Plugins/*/Binaries/* 51 | 52 | # Builds 53 | Build/* 54 | 55 | # Whitelist PakBlacklist-.txt files 56 | !Build/*/ 57 | Build/*/** 58 | !Build/*/PakBlacklist*.txt 59 | 60 | # Don't ignore icon files in Build 61 | !Build/**/*.ico 62 | 63 | # Built data for maps 64 | *_BuiltData.uasset 65 | 66 | # Configuration files generated by the Editor 67 | Saved/* 68 | 69 | # Compiled source files for the engine to use 70 | Intermediate/* 71 | Plugins/*/Intermediate/* 72 | 73 | # Cache files for the editor to use 74 | DerivedDataCache/* 75 | -------------------------------------------------------------------------------- /Config/DefaultEditor.ini: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simdsoft/yasio_unreal/ed5c93479b347db33f33b6d298a1dbdb493b36b0/Config/DefaultEditor.ini -------------------------------------------------------------------------------- /Config/DefaultEngine.ini: -------------------------------------------------------------------------------- 1 | [/Script/Engine.Engine] 2 | +ActiveGameNameRedirects=(OldGameName="TP_Blank",NewGameName="/Script/YAsioSample") 3 | +ActiveGameNameRedirects=(OldGameName="/Script/TP_Blank",NewGameName="/Script/YAsioSample") 4 | +ActiveClassRedirects=(OldClassName="TP_BlankGameModeBase",NewClassName="YAsioSampleGameModeBase") 5 | 6 | [/Script/EngineSettings.GameMapsSettings] 7 | EditorStartupMap=/Game/StarterContent/YAsioTest.umap 8 | GameDefaultMap=/Game/StarterContent/YAsioTest.umap 9 | ServerDefaultMap=/Game/StarterContent/YAsioTest.umap 10 | 11 | [/Script/Engine.RendererSettings] 12 | r.MobileHDR=True 13 | r.Mobile.DisableVertexFog=True 14 | r.Shadow.CSM.MaxMobileCascades=2 15 | r.MobileMSAA=1 16 | r.Mobile.UseLegacyShadingModel=False 17 | r.Mobile.UseHWsRGBEncoding=False 18 | r.Mobile.AllowDitheredLODTransition=False 19 | r.Mobile.AllowSoftwareOcclusion=False 20 | r.DiscardUnusedQuality=False 21 | r.AllowOcclusionQueries=True 22 | r.MinScreenRadiusForLights=0.030000 23 | r.MinScreenRadiusForDepthPrepass=0.030000 24 | r.MinScreenRadiusForCSMDepth=0.010000 25 | r.PrecomputedVisibilityWarning=False 26 | r.TextureStreaming=True 27 | Compat.UseDXT5NormalMaps=False 28 | r.VirtualTextures=False 29 | r.VirtualTexturedLightmaps=False 30 | r.VT.TileSize=128 31 | r.VT.TileBorderSize=4 32 | r.vt.FeedbackFactor=16 33 | r.VT.EnableCompressZlib=True 34 | r.VT.EnableCompressCrunch=False 35 | r.ClearCoatNormal=False 36 | r.ReflectionCaptureResolution=128 37 | r.ReflectionEnvironmentLightmapMixBasedOnRoughness=True 38 | r.ForwardShading=False 39 | r.VertexFoggingForOpaque=True 40 | r.AllowStaticLighting=True 41 | r.NormalMapsForStaticLighting=False 42 | r.GenerateMeshDistanceFields=False 43 | r.DistanceFieldBuild.EightBit=False 44 | r.GenerateLandscapeGIData=False 45 | r.DistanceFieldBuild.Compress=False 46 | r.TessellationAdaptivePixelsPerTriangle=48.000000 47 | r.SeparateTranslucency=True 48 | r.TranslucentSortPolicy=0 49 | TranslucentSortAxis=(X=0.000000,Y=-1.000000,Z=0.000000) 50 | r.CustomDepth=1 51 | r.CustomDepthTemporalAAJitter=True 52 | r.PostProcessing.PropagateAlpha=0 53 | r.DefaultFeature.Bloom=True 54 | r.DefaultFeature.AmbientOcclusion=True 55 | r.DefaultFeature.AmbientOcclusionStaticFraction=True 56 | r.DefaultFeature.AutoExposure=False 57 | r.DefaultFeature.AutoExposure.Method=0 58 | r.DefaultFeature.AutoExposure.ExtendDefaultLuminanceRange=False 59 | r.UsePreExposure=True 60 | r.EyeAdaptation.EditorOnly=True 61 | r.DefaultFeature.MotionBlur=False 62 | r.DefaultFeature.LensFlare=False 63 | r.TemporalAA.Upsampling=False 64 | r.SSGI.Enable=False 65 | r.DefaultFeature.AntiAliasing=0 66 | r.DefaultFeature.LightUnits=1 67 | r.DefaultBackBufferPixelFormat=4 68 | r.Shadow.UnbuiltPreviewInGame=True 69 | r.StencilForLODDither=False 70 | r.EarlyZPass=3 71 | r.EarlyZPassOnlyMaterialMasking=False 72 | r.DBuffer=True 73 | r.ClearSceneMethod=1 74 | r.BasePassOutputsVelocity=False 75 | r.SelectiveBasePassOutputs=False 76 | bDefaultParticleCutouts=False 77 | fx.GPUSimulationTextureSizeX=1024 78 | fx.GPUSimulationTextureSizeY=1024 79 | r.AllowGlobalClipPlane=False 80 | r.GBufferFormat=1 81 | r.MorphTarget.Mode=True 82 | r.GPUCrashDebugging=False 83 | vr.InstancedStereo=False 84 | vr.MultiView=False 85 | vr.MobileMultiView=False 86 | vr.MobileMultiView.Direct=False 87 | vr.RoundRobinOcclusion=False 88 | vr.ODSCapture=False 89 | r.WireframeCullThreshold=5.000000 90 | r.RayTracing=False 91 | r.RayTracing.UseTextureLod=False 92 | r.SupportStationarySkylight=True 93 | r.SupportLowQualityLightmaps=True 94 | r.SupportPointLightWholeSceneShadows=True 95 | r.SupportAtmosphericFog=True 96 | r.SupportSkyAtmosphere=True 97 | r.SupportSkyAtmosphereAffectsHeightFog=False 98 | r.SkinCache.CompileShaders=False 99 | r.Mobile.EnableStaticAndCSMShadowReceivers=True 100 | r.Mobile.EnableMovableLightCSMShaderCulling=True 101 | r.Mobile.AllowDistanceFieldShadows=True 102 | r.Mobile.AllowMovableDirectionalLights=True 103 | r.MobileNumDynamicPointLights=4 104 | r.MobileDynamicPointLightsUseStaticBranch=True 105 | r.Mobile.EnableMovableSpotlights=False 106 | r.SkinCache.SceneMemoryLimitInMB=128.000000 107 | r.GPUSkin.Limit2BoneInfluences=False 108 | r.SupportDepthOnlyIndexBuffers=True 109 | r.SupportReversedIndexBuffers=True 110 | r.SupportMaterialLayers=False 111 | r.LightPropagationVolume=False 112 | 113 | [/Script/HardwareTargeting.HardwareTargetingSettings] 114 | TargetedHardwareClass=Desktop 115 | AppliedTargetedHardwareClass=Desktop 116 | DefaultGraphicsPerformance=Scalable 117 | AppliedDefaultGraphicsPerformance=Scalable 118 | 119 | 120 | -------------------------------------------------------------------------------- /Config/DefaultGame.ini: -------------------------------------------------------------------------------- 1 | 2 | [/Script/EngineSettings.GeneralProjectSettings] 3 | ProjectID=1C68FA4145F0FDB29D44A59DAB323221 4 | -------------------------------------------------------------------------------- /Content/StarterContent/Materials/M_Basic_Wall.uasset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simdsoft/yasio_unreal/ed5c93479b347db33f33b6d298a1dbdb493b36b0/Content/StarterContent/Materials/M_Basic_Wall.uasset -------------------------------------------------------------------------------- /Content/StarterContent/Shapes/Shape_Cone.uasset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simdsoft/yasio_unreal/ed5c93479b347db33f33b6d298a1dbdb493b36b0/Content/StarterContent/Shapes/Shape_Cone.uasset -------------------------------------------------------------------------------- /Content/StarterContent/Shapes/Shape_Cube.uasset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simdsoft/yasio_unreal/ed5c93479b347db33f33b6d298a1dbdb493b36b0/Content/StarterContent/Shapes/Shape_Cube.uasset -------------------------------------------------------------------------------- /Content/StarterContent/Shapes/Shape_Cylinder.uasset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simdsoft/yasio_unreal/ed5c93479b347db33f33b6d298a1dbdb493b36b0/Content/StarterContent/Shapes/Shape_Cylinder.uasset -------------------------------------------------------------------------------- /Content/StarterContent/Shapes/Shape_NarrowCapsule.uasset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simdsoft/yasio_unreal/ed5c93479b347db33f33b6d298a1dbdb493b36b0/Content/StarterContent/Shapes/Shape_NarrowCapsule.uasset -------------------------------------------------------------------------------- /Content/StarterContent/Shapes/Shape_Pipe.uasset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simdsoft/yasio_unreal/ed5c93479b347db33f33b6d298a1dbdb493b36b0/Content/StarterContent/Shapes/Shape_Pipe.uasset -------------------------------------------------------------------------------- /Content/StarterContent/Shapes/Shape_Pipe_180.uasset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simdsoft/yasio_unreal/ed5c93479b347db33f33b6d298a1dbdb493b36b0/Content/StarterContent/Shapes/Shape_Pipe_180.uasset -------------------------------------------------------------------------------- /Content/StarterContent/Shapes/Shape_Pipe_90.uasset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simdsoft/yasio_unreal/ed5c93479b347db33f33b6d298a1dbdb493b36b0/Content/StarterContent/Shapes/Shape_Pipe_90.uasset -------------------------------------------------------------------------------- /Content/StarterContent/Shapes/Shape_Plane.uasset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simdsoft/yasio_unreal/ed5c93479b347db33f33b6d298a1dbdb493b36b0/Content/StarterContent/Shapes/Shape_Plane.uasset -------------------------------------------------------------------------------- /Content/StarterContent/Shapes/Shape_QuadPyramid.uasset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simdsoft/yasio_unreal/ed5c93479b347db33f33b6d298a1dbdb493b36b0/Content/StarterContent/Shapes/Shape_QuadPyramid.uasset -------------------------------------------------------------------------------- /Content/StarterContent/Shapes/Shape_Sphere.uasset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simdsoft/yasio_unreal/ed5c93479b347db33f33b6d298a1dbdb493b36b0/Content/StarterContent/Shapes/Shape_Sphere.uasset -------------------------------------------------------------------------------- /Content/StarterContent/Shapes/Shape_Torus.uasset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simdsoft/yasio_unreal/ed5c93479b347db33f33b6d298a1dbdb493b36b0/Content/StarterContent/Shapes/Shape_Torus.uasset -------------------------------------------------------------------------------- /Content/StarterContent/Shapes/Shape_TriPyramid.uasset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simdsoft/yasio_unreal/ed5c93479b347db33f33b6d298a1dbdb493b36b0/Content/StarterContent/Shapes/Shape_TriPyramid.uasset -------------------------------------------------------------------------------- /Content/StarterContent/Shapes/Shape_Trim.uasset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simdsoft/yasio_unreal/ed5c93479b347db33f33b6d298a1dbdb493b36b0/Content/StarterContent/Shapes/Shape_Trim.uasset -------------------------------------------------------------------------------- /Content/StarterContent/Shapes/Shape_Trim_90_In.uasset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simdsoft/yasio_unreal/ed5c93479b347db33f33b6d298a1dbdb493b36b0/Content/StarterContent/Shapes/Shape_Trim_90_In.uasset -------------------------------------------------------------------------------- /Content/StarterContent/Shapes/Shape_Trim_90_Out.uasset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simdsoft/yasio_unreal/ed5c93479b347db33f33b6d298a1dbdb493b36b0/Content/StarterContent/Shapes/Shape_Trim_90_Out.uasset -------------------------------------------------------------------------------- /Content/StarterContent/Shapes/Shape_Tube.uasset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simdsoft/yasio_unreal/ed5c93479b347db33f33b6d298a1dbdb493b36b0/Content/StarterContent/Shapes/Shape_Tube.uasset -------------------------------------------------------------------------------- /Content/StarterContent/Shapes/Shape_Wedge_A.uasset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simdsoft/yasio_unreal/ed5c93479b347db33f33b6d298a1dbdb493b36b0/Content/StarterContent/Shapes/Shape_Wedge_A.uasset -------------------------------------------------------------------------------- /Content/StarterContent/Shapes/Shape_Wedge_B.uasset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simdsoft/yasio_unreal/ed5c93479b347db33f33b6d298a1dbdb493b36b0/Content/StarterContent/Shapes/Shape_Wedge_B.uasset -------------------------------------------------------------------------------- /Content/StarterContent/Shapes/Shape_WideCapsule.uasset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simdsoft/yasio_unreal/ed5c93479b347db33f33b6d298a1dbdb493b36b0/Content/StarterContent/Shapes/Shape_WideCapsule.uasset -------------------------------------------------------------------------------- /Content/StarterContent/YAsioTest.umap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simdsoft/yasio_unreal/ed5c93479b347db33f33b6d298a1dbdb493b36b0/Content/StarterContent/YAsioTest.umap -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 yasio 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Plugins/yasio/Source/yasio/Private/yasio/platform/java/org/yasio/AppGlobals.java: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////////////////// 2 | // A multi-platform support c++11 library with focus on asynchronous socket I/O for any 3 | // client application. 4 | ////////////////////////////////////////////////////////////////////////////////////////// 5 | /* 6 | The MIT License (MIT) 7 | 8 | Copyright (c) 2012-2024 HALX99 9 | 10 | Permission is hereby granted, free of charge, to any person obtaining a copy 11 | of this software and associated documentation files (the "Software"), to deal 12 | in the Software without restriction, including without limitation the rights 13 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 14 | copies of the Software, and to permit persons to whom the Software is 15 | furnished to do so, subject to the following conditions: 16 | 17 | The above copyright notice and this permission notice shall be included in all 18 | copies or substantial portions of the Software. 19 | 20 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 23 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 24 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 25 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 26 | SOFTWARE. 27 | */ 28 | package org.yasio; 29 | 30 | import android.content.Context; 31 | 32 | public final class AppGlobals { 33 | private static Context sApplicationContext = null; 34 | 35 | public static void init(Context ctx) { 36 | sApplicationContext = ctx.getApplicationContext(); 37 | } 38 | 39 | @SuppressWarnings("unused") 40 | public static Context getApplicationContext() { 41 | return sApplicationContext; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Plugins/yasio/Source/yasio/Private/yasio/platform/yasio_jni.cpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////////////////// 2 | // A multi-platform support c++11 library with focus on asynchronous socket I/O for any 3 | // client application. 4 | ////////////////////////////////////////////////////////////////////////////////////////// 5 | /* 6 | The MIT License (MIT) 7 | 8 | Copyright (c) 2012-2024 HALX99 9 | 10 | Permission is hereby granted, free of charge, to any person obtaining a copy 11 | of this software and associated documentation files (the "Software"), to deal 12 | in the Software without restriction, including without limitation the rights 13 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 14 | copies of the Software, and to permit persons to whom the Software is 15 | furnished to do so, subject to the following conditions: 16 | 17 | The above copyright notice and this permission notice shall be included in all 18 | copies or substantial portions of the Software. 19 | 20 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 23 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 24 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 25 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 26 | SOFTWARE. 27 | */ 28 | #ifndef YASIO__JNI_CPP 29 | #define YASIO__JNI_CPP 30 | 31 | /* 32 | ** yasio_jni.cpp: The yasio native interface for initialize c-ares on android. 33 | org/yasio/AppGlobals.java provide 2 function: 34 | 1. getApplicationContext(), for native only 35 | 2. init(Context ctx), please call after your android app initialized. 36 | */ 37 | #include "yasio/config.hpp" 38 | #include "yasio/logging.hpp" 39 | 40 | #if defined(__ANDROID__) && defined(YASIO_USE_CARES) 41 | static JavaVM* yasio__jvm; 42 | static jclass yasio__appglobals_cls; 43 | static jobject yasio__get_app_context(JNIEnv* env, jclass obj_cls, const char* funcName, 44 | const char* signature) 45 | { 46 | jobject app_context = nullptr; 47 | do 48 | { 49 | if (obj_cls == nullptr) 50 | break; 51 | jmethodID android_get_app_mid = env->GetStaticMethodID(obj_cls, funcName, signature); 52 | if (android_get_app_mid == nullptr) 53 | break; 54 | app_context = env->CallStaticObjectMethod(obj_cls, android_get_app_mid); 55 | } while (false); 56 | 57 | if (env->ExceptionOccurred()) 58 | env->ExceptionClear(); 59 | 60 | return app_context; 61 | } 62 | 63 | static jobject yasio__get_app_context(JNIEnv* env, const char* className, const char* funcName, 64 | const char* signature) 65 | { 66 | jobject app_context = nullptr; 67 | jclass obj_cls = env->FindClass(className); 68 | if (obj_cls != nullptr) 69 | { 70 | app_context = yasio__get_app_context(env, obj_cls, funcName, signature); 71 | env->DeleteLocalRef(obj_cls); 72 | } 73 | if (env->ExceptionOccurred()) 74 | env->ExceptionClear(); 75 | return app_context; 76 | } 77 | 78 | extern "C" { 79 | # include "ares.h" 80 | 81 | int yasio__ares_init_android() 82 | { 83 | JNIEnv* env = nullptr; 84 | int ret = ARES_ENOTINITIALIZED; 85 | bool need_detatch = false; 86 | jclass obj_cls = nullptr; 87 | jobject app_context = nullptr; 88 | 89 | do 90 | { 91 | if (yasio__jvm == nullptr) 92 | break; 93 | 94 | jint res = yasio__jvm->GetEnv((void**)&env, JNI_VERSION_1_6); 95 | if (res == JNI_EDETACHED) 96 | { 97 | env = nullptr; 98 | res = yasio__jvm->AttachCurrentThread(&env, nullptr); 99 | need_detatch = true; 100 | } 101 | if (res != JNI_OK) 102 | break; // Get env failed 103 | 104 | /// Gets application context 105 | app_context = yasio__get_app_context(env, "android/app/AppGlobals", "getInitialApplication", 106 | "()Landroid/app/Application;"); 107 | if (app_context == nullptr) 108 | { 109 | app_context = yasio__get_app_context(env, yasio__appglobals_cls, "getApplicationContext", 110 | "()Landroid/content/Context;"); 111 | if (app_context == nullptr) 112 | break; 113 | } 114 | 115 | /// Gets connectivity_manager 116 | obj_cls = (env)->FindClass("android/content/Context"); 117 | if (obj_cls == nullptr) 118 | break; 119 | jmethodID android_get_service_mid = 120 | (env)->GetMethodID(obj_cls, "getSystemService", "(Ljava/lang/String;)Ljava/lang/Object;"); 121 | if (android_get_service_mid == nullptr) 122 | break; 123 | jfieldID cs_fid = env->GetStaticFieldID(obj_cls, "CONNECTIVITY_SERVICE", "Ljava/lang/String;"); 124 | if (cs_fid == nullptr) 125 | break; 126 | jstring jstr_service_name = (jstring)env->GetStaticObjectField(obj_cls, cs_fid); 127 | if (jstr_service_name == nullptr) 128 | break; 129 | jobject connectivity_manager = 130 | env->CallObjectMethod(app_context, android_get_service_mid, jstr_service_name); 131 | if (connectivity_manager != nullptr) 132 | { 133 | ret = ::ares_library_init_android(connectivity_manager); 134 | env->DeleteLocalRef(connectivity_manager); 135 | } 136 | else 137 | YASIO_LOG( 138 | "[c-ares] Gets ConnectivityManager service failed, please ensure you have permission " 139 | "'ACCESS_NETWORK_STATE'"); 140 | 141 | env->DeleteLocalRef(jstr_service_name); 142 | env->DeleteLocalRef(app_context); 143 | env->DeleteLocalRef(obj_cls); 144 | app_context = nullptr; 145 | obj_cls = nullptr; 146 | } while (false); 147 | 148 | if (env != nullptr) 149 | { 150 | if (env->ExceptionOccurred()) 151 | env->ExceptionClear(); 152 | 153 | if (app_context != nullptr) 154 | env->DeleteLocalRef(app_context); 155 | if (obj_cls != nullptr) 156 | env->DeleteLocalRef(obj_cls); 157 | } 158 | 159 | if (need_detatch) 160 | yasio__jvm->DetachCurrentThread(); 161 | 162 | return ret; 163 | } 164 | 165 | void yasio__jni_init(void* vm, void* env) 166 | { 167 | yasio__jvm = (JavaVM*)vm; 168 | JNIEnv* jenv = (JNIEnv*)env; 169 | if (jenv != nullptr) 170 | { 171 | // must find class at here, 172 | // see: https://developer.android.com/training/articles/perf-jni#faq_FindClass 173 | jclass obj_cls = jenv->FindClass("org/yasio/AppGlobals"); 174 | if (obj_cls != nullptr) 175 | { 176 | yasio__appglobals_cls = (jclass)jenv->NewGlobalRef(obj_cls); 177 | jenv->DeleteLocalRef(obj_cls); 178 | } 179 | 180 | if (jenv->ExceptionOccurred()) 181 | jenv->ExceptionClear(); 182 | } 183 | ::ares_library_init_jvm(yasio__jvm); 184 | } 185 | 186 | int yasio__jni_onload(void* vm, void* /*reserved*/) 187 | { 188 | JNIEnv* env = nullptr; 189 | jint res = ((JavaVM*)vm)->GetEnv((void**)&env, JNI_VERSION_1_6); 190 | if (res == JNI_OK) 191 | yasio__jni_init(vm, env); 192 | 193 | return JNI_VERSION_1_6; 194 | } 195 | # if defined(YASIO_BUILD_SHARED_LIBS) && !defined(YASIO_NO_JNI_ONLOAD) 196 | jint JNICALL JNI_OnLoad(JavaVM* vm, void* reserved) { return yasio__jni_onload(vm, reserved); } 197 | # endif 198 | } 199 | #endif 200 | 201 | #endif 202 | -------------------------------------------------------------------------------- /Plugins/yasio/Source/yasio/Private/yasio/platform/yasio_unreal.cpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////////////////// 2 | // A multi-platform support c++11 library with focus on asynchronous socket I/O for any 3 | // client application. 4 | ////////////////////////////////////////////////////////////////////////////////////////// 5 | /* 6 | The MIT License (MIT) 7 | Copyright (c) 2012-2024 HALX99 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | */ 24 | 25 | #include "Modules/ModuleManager.h" 26 | 27 | #include "yasio/yasio.hpp" 28 | 29 | using namespace yasio; 30 | 31 | DECLARE_LOG_CATEGORY_EXTERN(yasio_ue, Log, All); 32 | DEFINE_LOG_CATEGORY(yasio_ue); 33 | 34 | YASIO_API void yasio_unreal_init() 35 | { 36 | print_fn2_t log_cb = [](int level, const char* msg) { 37 | FString text(msg); 38 | const TCHAR* tstr = *text; 39 | UE_LOG(yasio_ue, Log, TEXT("%s"), tstr); 40 | }; 41 | io_service::init_globals(log_cb); 42 | } 43 | YASIO_API void yasio_unreal_cleanup() 44 | { 45 | io_service::cleanup_globals(); 46 | } 47 | 48 | #if defined(YASIO_INSIDE_UNREAL) && (YASIO_BUILD_SHARED_LIBS) 49 | class yasio_unreal_module : public IModuleInterface 50 | { 51 | public: 52 | /** IModuleInterface implementation */ 53 | void StartupModule() override {} 54 | void ShutdownModule() override {} 55 | }; 56 | IMPLEMENT_MODULE(yasio_unreal_module, yasio) 57 | #endif 58 | -------------------------------------------------------------------------------- /Plugins/yasio/Source/yasio/Public/yasio/.clang-format: -------------------------------------------------------------------------------- 1 | --- 2 | BasedOnStyle: LLVM 3 | 4 | # Allow double brackets such as std::vector>. 5 | Standard: Cpp11 6 | 7 | SortIncludes: false 8 | 9 | # Keep lines under 160 columns long. 10 | ColumnLimit: 160 11 | 12 | # Always break before braces 13 | BreakBeforeBraces: Custom 14 | BraceWrapping: 15 | AfterClass: false 16 | AfterControlStatement: true 17 | AfterEnum: true 18 | AfterFunction: true 19 | AfterNamespace: true 20 | AfterStruct: false 21 | AfterUnion: false 22 | BeforeCatch: true 23 | BeforeElse: true 24 | IndentBraces: false 25 | SplitEmptyFunction: false 26 | SplitEmptyRecord: false 27 | SplitEmptyNamespace: false 28 | 29 | # Keeps extern "C" blocks unindented. 30 | AfterExternBlock: false 31 | 32 | # Indent case labels. 33 | IndentCaseLabels: true 34 | 35 | # Right-align pointers and references 36 | PointerAlignment: Left 37 | 38 | # ANGLE likes to align things as much as possible. 39 | AlignOperands: true 40 | AlignConsecutiveAssignments: true 41 | 42 | # Use 2 space negative offset for access modifiers 43 | AccessModifierOffset: -2 44 | 45 | # TODO(jmadill): Decide if we want this on. Doesn't have an "all or none" mode. 46 | AllowShortCaseLabelsOnASingleLine: false 47 | 48 | # Useful for spacing out functions in classes 49 | KeepEmptyLinesAtTheStartOfBlocks: true 50 | 51 | # Indent nested PP directives. 52 | IndentPPDirectives: AfterHash 53 | 54 | AlwaysBreakTemplateDeclarations: Yes 55 | 56 | AlignEscapedNewlines: Left 57 | -------------------------------------------------------------------------------- /Plugins/yasio/Source/yasio/Public/yasio/buffer_alloc.hpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////////////////// 2 | // A multi-platform support c++11 library with focus on asynchronous socket I/O for any 3 | // client application. 4 | ////////////////////////////////////////////////////////////////////////////////////////// 5 | /* 6 | The MIT License (MIT) 7 | 8 | Copyright (c) 2012-2024 HALX99 9 | 10 | Permission is hereby granted, free of charge, to any person obtaining a copy 11 | of this software and associated documentation files (the "Software"), to deal 12 | in the Software without restriction, including without limitation the rights 13 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 14 | copies of the Software, and to permit persons to whom the Software is 15 | furnished to do so, subject to the following conditions: 16 | 17 | The above copyright notice and this permission notice shall be included in all 18 | copies or substantial portions of the Software. 19 | 20 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 23 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 24 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 25 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 26 | SOFTWARE. 27 | */ 28 | 29 | #ifndef YASIO__BUFFER_ALLOC_HPP 30 | #define YASIO__BUFFER_ALLOC_HPP 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include "yasio/compiler/feature_test.hpp" 37 | #include "yasio/type_traits.hpp" 38 | 39 | #define _YASIO_VERIFY_RANGE(cond, mesg) \ 40 | do \ 41 | { \ 42 | if (cond) \ 43 | ; /* contextually convertible to bool paranoia */ \ 44 | else \ 45 | { \ 46 | throw std::out_of_range(mesg); \ 47 | } \ 48 | \ 49 | } while (false) 50 | 51 | namespace yasio 52 | { 53 | template 54 | struct buffer_allocator_traits { 55 | using value_type = typename _Alty::value_type; 56 | using size_type = size_t; 57 | static YASIO__CONSTEXPR size_type max_size() { return static_cast(-1) / sizeof(value_type); } 58 | static value_type* reallocate(void* block, size_t size, size_t new_size) 59 | { 60 | return static_cast(_Alty::reallocate(block, size, new_size * sizeof(value_type))); 61 | } 62 | static void deallocate(void* block, size_t size) { _Alty::deallocate(block, size); } 63 | }; 64 | template ::value, int> = 0> 65 | struct buffer_allocator { 66 | using value_type = _Ty; 67 | static value_type* reallocate(void* block, size_t /*size*/, size_t new_size) 68 | { 69 | return static_cast(::realloc(block, new_size * sizeof(value_type))); 70 | } 71 | static void deallocate(void* block, size_t /*size*/) { ::free(block); } 72 | }; 73 | template ::value, int> = 0> 74 | struct std_buffer_allocator { 75 | using value_type = _Ty; 76 | static value_type* reallocate(void* block, size_t size, size_t new_size) 77 | { 78 | if (!block) 79 | return new (std::nothrow) value_type[new_size]; 80 | void* new_block = nullptr; 81 | if (new_size) 82 | { 83 | if (new_size <= size) 84 | return block; 85 | new_block = new (std::nothrow) value_type[new_size]; 86 | if (new_block) 87 | memcpy(new_block, block, size); 88 | } 89 | delete[] (value_type*)block; 90 | return (value_type*)new_block; 91 | } 92 | static void deallocate(void* block, size_t /*size*/) { delete[] (value_type*)block; } 93 | }; 94 | template 95 | struct construct_helper { 96 | template 97 | static _Ty* construct_at(_Ty* p, Args&&... args) 98 | { 99 | return ::new (static_cast(p)) _Ty(std::forward(args)...); 100 | } 101 | }; 102 | template 103 | struct construct_helper<_Ty, false> { 104 | template 105 | static _Ty* construct_at(_Ty* p, Args&&... args) 106 | { 107 | return ::new (static_cast(p)) _Ty{std::forward(args)...}; 108 | } 109 | }; 110 | 111 | template 112 | inline _Ty* construct_at(_Ty* p, Args&&... args) 113 | { 114 | return construct_helper<_Ty, std::is_constructible<_Ty, Args&&...>::value>::construct_at(p, std::forward(args)...); 115 | } 116 | 117 | } // namespace yasio 118 | 119 | #endif 120 | -------------------------------------------------------------------------------- /Plugins/yasio/Source/yasio/Public/yasio/byte_buffer.hpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////////////////// 2 | // A multi-platform support c++11 library with focus on asynchronous socket I/O for any 3 | // client application. 4 | ////////////////////////////////////////////////////////////////////////////////////////// 5 | /* 6 | The MIT License (MIT) 7 | 8 | Copyright (c) 2012-2024 HALX99 9 | 10 | Permission is hereby granted, free of charge, to any person obtaining a copy 11 | of this software and associated documentation files (the "Software"), to deal 12 | in the Software without restriction, including without limitation the rights 13 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 14 | copies of the Software, and to permit persons to whom the Software is 15 | furnished to do so, subject to the following conditions: 16 | 17 | The above copyright notice and this permission notice shall be included in all 18 | copies or substantial portions of the Software. 19 | 20 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 23 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 24 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 25 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 26 | SOFTWARE. 27 | */ 28 | #ifndef YASIO__BYTE_BUFFER_HPP 29 | #define YASIO__BYTE_BUFFER_HPP 30 | #include "yasio/pod_vector.hpp" 31 | 32 | namespace yasio 33 | { 34 | 35 | template , enable_if_t::value, int> = 0> 36 | using basic_byte_buffer = array_buffer<_Ty, _Alloc>; 37 | 38 | using sbyte_buffer = basic_byte_buffer; 39 | using byte_buffer = basic_byte_buffer; 40 | 41 | } // namespace yasio 42 | #endif 43 | -------------------------------------------------------------------------------- /Plugins/yasio/Source/yasio/Public/yasio/errc.hpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////////////////// 2 | // A multi-platform support c++11 library with focus on asynchronous socket I/O for any 3 | // client application. 4 | ////////////////////////////////////////////////////////////////////////////////////////// 5 | /* 6 | The MIT License (MIT) 7 | 8 | Copyright (c) 2012-2024 HALX99 9 | 10 | Permission is hereby granted, free of charge, to any person obtaining a copy 11 | of this software and associated documentation files (the "Software"), to deal 12 | in the Software without restriction, including without limitation the rights 13 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 14 | copies of the Software, and to permit persons to whom the Software is 15 | furnished to do so, subject to the following conditions: 16 | The above copyright notice and this permission notice shall be included in all 17 | copies or substantial portions of the Software. 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | */ 26 | #ifndef YAISO__ERRC_HPP 27 | #define YAISO__ERRC_HPP 28 | 29 | namespace yasio 30 | { 31 | namespace errc 32 | { 33 | enum 34 | { 35 | no_error = 0, // No error. 36 | read_timeout = -28, // The remote host did not respond after a period of time. 37 | invalid_packet = -27, // Invalid packet. 38 | resolve_host_failed = -26, // Resolve host failed. 39 | no_available_address = -25, // No available address to connect. 40 | shutdown_by_localhost = -24, // Local shutdown the connection. 41 | ssl_handshake_failed = -23, // SSL handshake failed. 42 | ssl_write_failed = -22, // SSL write failed. 43 | ssl_read_failed = -21, // SSL read failed. 44 | eof = -20, // end of file. 45 | }; 46 | } 47 | } // namespace yasio 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /Plugins/yasio/Source/yasio/Public/yasio/fsutils.hpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////////////////// 2 | // A multi-platform support c++11 library with focus on asynchronous socket I/O for any 3 | // client application. 4 | ////////////////////////////////////////////////////////////////////////////////////////// 5 | /* 6 | The MIT License (MIT) 7 | 8 | Copyright (c) 2012-2024 HALX99 9 | 10 | Permission is hereby granted, free of charge, to any person obtaining a copy 11 | of this software and associated documentation files (the "Software"), to deal 12 | in the Software without restriction, including without limitation the rights 13 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 14 | copies of the Software, and to permit persons to whom the Software is 15 | furnished to do so, subject to the following conditions: 16 | 17 | The above copyright notice and this permission notice shall be included in all 18 | copies or substantial portions of the Software. 19 | 20 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 23 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 24 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 25 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 26 | SOFTWARE. 27 | */ 28 | 29 | #pragma once 30 | 31 | #include "yasio/string.hpp" 32 | #include "yasio/string_view.hpp" 33 | #include 34 | 35 | namespace yasio 36 | { 37 | inline yasio::string read_text_file(cxx17::string_view file_path) 38 | { 39 | std::ifstream fin(file_path.data(), std::ios_base::binary); 40 | if (fin.is_open()) 41 | { 42 | fin.seekg(std::ios_base::end); 43 | auto n = static_cast(fin.tellg()); 44 | if (n > 0) 45 | { 46 | yasio::string ret; 47 | ret.resize_and_overwrite(n, [&fin](char* out, size_t outlen) { 48 | fin.seekg(std::ios_base::beg); 49 | fin.read(out, outlen); 50 | return outlen; 51 | }); 52 | return ret; 53 | } 54 | } 55 | return yasio::string{}; 56 | } 57 | } // namespace yasio 58 | -------------------------------------------------------------------------------- /Plugins/yasio/Source/yasio/Public/yasio/impl/ares.hpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////////////////// 2 | // A multi-platform support c++11 library with focus on asynchronous socket I/O for any 3 | // client application. 4 | ////////////////////////////////////////////////////////////////////////////////////////// 5 | /* 6 | The MIT License (MIT) 7 | 8 | Copyright (c) 2012-2024 HALX99 9 | 10 | Permission is hereby granted, free of charge, to any person obtaining a copy 11 | of this software and associated documentation files (the "Software"), to deal 12 | in the Software without restriction, including without limitation the rights 13 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 14 | copies of the Software, and to permit persons to whom the Software is 15 | furnished to do so, subject to the following conditions: 16 | 17 | The above copyright notice and this permission notice shall be included in all 18 | copies or substantial portions of the Software. 19 | 20 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 23 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 24 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 25 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 26 | SOFTWARE. 27 | */ 28 | #ifndef YASIO__ARES_HPP 29 | #define YASIO__ARES_HPP 30 | 31 | extern "C" { 32 | #include "ares.h" 33 | extern void (*ares_free)(void* ptr); 34 | } 35 | 36 | #if defined(__ANDROID__) 37 | # include "yasio/platform/yasio_jni.hpp" 38 | #endif 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /Plugins/yasio/Source/yasio/Public/yasio/impl/concurrent_queue.hpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////////////////// 2 | // A multi-platform support c++11 library with focus on asynchronous socket I/O for any 3 | // client application. 4 | ////////////////////////////////////////////////////////////////////////////////////////// 5 | /* 6 | The MIT License (MIT) 7 | 8 | Copyright (c) 2012-2024 HALX99 9 | 10 | Permission is hereby granted, free of charge, to any person obtaining a copy 11 | of this software and associated documentation files (the "Software"), to deal 12 | in the Software without restriction, including without limitation the rights 13 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 14 | copies of the Software, and to permit persons to whom the Software is 15 | furnished to do so, subject to the following conditions: 16 | 17 | The above copyright notice and this permission notice shall be included in all 18 | copies or substantial portions of the Software. 19 | 20 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 23 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 24 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 25 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 26 | SOFTWARE. 27 | */ 28 | #ifndef YASIO__CONCURRENT_QUEUE_HPP 29 | #define YASIO__CONCURRENT_QUEUE_HPP 30 | 31 | #include "yasio/config.hpp" 32 | #if defined(YASIO_USE_SPSC_QUEUE) 33 | # include "moodycamel/readerwriterqueue.h" 34 | #else 35 | # include 36 | #endif 37 | 38 | namespace yasio 39 | { 40 | template 41 | inline void clear_queue(_Ty& queue) 42 | { 43 | _Ty tmp; 44 | std::swap(tmp, queue); 45 | } 46 | namespace privacy 47 | { 48 | template 49 | class concurrent_queue; 50 | 51 | #if defined(YASIO_USE_SPSC_QUEUE) 52 | template 53 | class concurrent_queue : public moodycamel::ReaderWriterQueue<_Ty> { 54 | public: 55 | bool empty() const { return this->peek() == nullptr; } 56 | void consume(int count, const std::function& func) 57 | { 58 | _Ty event; 59 | while (count-- > 0 && this->try_dequeue(event)) 60 | func(std::move(event)); 61 | } 62 | void clear() { clear_queue(static_cast&>(*this)); } 63 | }; 64 | 65 | #else 66 | template 67 | inline _Ty* release_pointer(_Ty*& pointer) 68 | { 69 | auto tmp = pointer; 70 | pointer = nullptr; 71 | return tmp; 72 | } 73 | template 74 | class concurrent_queue_primitive { 75 | struct concurrent_item { 76 | 77 | public: 78 | concurrent_item() : pitem_(nullptr), pmtx_(nullptr) {} 79 | concurrent_item(_Ty* pitem, std::recursive_mutex* pmtx) : pitem_(pitem), pmtx_(pmtx) {} 80 | concurrent_item(const concurrent_item&) = delete; 81 | concurrent_item(concurrent_item&& rhs) : pitem_(release_pointer(rhs.pitem_)), pmtx_(release_pointer(rhs.pmtx_)) {} 82 | ~concurrent_item() 83 | { 84 | if (pmtx_ != nullptr) 85 | pmtx_->unlock(); 86 | } 87 | 88 | explicit operator bool() { return pitem_ != nullptr; } 89 | 90 | _Ty& operator*() { return *pitem_; } 91 | 92 | private: 93 | _Ty* pitem_; // the locked item 94 | std::recursive_mutex* pmtx_; 95 | }; 96 | 97 | public: 98 | template 99 | void emplace(_Types&&... values) 100 | { 101 | std::lock_guard lck(this->mtx_); 102 | queue_.emplace(std::forward<_Types>(values)...); 103 | } 104 | 105 | void pop() { queue_.pop(); } 106 | bool empty() const { return this->queue_.empty(); } 107 | void clear() 108 | { 109 | std::lock_guard lck(this->mtx_); 110 | clear_queue(this->queue_); 111 | } 112 | 113 | // peek item to read/write thread safe 114 | concurrent_item peek() 115 | { 116 | if (!empty()) 117 | { 118 | mtx_.lock(); 119 | if (!empty()) 120 | return concurrent_item{&queue_.front(), &mtx_}; 121 | mtx_.unlock(); 122 | } 123 | return concurrent_item{}; 124 | } 125 | 126 | protected: 127 | std::queue<_Ty> queue_; 128 | std::recursive_mutex mtx_; 129 | }; 130 | template 131 | class concurrent_queue<_Ty, false> : public concurrent_queue_primitive<_Ty> {}; 132 | template 133 | class concurrent_queue<_Ty, true> : public concurrent_queue_primitive<_Ty> { 134 | public: 135 | void consume(int count, const std::function& func) 136 | { 137 | if (this->deal_.empty()) 138 | { 139 | if (this->queue_.empty()) 140 | return; 141 | else 142 | { 143 | // swap event queue 144 | std::lock_guard lck(this->mtx_); 145 | std::swap(this->deal_, this->queue_); 146 | } 147 | } 148 | 149 | while (count-- > 0 && !this->deal_.empty()) 150 | { 151 | auto event = std::move(this->deal_.front()); 152 | deal_.pop(); 153 | func(std::move(event)); 154 | }; 155 | } 156 | 157 | size_t count() { return this->queue_.size() + this->deal_.size(); } 158 | 159 | void clear() 160 | { 161 | concurrent_queue_primitive<_Ty>::clear(); 162 | clear_queue(deal_); 163 | } 164 | 165 | private: 166 | std::queue<_Ty> deal_; 167 | }; 168 | #endif 169 | } // namespace privacy 170 | } // namespace yasio 171 | 172 | #endif 173 | -------------------------------------------------------------------------------- /Plugins/yasio/Source/yasio/Public/yasio/impl/epoll_io_watcher.hpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////////////////// 2 | // A multi-platform support c++11 library with focus on asynchronous socket I/O for any 3 | // client application. 4 | ////////////////////////////////////////////////////////////////////////////////////////// 5 | // 6 | // Copyright (c) 2012-2024 HALX99 (halx99 at live dot com) 7 | #ifndef YASIO__EPOLL_IO_WATCHER_HPP 8 | #define YASIO__EPOLL_IO_WATCHER_HPP 9 | #include 10 | #include 11 | #include 12 | #include "yasio/pod_vector.hpp" 13 | #include "yasio/impl/socket.hpp" 14 | #include "yasio/impl/select_interrupter.hpp" 15 | 16 | #if !defined(_WIN32) 17 | # define epoll_close close 18 | typedef int epoll_handle_t; 19 | #else 20 | # include "wepoll/wepoll.h" 21 | # undef YASIO__HAS_EPOLL 22 | # define YASIO__HAS_EPOLL 1 23 | typedef void* epoll_handle_t; 24 | #endif 25 | 26 | namespace yasio 27 | { 28 | YASIO__NS_INLINE 29 | namespace inet 30 | { 31 | class epoll_io_watcher { 32 | public: 33 | epoll_io_watcher() : epoll_handle_(do_epoll_create()) 34 | { 35 | this->revents_.reserve(16); 36 | this->mod_event(interrupter_.read_descriptor(), socket_event::read, 0, EPOLLONESHOT); 37 | interrupter_.interrupt(); 38 | poll_io(1); 39 | } 40 | ~epoll_io_watcher() 41 | { 42 | this->mod_event(interrupter_.read_descriptor(), 0, socket_event::read, EPOLLONESHOT); 43 | epoll_close(epoll_handle_); 44 | } 45 | 46 | void mod_event(socket_native_type fd, int add_events, int remove_events, int flags = 0) 47 | { 48 | auto it = events_.find(fd); 49 | const auto registered = it != events_.end(); 50 | int underlying_events = registered ? it->second : 0; 51 | underlying_events |= to_underlying_events(add_events); 52 | underlying_events &= ~to_underlying_events(remove_events); 53 | 54 | epoll_event ev = {0, {0}}; 55 | ev.events = underlying_events | flags; 56 | ev.data.fd = static_cast(fd); 57 | 58 | if (underlying_events) 59 | { // add or mod 60 | if (::epoll_ctl(epoll_handle_, !registered ? EPOLL_CTL_ADD : EPOLL_CTL_MOD, fd, &ev) == 0) 61 | { 62 | if (registered) 63 | it->second = underlying_events; 64 | else 65 | events_[fd] = underlying_events; 66 | } 67 | } 68 | else 69 | { // del if registered 70 | if (registered) 71 | { 72 | ::epoll_ctl(epoll_handle_, EPOLL_CTL_DEL, fd, &ev); 73 | events_.erase(it); 74 | } 75 | } 76 | 77 | max_events_ = (std::min)(static_cast(events_.size()), 128); 78 | } 79 | 80 | int poll_io(int64_t waitd_us) 81 | { 82 | assert(max_events_ > 0); 83 | this->revents_.reset(max_events_); 84 | 85 | #if YASIO__HAS_EPOLL_PWAIT2 86 | timespec timeout = {(decltype(timespec::tv_sec))(waitd_us / std::micro::den), 87 | (decltype(timespec::tv_nsec))((waitd_us % std::micro::den) * std::milli::den)}; 88 | int num_events = ::epoll_pwait2(epoll_handle_, revents_.data(), static_cast(revents_.size()), &timeout, nullptr); 89 | #else 90 | int num_events = ::epoll_wait(epoll_handle_, revents_.data(), static_cast(revents_.size()), static_cast(waitd_us / std::milli::den)); 91 | #endif 92 | nrevents_ = num_events; 93 | if (num_events > 0 && is_ready(this->interrupter_.read_descriptor(), socket_event::read)) 94 | --num_events; 95 | return num_events; 96 | } 97 | 98 | void wakeup() 99 | { 100 | epoll_event ev = {0, {0}}; 101 | ev.events = EPOLLIN | EPOLLERR | EPOLLONESHOT; 102 | ev.data.ptr = &interrupter_; 103 | epoll_ctl(epoll_handle_, EPOLL_CTL_MOD, interrupter_.read_descriptor(), &ev); 104 | } 105 | 106 | int is_ready(socket_native_type fd, int events) const 107 | { 108 | int underlying_events = 0; 109 | if (events & socket_event::read) 110 | underlying_events |= EPOLLIN; 111 | if (events & socket_event::write) 112 | underlying_events |= EPOLLOUT; 113 | if (events & socket_event::error) 114 | underlying_events |= (EPOLLERR | EPOLLHUP | EPOLLPRI); 115 | auto it = std::find_if(revents_.begin(), revents_.begin() + nrevents_, [fd](const epoll_event& ev) { return ev.data.fd == fd; }); 116 | return it != this->revents_.end() ? (it->events & underlying_events) : 0; 117 | } 118 | 119 | int max_descriptor() const { return -1; } 120 | 121 | protected: 122 | int to_underlying_events(int events) 123 | { 124 | int underlying_events = 0; 125 | if (events) 126 | { 127 | if (yasio__testbits(events, socket_event::read)) 128 | underlying_events |= EPOLLIN; 129 | 130 | if (yasio__testbits(events, socket_event::write)) 131 | underlying_events |= EPOLLOUT; 132 | 133 | if (yasio__testbits(events, socket_event::error)) 134 | underlying_events |= EPOLLERR; 135 | } 136 | return underlying_events; 137 | } 138 | 139 | enum 140 | { 141 | epoll_size = 20000 142 | }; 143 | epoll_handle_t do_epoll_create() 144 | { 145 | #if defined(EPOLL_CLOEXEC) 146 | epoll_handle_t handle = epoll_create1(EPOLL_CLOEXEC); 147 | #else // defined(EPOLL_CLOEXEC) 148 | epoll_handle_t handle = (epoll_handle_t)-1; 149 | errno = EINVAL; 150 | #endif // defined(EPOLL_CLOEXEC) 151 | 152 | if (handle == (epoll_handle_t)-1 && (errno == EINVAL || errno == ENOSYS)) 153 | handle = epoll_create(epoll_size); 154 | 155 | return handle; 156 | } 157 | 158 | epoll_handle_t epoll_handle_; 159 | 160 | int max_events_ = 0; 161 | int nrevents_ = 0; 162 | std::map events_; 163 | yasio::pod_vector revents_; 164 | 165 | select_interrupter interrupter_; 166 | }; 167 | } // namespace inet 168 | } // namespace yasio 169 | #endif 170 | -------------------------------------------------------------------------------- /Plugins/yasio/Source/yasio/Public/yasio/impl/eventfd_select_interrupter.hpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////////////////// 2 | // A multi-platform support c++11 library with focus on asynchronous socket I/O for any 3 | // client application. 4 | ////////////////////////////////////////////////////////////////////////////////////////// 5 | // 6 | // Copyright (c) 2012-2024 HALX99 (halx99 at live dot com) 7 | // Copyright (c) 2003-2020 Christopher M. Kohlhoff (chris at kohlhoff dot com) 8 | // Copyright (c) 2008 Roelof Naude (roelof.naude at gmail dot com) 9 | // 10 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 11 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 12 | // 13 | // see also: https://github.com/chriskohlhoff/asio 14 | // 15 | #ifndef YASIO__EVENTFD_SELECT_INTERRUPTER_HPP 16 | #define YASIO__EVENTFD_SELECT_INTERRUPTER_HPP 17 | 18 | #include "yasio/compiler/feature_test.hpp" 19 | 20 | #include 21 | #include 22 | #include 23 | #if defined(__GLIBC__) && (__GLIBC__ == 2 && __GLIBC_MINOR__ < 8) 24 | # include 25 | #else // __GLIBC__ == 2 && __GLIBC_MINOR__ < 8 26 | # include 27 | #endif // __GLIBC__ == 2 && __GLIBC_MINOR__ < 8 28 | 29 | #include 30 | 31 | namespace yasio 32 | { 33 | YASIO__NS_INLINE 34 | namespace inet 35 | { 36 | 37 | class eventfd_select_interrupter { 38 | public: 39 | // Constructor. 40 | inline eventfd_select_interrupter() { open_descriptors(); } 41 | 42 | // Destructor. 43 | inline ~eventfd_select_interrupter() { close_descriptors(); } 44 | 45 | // Recreate the interrupter's descriptors. Used after a fork. 46 | inline void recreate() 47 | { 48 | close_descriptors(); 49 | 50 | write_descriptor_ = -1; 51 | read_descriptor_ = -1; 52 | 53 | open_descriptors(); 54 | } 55 | 56 | // Interrupt the select call. 57 | inline void interrupt() 58 | { 59 | uint64_t counter(1UL); 60 | int result = ::write(write_descriptor_, &counter, sizeof(uint64_t)); 61 | (void)result; 62 | } 63 | 64 | // Reset the select interrupter. Returns true if the reset was successful. 65 | inline bool reset() 66 | { 67 | if (write_descriptor_ == read_descriptor_) 68 | { 69 | for (;;) 70 | { 71 | // Only perform one read. The kernel maintains an atomic counter. 72 | uint64_t counter(0); 73 | errno = 0; 74 | int bytes_read = ::read(read_descriptor_, &counter, sizeof(uint64_t)); 75 | if (bytes_read < 0 && errno == EINTR) 76 | continue; 77 | return true; 78 | } 79 | } 80 | else 81 | { 82 | char data[1024]; 83 | for (;;) 84 | { 85 | // Clear all data from the pipe. 86 | int bytes_read = ::read(read_descriptor_, data, sizeof(data)); 87 | if (bytes_read == sizeof(data)) 88 | continue; 89 | if (bytes_read > 0) 90 | return true; 91 | if (bytes_read == 0) 92 | return false; 93 | int ec = errno; 94 | if (ec == EINTR) 95 | continue; 96 | return (ec == EWOULDBLOCK || ec == EAGAIN); 97 | } 98 | } 99 | } 100 | 101 | // Get the read descriptor to be passed to select. 102 | int read_descriptor() const { return read_descriptor_; } 103 | 104 | private: 105 | // Open the descriptors. Throws on error. 106 | inline void open_descriptors() 107 | { 108 | #if defined(__GLIBC__) && (__GLIBC__ == 2 && __GLIBC_MINOR__ < 8) 109 | write_descriptor_ = read_descriptor_ = syscall(__NR_eventfd, 0); 110 | if (read_descriptor_ != -1) 111 | { 112 | ::fcntl(read_descriptor_, F_SETFL, O_NONBLOCK); 113 | ::fcntl(read_descriptor_, F_SETFD, FD_CLOEXEC); 114 | } 115 | #else // __GLIBC__ == 2 && __GLIBC_MINOR__ < 8 116 | # if defined(EFD_CLOEXEC) && defined(EFD_NONBLOCK) 117 | write_descriptor_ = read_descriptor_ = ::eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK); 118 | # else // defined(EFD_CLOEXEC) && defined(EFD_NONBLOCK) 119 | errno = EINVAL; 120 | write_descriptor_ = read_descriptor_ = -1; 121 | # endif // defined(EFD_CLOEXEC) && defined(EFD_NONBLOCK) 122 | if (read_descriptor_ == -1 && errno == EINVAL) 123 | { 124 | write_descriptor_ = read_descriptor_ = ::eventfd(0, 0); 125 | if (read_descriptor_ != -1) 126 | { 127 | ::fcntl(read_descriptor_, F_SETFL, O_NONBLOCK); 128 | ::fcntl(read_descriptor_, F_SETFD, FD_CLOEXEC); 129 | } 130 | } 131 | #endif // __GLIBC__ == 2 && __GLIBC_MINOR__ < 8 132 | 133 | if (read_descriptor_ == -1) 134 | { 135 | int pipe_fds[2]; 136 | if (pipe(pipe_fds) == 0) 137 | { 138 | read_descriptor_ = pipe_fds[0]; 139 | ::fcntl(read_descriptor_, F_SETFL, O_NONBLOCK); 140 | ::fcntl(read_descriptor_, F_SETFD, FD_CLOEXEC); 141 | write_descriptor_ = pipe_fds[1]; 142 | ::fcntl(write_descriptor_, F_SETFL, O_NONBLOCK); 143 | ::fcntl(write_descriptor_, F_SETFD, FD_CLOEXEC); 144 | } 145 | else 146 | yasio__throw_error(errno, "eventfd_select_interrupter"); 147 | } 148 | } 149 | 150 | // Close the descriptors. 151 | inline void close_descriptors() 152 | { 153 | if (write_descriptor_ != -1 && write_descriptor_ != read_descriptor_) 154 | ::close(write_descriptor_); 155 | if (read_descriptor_ != -1) 156 | ::close(read_descriptor_); 157 | } 158 | 159 | // The read end of a connection used to interrupt the select call. This file 160 | // descriptor is passed to select such that when it is time to stop, a single 161 | // 64bit value will be written on the other end of the connection and this 162 | // descriptor will become readable. 163 | int read_descriptor_; 164 | 165 | // The write end of a connection used to interrupt the select call. A single 166 | // 64bit non-zero value may be written to this to wake up the select which is 167 | // waiting for the other end to become readable. This descriptor will only 168 | // differ from the read descriptor when a pipe is used. 169 | int write_descriptor_; 170 | }; 171 | 172 | } // namespace inet 173 | } // namespace yasio 174 | 175 | #endif // YASIO__EVENTFD_SELECT_INTERRUPTER_HPP 176 | -------------------------------------------------------------------------------- /Plugins/yasio/Source/yasio/Public/yasio/impl/evport_io_watcher.hpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////////////////// 2 | // A multi-platform support c++11 library with focus on asynchronous socket I/O for any 3 | // client application. 4 | ////////////////////////////////////////////////////////////////////////////////////////// 5 | // 6 | // Copyright (c) 2012-2024 HALX99 (halx99 at live dot com) 7 | #ifndef YASIO__EVPORT_IO_WATCHER_HPP 8 | #define YASIO__EVPORT_IO_WATCHER_HPP 9 | #include 10 | #include 11 | 12 | #include 13 | 14 | #include "yasio/pod_vector.hpp" 15 | #include "yasio/impl/socket.hpp" 16 | #include "yasio/impl/select_interrupter.hpp" 17 | 18 | /* 19 | * port_event_t 20 | * struct { 21 | * int portev_events; 22 | * ushort_t portev_source; 23 | * uintptr_t portev_object; 24 | * void* portev_user; 25 | * } 26 | */ 27 | 28 | namespace yasio 29 | { 30 | YASIO__NS_INLINE 31 | namespace inet 32 | { 33 | class evport_io_watcher { 34 | public: 35 | evport_io_watcher() : port_handle_(::port_create()) { this->revents_.reserve(16); } 36 | ~evport_io_watcher() { ::close(port_handle_); } 37 | 38 | void mod_event(socket_native_type fd, int add_events, int remove_events, int flags = 0) 39 | { 40 | auto it = events_.find(fd); 41 | const auto registered = it != events_.end(); 42 | int underlying_events = registered ? it->second : 0; 43 | underlying_events |= to_underlying_events(add_events); 44 | underlying_events &= ~to_underlying_events(remove_events); 45 | 46 | if (underlying_events) 47 | { // add or mod 48 | if (::port_associate(port_handle_, PORT_SOURCE_FD, fd, underlying_events, nullptr) == 0) 49 | { 50 | if (registered) 51 | it->second = underlying_events; 52 | else 53 | events_[fd] = underlying_events; 54 | } 55 | } 56 | else 57 | { // del if registered 58 | if (registered) 59 | { 60 | ::port_dissociate(port_handle_, PORT_SOURCE_FD, fd); 61 | events_.erase(it); 62 | } 63 | } 64 | max_events_ = (std::min)(static_cast(events_.size()), 128u); 65 | } 66 | 67 | int poll_io(int64_t waitd_us) 68 | { 69 | assert(max_events_ > 0); 70 | this->revents_.reset(max_events_); 71 | 72 | timespec timeout = {(decltype(timespec::tv_sec))(waitd_us / std::micro::den), 73 | (decltype(timespec::tv_nsec))((waitd_us % std::micro::den) * std::milli::den)}; 74 | 75 | // The nget argument points to the desired number of events to be retrieved. 76 | // On return, the value pointed to by nget is updated to the actual number of events retrieved in list. 77 | uint_t num_events = 1; 78 | auto ret = ::port_getn(port_handle_, revents_.data(), static_cast(revents_.size()), &num_events, &timeout); 79 | 80 | // re-associate 81 | /* 82 | * PORT_SOURCE_FD events represent a transition in the poll(2) status of a given file descriptor. 83 | * Once an event is delivered, the file descriptor is no longer associated with the port. 84 | * A file descriptor is associated (or re-associated) with a port using the port_associate(3C) function. 85 | * refer to: https://docs.oracle.com/cd/E19253-01/816-5168/port-create-3c/index.html 86 | */ 87 | int interrupt_hint = 0; 88 | for (int i = 0; i < num_events; ++i) 89 | { 90 | auto event_source = revents_[i].portev_source; 91 | if (event_source != PORT_SOURCE_FD) 92 | { 93 | interrupt_hint = 1; 94 | continue; 95 | } 96 | int fd = static_cast(revents_[i].portev_object); 97 | auto underlying_events = events_[fd]; 98 | if (underlying_events) 99 | ::port_associate(port_handle_, PORT_SOURCE_FD, fd, underlying_events, nullptr); 100 | } 101 | 102 | nrevents_ = num_events; 103 | num_events -= interrupt_hint; 104 | } 105 | 106 | void wakeup() { ::port_send(port_handle_, POLLIN, nullptr); } 107 | 108 | int is_ready(socket_native_type fd, int events) const 109 | { 110 | int underlying_events = 0; 111 | if (events & socket_event::read) 112 | underlying_events |= POLLIN; 113 | if (events & socket_event::write) 114 | underlying_events |= POLLOUT; 115 | if (events & socket_event::error) 116 | underlying_events |= (POLLERR | POLLHUP | POLLPRI); 117 | auto it = std::find_if(revents_.begin(), this->revents_.begin() + static_cast(nrevents_), 118 | [fd](const port_event_t& ev) { return static_cast(ev.portev_object) == fd; }); 119 | return it != this->revents_.end() ? (it->portev_events & underlying_events) : 0; 120 | } 121 | 122 | int max_descriptor() const { return -1; } 123 | 124 | protected: 125 | int to_underlying_events(int events) 126 | { 127 | int underlying_events = 0; 128 | if (events) 129 | { 130 | if (yasio__testbits(events, socket_event::read)) 131 | underlying_events |= POLLIN; 132 | 133 | if (yasio__testbits(events, socket_event::write)) 134 | underlying_events |= POLLOUT; 135 | 136 | if (yasio__testbits(events, socket_event::error)) 137 | underlying_events |= POLLERR; 138 | } 139 | return underlying_events; 140 | } 141 | 142 | int port_handle_; 143 | uint_t max_events_ = 0; 144 | uint_t nrevents_ = 0; 145 | std::map events_; 146 | yasio::pod_vector revents_; 147 | }; 148 | } // namespace inet 149 | } // namespace yasio 150 | #endif 151 | -------------------------------------------------------------------------------- /Plugins/yasio/Source/yasio/Public/yasio/impl/fp16.hpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////////////////// 2 | // A multi-platform support c++11 library with focus on asynchronous socket I/O for any 3 | // client application. 4 | ////////////////////////////////////////////////////////////////////////////////////////// 5 | /* 6 | The MIT License (MIT) 7 | 8 | Copyright (c) 2012-2024 HALX99 9 | 10 | Permission is hereby granted, free of charge, to any person obtaining a copy 11 | of this software and associated documentation files (the "Software"), to deal 12 | in the Software without restriction, including without limitation the rights 13 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 14 | copies of the Software, and to permit persons to whom the Software is 15 | furnished to do so, subject to the following conditions: 16 | The above copyright notice and this permission notice shall be included in all 17 | copies or substantial portions of the Software. 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | */ 26 | #ifndef YASIO__FP16_HPP 27 | #define YASIO__FP16_HPP 28 | #include "yasio/config.hpp" 29 | 30 | #if defined(YASIO_ENABLE_HALF_FLOAT) 31 | // Includes IEEE 754 16-bit half-precision floating-point library 32 | # include "half/half.hpp" 33 | typedef half_float::half fp16_t; 34 | #endif 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /Plugins/yasio/Source/yasio/Public/yasio/impl/kqueue_io_watcher.hpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////////////////// 2 | // A multi-platform support c++11 library with focus on asynchronous socket I/O for any 3 | // client application. 4 | ////////////////////////////////////////////////////////////////////////////////////////// 5 | // 6 | // Copyright (c) 2012-2024 HALX99 (halx99 at live dot com) 7 | #ifndef YASIO__KQUEUE_IO_WATCHER_HPP 8 | #define YASIO__KQUEUE_IO_WATCHER_HPP 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include "yasio/pod_vector.hpp" 15 | #include "yasio/impl/socket.hpp" 16 | #include "yasio/impl/select_interrupter.hpp" 17 | 18 | #if defined(__NetBSD__) && __NetBSD_Version__ < 999001500 19 | # define YASIO_KQUEUE_EV_SET(ev, ident, filt, flags, fflags, data, udata) \ 20 | EV_SET(ev, ident, filt, flags, fflags, data, reinterpret_cast(static_cast(udata))) 21 | #else 22 | # define YASIO_KQUEUE_EV_SET(ev, ident, filt, flags, fflags, data, udata) EV_SET(ev, ident, filt, flags, fflags, data, udata) 23 | #endif 24 | 25 | namespace yasio 26 | { 27 | YASIO__NS_INLINE 28 | namespace inet 29 | { 30 | class kqueue_io_watcher { 31 | public: 32 | kqueue_io_watcher() : kqueue_fd_(kqueue()) 33 | { 34 | revents_.reserve(32); 35 | this->register_event(interrupter_.read_descriptor(), socket_event::read); 36 | } 37 | ~kqueue_io_watcher() 38 | { 39 | this->deregister_event(interrupter_.read_descriptor(), socket_event::read); 40 | close(kqueue_fd_); 41 | } 42 | 43 | void mod_event(socket_native_type fd, int add_events, int remove_events) 44 | { 45 | if (add_events) 46 | register_event(fd, add_events); 47 | if (remove_events) 48 | deregister_event(fd, remove_events); 49 | } 50 | 51 | int poll_io(int64_t waitd_us) 52 | { 53 | assert(max_events_ > 0); 54 | revents_.reset(max_events_); 55 | 56 | timespec timeout = {(decltype(timespec::tv_sec))(waitd_us / std::micro::den), 57 | (decltype(timespec::tv_nsec))((waitd_us % std::micro::den) * std::milli::den)}; 58 | int num_events = kevent(kqueue_fd_, 0, 0, revents_.data(), static_cast(revents_.size()), &timeout); 59 | nrevents_ = num_events; 60 | if (num_events > 0 && is_ready(this->interrupter_.read_descriptor(), socket_event::read)) 61 | { 62 | if (!interrupter_.reset()) 63 | interrupter_.recreate(); 64 | --num_events; 65 | } 66 | return num_events; 67 | } 68 | 69 | void wakeup() { interrupter_.interrupt(); } 70 | 71 | int is_ready(socket_native_type fd, int events) const 72 | { 73 | auto it = std::find_if(revents_.begin(), this->revents_.begin() + nrevents_, [fd, events](const struct kevent& ev) { 74 | int rfd = static_cast(reinterpret_cast(ev.udata)); 75 | if (rfd == fd) 76 | { 77 | if (ev.flags & EV_ERROR) 78 | return !!(events & socket_event::error); 79 | switch (ev.filter) 80 | { 81 | case EVFILT_READ: 82 | return !!(events & socket_event::read); 83 | case EVFILT_WRITE: 84 | return !!(events & socket_event::write); 85 | #if defined(EVFILT_EXCEPT) 86 | case EVFILT_EXCEPT: 87 | return !!(events & socket_event::error); 88 | #endif 89 | default: 90 | return false; 91 | } 92 | } 93 | return false; 94 | }); 95 | return it != revents_.end() ? -it->filter : 0; 96 | } 97 | 98 | int max_descriptor() const { return -1; } 99 | 100 | protected: 101 | void register_event(socket_native_type fd, int events) 102 | { 103 | int prev_events = events_[fd]; 104 | int nkv_old = prev_events > 0 ? ((prev_events >> 1) + 1) : 0; 105 | 106 | struct kevent kevlist[3]; 107 | int nkvlist = 0; 108 | if (yasio__testbits(events, socket_event::read)) 109 | { 110 | YASIO_KQUEUE_EV_SET(&kevlist[nkvlist], fd, EVFILT_READ, EV_ADD, 0, 0, reinterpret_cast(static_cast(fd))); 111 | ++nkvlist; 112 | } 113 | 114 | if (yasio__testbits(events, socket_event::write)) 115 | { 116 | YASIO_KQUEUE_EV_SET(&kevlist[nkvlist], fd, EVFILT_WRITE, EV_ADD, 0, 0, reinterpret_cast(static_cast(fd))); 117 | ++nkvlist; 118 | } 119 | 120 | #if defined(EVFILT_EXCEPT) 121 | if (yasio__testbits(events, socket_event::error)) 122 | { 123 | YASIO_KQUEUE_EV_SET(&kevlist[nkvlist], fd, EVFILT_EXCEPT, EV_ADD, 0, 0, reinterpret_cast(static_cast(fd))); 124 | ++nkvlist; 125 | } 126 | #endif 127 | 128 | if (nkvlist > 0) 129 | { 130 | int ret = ::kevent(kqueue_fd_, kevlist, nkvlist, 0, 0, 0); 131 | if (ret != -1) 132 | { 133 | events_[fd] = events; 134 | int diff = nkvlist - nkv_old; 135 | if (diff != 0) 136 | max_events_ += diff; 137 | } 138 | } 139 | } 140 | 141 | void deregister_event(socket_native_type fd, int events) 142 | { 143 | int curr_events = events_[fd]; 144 | int curr_count = curr_events > 0 ? ((curr_events >> 1) + 1) : 0; 145 | 146 | struct kevent kevlist[3]; 147 | int nkvlist = 0; 148 | if (yasio__testbits(events, socket_event::read)) 149 | { 150 | curr_events &= ~socket_event::read; 151 | YASIO_KQUEUE_EV_SET(&kevlist[nkvlist], fd, EVFILT_READ, EV_DELETE, 0, 0, nullptr); 152 | ++nkvlist; 153 | } 154 | 155 | if (yasio__testbits(events, socket_event::write)) 156 | { 157 | curr_events &= ~socket_event::write; 158 | YASIO_KQUEUE_EV_SET(&kevlist[nkvlist], fd, EVFILT_WRITE, EV_DELETE, 0, 0, nullptr); 159 | ++nkvlist; 160 | } 161 | 162 | #if defined(EVFILT_EXCEPT) 163 | if (yasio__testbits(events, socket_event::error)) 164 | { 165 | curr_events &= ~socket_event::error; 166 | YASIO_KQUEUE_EV_SET(&kevlist[nkvlist], fd, EVFILT_EXCEPT, EV_DELETE, 0, 0, nullptr); 167 | ++nkvlist; 168 | } 169 | #endif 170 | 171 | if (nkvlist > 0) 172 | { 173 | int ret = ::kevent(kqueue_fd_, kevlist, nkvlist, 0, 0, 0); 174 | if (ret == 0) 175 | { 176 | if (curr_events != 0) 177 | events_[fd] = curr_events; 178 | else 179 | events_.erase(fd); 180 | int diff = nkvlist - curr_count; 181 | if (diff != 0) 182 | max_events_ += diff; 183 | } 184 | } 185 | } 186 | 187 | int kqueue_fd_; 188 | int max_events_ = 0; 189 | int nrevents_ = 0; 190 | std::map events_; 191 | yasio::pod_vector revents_; 192 | select_interrupter interrupter_; 193 | }; 194 | } // namespace inet 195 | } // namespace yasio 196 | #endif 197 | -------------------------------------------------------------------------------- /Plugins/yasio/Source/yasio/Public/yasio/impl/object_pool.hpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////////////////// 2 | // A multi-platform support c++11 library with focus on asynchronous socket I/O for any 3 | // client application. 4 | ////////////////////////////////////////////////////////////////////////////////////////// 5 | /* 6 | The MIT License (MIT) 7 | 8 | Copyright (c) 2012-2024 HALX99 9 | 10 | Permission is hereby granted, free of charge, to any person obtaining a copy 11 | of this software and associated documentation files (the "Software"), to deal 12 | in the Software without restriction, including without limitation the rights 13 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 14 | copies of the Software, and to permit persons to whom the Software is 15 | furnished to do so, subject to the following conditions: 16 | 17 | The above copyright notice and this permission notice shall be included in all 18 | copies or substantial portions of the Software. 19 | 20 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 23 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 24 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 25 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 26 | SOFTWARE. 27 | */ 28 | // core/impl/object_pool.hpp: a simple & high-performance object pool implementation v1.3.5 29 | #pragma once 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | #if defined(_MSC_VER) 39 | # pragma warning(push) 40 | # pragma warning(disable : 4200) 41 | #endif 42 | 43 | #define OBJECT_POOL_DECL inline 44 | 45 | namespace yasio 46 | { 47 | namespace detail 48 | { 49 | class object_pool { 50 | #if defined(_DEBUG) 51 | typedef struct free_link_node { 52 | free_link_node* next; 53 | }* free_link; 54 | #endif 55 | typedef struct chunk_link_node { 56 | union { 57 | chunk_link_node* next; 58 | char padding[sizeof(std::max_align_t)]; 59 | }; 60 | char data[0]; 61 | }* chunk_link; 62 | 63 | object_pool(const object_pool&) = delete; 64 | void operator=(const object_pool&) = delete; 65 | 66 | public: 67 | OBJECT_POOL_DECL object_pool(size_t element_size, size_t element_count) 68 | : first_(nullptr), chunk_(nullptr), element_size_(element_size), element_count_(element_count) 69 | { 70 | release(allocate_from_process_heap()); // preallocate 1 chunk 71 | } 72 | 73 | OBJECT_POOL_DECL object_pool(size_t element_size, size_t element_count, std::false_type /*preallocate?*/) 74 | : first_(nullptr), chunk_(nullptr), element_size_(element_size), element_count_(element_count) 75 | {} 76 | 77 | OBJECT_POOL_DECL virtual ~object_pool(void) { this->purge(); } 78 | 79 | OBJECT_POOL_DECL void purge(void) 80 | { 81 | if (this->chunk_ == nullptr) 82 | return; 83 | 84 | chunk_link_node *p, **q = &this->chunk_; 85 | while ((p = *q) != nullptr) 86 | { 87 | *q = p->next; 88 | delete[] (uint8_t*)(p); 89 | } 90 | 91 | first_ = nullptr; 92 | } 93 | 94 | OBJECT_POOL_DECL void cleanup(void) 95 | { 96 | if (this->chunk_ == nullptr) 97 | return; 98 | 99 | chunk_link_node* chunk = this->chunk_; 100 | void* last = this->tidy_chunk(chunk); 101 | 102 | while ((chunk = chunk->next) != nullptr) 103 | { 104 | nextof(last) = firstof(chunk); 105 | last = this->tidy_chunk(chunk); 106 | } 107 | 108 | nextof(last) = nullptr; 109 | 110 | first_ = firstof(this->chunk_); 111 | } 112 | 113 | OBJECT_POOL_DECL void* get(void) { return (first_ != nullptr) ? allocate_from_chunk(first_) : allocate_from_process_heap(); } 114 | 115 | OBJECT_POOL_DECL void release(void* _Ptr) 116 | { 117 | nextof(_Ptr) = first_; 118 | first_ = _Ptr; 119 | } 120 | 121 | private: 122 | OBJECT_POOL_DECL void* allocate_from_chunk(void* current) 123 | { 124 | first_ = nextof(current); 125 | return current; 126 | } 127 | OBJECT_POOL_DECL static void* firstof(chunk_link chunk) { return chunk->data; } 128 | OBJECT_POOL_DECL static void*& nextof(void* const ptr) { return *(static_cast(ptr)); } 129 | OBJECT_POOL_DECL void* allocate_from_process_heap(void) 130 | { 131 | chunk_link new_chunk = (chunk_link) new uint8_t[sizeof(chunk_link_node) + element_size_ * element_count_]; 132 | #ifdef _DEBUG 133 | ::memset(new_chunk, 0x00, sizeof(chunk_link_node)); 134 | #endif 135 | nextof(tidy_chunk(new_chunk)) = nullptr; 136 | 137 | // link the new_chunk 138 | new_chunk->next = this->chunk_; 139 | this->chunk_ = new_chunk; 140 | 141 | // allocate 1 object 142 | return allocate_from_chunk(firstof(new_chunk)); 143 | } 144 | 145 | OBJECT_POOL_DECL void* tidy_chunk(chunk_link chunk) 146 | { 147 | char* last = chunk->data + (element_count_ - 1) * element_size_; 148 | for (char* ptr = chunk->data; ptr < last; ptr += element_size_) 149 | nextof(ptr) = (ptr + element_size_); 150 | return last; 151 | } 152 | 153 | private: 154 | void* first_; // link to free head 155 | chunk_link chunk_; // chunk link 156 | const size_t element_size_; 157 | const size_t element_count_; 158 | }; 159 | } // namespace detail 160 | } // namespace yasio 161 | 162 | #if defined(_MSC_VER) 163 | # pragma warning(pop) 164 | #endif 165 | -------------------------------------------------------------------------------- /Plugins/yasio/Source/yasio/Public/yasio/impl/pipe_select_interrupter.hpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////////////////// 2 | // A multi-platform support c++11 library with focus on asynchronous socket I/O for any 3 | // client application. 4 | ////////////////////////////////////////////////////////////////////////////////////////// 5 | // 6 | // 7 | // Copyright (c) 2012-2024 HALX99 (halx99 at live dot com) 8 | // Copyright (c) 2003-2020 Christopher M. Kohlhoff (chris at kohlhoff dot com) 9 | // Copyright (c) 2008 Roelof Naude (roelof.naude at gmail dot com) 10 | // 11 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 12 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 13 | // 14 | // see also: https://github.com/chriskohlhoff/asio 15 | // 16 | #ifndef YASIO__PIPE_SELECT_INTERRUPTER_HPP 17 | #define YASIO__PIPE_SELECT_INTERRUPTER_HPP 18 | 19 | #include "yasio/compiler/feature_test.hpp" 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | namespace yasio 27 | { 28 | YASIO__NS_INLINE 29 | namespace inet 30 | { 31 | class pipe_select_interrupter { 32 | public: 33 | // Constructor. 34 | inline pipe_select_interrupter() { open_descriptors(); } 35 | 36 | // Destructor. 37 | inline ~pipe_select_interrupter() { close_descriptors(); } 38 | 39 | // Recreate the interrupter's descriptors. Used after a fork. 40 | inline void recreate() 41 | { 42 | close_descriptors(); 43 | 44 | write_descriptor_ = -1; 45 | read_descriptor_ = -1; 46 | 47 | open_descriptors(); 48 | } 49 | 50 | // Interrupt the select call. 51 | inline void interrupt() 52 | { 53 | char byte = 0; 54 | auto result = ::write(write_descriptor_, &byte, 1); 55 | (void)result; 56 | } 57 | 58 | // Reset the select interrupter. Returns true if the reset was successful. 59 | inline bool reset() 60 | { 61 | char data[1024]; 62 | for (;;) 63 | { 64 | // Clear all data from the pipe. 65 | int bytes_read = static_cast(::read(read_descriptor_, data, sizeof(data))); 66 | if (bytes_read == sizeof(data)) 67 | continue; 68 | if (bytes_read > 0) 69 | return true; 70 | if (bytes_read == 0) 71 | return false; 72 | int ec = errno; 73 | if (ec == EINTR) 74 | continue; 75 | return (ec == EWOULDBLOCK || ec == EAGAIN); 76 | } 77 | } 78 | 79 | // Get the read descriptor to be passed to select. 80 | int read_descriptor() const { return read_descriptor_; } 81 | 82 | private: 83 | // Open the descriptors. Throws on error. 84 | inline void open_descriptors() 85 | { 86 | int pipe_fds[2]; 87 | if (pipe(pipe_fds) == 0) 88 | { 89 | read_descriptor_ = pipe_fds[0]; 90 | ::fcntl(read_descriptor_, F_SETFL, O_NONBLOCK); 91 | write_descriptor_ = pipe_fds[1]; 92 | ::fcntl(write_descriptor_, F_SETFL, O_NONBLOCK); 93 | 94 | #if defined(FD_CLOEXEC) 95 | ::fcntl(read_descriptor_, F_SETFD, FD_CLOEXEC); 96 | ::fcntl(write_descriptor_, F_SETFD, FD_CLOEXEC); 97 | #endif // defined(FD_CLOEXEC) 98 | } 99 | else 100 | yasio__throw_error(errno, "pipe_select_interrupter"); 101 | } 102 | 103 | // Close the descriptors. 104 | inline void close_descriptors() 105 | { 106 | if (read_descriptor_ != -1) 107 | ::close(read_descriptor_); 108 | if (write_descriptor_ != -1) 109 | ::close(write_descriptor_); 110 | } 111 | 112 | // The read end of a connection used to interrupt the select call. This file 113 | // descriptor is passed to select such that when it is time to stop, a single 114 | // byte will be written on the other end of the connection and this 115 | // descriptor will become readable. 116 | int read_descriptor_; 117 | 118 | // The write end of a connection used to interrupt the select call. A single 119 | // byte may be written to this to wake up the select which is waiting for the 120 | // other end to become readable. 121 | int write_descriptor_; 122 | }; 123 | 124 | } // namespace inet 125 | } // namespace yasio 126 | 127 | #endif // YASIO__PIPE_SELECT_INTERRUPTER_HPP 128 | -------------------------------------------------------------------------------- /Plugins/yasio/Source/yasio/Public/yasio/impl/poll_io_watcher.hpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////////////////// 2 | // A multi-platform support c++11 library with focus on asynchronous socket I/O for any 3 | // client application. 4 | ////////////////////////////////////////////////////////////////////////////////////////// 5 | // 6 | // Copyright (c) 2012-2024 HALX99 (halx99 at live dot com) 7 | #ifndef YASIO__POLL_IO_WATCHER_HPP 8 | #define YASIO__POLL_IO_WATCHER_HPP 9 | #include "yasio/pod_vector.hpp" 10 | #include "yasio/impl/socket.hpp" 11 | #include "yasio/impl/select_interrupter.hpp" 12 | 13 | namespace yasio 14 | { 15 | YASIO__NS_INLINE 16 | namespace inet 17 | { 18 | class poll_io_watcher { 19 | public: 20 | poll_io_watcher() { this->mod_event(interrupter_.read_descriptor(), socket_event::read, 0); } 21 | 22 | void mod_event(socket_native_type fd, int add_events, int remove_events) 23 | { 24 | pollfd_mod(this->events_, fd, to_underlying_events(add_events), to_underlying_events(remove_events)); 25 | } 26 | 27 | int poll_io(int64_t waitd_us) 28 | { 29 | revents_ = this->events_; 30 | #if YASIO__HAS_PPOLL 31 | timespec timeout = {(decltype(timespec::tv_sec))(waitd_us / std::micro::den), 32 | (decltype(timespec::tv_nsec))((waitd_us % std::micro::den) * std::milli::den)}; 33 | int num_events = ::ppoll(this->revents_.data(), static_cast(this->revents_.size()), &timeout, nullptr); 34 | #else 35 | int num_events = ::poll(this->revents_.data(), static_cast(this->revents_.size()), static_cast(waitd_us / std::milli::den)); 36 | #endif 37 | if (num_events > 0 && is_ready(this->interrupter_.read_descriptor(), socket_event::read)) 38 | { 39 | if (!interrupter_.reset()) 40 | interrupter_.recreate(); 41 | --num_events; 42 | } 43 | return num_events; 44 | } 45 | 46 | void wakeup() { interrupter_.interrupt(); } 47 | 48 | int is_ready(socket_native_type fd, int events) const 49 | { 50 | int underlying_events = 0; 51 | if (events & socket_event::read) 52 | underlying_events |= POLLIN; 53 | if (events & socket_event::write) 54 | underlying_events |= POLLOUT; 55 | if (events & socket_event::error) 56 | underlying_events |= (POLLERR | POLLHUP | POLLNVAL); 57 | auto it = std::find_if(this->revents_.begin(), this->revents_.end(), [fd](const pollfd& pfd) { return pfd.fd == fd; }); 58 | return it != this->revents_.end() ? (it->revents & underlying_events) : 0; 59 | } 60 | 61 | int max_descriptor() const { return -1; } 62 | 63 | protected: 64 | int to_underlying_events(int events) 65 | { 66 | int underlying_events = 0; 67 | if (events) 68 | { 69 | if (yasio__testbits(events, socket_event::read)) 70 | underlying_events |= POLLIN; 71 | 72 | if (yasio__testbits(events, socket_event::write)) 73 | underlying_events |= POLLOUT; 74 | 75 | if (yasio__testbits(events, socket_event::error)) 76 | underlying_events |= POLLERR; 77 | } 78 | return underlying_events; 79 | } 80 | static void pollfd_mod(yasio::pod_vector& fdset, socket_native_type fd, int add_events, int remove_events) 81 | { 82 | auto it = std::find_if(fdset.begin(), fdset.end(), [fd](const pollfd& pfd) { return pfd.fd == fd; }); 83 | if (it != fdset.end()) 84 | { 85 | it->events |= add_events; 86 | it->events &= ~remove_events; 87 | if (it->events == 0) 88 | fdset.erase(it); 89 | } 90 | else 91 | { 92 | auto events = add_events & ~remove_events; 93 | if (events) 94 | fdset.emplace_back(fd, static_cast(events), static_cast(0)); 95 | } 96 | } 97 | 98 | protected: 99 | yasio::pod_vector events_; 100 | yasio::pod_vector revents_; 101 | 102 | select_interrupter interrupter_; 103 | }; 104 | } // namespace inet 105 | } // namespace yasio 106 | #endif 107 | -------------------------------------------------------------------------------- /Plugins/yasio/Source/yasio/Public/yasio/impl/select_interrupter.hpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////////////////// 2 | // A multi-platform support c++11 library with focus on asynchronous socket I/O for any 3 | // client application. 4 | ////////////////////////////////////////////////////////////////////////////////////////// 5 | // 6 | // Copyright (c) 2012-2024 HALX99 (halx99 at live dot com) 7 | // Copyright (c) 2003-2020 Christopher M. Kohlhoff (chris at kohlhoff dot com) 8 | // 9 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 10 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 11 | // 12 | // see also: https://github.com/chriskohlhoff/asio 13 | // 14 | #ifndef YASIO__SELECT_INTERRUPTER_HPP 15 | #define YASIO__SELECT_INTERRUPTER_HPP 16 | 17 | #include "yasio/compiler/feature_test.hpp" 18 | 19 | #if defined(_WIN32) 20 | # include "yasio/impl/socket_select_interrupter.hpp" 21 | #elif defined(__linux__) 22 | # include "yasio/impl/eventfd_select_interrupter.hpp" 23 | #else 24 | # include "yasio/impl/pipe_select_interrupter.hpp" 25 | #endif 26 | 27 | namespace yasio 28 | { 29 | YASIO__NS_INLINE 30 | namespace inet 31 | { 32 | 33 | #if defined(_WIN32) 34 | typedef socket_select_interrupter select_interrupter; 35 | #elif defined(__linux__) 36 | typedef eventfd_select_interrupter select_interrupter; 37 | #else 38 | typedef pipe_select_interrupter select_interrupter; 39 | #endif 40 | 41 | } // namespace inet 42 | } // namespace yasio 43 | 44 | #endif // YASIO__SELECT_INTERRUPTER_HPP 45 | -------------------------------------------------------------------------------- /Plugins/yasio/Source/yasio/Public/yasio/impl/select_io_watcher.hpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////////////////// 2 | // A multi-platform support c++11 library with focus on asynchronous socket I/O for any 3 | // client application. 4 | ////////////////////////////////////////////////////////////////////////////////////////// 5 | // 6 | // Copyright (c) 2012-2024 HALX99 (halx99 at live dot com) 7 | #ifndef YASIO__SELECT_IO_WATCHER_HPP 8 | #define YASIO__SELECT_IO_WATCHER_HPP 9 | #include 10 | #include 11 | #include "yasio/impl/socket.hpp" 12 | #include "yasio/impl/select_interrupter.hpp" 13 | 14 | namespace yasio 15 | { 16 | YASIO__NS_INLINE 17 | namespace inet 18 | { 19 | class select_io_watcher { 20 | public: 21 | select_io_watcher() 22 | { 23 | FD_ZERO(&events_[read_op]); 24 | FD_ZERO(&events_[write_op]); 25 | FD_ZERO(&events_[except_op]); 26 | this->mod_event(interrupter_.read_descriptor(), socket_event::read, 0); 27 | } 28 | 29 | void mod_event(socket_native_type fd, int add_events, int remove_events) 30 | { 31 | if (add_events) 32 | { 33 | if (yasio__testbits(add_events, socket_event::read)) 34 | FD_SET(fd, &(events_[read_op])); 35 | 36 | if (yasio__testbits(add_events, socket_event::write)) 37 | FD_SET(fd, &(events_[write_op])); 38 | 39 | if (yasio__testbits(add_events, socket_event::error)) 40 | FD_SET(fd, &(events_[except_op])); 41 | 42 | if (max_descriptor_ < static_cast(fd) + 1) 43 | max_descriptor_ = static_cast(fd) + 1; 44 | } 45 | 46 | if (remove_events) 47 | { 48 | if (yasio__testbits(remove_events, socket_event::read)) 49 | FD_CLR(fd, &(events_[read_op])); 50 | 51 | if (yasio__testbits(remove_events, socket_event::write)) 52 | FD_CLR(fd, &(events_[write_op])); 53 | 54 | if (yasio__testbits(remove_events, socket_event::error)) 55 | FD_CLR(fd, &(events_[except_op])); 56 | } 57 | } 58 | 59 | int poll_io(int64_t waitd_us) 60 | { 61 | ::memcpy(this->revents_, events_, sizeof(revents_)); 62 | timeval timeout = {(decltype(timeval::tv_sec))(waitd_us / std::micro::den), (decltype(timeval::tv_usec))(waitd_us % std::micro::den)}; 63 | int num_events = ::select(this->max_descriptor_, &(revents_[read_op]), &(revents_[write_op]), nullptr, &timeout); 64 | if (num_events > 0 && is_ready(this->interrupter_.read_descriptor(), socket_event::read)) 65 | { 66 | if (!interrupter_.reset()) 67 | interrupter_.recreate(); 68 | --num_events; 69 | } 70 | return num_events; 71 | } 72 | 73 | void wakeup() { interrupter_.interrupt(); } 74 | 75 | int is_ready(socket_native_type fd, int events) const 76 | { 77 | int retval = 0; 78 | if (events & socket_event::read) 79 | retval |= FD_ISSET(fd, &revents_[read_op]); 80 | if (events & socket_event::write) 81 | retval |= FD_ISSET(fd, &revents_[write_op]); 82 | if (events & socket_event::error) 83 | retval |= FD_ISSET(fd, &revents_[except_op]); 84 | return retval; 85 | } 86 | 87 | int max_descriptor() const { return max_descriptor_; } 88 | 89 | protected: 90 | enum 91 | { 92 | read_op, 93 | write_op, 94 | except_op, 95 | max_ops, 96 | }; 97 | fd_set events_[max_ops]; 98 | fd_set revents_[max_ops]; 99 | int max_descriptor_ = 0; 100 | 101 | select_interrupter interrupter_; 102 | }; 103 | } // namespace inet 104 | } // namespace yasio 105 | #endif 106 | -------------------------------------------------------------------------------- /Plugins/yasio/Source/yasio/Public/yasio/impl/socket.hpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////////////////// 2 | // A multi-platform support c++11 library with focus on asynchronous socket I/O for any 3 | // client application. 4 | ////////////////////////////////////////////////////////////////////////////////////////// 5 | /* 6 | The MIT License (MIT) 7 | 8 | Copyright (c) 2012-2024 HALX99 9 | 10 | Permission is hereby granted, free of charge, to any person obtaining a copy 11 | of this software and associated documentation files (the "Software"), to deal 12 | in the Software without restriction, including without limitation the rights 13 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 14 | copies of the Software, and to permit persons to whom the Software is 15 | furnished to do so, subject to the following conditions: 16 | 17 | The above copyright notice and this permission notice shall be included in all 18 | copies or substantial portions of the Software. 19 | 20 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 23 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 24 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 25 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 26 | SOFTWARE. 27 | */ 28 | #ifndef YASIO__SOCKET_HPP 29 | #define YASIO__SOCKET_HPP 30 | 31 | #include "yasio/config.hpp" 32 | 33 | #ifdef _WIN32 34 | # if !defined(WIN32_LEAN_AND_MEAN) 35 | # define WIN32_LEAN_AND_MEAN 36 | # endif 37 | # include 38 | # include 39 | # if defined(YASIO_INSIDE_UNREAL) 40 | # if !defined(TRUE) 41 | # define TRUE 1 42 | # endif 43 | # if !defined(FALSE) 44 | # define FALSE 0 45 | # endif 46 | # endif 47 | # include 48 | # include 49 | # include 50 | # if defined(YASIO_NT_COMPAT_GAI) 51 | # include 52 | # endif 53 | # if YASIO__HAS_UDS 54 | # include 55 | # endif 56 | typedef SOCKET socket_native_type; 57 | typedef int socklen_t; 58 | # define poll WSAPoll 59 | # pragma comment(lib, "ws2_32.lib") 60 | 61 | # undef gai_strerror 62 | #else 63 | # include 64 | # include 65 | # include 66 | # include 67 | # include 68 | # if defined(__EMSCRIPTEN__) 69 | # include 70 | # else 71 | # include 72 | # endif 73 | # if defined(__linux__) 74 | # include 75 | # endif 76 | # include 77 | # include 78 | # include 79 | # include 80 | # include 81 | # include 82 | # include 83 | # if !defined(SD_RECEIVE) 84 | # define SD_RECEIVE SHUT_RD 85 | # endif 86 | # if !defined(SD_SEND) 87 | # define SD_SEND SHUT_WR 88 | # endif 89 | # if !defined(SD_BOTH) 90 | # define SD_BOTH SHUT_RDWR 91 | # endif 92 | # if !defined(closesocket) 93 | # define closesocket close 94 | # endif 95 | # if !defined(ioctlsocket) 96 | # define ioctlsocket ioctl 97 | # endif 98 | typedef int socket_native_type; 99 | # undef socket 100 | #endif 101 | #define SD_NONE -1 102 | 103 | #include // common platform header 104 | 105 | #include "yasio/endian_portable.hpp" 106 | 107 | // redefine socket error code for posix api 108 | #ifdef _WIN32 109 | # undef EWOULDBLOCK 110 | # undef EINPROGRESS 111 | # undef EALREADY 112 | # undef ENOTSOCK 113 | # undef EDESTADDRREQ 114 | # undef EMSGSIZE 115 | # undef EPROTOTYPE 116 | # undef ENOPROTOOPT 117 | # undef EPROTONOSUPPORT 118 | # undef ESOCKTNOSUPPORT 119 | # undef EOPNOTSUPP 120 | # undef EPFNOSUPPORT 121 | # undef EAFNOSUPPORT 122 | # undef EADDRINUSE 123 | # undef EADDRNOTAVAIL 124 | # undef ENETDOWN 125 | # undef ENETUNREACH 126 | # undef ENETRESET 127 | # undef ECONNABORTED 128 | # undef ECONNRESET 129 | # undef ENOBUFS 130 | # undef EISCONN 131 | # undef ENOTCONN 132 | # undef ESHUTDOWN 133 | # undef ETOOMANYREFS 134 | # undef ETIMEDOUT 135 | # undef ECONNREFUSED 136 | # undef ELOOP 137 | # undef ENAMETOOLONG 138 | # undef EHOSTDOWN 139 | # undef EHOSTUNREACH 140 | # undef ENOTEMPTY 141 | # undef EPROCLIM 142 | # undef EUSERS 143 | # undef EDQUOT 144 | # undef ESTALE 145 | # undef EREMOTE 146 | # undef EBADF 147 | # undef EFAULT 148 | # undef EAGAIN 149 | 150 | # define EWOULDBLOCK WSAEWOULDBLOCK 151 | # define EINPROGRESS WSAEINPROGRESS 152 | # define EALREADY WSAEALREADY 153 | # define ENOTSOCK WSAENOTSOCK 154 | # define EDESTADDRREQ WSAEDESTADDRREQ 155 | # define EMSGSIZE WSAEMSGSIZE 156 | # define EPROTOTYPE WSAEPROTOTYPE 157 | # define ENOPROTOOPT WSAENOPROTOOPT 158 | # define EPROTONOSUPPORT WSAEPROTONOSUPPORT 159 | # define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT 160 | # define EOPNOTSUPP WSAEOPNOTSUPP 161 | # define EPFNOSUPPORT WSAEPFNOSUPPORT 162 | # define EAFNOSUPPORT WSAEAFNOSUPPORT 163 | # define EADDRINUSE WSAEADDRINUSE 164 | # define EADDRNOTAVAIL WSAEADDRNOTAVAIL 165 | # define ENETDOWN WSAENETDOWN 166 | # define ENETUNREACH WSAENETUNREACH 167 | # define ENETRESET WSAENETRESET 168 | # define ECONNABORTED WSAECONNABORTED 169 | # define ECONNRESET WSAECONNRESET 170 | # define ENOBUFS WSAENOBUFS 171 | # define EISCONN WSAEISCONN 172 | # define ENOTCONN WSAENOTCONN 173 | # define ESHUTDOWN WSAESHUTDOWN 174 | # define ETOOMANYREFS WSAETOOMANYREFS 175 | # define ETIMEDOUT WSAETIMEDOUT 176 | # define ECONNREFUSED WSAECONNREFUSED 177 | # define ELOOP WSAELOOP 178 | # define ENAMETOOLONG WSAENAMETOOLONG 179 | # define EHOSTDOWN WSAEHOSTDOWN 180 | # define EHOSTUNREACH WSAEHOSTUNREACH 181 | # define ENOTEMPTY WSAENOTEMPTY 182 | # define EPROCLIM WSAEPROCLIM 183 | # define EUSERS WSAEUSERS 184 | # define EDQUOT WSAEDQUOT 185 | # define ESTALE WSAESTALE 186 | # define EREMOTE WSAEREMOTE 187 | # define EBADF WSAEBADF 188 | # define EFAULT WSAEFAULT 189 | # define EAGAIN WSATRY_AGAIN 190 | #endif 191 | 192 | #if !defined(MAXNS) 193 | # define MAXNS 3 194 | #endif 195 | 196 | #define IN_MAX_ADDRSTRLEN INET6_ADDRSTRLEN 197 | 198 | // Workaround for older MinGW missing AI_XXX macros 199 | #if defined(__MINGW32__) 200 | # if !defined(AI_ALL) 201 | # define AI_ALL 0x00000100 202 | # endif 203 | # if !defined(AI_V4MAPPED) 204 | # define AI_V4MAPPED 0x00000800 205 | # endif 206 | #endif 207 | 208 | #if !defined(_WS2IPDEF_) || defined(__MINGW32__) 209 | inline bool IN4_IS_ADDR_LOOPBACK(const in_addr* a) 210 | { 211 | return ((a->s_addr & 0xff) == 0x7f); // 127/8 212 | } 213 | inline bool IN4_IS_ADDR_LINKLOCAL(const in_addr* a) 214 | { 215 | return ((a->s_addr & 0xffff) == 0xfea9); // 169.254/16 216 | } 217 | inline bool IN6_IS_ADDR_GLOBAL(const in6_addr* a) 218 | { 219 | // 220 | // Check the format prefix and exclude addresses 221 | // whose high 4 bits are all zero or all one. 222 | // This is a cheap way of excluding v4-compatible, 223 | // v4-mapped, loopback, multicast, link-local, site-local. 224 | // 225 | unsigned int High = (a->s6_addr[0] & 0xf0); 226 | return ((High != 0) && (High != 0xf0)); 227 | } 228 | #endif 229 | 230 | #define YASIO_ADDR_ANY(af) (af == AF_INET ? "0.0.0.0" : "::") 231 | 232 | #define yasio__setbits(x, m) ((x) |= (m)) 233 | #define yasio__clearbits(x, m) ((x) &= ~(m)) 234 | #define yasio__testbits(x, m) ((x) & (m)) 235 | #define yasio__setlobyte(x, v) ((x) = ((x) & ~((decltype(x))0xff)) | (v)) 236 | 237 | namespace yasio 238 | { 239 | YASIO__NS_INLINE 240 | namespace inet 241 | { 242 | struct socket_event { 243 | enum 244 | { // event mask 245 | null = 0, 246 | read = 1, 247 | write = 2, 248 | error = 4, 249 | readwrite = read | write, 250 | }; 251 | }; 252 | } // namespace inet 253 | } // namespace yasio 254 | #endif 255 | -------------------------------------------------------------------------------- /Plugins/yasio/Source/yasio/Public/yasio/impl/socket_select_interrupter.hpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////////////////// 2 | // A multi-platform support c++11 library with focus on asynchronous socket I/O for any 3 | // client application. 4 | ////////////////////////////////////////////////////////////////////////////////////////// 5 | // 6 | // 7 | // Copyright (c) 2012-2024 HALX99 (halx99 at live dot com) 8 | // Copyright (c) 2003-2020 Christopher M. Kohlhoff (chris at kohlhoff dot com) 9 | // Copyright (c) 2008 Roelof Naude (roelof.naude at gmail dot com) 10 | // 11 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 12 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 13 | // 14 | // see also: https://github.com/chriskohlhoff/asio 15 | // 16 | #ifndef YASIO__SOCKET_SELECT_INTERRUPTER_HPP 17 | #define YASIO__SOCKET_SELECT_INTERRUPTER_HPP 18 | #include "yasio/xxsocket.hpp" 19 | 20 | namespace yasio 21 | { 22 | YASIO__NS_INLINE 23 | namespace inet 24 | { 25 | class socket_select_interrupter { 26 | public: 27 | // Constructor. 28 | inline socket_select_interrupter() { open_descriptors(); } 29 | 30 | // Destructor. 31 | inline ~socket_select_interrupter() { close_descriptors(); } 32 | 33 | // Recreate the interrupter's descriptors. Used after a fork. 34 | inline void recreate() 35 | { 36 | close_descriptors(); 37 | 38 | write_descriptor_ = invalid_socket; 39 | read_descriptor_ = invalid_socket; 40 | 41 | open_descriptors(); 42 | } 43 | 44 | // Interrupt the select call. 45 | inline void interrupt() { xxsocket::send(write_descriptor_, "\0", 1); } 46 | 47 | // Reset the select interrupter. Returns true if the reset was successful. 48 | inline bool reset() 49 | { 50 | char data[1024]; 51 | for (;;) 52 | { 53 | int bytes_read = xxsocket::recv(read_descriptor_, data, sizeof(data), 0); 54 | if (bytes_read == sizeof(data)) 55 | continue; 56 | if (bytes_read > 0) 57 | return true; 58 | if (bytes_read == 0) 59 | return false; 60 | int ec = xxsocket::get_last_errno(); 61 | if (ec == EINTR) 62 | continue; 63 | return (ec == EWOULDBLOCK || ec == EAGAIN); 64 | } 65 | } 66 | 67 | // Get the read descriptor to be passed to select. 68 | socket_native_type read_descriptor() const { return read_descriptor_; } 69 | 70 | private: 71 | // Open the descriptors. Throws on error. 72 | inline void open_descriptors() 73 | { 74 | xxsocket acceptor(AF_INET, SOCK_STREAM, IPPROTO_TCP); 75 | acceptor.set_optval(SOL_SOCKET, SO_REUSEADDR, 1); 76 | 77 | ip::endpoint ep(INADDR_LOOPBACK, 0); 78 | 79 | int retval = acceptor.bind(ep); 80 | if (retval < 0) 81 | yasio__throw_error(xxsocket::get_last_errno(), "socket_select_interrupter"); 82 | ep = acceptor.local_endpoint(); 83 | // Some broken firewalls on Windows will intermittently cause getsockname to 84 | // return 0.0.0.0 when the socket is actually bound to 127.0.0.1. We 85 | // explicitly specify the target address here to work around this problem. 86 | if (INADDR_ANY == ep.addr_v4()) 87 | ep.addr_v4(INADDR_LOOPBACK); 88 | retval = acceptor.listen(); 89 | if (retval < 0) 90 | yasio__throw_error(xxsocket::get_last_errno(), "socket_select_interrupter"); 91 | 92 | xxsocket client(AF_INET, SOCK_STREAM, IPPROTO_TCP); 93 | retval = client.connect(ep); 94 | if (retval < 0) 95 | yasio__throw_error(xxsocket::get_last_errno(), "socket_select_interrupter"); 96 | 97 | auto server = acceptor.accept(); 98 | if (!server.is_open()) 99 | yasio__throw_error(xxsocket::get_last_errno(), "socket_select_interrupter"); 100 | 101 | client.set_nonblocking(true); 102 | client.set_optval(IPPROTO_TCP, TCP_NODELAY, 1); 103 | 104 | server.set_nonblocking(true); 105 | server.set_optval(IPPROTO_TCP, TCP_NODELAY, 1); 106 | 107 | read_descriptor_ = server.release_handle(); 108 | write_descriptor_ = client.release_handle(); 109 | } 110 | 111 | // Close the descriptors. 112 | inline void close_descriptors() 113 | { 114 | if (read_descriptor_ != invalid_socket) 115 | ::closesocket(read_descriptor_); 116 | 117 | if (write_descriptor_ != invalid_socket) 118 | ::closesocket(write_descriptor_); 119 | } 120 | 121 | // The read end of a connection used to interrupt the select call. This file 122 | // descriptor is passed to select such that when it is time to stop, a single 123 | // byte will be written on the other end of the connection and this 124 | // descriptor will become readable. 125 | socket_native_type read_descriptor_; 126 | 127 | // The write end of a connection used to interrupt the select call. A single 128 | // byte may be written to this to wake up the select which is waiting for the 129 | // other end to become readable. 130 | socket_native_type write_descriptor_; 131 | }; 132 | 133 | } // namespace inet 134 | } // namespace yasio 135 | 136 | #endif // YASIO__SOCKET_SELECT_INTERRUPTER_HPP 137 | -------------------------------------------------------------------------------- /Plugins/yasio/Source/yasio/Public/yasio/io_watcher.hpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////////////////// 2 | // A multi-platform support c++11 library with focus on asynchronous socket I/O for any 3 | // client application. 4 | ////////////////////////////////////////////////////////////////////////////////////////// 5 | // 6 | // 7 | // Copyright (c) 2012-2024 HALX99 (halx99 at live dot com) 8 | 9 | #pragma once 10 | 11 | #include "yasio/config.hpp" 12 | 13 | #if YASIO__HAS_KQUEUE && defined(YASIO_ENABLE_HPERF_IO) 14 | # include "yasio/impl/kqueue_io_watcher.hpp" 15 | #elif YASIO__HAS_EPOLL && defined(YASIO_ENABLE_HPERF_IO) 16 | # include "yasio/impl/epoll_io_watcher.hpp" 17 | #elif YASIO__HAS_EVPORT && defined(YASIO_ENABLE_HPERF_IO) 18 | # include "yasio/impl/evport_io_watcher.hpp" 19 | #elif !defined(YASIO_DISABLE_POLL) 20 | # include "yasio/impl/poll_io_watcher.hpp" 21 | #else 22 | # include "yasio/impl/select_io_watcher.hpp" 23 | #endif 24 | 25 | namespace yasio 26 | { 27 | YASIO__NS_INLINE 28 | namespace inet 29 | { 30 | #if defined(YASIO__KQUEUE_IO_WATCHER_HPP) 31 | using io_watcher = kqueue_io_watcher; 32 | #elif defined(YASIO__EPOLL_IO_WATCHER_HPP) 33 | using io_watcher = epoll_io_watcher; 34 | #elif defined(YASIO__EVPORT_IO_WATCHER_HPP) 35 | using io_watcher = evport_io_watcher; 36 | #elif !defined(YASIO_DISABLE_POLL) 37 | using io_watcher = poll_io_watcher; 38 | #else 39 | using io_watcher = select_io_watcher; 40 | #endif 41 | } // namespace inet 42 | } // namespace yasio 43 | -------------------------------------------------------------------------------- /Plugins/yasio/Source/yasio/Public/yasio/logging.hpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////////////////// 2 | // A multi-platform support c++11 library with focus on asynchronous socket I/O for any 3 | // client application. 4 | ////////////////////////////////////////////////////////////////////////////////////////// 5 | /* 6 | The MIT License (MIT) 7 | 8 | Copyright (c) 2012-2024 HALX99 9 | 10 | Permission is hereby granted, free of charge, to any person obtaining a copy 11 | of this software and associated documentation files (the "Software"), to deal 12 | in the Software without restriction, including without limitation the rights 13 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 14 | copies of the Software, and to permit persons to whom the Software is 15 | furnished to do so, subject to the following conditions: 16 | 17 | The above copyright notice and this permission notice shall be included in all 18 | copies or substantial portions of the Software. 19 | 20 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 23 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 24 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 25 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 26 | SOFTWARE. 27 | */ 28 | #ifndef YASIO__LOGGING_HPP 29 | #define YASIO__LOGGING_HPP 30 | #include "yasio/strfmt.hpp" 31 | 32 | #if defined(__EMSCRIPTEN__) 33 | # define YASIO_LOG_TAG(tag, format, ...) printf((tag format "\n"), ##__VA_ARGS__) 34 | #elif defined(_WIN32) 35 | # define YASIO_LOG_TAG(tag, format, ...) OutputDebugStringA(::yasio::strfmt(127, (tag format "\n"), ##__VA_ARGS__).c_str()) 36 | #elif defined(ANDROID) || defined(__ANDROID__) 37 | # include 38 | # include 39 | # define YASIO_LOG_TAG(tag, format, ...) __android_log_print(ANDROID_LOG_INFO, "yasio", (tag format), ##__VA_ARGS__) 40 | #else 41 | # define YASIO_LOG_TAG(tag, format, ...) printf((tag format "\n"), ##__VA_ARGS__) 42 | #endif 43 | 44 | #define YASIO_LOG(format, ...) YASIO_LOG_TAG("[yasio]", format, ##__VA_ARGS__) 45 | 46 | #if !defined(YASIO_VERBOSE_LOG) 47 | # define YASIO_LOGV(fmt, ...) (void)0 48 | #else 49 | # define YASIO_LOGV YASIO_LOG 50 | #endif 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /Plugins/yasio/Source/yasio/Public/yasio/memory.hpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////////////////// 2 | // A multi-platform support c++11 library with focus on asynchronous socket I/O for any 3 | // client application. 4 | ////////////////////////////////////////////////////////////////////////////////////////// 5 | /* 6 | The MIT License (MIT) 7 | 8 | Copyright (c) 2012-2024 HALX99 9 | 10 | Permission is hereby granted, free of charge, to any person obtaining a copy 11 | of this software and associated documentation files (the "Software"), to deal 12 | in the Software without restriction, including without limitation the rights 13 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 14 | copies of the Software, and to permit persons to whom the Software is 15 | furnished to do so, subject to the following conditions: 16 | 17 | The above copyright notice and this permission notice shall be included in all 18 | copies or substantial portions of the Software. 19 | 20 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 23 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 24 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 25 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 26 | SOFTWARE. 27 | */ 28 | #ifndef YASIO__MEMORY 29 | #define YASIO__MEMORY 30 | #include 31 | 32 | #include "yasio/compiler/feature_test.hpp" 33 | 34 | /// The make_unique workaround on c++11 35 | #if !YASIO__HAS_CXX14 36 | namespace cxx14 37 | { 38 | template std::unique_ptr<_Ty> make_unique(_Args&&... args) 39 | { 40 | return std::unique_ptr<_Ty>(new _Ty(std::forward<_Args>(args)...)); 41 | } 42 | } // namespace cxx14 43 | #endif 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /Plugins/yasio/Source/yasio/Public/yasio/object_pool.hpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////////////////// 2 | // A multi-platform support c++11 library with focus on asynchronous socket I/O for any 3 | // client application. 4 | ////////////////////////////////////////////////////////////////////////////////////////// 5 | /* 6 | The MIT License (MIT) 7 | 8 | Copyright (c) 2012-2024 HALX99 9 | 10 | Permission is hereby granted, free of charge, to any person obtaining a copy 11 | of this software and associated documentation files (the "Software"), to deal 12 | in the Software without restriction, including without limitation the rights 13 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 14 | copies of the Software, and to permit persons to whom the Software is 15 | furnished to do so, subject to the following conditions: 16 | 17 | The above copyright notice and this permission notice shall be included in all 18 | copies or substantial portions of the Software. 19 | 20 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 23 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 24 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 25 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 26 | SOFTWARE. 27 | */ 28 | #ifndef YASIO__OBJECT_POOL_HPP 29 | #define YASIO__OBJECT_POOL_HPP 30 | 31 | #include "yasio/type_traits.hpp" 32 | #include "yasio/impl/object_pool.hpp" 33 | 34 | namespace yasio 35 | { 36 | struct null_mutex { 37 | void lock() {} 38 | void unlock() {} 39 | }; 40 | template 41 | class object_pool : public detail::object_pool { 42 | public: 43 | object_pool(size_t _ElemCount = 128) : detail::object_pool(::yasio::aligned_storage_size<_Ty>::value, _ElemCount) {} 44 | 45 | template 46 | _Ty* create(_Types&&... args) 47 | { 48 | return new (allocate()) _Ty(std::forward<_Types>(args)...); 49 | } 50 | 51 | void destroy(void* _Ptr) 52 | { 53 | ((_Ty*)_Ptr)->~_Ty(); // call the destructor 54 | deallocate(_Ptr); 55 | } 56 | 57 | void* allocate() 58 | { 59 | std::lock_guard<_Mutex> lk(this->mutex_); 60 | return get(); 61 | } 62 | 63 | void deallocate(void* _Ptr) 64 | { 65 | std::lock_guard<_Mutex> lk(this->mutex_); 66 | release(_Ptr); 67 | } 68 | 69 | _Mutex mutex_; 70 | }; 71 | 72 | #define DEFINE_OBJECT_POOL_ALLOCATION_ANY(ELEMENT_TYPE, ELEMENT_COUNT, MUTEX_TYPE) \ 73 | public: \ 74 | using object_pool_type = yasio::object_pool; \ 75 | static void* operator new(size_t /*size*/) \ 76 | { \ 77 | return get_pool().allocate(); \ 78 | } \ 79 | \ 80 | static void* operator new(size_t /*size*/, std::nothrow_t) \ 81 | { \ 82 | return get_pool().allocate(); \ 83 | } \ 84 | \ 85 | static void operator delete(void* p) \ 86 | { \ 87 | get_pool().deallocate(p); \ 88 | } \ 89 | \ 90 | static object_pool_type& get_pool() \ 91 | { \ 92 | static object_pool_type s_pool(ELEMENT_COUNT); \ 93 | return s_pool; \ 94 | } 95 | 96 | // The non thread safe edition 97 | #define DEFINE_FAST_OBJECT_POOL_ALLOCATION(ELEMENT_TYPE, ELEMENT_COUNT) DEFINE_OBJECT_POOL_ALLOCATION_ANY(ELEMENT_TYPE, ELEMENT_COUNT, ::yasio::null_mutex) 98 | 99 | // The thread safe edition 100 | #define DEFINE_CONCURRENT_OBJECT_POOL_ALLOCATION(ELEMENT_TYPE, ELEMENT_COUNT) DEFINE_OBJECT_POOL_ALLOCATION_ANY(ELEMENT_TYPE, ELEMENT_COUNT, std::mutex) 101 | 102 | } // namespace yasio 103 | 104 | #endif 105 | -------------------------------------------------------------------------------- /Plugins/yasio/Source/yasio/Public/yasio/object_pool_alloc.hpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////////////////// 2 | // A multi-platform support c++11 library with focus on asynchronous socket I/O for any 3 | // client application. 4 | ////////////////////////////////////////////////////////////////////////////////////////// 5 | /* 6 | The MIT License (MIT) 7 | 8 | Copyright (c) 2012-2024 HALX99 9 | 10 | Permission is hereby granted, free of charge, to any person obtaining a copy 11 | of this software and associated documentation files (the "Software"), to deal 12 | in the Software without restriction, including without limitation the rights 13 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 14 | copies of the Software, and to permit persons to whom the Software is 15 | furnished to do so, subject to the following conditions: 16 | 17 | The above copyright notice and this permission notice shall be included in all 18 | copies or substantial portions of the Software. 19 | 20 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 23 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 24 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 25 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 26 | SOFTWARE. 27 | */ 28 | #ifndef YASIO__OBJECT_POOL_ALLOC_HPP 29 | #define YASIO__OBJECT_POOL_ALLOC_HPP 30 | 31 | #include "yasio/object_pool.hpp" 32 | 33 | namespace yasio 34 | { 35 | // TEMPLATE class object_pool_allocator, can't used by sequence container 36 | template 37 | class object_pool_allocator { // generic allocator for objects of class _Ty 38 | public: 39 | typedef _Ty value_type; 40 | 41 | typedef value_type* pointer; 42 | typedef value_type& reference; 43 | typedef const value_type* const_pointer; 44 | typedef const value_type& const_reference; 45 | 46 | typedef size_t size_type; 47 | #ifdef _WIN32 48 | typedef ptrdiff_t difference_type; 49 | #else 50 | typedef long difference_type; 51 | #endif 52 | 53 | using object_pool_type = object_pool<_Ty, _Mutex>; 54 | using my_type = object_pool_allocator<_Ty, _ElemCount, _Mutex>; 55 | 56 | template 57 | struct rebind { // convert this type to _ALLOCATOR<_Other> 58 | typedef object_pool_allocator<_Other, _ElemCount, _Mutex> other; 59 | }; 60 | 61 | pointer address(reference _Val) const 62 | { // return address of mutable _Val 63 | return ((pointer) & (char&)_Val); 64 | } 65 | 66 | const_pointer address(const_reference _Val) const 67 | { // return address of nonmutable _Val 68 | return ((const_pointer) & (const char&)_Val); 69 | } 70 | 71 | object_pool_allocator() throw() 72 | { // construct default allocator (do nothing) 73 | } 74 | 75 | object_pool_allocator(const my_type&) throw() 76 | { // construct by copying (do nothing) 77 | } 78 | 79 | template 80 | object_pool_allocator(const object_pool_allocator<_Other, _ElemCount, _Mutex>&) throw() 81 | { // construct from a related allocator (do nothing) 82 | } 83 | 84 | template 85 | my_type& operator=(const object_pool_allocator<_Other, _ElemCount, _Mutex>&) throw() 86 | { // assign from a related allocator (do nothing) 87 | return (*this); 88 | } 89 | 90 | void deallocate(pointer _Ptr, size_type) 91 | { // deallocate object at _Ptr, ignore size 92 | _Spool().deallocate(_Ptr); 93 | } 94 | 95 | pointer allocate(size_type count) 96 | { // allocate array of _Count elements 97 | assert(count == 1); 98 | (void)count; 99 | return static_cast(_Spool().allocate()); 100 | } 101 | 102 | pointer allocate(size_type count, const void*) 103 | { // allocate array of _Count elements, not support, such as std::vector 104 | return allocate(count); 105 | } 106 | 107 | void construct(_Ty* _Ptr) 108 | { // default construct object at _Ptr 109 | ::new ((void*)_Ptr) _Ty(); 110 | } 111 | 112 | void construct(pointer _Ptr, const _Ty& _Val) 113 | { // construct object at _Ptr with value _Val 114 | new (_Ptr) _Ty(_Val); 115 | } 116 | 117 | void construct(pointer _Ptr, _Ty&& _Val) 118 | { // construct object at _Ptr with value _Val 119 | new ((void*)_Ptr) _Ty(std::forward<_Ty>(_Val)); 120 | } 121 | 122 | template 123 | void construct(pointer _Ptr, _Other&& _Val) 124 | { // construct object at _Ptr with value _Val 125 | new ((void*)_Ptr) _Ty(std::forward<_Other>(_Val)); 126 | } 127 | 128 | template 129 | void construct(_Objty* _Ptr, _Types&&... _Args) 130 | { // construct _Objty(_Types...) at _Ptr 131 | ::new ((void*)_Ptr) _Objty(std::forward<_Types>(_Args)...); 132 | } 133 | 134 | template 135 | void destroy(_Uty* _Ptr) 136 | { // destroy object at _Ptr, do nothing 137 | _Ptr->~_Uty(); 138 | } 139 | 140 | size_type max_size() const throw() 141 | { // estimate maximum array size 142 | size_type _Count = (size_type)(-1) / sizeof(_Ty); 143 | return (0 < _Count ? _Count : 1); 144 | } 145 | 146 | static object_pool_type& _Spool() 147 | { 148 | static object_pool_type s_pool(_ElemCount); 149 | return s_pool; 150 | } 151 | }; 152 | } // namespace yasio 153 | 154 | #endif 155 | -------------------------------------------------------------------------------- /Plugins/yasio/Source/yasio/Public/yasio/platform/yasio_jni.hpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////////////////// 2 | // A multi-platform support c++11 library with focus on asynchronous socket I/O for any 3 | // client application. 4 | ////////////////////////////////////////////////////////////////////////////////////////// 5 | /* 6 | The MIT License (MIT) 7 | Copyright (c) 2012-2024 HALX99 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | */ 24 | #ifndef YASIO__JNI_HPP 25 | #define YASIO__JNI_HPP 26 | 27 | extern "C" void yasio__jni_init(void* vm, void* env); 28 | extern "C" int yasio__jni_onload(void* vm, void* reserved); 29 | 30 | extern "C" int yasio__ares_init_android(); 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /Plugins/yasio/Source/yasio/Public/yasio/platform/yasio_unreal.hpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////////////////// 2 | // A multi-platform support c++11 library with focus on asynchronous socket I/O for any 3 | // client application. 4 | ////////////////////////////////////////////////////////////////////////////////////////// 5 | /* 6 | The MIT License (MIT) 7 | Copyright (c) 2012-2024 HALX99 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | */ 24 | #ifndef YASIO__UNREAL_HPP 25 | #define YASIO__UNREAL_HPP 26 | 27 | #include "yasio/config.hpp" 28 | 29 | YASIO_API void yasio_unreal_init(); 30 | YASIO_API void yasio_unreal_cleanup(); 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /Plugins/yasio/Source/yasio/Public/yasio/ref_ptr.hpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////////////////// 2 | // A multi-platform support c++11 library with focus on asynchronous socket I/O for any 3 | // client application. 4 | ////////////////////////////////////////////////////////////////////////////////////////// 5 | /* 6 | The MIT License (MIT) 7 | 8 | Copyright (c) 2012-2024 HALX99 9 | 10 | Permission is hereby granted, free of charge, to any person obtaining a copy 11 | of this software and associated documentation files (the "Software"), to deal 12 | in the Software without restriction, including without limitation the rights 13 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 14 | copies of the Software, and to permit persons to whom the Software is 15 | furnished to do so, subject to the following conditions: 16 | 17 | The above copyright notice and this permission notice shall be included in all 18 | copies or substantial portions of the Software. 19 | 20 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 23 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 24 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 25 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 26 | SOFTWARE. 27 | */ 28 | #ifndef YASIO__REF_PTR_HPP 29 | #define YASIO__REF_PTR_HPP 30 | #include "yasio/config.hpp" 31 | 32 | // clang-format off 33 | #define YASIO__DEFINE_REFERENCE_CLASS \ 34 | private: \ 35 | unsigned int __strong_refs = 1; \ 36 | \ 37 | public: \ 38 | void retain() { ++__strong_refs; } \ 39 | void release() \ 40 | { \ 41 | --__strong_refs; \ 42 | if (__strong_refs == 0) \ 43 | delete this; \ 44 | } \ 45 | \ 46 | private: 47 | 48 | #define YASIO__SAFE_RELEASE(p) \ 49 | if (p) \ 50 | (p)->release() 51 | 52 | #define YASIO__SAFE_RELEASE_NULL(p) \ 53 | do \ 54 | { \ 55 | if (p) \ 56 | { \ 57 | (p)->release(); \ 58 | (p) = nullptr; \ 59 | } \ 60 | } while (0) 61 | 62 | #define YASIO__SAFE_RETAIN(p) \ 63 | if (p) \ 64 | (p)->retain() 65 | // clang-format on 66 | 67 | namespace yasio 68 | { 69 | struct own_ref_t {}; 70 | 71 | // TEMPLATE CLASS ref_ptr, allow any time with functions 'retain' and 'release' 72 | template 73 | class ref_ptr; 74 | 75 | template 76 | class ref_ptr { // wrap an object pointer to ensure destruction 77 | public: 78 | typedef ref_ptr<_Ty> _Myt; 79 | typedef _Ty element_type; 80 | 81 | explicit ref_ptr(_Ty* _Ptr = nullptr) throw() : ptr_(_Ptr) 82 | { // construct from object pointer 83 | } 84 | 85 | ref_ptr(_Ty* _Ptr, own_ref_t) throw() : ptr_(_Ptr) 86 | { // construct from object pointer 87 | YASIO__SAFE_RETAIN(ptr_); 88 | } 89 | 90 | ref_ptr(std::nullptr_t) throw() : ptr_(nullptr) {} 91 | 92 | ref_ptr(const _Myt& _Right) throw() 93 | { // construct by assuming pointer from _Right ref_ptr 94 | ptr_ = _Right.get(); 95 | YASIO__SAFE_RETAIN(ptr_); 96 | } 97 | 98 | template 99 | ref_ptr(const ref_ptr<_Other>& _Right) throw() 100 | { // construct by assuming pointer from _Right 101 | ptr_ = (_Ty*)_Right.get(); 102 | YASIO__SAFE_RETAIN(ptr_); 103 | } 104 | 105 | ref_ptr(_Myt&& _Right) throw() : ptr_(_Right.release()) {} 106 | 107 | template 108 | ref_ptr(ref_ptr<_Other>&& _Right) throw() : ptr_((_Ty*)_Right.release()) 109 | {} 110 | 111 | _Myt& operator=(const _Myt& _Right) throw() 112 | { // assign compatible _Right (assume pointer) 113 | if (this == &_Right) 114 | return *this; 115 | 116 | reset(_Right.get()); 117 | YASIO__SAFE_RETAIN(ptr_); 118 | return (*this); 119 | } 120 | 121 | _Myt& operator=(_Myt&& _Right) throw() 122 | { // assign compatible _Right (assume pointer) 123 | reset(_Right.release()); 124 | return (*this); 125 | } 126 | 127 | // release ownership 128 | _Ty* release() 129 | { 130 | auto tmp = ptr_; 131 | ptr_ = nullptr; 132 | return tmp; 133 | } 134 | 135 | template 136 | _Myt& operator=(const ref_ptr<_Other>& _Right) throw() 137 | { // assign compatible _Right (assume pointer) 138 | if (this == &_Right) 139 | return *this; 140 | 141 | reset((_Ty*)_Right.get()); 142 | YASIO__SAFE_RETAIN(ptr_); 143 | return (*this); 144 | } 145 | 146 | template 147 | _Myt& operator=(ref_ptr<_Other>&& _Right) throw() 148 | { // assign compatible _Right (assume pointer) 149 | reset((_Ty*)_Right.release()); 150 | return (*this); 151 | } 152 | 153 | _Myt& operator=(std::nullptr_t) throw() 154 | { 155 | reset(); 156 | return (*this); 157 | } 158 | 159 | ~ref_ptr() 160 | { // release the object 161 | YASIO__SAFE_RELEASE(ptr_); 162 | } 163 | 164 | _Ty& operator*() const throw() 165 | { // return designated value 166 | return (*ptr_); // return (*get()); 167 | } 168 | 169 | _Ty** operator&() throw() { return &(ptr_); } 170 | 171 | _Ty* operator->() const throw() 172 | { // return pointer to class object 173 | return (ptr_); // return (get()); 174 | } 175 | 176 | template 177 | _Ty& operator[](_Int index) const throw() 178 | { 179 | return (ptr_[index]); 180 | } 181 | 182 | _Ty* get() const throw() 183 | { // return wrapped pointer 184 | return (ptr_); 185 | } 186 | 187 | operator _Ty*() const throw() 188 | { // convert to basic type 189 | return (ptr_); 190 | } 191 | 192 | /* 193 | ** if already have a valid pointer, will call release firstly 194 | */ 195 | void reset(_Ty* _Ptr = nullptr) 196 | { // relese designated object and store new pointer 197 | if (ptr_ != _Ptr) 198 | { 199 | if (ptr_ != nullptr) 200 | YASIO__SAFE_RELEASE(ptr_); 201 | ptr_ = _Ptr; 202 | } 203 | } 204 | 205 | private: 206 | _Ty* ptr_; // the wrapped object pointer 207 | }; 208 | 209 | }; // namespace yasio 210 | 211 | #endif 212 | -------------------------------------------------------------------------------- /Plugins/yasio/Source/yasio/Public/yasio/shared_mutex.hpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////////////////// 2 | // A multi-platform support c++11 library with focus on asynchronous socket I/O for any 3 | // client application. 4 | ////////////////////////////////////////////////////////////////////////////////////////// 5 | // 6 | // Copyright (c) 2012-2024 HALX99 (halx99 at live dot com) 7 | // Copyright Vicente J. Botet Escriba 2012. 8 | // Copyright Howard Hinnant 2007-2010. 9 | // 10 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 11 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 12 | // 13 | // see also: https://github.com/boostorg/thread/blob/develop/include/boost/thread/v2/shared_mutex.hpp 14 | // 15 | 16 | #ifndef YASIO__SHARED_MUTEX_HPP 17 | #define YASIO__SHARED_MUTEX_HPP 18 | 19 | #include "yasio/compiler/feature_test.hpp" 20 | #include 21 | 22 | /// The shared_mutex workaround on c++11 23 | #if YASIO__HAS_CXX17 && !defined(__APPLE__) 24 | # include 25 | #else 26 | # include 27 | # include 28 | namespace cxx17 29 | { 30 | // CLASS TEMPLATE shared_mutex 31 | class shared_mutex { 32 | typedef std::mutex mutex_t; 33 | typedef std::condition_variable cond_t; 34 | typedef unsigned count_t; 35 | 36 | mutex_t mut_; 37 | cond_t gate1_; 38 | // the gate2_ condition variable is only used by functions that 39 | // have taken write_entered_ but are waiting for no_readers() 40 | cond_t gate2_; 41 | count_t state_; 42 | 43 | static const count_t write_entered_ = 1U << (sizeof(count_t) * CHAR_BIT - 1); 44 | static const count_t n_readers_ = ~write_entered_; 45 | 46 | bool no_writer() const { return (state_ & write_entered_) == 0; } 47 | 48 | bool one_writer() const { return (state_ & write_entered_) != 0; } 49 | 50 | bool no_writer_no_readers() const 51 | { 52 | // return (state_ & write_entered_) == 0 && 53 | // (state_ & n_readers_) == 0; 54 | return state_ == 0; 55 | } 56 | 57 | bool no_writer_no_max_readers() const { return (state_ & write_entered_) == 0 && (state_ & n_readers_) != n_readers_; } 58 | 59 | bool no_readers() const { return (state_ & n_readers_) == 0; } 60 | 61 | bool one_or_more_readers() const { return (state_ & n_readers_) > 0; } 62 | 63 | shared_mutex(shared_mutex const&) = delete; 64 | shared_mutex& operator=(shared_mutex const&) = delete; 65 | 66 | public: 67 | shared_mutex() : state_(0) {} 68 | ~shared_mutex() { std::lock_guard _(mut_); } 69 | 70 | // Exclusive ownership 71 | 72 | void lock() 73 | { 74 | std::unique_lock lk(mut_); 75 | gate1_.wait(lk, std::bind(&shared_mutex::no_writer, std::ref(*this))); 76 | state_ |= write_entered_; 77 | gate2_.wait(lk, std::bind(&shared_mutex::no_readers, std::ref(*this))); 78 | } 79 | bool try_lock() 80 | { 81 | std::unique_lock lk(mut_); 82 | if (!no_writer_no_readers()) 83 | { 84 | return false; 85 | } 86 | state_ = write_entered_; 87 | return true; 88 | } 89 | void unlock() 90 | { 91 | std::lock_guard _(mut_); 92 | assert(one_writer()); 93 | assert(no_readers()); 94 | state_ = 0; 95 | // notify all since multiple *lock_shared*() calls may be able 96 | // to proceed in response to this notification 97 | gate1_.notify_all(); 98 | } 99 | 100 | // Shared ownership 101 | 102 | void lock_shared() 103 | { 104 | std::unique_lock lk(mut_); 105 | gate1_.wait(lk, std::bind(&shared_mutex::no_writer_no_max_readers, std::ref(*this))); 106 | count_t num_readers = (state_ & n_readers_) + 1; 107 | state_ &= ~n_readers_; 108 | state_ |= num_readers; 109 | } 110 | bool try_lock_shared() 111 | { 112 | std::unique_lock lk(mut_); 113 | if (!no_writer_no_max_readers()) 114 | { 115 | return false; 116 | } 117 | count_t num_readers = (state_ & n_readers_) + 1; 118 | state_ &= ~n_readers_; 119 | state_ |= num_readers; 120 | return true; 121 | } 122 | void unlock_shared() 123 | { 124 | std::lock_guard _(mut_); 125 | assert(one_or_more_readers()); 126 | count_t num_readers = (state_ & n_readers_) - 1; 127 | state_ &= ~n_readers_; 128 | state_ |= num_readers; 129 | if (no_writer()) 130 | { 131 | if (num_readers == n_readers_ - 1) 132 | gate1_.notify_one(); 133 | } 134 | else 135 | { 136 | if (num_readers == 0) 137 | gate2_.notify_one(); 138 | } 139 | } 140 | }; 141 | 142 | // CLASS TEMPLATE shared_lock 143 | template 144 | class shared_lock { 145 | public: 146 | using mutex_type = _Mutex; 147 | 148 | shared_lock() : _Pmtx(nullptr), _Owns(false) {} 149 | 150 | explicit shared_lock(mutex_type& _Mtx) : _Pmtx(YASIO__STD addressof(_Mtx)), _Owns(true) 151 | { // construct with mutex and lock shared 152 | _Mtx.lock_shared(); 153 | } 154 | 155 | explicit shared_lock(mutex_type& _Mtx, YASIO__STD defer_lock_t) : _Pmtx(YASIO__STD addressof(_Mtx)), _Owns(false) {} // // construct with unlocked mutex 156 | 157 | explicit shared_lock(mutex_type& _Mtx, YASIO__STD try_to_lock_t) 158 | : _Pmtx(YASIO__STD addressof(_Mtx)), _Owns(_Mtx.try_lock_shared()) {} // construct with mutex and try to lock shared 159 | 160 | explicit shared_lock(mutex_type& _Mtx, YASIO__STD adopt_lock_t) : _Pmtx(YASIO__STD addressof(_Mtx)), _Owns(true) {} // construct with mutex and adopt owership 161 | 162 | ~shared_lock() 163 | { 164 | if (_Owns) 165 | _Pmtx->unlock_shared(); 166 | } 167 | 168 | shared_lock(shared_lock&& _Other) : _Pmtx(_Other._Pmtx), _Owns(_Other._Owns) 169 | { 170 | _Other._Pmtx = nullptr; 171 | _Other._Owns = false; 172 | } 173 | 174 | shared_lock& operator=(shared_lock&& _Right) 175 | { 176 | if (_Owns) 177 | _Pmtx->unlock_shared(); 178 | 179 | _Pmtx = _Right._Pmtx; 180 | _Owns = _Right._Owns; 181 | _Right._Pmtx = nullptr; 182 | _Right._Owns = false; 183 | return *this; 184 | } 185 | 186 | shared_lock(const shared_lock&) = delete; 187 | shared_lock& operator=(const shared_lock&) = delete; 188 | 189 | void lock() 190 | { // lock the mutex 191 | _Validate(); 192 | _Pmtx->lock_shared(); 193 | _Owns = true; 194 | } 195 | 196 | bool try_lock() 197 | { // try to lock the mutex 198 | _Validate(); 199 | _Owns = _Pmtx->try_lock_shared(); 200 | return _Owns; 201 | } 202 | 203 | void unlock() 204 | { // try to unlock the mutex 205 | if (!_Pmtx || !_Owns) 206 | yasio__throw_error0(std::errc::operation_not_permitted); 207 | 208 | _Pmtx->unlock_shared(); 209 | _Owns = false; 210 | } 211 | 212 | // MUTATE 213 | void swap(shared_lock& _Right) 214 | { 215 | YASIO__STD swap(_Pmtx, _Right._Pmtx); 216 | YASIO__STD swap(_Owns, _Right._Owns); 217 | } 218 | 219 | mutex_type* release() 220 | { 221 | _Mutex* _Res = _Pmtx; 222 | _Pmtx = nullptr; 223 | _Owns = false; 224 | return _Res; 225 | } 226 | 227 | // OBSERVE 228 | bool owns_lock() const { return _Owns; } 229 | 230 | explicit operator bool() const { return _Owns; } 231 | 232 | mutex_type* mutex() const { return _Pmtx; } 233 | 234 | private: 235 | _Mutex* _Pmtx; 236 | bool _Owns; 237 | 238 | void _Validate() const 239 | { // check if the mutex can be locked 240 | if (!_Pmtx) 241 | yasio__throw_error0(std::errc::operation_not_permitted); 242 | 243 | if (_Owns) 244 | yasio__throw_error0(std::errc::resource_deadlock_would_occur); 245 | } 246 | }; 247 | } // namespace cxx17 248 | #endif 249 | 250 | #endif 251 | -------------------------------------------------------------------------------- /Plugins/yasio/Source/yasio/Public/yasio/singleton.hpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////////////////// 2 | // A multi-platform support c++11 library with focus on asynchronous socket I/O for any 3 | // client application. 4 | ////////////////////////////////////////////////////////////////////////////////////////// 5 | /* 6 | The MIT License (MIT) 7 | 8 | Copyright (c) 2012-2024 HALX99 9 | 10 | Permission is hereby granted, free of charge, to any person obtaining a copy 11 | of this software and associated documentation files (the "Software"), to deal 12 | in the Software without restriction, including without limitation the rights 13 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 14 | copies of the Software, and to permit persons to whom the Software is 15 | furnished to do so, subject to the following conditions: 16 | 17 | The above copyright notice and this permission notice shall be included in all 18 | copies or substantial portions of the Software. 19 | 20 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 23 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 24 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 25 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 26 | SOFTWARE. 27 | */ 28 | // core/singleton.hpp: A common use thread safe singleton class template, support non-delayed or delayed init with variadic args. 29 | // 30 | // refer to: 31 | // https://www.youtube.com/watch?v=c1gO9aB9nbs&t=1120s 32 | // 33 | // remark: 34 | // Singletons make it hard to determine the lifetime of an object, which can 35 | // lead to buggy code and spurious crashes. 36 | // 37 | // Instead of adding another singleton into the mix, try to identify either: 38 | // a) An existing singleton that can manage your object's lifetime 39 | // b) Locations where you can deterministically create the object and pass 40 | // into other objects 41 | // 42 | // If you absolutely need a singleton, please keep them as trivial as possible 43 | // and ideally a leaf dependency. Singletons get problematic when they attempt 44 | // to do too much in their destructor or have circular dependencies. 45 | #ifndef YASIO__SINGLETON_HPP 46 | #define YASIO__SINGLETON_HPP 47 | #include 48 | #include 49 | #include 50 | #include 51 | #include 52 | 53 | namespace yasio 54 | { 55 | template 56 | class singleton_constructor { 57 | public: 58 | template 59 | static _Ty* construct(_Types&&... args) 60 | { 61 | return new _Ty(std::forward<_Types>(args)...); 62 | } 63 | }; 64 | 65 | template 66 | class singleton_constructor<_Ty, true> { 67 | public: 68 | template 69 | static _Ty* construct(_Types&&... args) 70 | { 71 | auto inst = new _Ty(); 72 | delay_init(inst, std::forward<_Types>(args)...); 73 | return inst; 74 | } 75 | 76 | private: 77 | template 78 | static void delay_init(_Ty* inst, _Fty&& memf, _Types&&... args) 79 | { // init use specific member func with more than 1 args 80 | std::mem_fn(memf)(inst, std::forward<_Types>(args)...); 81 | } 82 | 83 | template 84 | static void delay_init(_Ty* inst, _Fty&& memf, _Arg&& arg) 85 | { // init use specific member func with 1 arg 86 | std::mem_fn(memf)(inst, std::forward<_Arg>(arg)); 87 | } 88 | 89 | template 90 | static void delay_init(_Ty* inst, _Fty&& memf) 91 | { // init use specific member func without arg 92 | std::mem_fn(memf)(inst); 93 | } 94 | 95 | static void delay_init(_Ty* inst) 96 | { // dummy init without delay init member func, same as no delay constructor 97 | } 98 | }; 99 | 100 | template 101 | class singleton { 102 | typedef singleton<_Ty> _Myt; 103 | typedef _Ty* pointer; 104 | 105 | public: 106 | // Return the singleton instance 107 | template 108 | static pointer instance(_Types&&... args) 109 | { 110 | return get_instance(std::forward<_Types>(args)...); 111 | } 112 | 113 | template 114 | static pointer instance1(_Types&&... args) 115 | { 116 | return get_instance(std::forward<_Types>(args)...); 117 | } 118 | 119 | static void destroy(void) 120 | { 121 | if (auto inst = _Myt::__single__.exchange(nullptr, std::memory_order_acq_rel)) 122 | delete inst; 123 | } 124 | 125 | // Peek the singleton instance 126 | static pointer peek() { return _Myt::__single__; } 127 | 128 | private: 129 | template 130 | static pointer get_instance(_Types&&... args) 131 | { 132 | auto& inst = _Myt::__single__; 133 | if (inst.load(std::memory_order_acquire)) 134 | return inst; 135 | 136 | { 137 | std::lock_guard lck(__mutex__); 138 | if (!inst.load(std::memory_order_relaxed)) 139 | inst.store(singleton_constructor<_Ty, delay>::construct(std::forward<_Types>(args)...), std::memory_order_release); 140 | } 141 | return inst; 142 | } 143 | 144 | static std::atomic<_Ty*> __single__; 145 | static std::mutex __mutex__; 146 | 147 | private: 148 | // disable construct, assign operation, copy construct also not allowed. 149 | singleton(void) = delete; 150 | }; 151 | 152 | template 153 | std::atomic<_Ty*> singleton<_Ty>::__single__; 154 | template 155 | std::mutex singleton<_Ty>::__mutex__; 156 | 157 | } // namespace yasio 158 | 159 | #endif 160 | -------------------------------------------------------------------------------- /Plugins/yasio/Source/yasio/Public/yasio/split.hpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////////////////// 2 | // A multi-platform support c++11 library with focus on asynchronous socket I/O for any 3 | // client application. 4 | ////////////////////////////////////////////////////////////////////////////////////////// 5 | /* 6 | The MIT License (MIT) 7 | 8 | Copyright (c) 2012-2024 HALX99 9 | 10 | Permission is hereby granted, free of charge, to any person obtaining a copy 11 | of this software and associated documentation files (the "Software"), to deal 12 | in the Software without restriction, including without limitation the rights 13 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 14 | copies of the Software, and to permit persons to whom the Software is 15 | furnished to do so, subject to the following conditions: 16 | 17 | The above copyright notice and this permission notice shall be included in all 18 | copies or substantial portions of the Software. 19 | 20 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 23 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 24 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 25 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 26 | SOFTWARE. 27 | */ 28 | 29 | /* 30 | * The standard split stub of yasio: 31 | * The pred callback prototype: [](CStr first, CStr last) ->bool{ return true; } 32 | * returns: 33 | * true: want continue split 34 | * false: abort split 35 | * 36 | */ 37 | 38 | #pragma once 39 | 40 | #include "yasio/string_view.hpp" 41 | #include 42 | 43 | #if defined(_MSC_VER) 44 | # pragma warning(push) 45 | # pragma warning(disable : 4706) 46 | #endif 47 | 48 | namespace yasio 49 | { 50 | template 51 | inline void split_if(_CStr s, typename std::remove_pointer<_CStr>::type delim, _Pred&& pred) 52 | { 53 | auto _Start = s; // the start of every string 54 | auto _Ptr = s; // source string iterator 55 | while ((_Ptr = strchr(_Ptr, delim))) 56 | { 57 | if (_Start <= _Ptr && !pred(_Start, _Ptr)) 58 | return; 59 | _Start = _Ptr + 1; 60 | ++_Ptr; 61 | } 62 | pred(_Start, nullptr); // last one, end is nullptr 63 | } 64 | 65 | template 66 | inline void split_if_n(_CStr s, size_t slen, typename std::remove_pointer<_CStr>::type delim, _Pred&& pred) 67 | { 68 | auto _Start = s; // the start of every string 69 | auto _Ptr = s; // source string iterator 70 | auto _End = s + slen; 71 | while ((_Ptr = strchr(_Ptr, delim))) 72 | { 73 | if (_Ptr >= _End) 74 | break; 75 | 76 | if (_Start <= _Ptr && !pred(_Start, _Ptr)) 77 | return; 78 | _Start = _Ptr + 1; 79 | ++_Ptr; 80 | } 81 | if (_Start <= _End) 82 | pred(_Start, _End); 83 | } 84 | 85 | template 86 | inline void split(_CStr s, typename std::remove_pointer<_CStr>::type delim, _Func&& func) 87 | { 88 | split_if(s, delim, [func](_CStr first, _CStr last) { 89 | func(first, last); 90 | return true; 91 | }); 92 | } 93 | 94 | template 95 | inline void split_n(_CStr s, size_t slen, typename std::remove_pointer<_CStr>::type delim, _Func&& func) 96 | { 97 | split_if_n(s, slen, delim, [func](_CStr first, _CStr last) { 98 | func(first, last); 99 | return true; 100 | }); 101 | } 102 | 103 | struct split_term { 104 | split_term(char* end) 105 | { 106 | if (end) 107 | { 108 | this->val_ = *end; 109 | *end = '\0'; 110 | this->end_ = end; 111 | } 112 | } 113 | ~split_term() 114 | { 115 | if (this->end_) 116 | *this->end_ = this->val_; 117 | } 118 | 119 | private: 120 | char* end_ = nullptr; 121 | char val_ = '\0'; 122 | }; 123 | } // namespace yasio 124 | 125 | #if defined(_MSC_VER) 126 | # pragma warning(pop) 127 | #endif 128 | -------------------------------------------------------------------------------- /Plugins/yasio/Source/yasio/Public/yasio/ssl.hpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////////////////// 2 | // A multi-platform support c++11 library with focus on asynchronous socket I/O for any 3 | // client application. 4 | ////////////////////////////////////////////////////////////////////////////////////////// 5 | /* 6 | The MIT License (MIT) 7 | 8 | Copyright (c) 2012-2024 HALX99 9 | 10 | Permission is hereby granted, free of charge, to any person obtaining a copy 11 | of this software and associated documentation files (the "Software"), to deal 12 | in the Software without restriction, including without limitation the rights 13 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 14 | copies of the Software, and to permit persons to whom the Software is 15 | furnished to do so, subject to the following conditions: 16 | 17 | The above copyright notice and this permission notice shall be included in all 18 | copies or substantial portions of the Software. 19 | 20 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 23 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 24 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 25 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 26 | SOFTWARE. 27 | */ 28 | 29 | #ifndef YASIO__SSL_HPP 30 | #define YASIO__SSL_HPP 31 | 32 | #include "yasio/config.hpp" 33 | 34 | #if YASIO_SSL_BACKEND == 1 // OpenSSL 35 | # include 36 | # include 37 | # include 38 | typedef struct ssl_ctx_st yssl_ctx_st; 39 | struct yssl_st { 40 | ssl_st* session; 41 | int fd; 42 | BIO_METHOD* bmth; 43 | }; 44 | # define yssl_unwrap(ssl) ssl->session 45 | 46 | #elif YASIO_SSL_BACKEND == 2 // mbedtls 47 | # define MBEDTLS_ALLOW_PRIVATE_ACCESS 48 | # include "mbedtls/net_sockets.h" 49 | # include "mbedtls/debug.h" 50 | # include "mbedtls/ssl.h" 51 | # include "mbedtls/entropy.h" 52 | # include "mbedtls/ctr_drbg.h" 53 | # include "mbedtls/error.h" 54 | # include "mbedtls/version.h" 55 | typedef struct ssl_ctx_st { 56 | mbedtls_ctr_drbg_context ctr_drbg; 57 | mbedtls_entropy_context entropy; 58 | mbedtls_x509_crt cert; 59 | mbedtls_pk_context pkey; 60 | mbedtls_ssl_config conf; 61 | } yssl_ctx_st; 62 | struct yssl_st : public mbedtls_ssl_context { 63 | mbedtls_net_context bio; 64 | }; 65 | #endif 66 | 67 | #if defined(YASIO_SSL_BACKEND) 68 | struct yssl_options { 69 | char* crtfile_; 70 | char* keyfile_; 71 | bool client; 72 | }; 73 | 74 | YASIO__DECL yssl_ctx_st* yssl_ctx_new(const yssl_options& opts); 75 | YASIO__DECL void yssl_ctx_free(yssl_ctx_st*& ctx); 76 | 77 | YASIO__DECL yssl_st* yssl_new(yssl_ctx_st* ctx, int fd, const char* hostname, bool client); 78 | YASIO__DECL void yssl_shutdown(yssl_st*&, bool writable); 79 | 80 | /** 81 | * @returns 82 | * 0: succeed 83 | * other: use yssl_strerror(ret & YSSL_ERROR_MASK, ...) get error message 84 | * - err can bb 85 | - EWOULDBLOCK: status ok, repeat call next time 86 | * - yasio::errc::ssl_handshake_failed: failed 87 | */ 88 | YASIO__DECL int yssl_do_handshake(yssl_st* ssl, int& err); 89 | YASIO__DECL const char* yssl_strerror(yssl_st* ssl, int sslerr, char* buf, size_t buflen); 90 | 91 | YASIO__DECL int yssl_write(yssl_st* ssl, const void* data, size_t len, int& err); 92 | YASIO__DECL int yssl_read(yssl_st* ssl, void* data, size_t len, int& err); 93 | #endif 94 | 95 | /////////////////////////////////////////////////////////////////// 96 | // --- Implement common yasio ssl api with different ssl backends 97 | 98 | #define yasio__valid_str(cstr) (cstr && *cstr) 99 | #define yasio__c_str(str) (!str.empty() ? &str.front() : nullptr) 100 | 101 | #if YASIO_SSL_BACKEND == 1 // openssl 102 | # include "yasio/impl/openssl.hpp" 103 | #elif YASIO_SSL_BACKEND == 2 // mbedtls 104 | # include "yasio/impl/mbedtls.hpp" 105 | #else 106 | # error "yasio - Unsupported ssl backend provided!" 107 | #endif 108 | 109 | #endif 110 | -------------------------------------------------------------------------------- /Plugins/yasio/Source/yasio/Public/yasio/strfmt.hpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////////////////// 2 | // A multi-platform support c++11 library with focus on asynchronous socket I/O for any 3 | // client application. 4 | ////////////////////////////////////////////////////////////////////////////////////////// 5 | /* 6 | The MIT License (MIT) 7 | 8 | Copyright (c) 2012-2024 HALX99 9 | 10 | Permission is hereby granted, free of charge, to any person obtaining a copy 11 | of this software and associated documentation files (the "Software"), to deal 12 | in the Software without restriction, including without limitation the rights 13 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 14 | copies of the Software, and to permit persons to whom the Software is 15 | furnished to do so, subject to the following conditions: 16 | 17 | The above copyright notice and this permission notice shall be included in all 18 | copies or substantial portions of the Software. 19 | 20 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 23 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 24 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 25 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 26 | SOFTWARE. 27 | */ 28 | #ifndef YASIO__SFMT_HPP 29 | #define YASIO__SFMT_HPP 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include "yasio/compiler/feature_test.hpp" 36 | 37 | namespace yasio 38 | { 39 | // yasio::format_traits: the vsnprintf/vswprintf wrapper 40 | // !!! if '_BufferCount' had been sufficiently large, not counting the terminating null character. 41 | template struct format_traits {}; 42 | template <> struct format_traits { 43 | static int format(char* const _Buffer, size_t const _BufferCount, char const* const _Format, va_list _ArgList) 44 | { 45 | return vsnprintf(_Buffer, _BufferCount, _Format, _ArgList); 46 | } 47 | static const char* report_error() { return "yasio::_strfmt: an error is encountered!"; } 48 | }; 49 | template <> struct format_traits { 50 | static int format(wchar_t* const _Buffer, size_t const _BufferCount, wchar_t const* const _Format, va_list _ArgList) 51 | { 52 | return vswprintf(_Buffer, _BufferCount, _Format, _ArgList); 53 | } 54 | static const wchar_t* report_error() { return L"yasio::_strfmt: an error is encountered!"; } 55 | }; 56 | 57 | template , class _Alloc = std::allocator<_Elem>> 58 | inline bool _vstrfmt(std::basic_string<_Elem, _Traits, _Alloc>& buf, size_t initial_buf_size, const _Elem* format, va_list initialized_args) 59 | { 60 | bool ok = true; 61 | va_list args; 62 | 63 | auto offset = buf.size(); 64 | buf.resize(offset + initial_buf_size); 65 | 66 | va_copy(args, initialized_args); 67 | int nret = format_traits<_Elem>::format(&buf.front() + offset, buf.length() - offset + 1, format, args); 68 | va_end(args); 69 | 70 | if (nret >= 0) 71 | { 72 | if ((unsigned int)nret < (buf.length() - offset)) 73 | { 74 | buf.resize(offset + nret); 75 | } 76 | else if ((unsigned int)nret > (buf.length() - offset)) 77 | { // handle return required length when buffer insufficient 78 | buf.resize(offset + nret); 79 | 80 | va_copy(args, initialized_args); 81 | nret = format_traits<_Elem>::format(&buf.front() + offset, buf.length() - offset + 1, format, args); 82 | va_end(args); 83 | } 84 | // else equals, do nothing. 85 | } 86 | else 87 | { // handle return -1 when buffer insufficient 88 | /* 89 | return -1 when the output was truncated: 90 | - vsnprintf: vs2013/older & glibc <= 2.0.6 91 | - vswprintf: all standard implemetations 92 | references: 93 | - https://man7.org/linux/man-pages/man3/vsnprintf.3.html 94 | - https://www.cplusplus.com/reference/cstdio/vsnprintf/ 95 | - https://www.cplusplus.com/reference/cwchar/vswprintf/ 96 | - https://stackoverflow.com/questions/51134188/why-vsnwprintf-missing 97 | - https://stackoverflow.com/questions/10446754/vsnwprintf-alternative-on-linux 98 | 99 | */ 100 | enum : size_t 101 | { 102 | enlarge_limits = (1 << 20), // limits the buffer cost memory less than 2MB 103 | }; 104 | do 105 | { 106 | buf.resize(offset + ((buf.length() - offset) << 1)); 107 | 108 | va_copy(args, initialized_args); 109 | nret = format_traits<_Elem>::format(&buf.front() + offset, buf.length() - offset + 1, format, args); 110 | va_end(args); 111 | 112 | } while (nret < 0 && (buf.length() - offset) <= enlarge_limits); 113 | if (nret > 0) 114 | buf.resize(offset + nret); 115 | else 116 | ok = false; 117 | } 118 | 119 | return ok; 120 | } 121 | 122 | template , class _Alloc = std::allocator<_Elem>> 123 | inline std::basic_string<_Elem, _Traits, _Alloc> _vstrfmt(size_t initial_buf_size, const _Elem* format, va_list initialized_args) 124 | { 125 | std::basic_string<_Elem, _Traits, _Alloc> buf; 126 | if (!_vstrfmt(buf, initial_buf_size, format, initialized_args)) 127 | { 128 | buf.clear(); 129 | buf.shrink_to_fit(); 130 | buf = format_traits<_Elem>::report_error(); 131 | } 132 | return buf; 133 | } 134 | 135 | template , class _Alloc = std::allocator<_Elem>> 136 | inline std::basic_string<_Elem, _Traits, _Alloc> basic_strfmt(size_t n, const _Elem* format, ...) 137 | { 138 | va_list initialized_args; 139 | 140 | va_start(initialized_args, format); 141 | auto buf = _vstrfmt(n, format, initialized_args); 142 | va_end(initialized_args); 143 | 144 | return buf; 145 | } 146 | 147 | static auto YASIO__CONSTEXPR strfmt = basic_strfmt; 148 | static auto YASIO__CONSTEXPR wcsfmt = basic_strfmt; 149 | 150 | } // namespace yasio 151 | 152 | #endif 153 | -------------------------------------------------------------------------------- /Plugins/yasio/Source/yasio/Public/yasio/sz.hpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////////////////// 2 | // A multi-platform support c++11 library with focus on asynchronous socket I/O for any 3 | // client application. 4 | ////////////////////////////////////////////////////////////////////////////////////////// 5 | /* 6 | The MIT License (MIT) 7 | 8 | Copyright (c) 2012-2024 HALX99 9 | 10 | Permission is hereby granted, free of charge, to any person obtaining a copy 11 | of this software and associated documentation files (the "Software"), to deal 12 | in the Software without restriction, including without limitation the rights 13 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 14 | copies of the Software, and to permit persons to whom the Software is 15 | furnished to do so, subject to the following conditions: 16 | The above copyright notice and this permission notice shall be included in all 17 | copies or substantial portions of the Software. 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | */ 26 | #ifndef YASIO__SZ_HPP 27 | #define YASIO__SZ_HPP 28 | 29 | #include 30 | 31 | static const uint64_t YASIO__B = (1); 32 | static const uint64_t YASIO__KB = (1024 * YASIO__B); 33 | static const uint64_t YASIO__MB = (1024 * YASIO__KB); 34 | static const uint64_t YASIO__GB = (1024 * YASIO__MB); 35 | static const uint64_t YASIO__TB = (1024 * YASIO__GB); 36 | static const uint64_t YASIO__PB = (1024 * YASIO__TB); 37 | static const uint64_t YASIO__EB = (1024 * YASIO__PB); // lgtm [cpp/unused-static-variable] 38 | 39 | #define YASIO__K YASIO__KB 40 | #define YASIO__M YASIO__MB 41 | #define YASIO__G YASIO__GB 42 | #define YASIO__T YASIO__TB 43 | #define YASIO__P YASIO__PB 44 | #define YASIO__E YASIO__EB 45 | #define YASIO__b YASIO__B 46 | #define YASIO__k YASIO__K 47 | #define YASIO__m YASIO__M 48 | #define YASIO__g YASIO__G 49 | #define YASIO__t YASIO__T 50 | #define YASIO__p YASIO__P 51 | #define YASIO__e YASIO__E 52 | 53 | #define YASIO_SZ(n, u) ((n)*YASIO__##u) 54 | 55 | #define YASIO_SZ_ALIGN(d, a) (((d) + ((a)-1)) & ~((a)-1)) 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /Plugins/yasio/Source/yasio/Public/yasio/thread_name.hpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////////////////// 2 | // A multi-platform support c++11 library with focus on asynchronous socket I/O for any 3 | // client application. 4 | ////////////////////////////////////////////////////////////////////////////////////////// 5 | /* 6 | The MIT License (MIT) 7 | 8 | Copyright (c) 2012-2024 HALX99 9 | 10 | Permission is hereby granted, free of charge, to any person obtaining a copy 11 | of this software and associated documentation files (the "Software"), to deal 12 | in the Software without restriction, including without limitation the rights 13 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 14 | copies of the Software, and to permit persons to whom the Software is 15 | furnished to do so, subject to the following conditions: 16 | 17 | The above copyright notice and this permission notice shall be included in all 18 | copies or substantial portions of the Software. 19 | 20 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 23 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 24 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 25 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 26 | SOFTWARE. 27 | */ 28 | #ifndef YASIO__THREAD_NAME_HPP 29 | #define YASIO__THREAD_NAME_HPP 30 | #if defined(WIN32) 31 | # if !defined(WIN32_LEAN_AND_MEAN) 32 | # define WIN32_LEAN_AND_MEAN 33 | # endif 34 | # include 35 | #else 36 | # include 37 | # if defined(__FreeBSD__) || defined(__OpenBSD__) 38 | # include // For pthread_getthreadid_np() / pthread_set_name_np() 39 | # endif 40 | #endif 41 | 42 | #if defined(_WIN32) 43 | const DWORD MS_VC_EXCEPTION = 0x406D1388; 44 | # pragma pack(push, 8) 45 | typedef struct _yasio__thread_info { 46 | DWORD dwType; // Must be 0x1000. 47 | LPCSTR szName; // Pointer to name (in user addr space). 48 | DWORD dwThreadID; // Thread ID (-1=caller thread). 49 | DWORD dwFlags; // Reserved for future use, must be zero. 50 | } yasio__thread_info; 51 | # pragma pack(pop) 52 | static void yasio__set_thread_name(const char* threadName) 53 | { 54 | yasio__thread_info info; 55 | info.dwType = 0x1000; 56 | info.szName = threadName; 57 | info.dwThreadID = GetCurrentThreadId(); 58 | info.dwFlags = 0; 59 | # if !defined(__MINGW64__) && !defined(__MINGW32__) 60 | __try 61 | { 62 | RaiseException(MS_VC_EXCEPTION, 0, sizeof(info) / sizeof(ULONG_PTR), (ULONG_PTR*)&info); 63 | } 64 | __except (EXCEPTION_EXECUTE_HANDLER) 65 | {} 66 | # endif 67 | } 68 | #elif defined(__linux__) 69 | # if (defined(__GLIBC__) && defined(_GNU_SOURCE)) || defined(__ANDROID__) 70 | # define yasio__set_thread_name(name) pthread_setname_np(pthread_self(), name) 71 | # else 72 | # define yasio__set_thread_name(name) 73 | # endif 74 | #elif defined(__APPLE__) 75 | # define yasio__set_thread_name(name) pthread_setname_np(name) 76 | #elif defined(__FreeBSD__) || defined(__OpenBSD__) 77 | # define yasio__set_thread_name(name) pthread_set_name_np(pthread_self(), name) 78 | #elif defined(__NetBSD__) 79 | # define yasio__set_thread_name(name) pthread_setname_np(pthread_self(), "%s", (void*)name); 80 | #else 81 | # define yasio__set_thread_name(name) 82 | #endif 83 | 84 | namespace yasio 85 | { 86 | inline void set_thread_name(const char* name) { yasio__set_thread_name(name); } 87 | } // namespace yasio 88 | #endif 89 | -------------------------------------------------------------------------------- /Plugins/yasio/Source/yasio/Public/yasio/type_traits.hpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////////////////// 2 | // A multi-platform support c++11 library with focus on asynchronous socket I/O for any 3 | // client application. 4 | ////////////////////////////////////////////////////////////////////////////////////////// 5 | /* 6 | The MIT License (MIT) 7 | 8 | Copyright (c) 2012-2024 HALX99 9 | 10 | Permission is hereby granted, free of charge, to any person obtaining a copy 11 | of this software and associated documentation files (the "Software"), to deal 12 | in the Software without restriction, including without limitation the rights 13 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 14 | copies of the Software, and to permit persons to whom the Software is 15 | furnished to do so, subject to the following conditions: 16 | 17 | The above copyright notice and this permission notice shall be included in all 18 | copies or substantial portions of the Software. 19 | 20 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 23 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 24 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 25 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 26 | SOFTWARE. 27 | */ 28 | 29 | #pragma once 30 | #include 31 | 32 | namespace yasio 33 | { 34 | template 35 | struct aligned_storage_size { 36 | static const size_t value = sizeof(typename std::aligned_storage::type); 37 | }; 38 | template 39 | struct is_aligned_storage { 40 | static const bool value = aligned_storage_size<_Ty>::value == sizeof(_Ty); 41 | }; 42 | template 43 | struct is_iterator : public std::integral_constant::value> {}; 44 | 45 | template 46 | using enable_if_t = typename ::std::enable_if<_Test, _Ty>::type; 47 | 48 | template 49 | struct is_byte_type { 50 | static const bool value = std::is_same<_Ty, char>::value || std::is_same<_Ty, unsigned char>::value; 51 | }; 52 | 53 | template 54 | struct is_char_type { 55 | static const bool value = std::is_integral<_Ty>::value && sizeof(_Ty) <= sizeof(char32_t); 56 | }; 57 | 58 | } // namespace yasio 59 | -------------------------------------------------------------------------------- /Plugins/yasio/Source/yasio/Public/yasio/utils.hpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////////////////// 2 | // A multi-platform support c++11 library with focus on asynchronous socket I/O for any 3 | // client application. 4 | ////////////////////////////////////////////////////////////////////////////////////////// 5 | /* 6 | The MIT License (MIT) 7 | 8 | Copyright (c) 2012-2024 HALX99 9 | 10 | Permission is hereby granted, free of charge, to any person obtaining a copy 11 | of this software and associated documentation files (the "Software"), to deal 12 | in the Software without restriction, including without limitation the rights 13 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 14 | copies of the Software, and to permit persons to whom the Software is 15 | furnished to do so, subject to the following conditions: 16 | 17 | The above copyright notice and this permission notice shall be included in all 18 | copies or substantial portions of the Software. 19 | 20 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 23 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 24 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 25 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 26 | SOFTWARE. 27 | */ 28 | #ifndef YASIO__UTILS_HPP 29 | #define YASIO__UTILS_HPP 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include "yasio/compiler/feature_test.hpp" 35 | 36 | namespace yasio 37 | { 38 | // typedefs 39 | typedef long long highp_time_t; 40 | #if YASIO__HAS_CXX11 41 | typedef std::chrono::steady_clock steady_clock_t; 42 | #else 43 | typedef std::chrono::high_resolution_clock steady_clock_t; 44 | #endif 45 | typedef std::chrono::system_clock system_clock_t; 46 | 47 | // The high precision nano seconds timestamp since epoch 48 | template 49 | inline highp_time_t xhighp_clock() 50 | { 51 | auto duration = _Ty::now().time_since_epoch(); 52 | return std::chrono::duration_cast(duration).count(); 53 | } 54 | // The high precision micro seconds timestamp since epoch 55 | template 56 | inline highp_time_t highp_clock() 57 | { 58 | return xhighp_clock<_Ty>() / std::milli::den; 59 | } 60 | // The normal precision milli seconds timestamp since epoch 61 | template 62 | inline highp_time_t clock() 63 | { 64 | return xhighp_clock<_Ty>() / std::micro::den; 65 | } 66 | // The time now in seconds since epoch, better performance than chrono on win32 67 | // see: win10 sdk ucrt/time/time.cpp:common_time 68 | // https://docs.microsoft.com/en-us/windows/desktop/sysinfo/acquiring-high-resolution-time-stamps 69 | inline highp_time_t time_now() { return ::time(nullptr); } 70 | 71 | #if YASIO__HAS_CXX17 72 | using std::clamp; 73 | #else 74 | template 75 | const _Ty& clamp(const _Ty& v, const _Ty& lo, const _Ty& hi) 76 | { 77 | assert(!(hi < lo)); 78 | return v < lo ? lo : hi < v ? hi : v; 79 | } 80 | #endif 81 | 82 | template 83 | inline void invoke_dtor(_Ty* p) 84 | { 85 | p->~_Ty(); 86 | } 87 | 88 | inline bool is_regular_file(const char* path) 89 | { 90 | struct stat st; 91 | return (::stat(path, &st) == 0) && (st.st_mode & S_IFREG); 92 | } 93 | 94 | } // namespace yasio 95 | 96 | #endif 97 | -------------------------------------------------------------------------------- /Plugins/yasio/Source/yasio/Public/yasio/wtimer_hres.hpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////////////////// 2 | // A multi-platform support c++11 library with focus on asynchronous socket I/O for any 3 | // client application. 4 | ////////////////////////////////////////////////////////////////////////////////////////// 5 | /* 6 | The MIT License (MIT) 7 | 8 | Copyright (c) 2012-2024 HALX99 9 | 10 | Permission is hereby granted, free of charge, to any person obtaining a copy 11 | of this software and associated documentation files (the "Software"), to deal 12 | in the Software without restriction, including without limitation the rights 13 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 14 | copies of the Software, and to permit persons to whom the Software is 15 | furnished to do so, subject to the following conditions: 16 | The above copyright notice and this permission notice shall be included in all 17 | copies or substantial portions of the Software. 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | */ 26 | 27 | #pragma once 28 | 29 | #ifdef _WIN32 30 | 31 | # include "yasio/config.hpp" 32 | # include "yasio/utils.hpp" 33 | 34 | # if defined(YASIO__USE_TIMEAPI) 35 | # include 36 | # pragma comment(lib, "Winmm.lib") 37 | # endif 38 | 39 | namespace yasio 40 | { 41 | /** 42 | * CLASS wtimer_hres: The windows timer high-resolution setup helper 43 | */ 44 | struct wtimer_hres { 45 | using NTSTATUS = LONG; 46 | /** 47 | * @param res the timer resolution in 100-ns units: 100-ns * 10000 = 1ms 48 | * @remark 49 | * - timeapi timeBeginPeriod max resolution is 1ms 50 | * - ZwSetTimerResolution max resolution is 0.5ms aka 100-ns * 5000 51 | */ 52 | static const ULONG _1ms_den = 10000; 53 | wtimer_hres(ULONG timer_res = _1ms_den) 54 | { 55 | # if defined(YASIO__USE_TIMEAPI) 56 | TIMECAPS tc; 57 | if (TIMERR_NOERROR == timeGetDevCaps(&tc, sizeof(TIMECAPS))) 58 | { 59 | timer_res_ = yasio::clamp(static_cast(timer_res / _1ms_den), tc.wPeriodMin, tc.wPeriodMax); 60 | timeBeginPeriod(timer_res_); 61 | } 62 | # else 63 | do 64 | { 65 | HMODULE hNtDll = GetModuleHandleW(L"ntdll"); 66 | if (!hNtDll) 67 | break; 68 | 69 | NTSTATUS(__stdcall * NtQueryTimerResolution) 70 | (OUT PULONG MinimumResolution, OUT PULONG MaximumResolution, OUT PULONG CurrentResolution) = 71 | reinterpret_cast(GetProcAddress(hNtDll, "NtQueryTimerResolution")); 72 | if (!NtQueryTimerResolution) 73 | break; 74 | ZwSetTimerResolution = reinterpret_cast(GetProcAddress(hNtDll, "ZwSetTimerResolution")); 75 | if (!ZwSetTimerResolution) 76 | break; 77 | 78 | ULONG MinimumResolution, MaximumResolution, CurrentResolution; 79 | if (NtQueryTimerResolution(&MinimumResolution, &MaximumResolution, &CurrentResolution) != 0) 80 | break; 81 | ZwSetTimerResolution(yasio::clamp(timer_res, MaximumResolution, MinimumResolution), TRUE, &timer_res); 82 | } while (false); 83 | # endif 84 | } 85 | ~wtimer_hres() 86 | { 87 | # if defined(YASIO__USE_TIMEAPI) 88 | if (timer_res_ != 0) 89 | timeEndPeriod(timer_res_); 90 | # else 91 | if (timer_res_) 92 | ZwSetTimerResolution(timer_res_, FALSE, nullptr); 93 | # endif 94 | } 95 | # if defined(YASIO__USE_TIMEAPI) 96 | UINT timer_res_{0}; 97 | # else 98 | NTSTATUS(__stdcall* ZwSetTimerResolution) 99 | (IN ULONG RequestedResolution, IN BOOLEAN Set, OUT PULONG ActualResolution){nullptr}; 100 | ULONG timer_res_{0}; 101 | # endif 102 | }; 103 | 104 | } // namespace yasio 105 | #endif 106 | -------------------------------------------------------------------------------- /Plugins/yasio/Source/yasio/Public/yasio/yasio.hpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////////////////// 2 | // A multi-platform support c++11 library with focus on asynchronous socket I/O for any 3 | // client application. 4 | ////////////////////////////////////////////////////////////////////////////////////////// 5 | /* 6 | The MIT License (MIT) 7 | 8 | Copyright (c) 2012-2024 HALX99 9 | 10 | Permission is hereby granted, free of charge, to any person obtaining a copy 11 | of this software and associated documentation files (the "Software"), to deal 12 | in the Software without restriction, including without limitation the rights 13 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 14 | copies of the Software, and to permit persons to whom the Software is 15 | furnished to do so, subject to the following conditions: 16 | 17 | The above copyright notice and this permission notice shall be included in all 18 | copies or substantial portions of the Software. 19 | 20 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 23 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 24 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 25 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 26 | SOFTWARE. 27 | */ 28 | #ifndef YASIO__CORE_HPP 29 | #define YASIO__CORE_HPP 30 | 31 | #include "yasio/ibstream.hpp" 32 | #include "yasio/obstream.hpp" 33 | #include "yasio/io_service.hpp" 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /Plugins/yasio/Source/yasio/Public/yasio/yasio.natvis: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {{ size={_Mysize} capacity={_Myres} }} 6 | 7 | _Mysize 8 | _Myres 9 | 10 | _Mysize 11 | _Myfirst 12 | 13 | 14 | 15 | 16 | {{ size={_Mysize} {_Myfirst,[_Mysize]s8} }} 17 | 18 | _Mysize 19 | _Myres 20 | 21 | _Mysize 22 | _Myfirst 23 | 24 | 25 | 26 | 27 | 28 | {_Myfirst,s8} 29 | {&_Myfirst,s8} 30 | _Myfirst,s8 31 | &_Myfirst,s8 32 | 33 | _Mysize 34 | _Myres 35 | 36 | _Mysize 37 | _Myfirst 38 | 39 | 40 | _Mysize 41 | &_Myfirst 42 | 43 | 44 | 45 | 46 | 47 | 48 | {_Myfirst,su} 49 | {&_Myfirst,su} 50 | _Myfirst,su 51 | &_Myfirst,su 52 | 53 | _Mysize 54 | _Myres 55 | 56 | _Mysize 57 | _Myfirst 58 | 59 | 60 | _Mysize 61 | &_Myfirst 62 | 63 | 64 | 65 | 66 | {_Myfirst,s32} 67 | {&_Myfirst,s32} 68 | _Myfirst,s32 69 | &_Myfirst,s32 70 | 71 | _Mysize 72 | _Myres 73 | 74 | _Mysize 75 | _Myfirst 76 | 77 | 78 | _Mysize 79 | &_Myfirst 80 | 81 | 82 | 83 | 84 | -------------------------------------------------------------------------------- /Plugins/yasio/Source/yasio/Public/yasio/yasio_fwd.hpp: -------------------------------------------------------------------------------- 1 | // A multi-platform support c++11 library with focus on asynchronous socket I/O for any 2 | // client application. 3 | // 4 | ////////////////////////////////////////////////////////////////////////////////////////// 5 | /* 6 | The MIT License (MIT) 7 | 8 | Copyright (c) 2012-2024 HALX99 9 | 10 | Permission is hereby granted, free of charge, to any person obtaining a copy 11 | of this software and associated documentation files (the "Software"), to deal 12 | in the Software without restriction, including without limitation the rights 13 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 14 | copies of the Software, and to permit persons to whom the Software is 15 | furnished to do so, subject to the following conditions: 16 | 17 | The above copyright notice and this permission notice shall be included in all 18 | copies or substantial portions of the Software. 19 | 20 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 23 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 24 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 25 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 26 | SOFTWARE. 27 | */ 28 | #ifndef YASIO__FWD_HPP 29 | #define YASIO__FWD_HPP 30 | #include "yasio/compiler/feature_test.hpp" 31 | 32 | namespace yasio 33 | { 34 | YASIO__NS_INLINE 35 | namespace inet 36 | { 37 | class highp_timer; 38 | class io_service; 39 | class io_event; 40 | class io_channel; 41 | typedef class io_transport* transport_handle_t; 42 | } // namespace inet 43 | #if !YASIO__HAS_CXX11 44 | using namespace yasio::inet; 45 | #endif 46 | } // namespace yasio 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /Plugins/yasio/Source/yasio/yasio.Build.cs: -------------------------------------------------------------------------------- 1 | // Copyright 1998-2018 Epic Games, Inc. All Rights Reserved. 2 | 3 | using UnrealBuildTool; 4 | using System.IO; 5 | public class yasio : ModuleRules 6 | { 7 | public yasio(ReadOnlyTargetRules Target) : base(Target) 8 | { 9 | PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs; 10 | bUseRTTI = true; 11 | PrivateIncludePaths.AddRange(new string[] { Path.Combine(ModuleDirectory, "Private")}); 12 | PublicIncludePaths.AddRange(new string[] { Path.Combine(ModuleDirectory, "Public")}); 13 | PublicDependencyModuleNames.AddRange( 14 | new string[] 15 | { 16 | 17 | // ... add other public dependencies that you statically link with here ... 18 | } 19 | ); 20 | 21 | 22 | PrivateDependencyModuleNames.AddRange( 23 | new string[] 24 | { 25 | "OpenSSL", "Core" 26 | // ... add private dependencies that you statically link with here ... 27 | } 28 | ); 29 | 30 | DynamicallyLoadedModuleNames.AddRange( 31 | new string[] 32 | { 33 | // ... add any modules that your module loads dynamically here ... 34 | } 35 | ); 36 | 37 | PublicDefinitions.Add("YASIO_SSL_BACKEND=1"); 38 | PublicDefinitions.Add("YASIO_BUILD_SHARED_LIBS=1"); 39 | PrivateDefinitions.Add("YASIO_LIB=1"); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Plugins/yasio/yasio.uplugin: -------------------------------------------------------------------------------- 1 | { 2 | "FileVersion": 3, 3 | "Version": 1, 4 | "VersionName": "4.2.1", 5 | "FriendlyName": "yasio", 6 | "Description": "yasio for unreal engine", 7 | "Category": "Other", 8 | "CreatedBy": "halx99", 9 | "CreatedByURL": "", 10 | "DocsURL": "", 11 | "MarketplaceURL": "", 12 | "SupportURL": "", 13 | "CanContainContent": true, 14 | "IsBetaVersion": false, 15 | "Installed": false, 16 | "Modules": [ 17 | { 18 | "Name": "yasio", 19 | "Type": "Runtime", 20 | "LoadingPhase": "PreLoadingScreen" 21 | } 22 | ] 23 | } 24 | -------------------------------------------------------------------------------- /Plugins/yasio_http/.clang-format: -------------------------------------------------------------------------------- 1 | # This file is copy from https://github.com/google/angle with some modifications 2 | # Defines the ADXE style for automatic reformatting. 3 | # https://code.google.com/p/angleproject/wiki/CodingStandard 4 | # See Clang docs: http://clang.llvm.org/docs/ClangFormatStyleOptions.html 5 | BasedOnStyle: Chromium 6 | 7 | # Allow double brackets such as std::vector>. 8 | Standard: Cpp11 9 | 10 | # Indent 4 spaces at a time. 11 | IndentWidth: 4 12 | 13 | # Keep lines under 120 columns long. 14 | ColumnLimit: 120 15 | 16 | SortIncludes: false 17 | 18 | # Always break before braces 19 | BreakBeforeBraces: Custom 20 | BraceWrapping: 21 | AfterCaseLabel: true 22 | AfterClass: true 23 | AfterControlStatement: true 24 | AfterEnum: true 25 | AfterFunction: true 26 | AfterNamespace: true 27 | AfterStruct: true 28 | AfterUnion: true 29 | BeforeCatch: true 30 | BeforeElse: true 31 | IndentBraces: false 32 | SplitEmptyFunction: false 33 | SplitEmptyRecord: false 34 | SplitEmptyNamespace: false 35 | 36 | # Keeps extern "C" blocks unindented. 37 | AfterExternBlock: false 38 | 39 | # Indent case labels. 40 | IndentCaseLabels: false 41 | 42 | # Left-align pointers and references 43 | PointerAlignment: Left 44 | 45 | # ANGLE likes to align things as much as possible. 46 | AlignOperands: true 47 | AlignConsecutiveAssignments: true 48 | 49 | # Use 0 space negative offset for access modifiers 50 | AccessModifierOffset: -4 51 | 52 | # TODO(jmadill): Decide if we want this on. Doesn't have an "all or none" mode. 53 | AllowShortCaseLabelsOnASingleLine: false 54 | 55 | # Useful for spacing out functions in classes 56 | KeepEmptyLinesAtTheStartOfBlocks: true 57 | 58 | # Indent nested PP directives. 59 | IndentPPDirectives: AfterHash 60 | 61 | # Include blocks style 62 | IncludeBlocks: Preserve 63 | UseTab: Never 64 | BreakConstructorInitializers: BeforeComma -------------------------------------------------------------------------------- /Plugins/yasio_http/Source/yasio_http/Private/yasio_http/llhttp/http.c: -------------------------------------------------------------------------------- 1 | #include 2 | #ifndef LLHTTP__TEST 3 | # include "llhttp.h" 4 | #else 5 | # define llhttp_t llparse_t 6 | #endif /* */ 7 | 8 | int llhttp_message_needs_eof(const llhttp_t* parser); 9 | int llhttp_should_keep_alive(const llhttp_t* parser); 10 | 11 | int llhttp__before_headers_complete(llhttp_t* parser, const char* p, 12 | const char* endp) { 13 | /* Set this here so that on_headers_complete() callbacks can see it */ 14 | if ((parser->flags & F_UPGRADE) && 15 | (parser->flags & F_CONNECTION_UPGRADE)) { 16 | /* For responses, "Upgrade: foo" and "Connection: upgrade" are 17 | * mandatory only when it is a 101 Switching Protocols response, 18 | * otherwise it is purely informational, to announce support. 19 | */ 20 | parser->upgrade = 21 | (parser->type == HTTP_REQUEST || parser->status_code == 101); 22 | } else { 23 | parser->upgrade = (parser->method == HTTP_CONNECT); 24 | } 25 | return 0; 26 | } 27 | 28 | 29 | /* Return values: 30 | * 0 - No body, `restart`, message_complete 31 | * 1 - CONNECT request, `restart`, message_complete, and pause 32 | * 2 - chunk_size_start 33 | * 3 - body_identity 34 | * 4 - body_identity_eof 35 | * 5 - invalid transfer-encoding for request 36 | */ 37 | int llhttp__after_headers_complete(llhttp_t* parser, const char* p, 38 | const char* endp) { 39 | int hasBody; 40 | 41 | hasBody = parser->flags & F_CHUNKED || parser->content_length > 0; 42 | if ( 43 | (parser->upgrade && (parser->method == HTTP_CONNECT || 44 | (parser->flags & F_SKIPBODY) || !hasBody)) || 45 | /* See RFC 2616 section 4.4 - 1xx e.g. Continue */ 46 | (parser->type == HTTP_RESPONSE && parser->status_code == 101) 47 | ) { 48 | /* Exit, the rest of the message is in a different protocol. */ 49 | return 1; 50 | } 51 | 52 | if (parser->type == HTTP_RESPONSE && parser->status_code == 100) { 53 | /* No body, restart as the message is complete */ 54 | return 0; 55 | } 56 | 57 | /* See RFC 2616 section 4.4 */ 58 | if ( 59 | parser->flags & F_SKIPBODY || /* response to a HEAD request */ 60 | ( 61 | parser->type == HTTP_RESPONSE && ( 62 | parser->status_code == 102 || /* Processing */ 63 | parser->status_code == 103 || /* Early Hints */ 64 | parser->status_code == 204 || /* No Content */ 65 | parser->status_code == 304 /* Not Modified */ 66 | ) 67 | ) 68 | ) { 69 | return 0; 70 | } else if (parser->flags & F_CHUNKED) { 71 | /* chunked encoding - ignore Content-Length header, prepare for a chunk */ 72 | return 2; 73 | } else if (parser->flags & F_TRANSFER_ENCODING) { 74 | if (parser->type == HTTP_REQUEST && 75 | (parser->lenient_flags & LENIENT_CHUNKED_LENGTH) == 0 && 76 | (parser->lenient_flags & LENIENT_TRANSFER_ENCODING) == 0) { 77 | /* RFC 7230 3.3.3 */ 78 | 79 | /* If a Transfer-Encoding header field 80 | * is present in a request and the chunked transfer coding is not 81 | * the final encoding, the message body length cannot be determined 82 | * reliably; the server MUST respond with the 400 (Bad Request) 83 | * status code and then close the connection. 84 | */ 85 | return 5; 86 | } else { 87 | /* RFC 7230 3.3.3 */ 88 | 89 | /* If a Transfer-Encoding header field is present in a response and 90 | * the chunked transfer coding is not the final encoding, the 91 | * message body length is determined by reading the connection until 92 | * it is closed by the server. 93 | */ 94 | return 4; 95 | } 96 | } else { 97 | if (!(parser->flags & F_CONTENT_LENGTH)) { 98 | if (!llhttp_message_needs_eof(parser)) { 99 | /* Assume content-length 0 - read the next */ 100 | return 0; 101 | } else { 102 | /* Read body until EOF */ 103 | return 4; 104 | } 105 | } else if (parser->content_length == 0) { 106 | /* Content-Length header given but zero: Content-Length: 0\r\n */ 107 | return 0; 108 | } else { 109 | /* Content-Length header given and non-zero */ 110 | return 3; 111 | } 112 | } 113 | } 114 | 115 | 116 | int llhttp__after_message_complete(llhttp_t* parser, const char* p, 117 | const char* endp) { 118 | int should_keep_alive; 119 | 120 | should_keep_alive = llhttp_should_keep_alive(parser); 121 | parser->finish = HTTP_FINISH_SAFE; 122 | parser->flags = 0; 123 | 124 | /* NOTE: this is ignored in loose parsing mode */ 125 | return should_keep_alive; 126 | } 127 | 128 | 129 | int llhttp_message_needs_eof(const llhttp_t* parser) { 130 | if (parser->type == HTTP_REQUEST) { 131 | return 0; 132 | } 133 | 134 | /* See RFC 2616 section 4.4 */ 135 | if (parser->status_code / 100 == 1 || /* 1xx e.g. Continue */ 136 | parser->status_code == 204 || /* No Content */ 137 | parser->status_code == 304 || /* Not Modified */ 138 | (parser->flags & F_SKIPBODY)) { /* response to a HEAD request */ 139 | return 0; 140 | } 141 | 142 | /* RFC 7230 3.3.3, see `llhttp__after_headers_complete` */ 143 | if ((parser->flags & F_TRANSFER_ENCODING) && 144 | (parser->flags & F_CHUNKED) == 0) { 145 | return 1; 146 | } 147 | 148 | if (parser->flags & (F_CHUNKED | F_CONTENT_LENGTH)) { 149 | return 0; 150 | } 151 | 152 | return 1; 153 | } 154 | 155 | 156 | int llhttp_should_keep_alive(const llhttp_t* parser) { 157 | if (parser->http_major > 0 && parser->http_minor > 0) { 158 | /* HTTP/1.1 */ 159 | if (parser->flags & F_CONNECTION_CLOSE) { 160 | return 0; 161 | } 162 | } else { 163 | /* HTTP/1.0 or earlier */ 164 | if (!(parser->flags & F_CONNECTION_KEEP_ALIVE)) { 165 | return 0; 166 | } 167 | } 168 | 169 | return !llhttp_message_needs_eof(parser); 170 | } 171 | -------------------------------------------------------------------------------- /Plugins/yasio_http/Source/yasio_http/Private/yasio_http/yasio_http.cpp: -------------------------------------------------------------------------------- 1 | #include "yasio/config.hpp" 2 | 3 | #if defined(YASIO_INSIDE_UNREAL) 4 | 5 | #include "Modules/ModuleManager.h" 6 | 7 | class yasio_http_unreal_module : public IModuleInterface 8 | { 9 | public: 10 | /** IModuleInterface implementation */ 11 | void StartupModule() override {} 12 | void ShutdownModule() override {} 13 | }; 14 | IMPLEMENT_MODULE(yasio_http_unreal_module, yasio_http) 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /Plugins/yasio_http/Source/yasio_http/Public/yasio_http/HttpCookie.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | Copyright (c) 2013-2016 Chukong Technologies Inc. 3 | Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. 4 | Copyright (c) 2019-present Axmol Engine contributors. 5 | 6 | https://axmolengine.github.io/ 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in 16 | all copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | THE SOFTWARE. 25 | ****************************************************************************/ 26 | 27 | #ifndef YASIO_EXT_HTTP_COOKIE_H 28 | #define YASIO_EXT_HTTP_COOKIE_H 29 | /// @cond DO_NOT_SHOW 30 | 31 | #include 32 | #include 33 | #include 34 | 35 | #include "yasio/string_view.hpp" 36 | 37 | namespace yasio_ext 38 | { 39 | 40 | namespace network 41 | { 42 | #if YASIO__HAS_CXX14 43 | using namespace cxx17::string_view_literals; 44 | # define _mksv(a) a ""_sv 45 | #else 46 | template 47 | inline cxx17::string_view _mksv(const char (&str)[_Size]) 48 | { 49 | return cxx17::string_view{str, _Size - 1}; 50 | } 51 | #endif 52 | 53 | class Uri; 54 | struct CookieInfo 55 | { 56 | CookieInfo() = default; 57 | CookieInfo(const CookieInfo&) = default; 58 | CookieInfo(CookieInfo&& rhs) 59 | : domain(std::move(rhs.domain)) 60 | , tailmatch(rhs.tailmatch) 61 | , path(std::move(rhs.path)) 62 | , secure(rhs.secure) 63 | , name(std::move(rhs.name)) 64 | , value(std::move(rhs.value)) 65 | , expires(rhs.expires) 66 | {} 67 | 68 | CookieInfo& operator=(CookieInfo&& rhs) 69 | { 70 | domain = std::move(rhs.domain); 71 | tailmatch = rhs.tailmatch; 72 | path = std::move(rhs.path); 73 | secure = rhs.secure; 74 | name = std::move(rhs.name); 75 | value = std::move(rhs.value); 76 | expires = rhs.expires; 77 | return *this; 78 | } 79 | 80 | bool isSame(const CookieInfo& rhs) { return name == rhs.name && domain == rhs.domain; } 81 | 82 | void updateValue(const CookieInfo& rhs) 83 | { 84 | value = rhs.value; 85 | expires = rhs.expires; 86 | path = rhs.path; 87 | } 88 | 89 | std::string domain; 90 | bool tailmatch = true; 91 | std::string path; 92 | bool secure = false; 93 | std::string name; 94 | std::string value; 95 | time_t expires = 0; 96 | }; 97 | 98 | class HttpCookie 99 | { 100 | public: 101 | void readFile(); 102 | 103 | void writeFile(); 104 | void setCookieFileName(cxx17::string_view fileName); 105 | 106 | const std::vector* getCookies() const; 107 | const CookieInfo* getMatchCookie(const Uri& uri) const; 108 | void updateOrAddCookie(CookieInfo* cookie); 109 | 110 | // Check match cookies for http request 111 | std::string checkAndGetFormatedMatchCookies(const Uri& uri); 112 | bool updateOrAddCookie(const cxx17::string_view& cookie, const Uri& uri); 113 | 114 | private: 115 | std::string _cookieFileName; 116 | std::vector _cookies; 117 | }; 118 | 119 | } // namespace network 120 | } // namespace yasio_ext 121 | 122 | /// @endcond 123 | #endif /* HTTP_COOKIE_H */ 124 | -------------------------------------------------------------------------------- /Plugins/yasio_http/Source/yasio_http/Public/yasio_http/Uri.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Facebook, Inc. 3 | * Copyright (c) 2017 Chukong Technologies 4 | * Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | * Uri class is based on the original file here https://github.com/facebook/folly/blob/master/folly/Uri.cpp 19 | */ 20 | 21 | #pragma once 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | #include "yasio/string_view.hpp" 28 | 29 | /** 30 | * @addtogroup network 31 | * @{ 32 | */ 33 | 34 | namespace yasio_ext 35 | { 36 | 37 | namespace network 38 | { 39 | 40 | /** 41 | * Class representing a URI. 42 | * 43 | * Consider http://www.facebook.com/foo/bar?key=foo#anchor 44 | * 45 | * The URI is broken down into its parts: scheme ("http"), authority 46 | * (ie. host and port, in most cases: "www.facebook.com"), path 47 | * ("/foo/bar"), query ("key=foo") and fragment ("anchor"). The scheme is 48 | * lower-cased. 49 | * 50 | * If this Uri represents a URL, note that, to prevent ambiguity, the component 51 | * parts are NOT percent-decoded; you should do this yourself with 52 | * uriUnescape() (for the authority and path) and uriUnescape(..., 53 | * UriEscapeMode::QUERY) (for the query, but probably only after splitting at 54 | * '&' to identify the individual parameters). 55 | */ 56 | class Uri 57 | { 58 | public: 59 | /** 60 | * Parse a Uri from a string. Throws std::invalid_argument on parse error. 61 | */ 62 | static Uri parse(cxx17::string_view str); 63 | 64 | /** Default constructor */ 65 | Uri(); 66 | 67 | /** Copy constructor */ 68 | Uri(const Uri& o); 69 | 70 | /** Move constructor */ 71 | Uri(Uri&& o); 72 | 73 | /** Copy assignment */ 74 | Uri& operator=(const Uri& o); 75 | 76 | /** Move assignment */ 77 | Uri& operator=(Uri&& o); 78 | 79 | /** Checks whether two Uri instances contain the same values */ 80 | bool operator==(const Uri& o) const; 81 | 82 | /** Checks wether it's a valid URI */ 83 | bool isValid() const { return _isValid; } 84 | 85 | /** Checks whether it's a SSL connection */ 86 | bool isSecure() const { return _isSecure; } 87 | 88 | void invalid() { _isValid = false; } 89 | /** Gets the scheme name for this URI. */ 90 | cxx17::string_view getScheme() const { return _scheme; } 91 | 92 | /** Gets the user name with the specified URI. */ 93 | cxx17::string_view getUserName() const { return _username; } 94 | 95 | /** Gets the password with the specified URI. */ 96 | cxx17::string_view getPassword() const { return _password; } 97 | /** 98 | * Get host part of URI. If host is an IPv6 address, square brackets will be 99 | * returned, for example: "[::1]". 100 | */ 101 | cxx17::string_view getHost() const { return _host; } 102 | /** 103 | * Get host part of URI. If host is an IPv6 address, square brackets will not 104 | * be returned, for exmaple "::1"; otherwise it returns the same thing as 105 | * getHost(). 106 | * 107 | * getHostName() is what one needs to call if passing the host to any other tool 108 | * or API that connects to that host/port; e.g. getaddrinfo() only understands 109 | * IPv6 host without square brackets 110 | */ 111 | cxx17::string_view getHostName() const { return _hostName; } 112 | 113 | /** Gets the port number of the URI. */ 114 | uint16_t getPort() const { return _port; } 115 | 116 | /** Gets the path part of the URI. */ 117 | cxx17::string_view getPath() const { return _path; } 118 | 119 | /// Gets the path, query and fragment parts of the URI. 120 | cxx17::string_view getPathEtc() const { return _pathEtc; } 121 | 122 | /** Gets the query part of the URI. */ 123 | cxx17::string_view getQuery() const { return _query; } 124 | 125 | /** Gets the fragment part of the URI */ 126 | cxx17::string_view getFragment() const { return _fragment; } 127 | 128 | /** Gets the authority part (userName, password, host and port) of the URI. 129 | * @note If the port number is a well-known port 130 | * number for the given scheme (e.g., 80 for http), it 131 | * is not included in the authority. 132 | */ 133 | cxx17::string_view getAuthority() const { return _authority; } 134 | 135 | bool isCustomPort() const { return _isCustomPort; } 136 | 137 | /** Gets a string representation of the URI. */ 138 | std::string toString() const; 139 | 140 | /** 141 | * Get query parameters as key-value pairs. 142 | * e.g. for URI containing query string: key1=foo&key2=&key3&=bar&=bar= 143 | * In returned list, there are 3 entries: 144 | * "key1" => "foo" 145 | * "key2" => "" 146 | * "key3" => "" 147 | * Parts "=bar" and "=bar=" are ignored, as they are not valid query 148 | * parameters. "=bar" is missing parameter name, while "=bar=" has more than 149 | * one equal signs, we don't know which one is the delimiter for key and 150 | * value. 151 | * 152 | * Note, this method is not thread safe, it might update internal state, but 153 | * only the first call to this method update the state. After the first call 154 | * is finished, subsequent calls to this method are thread safe. 155 | * 156 | * @return query parameter key-value pairs in a vector, each element is a 157 | * pair of which the first element is parameter name and the second 158 | * one is parameter value 159 | */ 160 | const std::vector>& getQueryParams(); 161 | 162 | /** Clears all parts of the URI. */ 163 | void clear(); 164 | 165 | private: 166 | bool doParse(cxx17::string_view str); 167 | 168 | bool _isValid; 169 | bool _isSecure; 170 | bool _hasAuthority; 171 | bool _isCustomPort; 172 | uint16_t _port; 173 | std::string _scheme; 174 | std::string _username; 175 | std::string _password; 176 | std::string _host; 177 | std::string _hostName; 178 | std::string _authority; 179 | std::string _pathEtc; 180 | std::string _path; 181 | std::string _query; 182 | std::string _fragment; 183 | std::vector> _queryParams; 184 | }; 185 | 186 | } // namespace network 187 | 188 | } // namespace yasio_ext 189 | 190 | // end group 191 | /// @} 192 | -------------------------------------------------------------------------------- /Plugins/yasio_http/Source/yasio_http/Public/yasio_http/utils/concurrent_deque.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * 3 | Copyright (c) 2019-present Axmol Engine contributors. 4 | 5 | https://axmolengine.github.io/ 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | ****************************************************************************/ 25 | 26 | #pragma once 27 | 28 | #include 29 | #include 30 | 31 | namespace yasio_ext { 32 | template 33 | class concurrent_deque { 34 | public: 35 | /** Iterator, can be used to loop the Vector. */ 36 | using iterator = typename std::deque<_Ty>::iterator; 37 | /** Const iterator, can be used to loop the Vector. */ 38 | using const_iterator = typename std::deque<_Ty>::const_iterator; 39 | 40 | void push_back(_Ty&& value) { 41 | std::lock_guard lck(this->mtx_); 42 | queue_.push_back(std::forward<_Ty>(value)); 43 | } 44 | void push_back(const _Ty& value) { 45 | std::lock_guard lck(this->mtx_); 46 | queue_.push_back(value); 47 | } 48 | _Ty& front() { 49 | std::lock_guard lck(this->mtx_); 50 | return queue_.front(); 51 | } 52 | void pop_front() { 53 | std::lock_guard lck(this->mtx_); 54 | queue_.pop_front(); 55 | } 56 | void push_front(_Ty&& value) 57 | { 58 | std::lock_guard lck(this->mtx_); 59 | queue_.push_front(std::forward<_Ty>(value)); 60 | } 61 | void push_front(const _Ty& value) 62 | { 63 | std::lock_guard lck(this->mtx_); 64 | queue_.push_front(value); 65 | } 66 | size_t size() const { 67 | std::lock_guard lck(this->mtx_); 68 | return this->queue_.size(); 69 | } 70 | bool empty() const { 71 | std::lock_guard lck(this->mtx_); 72 | return this->queue_.empty(); 73 | } 74 | void clear() { 75 | std::lock_guard lck(this->mtx_); 76 | this->queue_.clear(); 77 | } 78 | 79 | std::unique_lock get_lock() { 80 | return std::unique_lock{this->mtx_}; 81 | } 82 | 83 | void lock() { 84 | this->mtx_.lock(); 85 | } 86 | void unlock() { 87 | this->mtx_.unlock(); 88 | } 89 | 90 | void unsafe_push_back(_Ty&& value) { 91 | queue_.push_back(std::forward<_Ty>(value)); 92 | } 93 | void unsafe_push_back(const _Ty& value) { 94 | queue_.push_back(value); 95 | } 96 | _Ty& unsafe_front() { 97 | return queue_.front(); 98 | } 99 | void unsafe_pop_front() { 100 | queue_.pop_front(); 101 | } 102 | void unsafe_push_front(_Ty&& value) { queue_.push_font(std::forward<_Ty>(value)); } 103 | void unsafe_push_front(const _Ty& value) { queue_.push_font(value); } 104 | bool unsafe_empty() const { 105 | return this->queue_.empty(); 106 | } 107 | size_t unsafe_size() const { 108 | return this->queue_.size(); 109 | } 110 | void unsafe_clear() { 111 | this->queue_.clear(); 112 | } 113 | 114 | iterator unsafe_begin() { 115 | return this->queue_.begin(); 116 | } 117 | iterator unsafe_end() { 118 | return this->queue_.end(); 119 | } 120 | 121 | const_iterator unsafe_begin() const { 122 | return this->queue_.begin(); 123 | } 124 | 125 | const_iterator unsafe_end() const { 126 | return this->queue_.end(); 127 | } 128 | 129 | iterator unsafe_erase(iterator iter) { 130 | return this->queue_.erase(iter); 131 | } 132 | 133 | private: 134 | std::deque<_Ty> queue_; 135 | mutable std::recursive_mutex mtx_; 136 | }; 137 | } // namespace cocos2d 138 | -------------------------------------------------------------------------------- /Plugins/yasio_http/Source/yasio_http/yasio_http.Build.cs: -------------------------------------------------------------------------------- 1 | // Copyright 1998-2018 Epic Games, Inc. All Rights Reserved. 2 | 3 | using UnrealBuildTool; 4 | using System.IO; 5 | public class yasio_http : ModuleRules 6 | { 7 | public yasio_http(ReadOnlyTargetRules Target) : base(Target) 8 | { 9 | PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs; 10 | bUseRTTI = true; 11 | PrivateIncludePaths.AddRange(new string[] { Path.Combine(ModuleDirectory, "Private")}); 12 | PrivateIncludePaths.AddRange(new string[] { Path.Combine(ModuleDirectory, "Public/yasio_http/llhttp") }); 13 | PublicIncludePaths.AddRange(new string[] { Path.Combine(ModuleDirectory, "Public")}); 14 | PublicDependencyModuleNames.AddRange( 15 | new string[] 16 | { 17 | 18 | // ... add other public dependencies that you statically link with here ... 19 | } 20 | ); 21 | 22 | 23 | PrivateDependencyModuleNames.AddRange( 24 | new string[] 25 | { 26 | "OpenSSL", "Core", "yasio" 27 | // ... add private dependencies that you statically link with here ... 28 | } 29 | ); 30 | 31 | DynamicallyLoadedModuleNames.AddRange( 32 | new string[] 33 | { 34 | // ... add any modules that your module loads dynamically here ... 35 | } 36 | ); 37 | 38 | PublicDefinitions.Add("YASIO_SSL_BACKEND=1"); 39 | PublicDefinitions.Add("YASIO_BUILD_SHARED_LIBS=1"); 40 | // PrivateDefinitions.Add("YASIO_LIB=1"); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Plugins/yasio_http/yasio_http.uplugin: -------------------------------------------------------------------------------- 1 | { 2 | "FileVersion": 3, 3 | "Version": 1, 4 | "VersionName": "4.2.1", 5 | "FriendlyName": "yasio_http", 6 | "Description": "yasio_http for unreal engine", 7 | "Category": "Other", 8 | "CreatedBy": "halx99", 9 | "CreatedByURL": "", 10 | "DocsURL": "", 11 | "MarketplaceURL": "", 12 | "SupportURL": "", 13 | "CanContainContent": true, 14 | "IsBetaVersion": false, 15 | "Installed": false, 16 | "Modules": [ 17 | { 18 | "Name": "yasio_http", 19 | "Type": "Runtime", 20 | "LoadingPhase": "PreLoadingScreen" 21 | } 22 | ], 23 | "Plugins": [ 24 | { 25 | "Name": "yasio", 26 | "Enabled": true 27 | } 28 | ] 29 | } 30 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # The yasio plugin for UnrealEngine 2 | 3 | ## 支持 UE 版本 4 | 5 | 4.24.x~5.3.x 6 | 7 | ## 运行demo 8 | 9 | 1. Demo是4.24.x创建,打开项目,预览运行,查看日志输出窗口关于yasio的日志 10 | -------------------------------------------------------------------------------- /Source/YAsioSample.Target.cs: -------------------------------------------------------------------------------- 1 | // Copyright 1998-2019 Epic Games, Inc. All Rights Reserved. 2 | 3 | using UnrealBuildTool; 4 | using System.Collections.Generic; 5 | 6 | public class YAsioSampleTarget : TargetRules 7 | { 8 | public YAsioSampleTarget( TargetInfo Target) : base(Target) 9 | { 10 | Type = TargetType.Game; 11 | DefaultBuildSettings = BuildSettingsVersion.V2; 12 | ExtraModuleNames.AddRange( new string[] { "YAsioSample" } ); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Source/YAsioSample/YAsioSample.Build.cs: -------------------------------------------------------------------------------- 1 | // Copyright 1998-2019 Epic Games, Inc. All Rights Reserved. 2 | 3 | using System.IO; 4 | using UnrealBuildTool; 5 | 6 | public class YAsioSample : ModuleRules 7 | { 8 | public YAsioSample(ReadOnlyTargetRules Target) : base(Target) 9 | { 10 | PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs; 11 | 12 | // Adds ThirdParty to Public Include Paths, we can easy to use header-only c++ libraries 13 | // PublicIncludePaths.Add(Path.Combine(ThirdPartyPath)); 14 | 15 | PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "OpenSSL", "yasio" }); 16 | 17 | PrivateDependencyModuleNames.AddRange(new string[] { "yasio" }); 18 | PrivateIncludePathModuleNames.AddRange(new string[] { "yasio" }); 19 | 20 | // Uncomment if you are using Slate UI 21 | // PrivateDependencyModuleNames.AddRange(new string[] { "Slate", "SlateCore" }); 22 | 23 | // Uncomment if you are using online features 24 | // PrivateDependencyModuleNames.Add("OnlineSubsystem"); 25 | 26 | // To include OnlineSubsystemSteam, add it to the plugins section in your uproject file with the Enabled attribute set to true 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Source/YAsioSample/YAsioSample.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 1998-2019 Epic Games, Inc. All Rights Reserved. 2 | 3 | #include "YAsioSample.h" 4 | #include "Modules/ModuleManager.h" 5 | 6 | IMPLEMENT_PRIMARY_GAME_MODULE( FDefaultGameModuleImpl, YAsioSample, "YAsioSample" ); 7 | -------------------------------------------------------------------------------- /Source/YAsioSample/YAsioSample.h: -------------------------------------------------------------------------------- 1 | // Copyright 1998-2019 Epic Games, Inc. All Rights Reserved. 2 | 3 | #pragma once 4 | 5 | #include "CoreMinimal.h" 6 | 7 | -------------------------------------------------------------------------------- /Source/YAsioSample/YAsioSampleActor.cpp: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | 4 | #include "YAsioSampleActor.h" 5 | 6 | #include "yasio/platform/yasio_unreal.hpp" 7 | #include "yasio/yasio.hpp" 8 | #include "yasio/obstream.hpp" 9 | 10 | using namespace yasio; 11 | using namespace yasio::inet; 12 | 13 | DECLARE_LOG_CATEGORY_EXTERN(yasio_sample, Log, All); 14 | DEFINE_LOG_CATEGORY(yasio_sample); 15 | 16 | // Sets default values 17 | AYAsioSampleActor::AYAsioSampleActor() 18 | { 19 | this->service = nullptr; // the yasio io_service 20 | 21 | yasio_unreal_init(); 22 | 23 | // Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it. 24 | PrimaryActorTick.bCanEverTick = true; 25 | 26 | VisualMesh = CreateDefaultSubobject(TEXT("Mesh")); 27 | VisualMesh->SetupAttachment(RootComponent); 28 | 29 | static ConstructorHelpers::FObjectFinder CubeVisualAsset(TEXT("/Game/StarterContent/Shapes/Shape_Cube.Shape_Cube")); 30 | 31 | if (CubeVisualAsset.Succeeded()) 32 | { 33 | VisualMesh->SetStaticMesh(CubeVisualAsset.Object); 34 | VisualMesh->SetRelativeLocation(FVector(0.0f, 0.0f, 0.0f)); 35 | } 36 | } 37 | 38 | AYAsioSampleActor::~AYAsioSampleActor() 39 | { 40 | if (service) { 41 | service->stop(); 42 | delete service; 43 | } 44 | 45 | yasio_unreal_cleanup(); 46 | } 47 | 48 | void AYAsioSampleActor::StartYAsioService() 49 | { 50 | if (service) return; 51 | 52 | yasio::inet::io_hostent endpoints[] = { {"github.com", 443} }; 53 | service = new io_service(endpoints, YASIO_ARRAYSIZE(endpoints)); 54 | // service->set_option(YOPT_S_PRINT_FN2, &log_cb); 55 | service->start([=](event_ptr&& event) { 56 | switch (event->kind()) 57 | { 58 | case YEK_PACKET: { 59 | auto packet = std::move(event->packet()); 60 | //total_bytes_transferred += static_cast(packet.size()); 61 | //fwrite(packet.data(), packet.size(), 1, stdout); 62 | //fflush(stdout); 63 | packet.push_back('\0'); 64 | FString text(UTF8_TO_TCHAR(packet.data())); 65 | const TCHAR* tstr = *text; 66 | UE_LOG(yasio_sample, Log, TEXT("%s"), tstr); 67 | break; 68 | } 69 | case YEK_CONNECT_RESPONSE: 70 | if (event->status() == 0) 71 | { 72 | auto transport = event->transport(); 73 | if (event->cindex() == 0) 74 | { 75 | obstream obs; 76 | obs.write_bytes("GET / HTTP/1.1\r\n"); 77 | 78 | obs.write_bytes("Host: github.com\r\n"); 79 | 80 | obs.write_bytes("User-Agent: Mozilla/5.0 (Windows NT 10.0; " 81 | "WOW64) AppleWebKit/537.36 (KHTML, like Gecko) " 82 | "Chrome/87.0.4280.88 Safari/537.36\r\n"); 83 | obs.write_bytes("Accept: */*;q=0.8\r\n"); 84 | obs.write_bytes("Connection: Close\r\n\r\n"); 85 | 86 | service->write(transport, std::move(obs.buffer())); 87 | } 88 | } 89 | break; 90 | case YEK_CONNECTION_LOST: 91 | // printf("The connection is lost, %d bytes transferred\n", total_bytes_transferred); 92 | break; 93 | } 94 | }); 95 | } 96 | 97 | // Called when the game starts or when spawned 98 | void AYAsioSampleActor::BeginPlay() 99 | { 100 | Super::BeginPlay(); 101 | 102 | StartYAsioService(); 103 | service->open(0, YCK_SSL_CLIENT); // open https client 104 | } 105 | 106 | // Called every frame 107 | void AYAsioSampleActor::Tick(float DeltaTime) 108 | { 109 | Super::Tick(DeltaTime); 110 | 111 | service->dispatch(128); 112 | 113 | FVector NewLocation = GetActorLocation(); 114 | FRotator NewRotation = GetActorRotation(); 115 | float RunningTime = GetGameTimeSinceCreation(); 116 | float DeltaHeight = (FMath::Sin(RunningTime + DeltaTime) - FMath::Sin(RunningTime)); 117 | NewLocation.Z += DeltaHeight * 20.0f; //Scale our height by a factor of 20 118 | float DeltaRotation = DeltaTime * 20.0f; //Rotate by 20 degrees per second 119 | NewRotation.Yaw += DeltaRotation; 120 | SetActorLocationAndRotation(NewLocation, NewRotation); 121 | } 122 | 123 | -------------------------------------------------------------------------------- /Source/YAsioSample/YAsioSampleActor.h: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | #pragma once 4 | 5 | #include "CoreMinimal.h" 6 | #include "GameFramework/Actor.h" 7 | #include "yasio/yasio_fwd.hpp" 8 | 9 | #include "YAsioSampleActor.generated.h" 10 | 11 | 12 | UCLASS() 13 | class YASIOSAMPLE_API AYAsioSampleActor : public AActor 14 | { 15 | GENERATED_BODY() 16 | 17 | UPROPERTY(VisibleAnywhere) 18 | UStaticMeshComponent* VisualMesh; 19 | 20 | yasio::inet::io_service* service; 21 | public: 22 | // Sets default values for this actor's properties 23 | AYAsioSampleActor(); 24 | ~AYAsioSampleActor(); 25 | 26 | protected: 27 | // Called when the game starts or when spawned 28 | virtual void BeginPlay() override; 29 | 30 | // start yasio::io_service 31 | void StartYAsioService(); 32 | 33 | public: 34 | // Called every frame 35 | virtual void Tick(float DeltaTime) override; 36 | 37 | }; 38 | -------------------------------------------------------------------------------- /Source/YAsioSample/YAsioSampleGameModeBase.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 1998-2019 Epic Games, Inc. All Rights Reserved. 2 | 3 | 4 | #include "YAsioSampleGameModeBase.h" 5 | 6 | -------------------------------------------------------------------------------- /Source/YAsioSample/YAsioSampleGameModeBase.h: -------------------------------------------------------------------------------- 1 | // Copyright 1998-2019 Epic Games, Inc. All Rights Reserved. 2 | 3 | #pragma once 4 | 5 | #include "CoreMinimal.h" 6 | #include "GameFramework/GameModeBase.h" 7 | #include "YAsioSampleGameModeBase.generated.h" 8 | 9 | /** 10 | * 11 | */ 12 | UCLASS() 13 | class YASIOSAMPLE_API AYAsioSampleGameModeBase : public AGameModeBase 14 | { 15 | GENERATED_BODY() 16 | 17 | }; 18 | -------------------------------------------------------------------------------- /Source/YAsioSampleEditor.Target.cs: -------------------------------------------------------------------------------- 1 | // Copyright 1998-2019 Epic Games, Inc. All Rights Reserved. 2 | 3 | using UnrealBuildTool; 4 | using System.Collections.Generic; 5 | 6 | public class YAsioSampleEditorTarget : TargetRules 7 | { 8 | public YAsioSampleEditorTarget( TargetInfo Target) : base(Target) 9 | { 10 | Type = TargetType.Editor; 11 | DefaultBuildSettings = BuildSettingsVersion.V2; 12 | ExtraModuleNames.AddRange( new string[] { "YAsioSample" } ); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /yasio_unreal.uproject: -------------------------------------------------------------------------------- 1 | { 2 | "FileVersion": 3, 3 | "EngineAssociation": "4.24", 4 | "Category": "", 5 | "Description": "", 6 | "Modules": [ 7 | { 8 | "Name": "YAsioSample", 9 | "Type": "Runtime", 10 | "LoadingPhase": "Default", 11 | "AdditionalDependencies": [ 12 | "Engine" 13 | ] 14 | } 15 | ] 16 | } 17 | --------------------------------------------------------------------------------