HP-Socket/Linux/README.md
2022-03-03 23:04:51 +08:00

6.8 KiB

HP-Socket for Linux

    The exported API of HP-Socket for Linux is consistent with HP-Socket for Windows, but the implementation code is completely separated. HP-Socket for Linux uses the features of the C++14 standard, and thus need to be compiled by a compiler which version is GCC 6.x and above, and the compilation and execution environments of HP-Socket requires Linux kernel version 2.6.32 and above.

    HP-Socket Compilation Requirements
    1) Linux kernel version: 2.6.32 and above
    2) GCC version: 6.x and above
    3) glibc version: 2.14.x and above
    4) Dependent libraries: librt, libdl, libpthread

Compilation

    Binary library files and sample executable files are available in the HP-Socket distribution. These files were compiled with GCC 6.3.1 under Linux kernel version 2.6.32. Alternatively, you can compile these files using the following two options:

  1. Windows Remote Compilation: HP-Socket distribution package provides visual studio solutions for HP-Socket library and its demo, you can open the corresponding solution to compile them; And you can also compile HP-Socket library or (and) demo by runing script/ms-build-libs.bat, script/ms-build-demos.bat, script/ms-build-all.bat.
  2. compile.sh: You can compile HP-Socket library files yourself using compile.sh shell script. But compile.sh only compiles library files and will not compiles demo executable files.
$ ./compile.sh -h
Usage: compile.sh [...O.P.T.I.O.N.S...]
----------------------+-------------------------------------------------
  -d|--with-debug-lib : compile debug libs (default: true)
  -m|--mem-allocator  : memory allocator (default: mimalloc)
                      : (options: mimalloc / jemalloc / system)
  -u|--udp-enabled    : enable UDP components (default: true)
  -t|--http-enabled   : enable HTTP components (default: true)
  -s|--ssl-enabled    : enable SSL components (default: true)
  -z|--zlib-enabled   : enable ZLIB related functions (default: true)
  -b|--brotli-enabled : enable BROTLI related functions
                      : (x86/x64 default: true, arm/arm64 default: false)
  -i|--iconv-enabled  : enable ICONV related functions (default: true)
  -c|--compiler       : compiler (default: g++)
  -p|--platform       : platform: x86 / x64 / arm / arm64
                      : (default: current machine arch platform)
  -e|--clean          : clean compilation intermediate temp files
  -r|--remove         : remove all compilation target files
  -v|--version        : print hp-socket version
  -h|--help           : print this usage message
----------------------+-------------------------------------------------

Installation

    Use install.sh shell script to install HP-Socket library files and sample executable files to your system.

$ sudo ./install.sh -h
Usage: install.sh [...O.P.T.I.O.N.S...]
-----------------+-------------------------------------------------------
  -p|--prefix    : install/uninstall path (default: /usr/local)
  -l|--libdir    : lib dir (x86/arm default: 'lib', x64/arm64 default: 'lib64')
  -d|--with-demo : install demos or not (default: false)
  -u|--uninstall : execute uninstall operation from install path
  -v|--version   : print hp-socket version
  -h|--help      : print this usage message
-----------------+-------------------------------------------------------

    Note: The complle.sh build script depends on the script/, src/, include/, and dependent/ directories of the distribution; the install.sh install script depends on the script/, include/, and lib/ directories of the distribution, if you want to install the sample executable files, it also need to depends on the demo/Release/ directory.

Android NDK

    HP-Socket provides Android NDK build script build-android-ndk.sh (build-android-ndk.bat on Windows). After installing and configuring the NDK, execute build-android-ndk.sh to build it. By default, the build script will build all of ABI's dynamic libraries and static libraries supported by the current NDK, and output the library files to lib/android-ndk/ directory. If you have special needs, please set the corresponding command line parameters for build-android-ndk.sh.

    Build HP-Socket libraries use default settings:

$ cd HP-Socket/Linux
$ ./build-android-ndk.sh

ABIs

    By default, the build script generates libraries for all non-deprecated ABIs. You can modify the APP_ABI parameter for build-android-ndk.sh to generate libraries for specific ABIs.

    (for example: only generate armeabi-v7a and x86 libraries):

$ ./build-android-ndk.sh APP_ABI=armeabi-v7a,x86

Features

    By default, all optional features (UDP, SSL, HTTP, ZLIB, BROTLI, ICONV, MIMALLOC) were enabled. You can set one or more _XXX_DISABLED=true parameters for build-android-ndk.sh to disable corresponding features.

  • _UDP_DISABLED=true  (disable UDP)
  • _SSL_DISABLED=true  (disable SSL)
  • _HTTP_DISABLED=true  (disable HTTP)
  • _ZLIB_DISABLED=true  (disable ZLIB)
  • _BROTLI_DISABLED=true  (disable BROTLI)
  • _ICONV_DISABLED=true  (disable ICONV)
  • _MIMALLOC_DISABLED=true  (disable mimalloc memory allocator)

    (for example: disable SSL and ICONV features):

$ ./build-android-ndk.sh _SSL_DISABLED=true _ICONV_DISABLED=true

    Note: If you disable one or more features, you need to define corresponding macros while compiling your application. for example: If you disable the SSL and ICONV features of HP-Socket library, when you compile the application that uses this library, need to define macro like: -D_SSL_DISABLED -D_ICONV_DISABLED.

Other Options

    For more details of build-android-ndk.sh command, please refer to the ndk-build official documentation.
    The following example demonstrates: building armeabi-v7a and x86_64 ABI targets; disabling UDP, ZLIB, and ICONV features; library files output to lib/android-ndk/ directory; obj files output to lib/Android-ndk/obj/ directory:

$ ./build-android-ndk.sh APP_ABI=armeabi-v7a,x86_64 \
                         _UDP_DISABLED=true \
                         _ZLIB_DISABLED=true \
                         _ICONV_DISABLED=true \
                         NDK_LIBS_OUT=./lib/android-ndk \
                         NDK_OUT=./lib/android-ndk/obj