Giter Site home page Giter Site logo

y0n3t4n1 / curl-unity Goto Github PK

View Code? Open in Web Editor NEW

This project forked from 91act/curl-unity

0.0 0.0 0.0 132.74 MB

This is a C# wrapper for Unity to use libcurl with http2/openssl enabled.

CMake 0.36% Shell 1.56% Batchfile 0.10% C++ 5.74% C 66.81% Makefile 5.56% M4 1.20% Perl 10.26% Roff 5.30% Visual Basic 0.03% DIGITAL Command Language 0.38% Python 1.83% Perl 6 0.01% Dockerfile 0.01% Go 0.21% Ruby 0.01% Objective-C 0.31% Assembly 0.31% eC 0.01% Module Management System 0.01%

curl-unity's Introduction

curl-unity

This is a C# wrapper for Unity to use libcurl with http2/openssl enabled.

Prebuilt platforms

  • Windows x64
  • macOS 64bit
  • iOS arm64
  • Android armv7/arm64/x86

Libraries

Name Version
curl 7.67.0
nghttp2 1.39.2
openssl 1.1.1b

Build

Requirements

  • CMake is required for all platforms.
  • NDK r16b is required for Android.
  • Xcode is required for macOS/iOS.
  • Visual Studio 2017 is required for Windows.

Scripts

There are several build script under build folder for each platform:

All the scripts will auto deloy the output files into Assets/curl-unity/Plugins.

make_android.sh

Build libcurl.so for Android. Please use this script on macOS but it should also works on Linux.

make_ios.sh

Build libcurl.a for iOS. Please use this script on macOS

make_osx.sh

Build curl.bundle for macOS. Please use this script on macOS.

make_win.bat

Build curl.dll for Windows. Please use this script on Windows.

Install

Copy Assets/curl-unity to anywhere under your Unity project and done.

Optional

For a better performance you could enable Allow unsafe code and add ALLOW_UNSAFE to the Scripting Define Symbols in the project settings.

project settings

Usage

Select single thread/mutli thread mode

A CurlMultiUpdater component is needed to be created before any request and then you could check multiThread on or not.

Non-blocking multi perform

Only by using this multi perform that could take the advantage of HTTP/2 multiplexing feature.

void Start()
{
    for (int i = 0; i < 5; i++)
    {
        var easy = new CurlEasy();
        easy.url = "https://nghttp2.org";
        easy.timeout = 5000;
        // NOTICE: This callback may be invoked on other thread
        easy.performCallback = OnPerformCallback;

        // You could also create your own CurlMulti instance
        easy.MultiPerform(CurlMulti.DefaultMulti);
    }
}

void OnPerformCallback(CURLE result, CurlEasy easy)
{
    if (result == CURLE.OK)
    {
        Debug.Log(easy.inText);
    }
}

Non-blocking easy perform

Not recommended. You should take care of the thread safe issues and it can't be canceled before done.

async void Start()
{
    var easy = new CurlEasy();
    easy.url = "https://nghttp2.org";
    easy.timeout = 5000;
    if (await easy.PerformAsync() == CURLE.OK)
    {
        Debug.Log(easy.inText);
    }
}

Blocking easy perform

void Start()
{
    var easy = new CurlEasy();
    easy.url = "https://nghttp2.org";
    easy.timeout = 5000;
    if (easy.Perform() == CURLE.OK)
    {
        Debug.Log(easy.inText);
    }
}

curl-unity's People

Contributors

jayatubi avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.