2018-04-02 19:17:56 +00:00
|
|
|
# Copyright (c) 2017 - 2018 LiteSpeed Technologies Inc. See LICENSE.
|
2017-09-22 21:00:03 +00:00
|
|
|
cmake_minimum_required(VERSION 2.8)
|
|
|
|
|
|
|
|
|
|
|
|
project(lsquic)
|
|
|
|
|
2018-04-19 14:37:58 +00:00
|
|
|
IF (NOT MSVC)
|
2017-09-22 21:00:03 +00:00
|
|
|
# We prefer clang
|
|
|
|
IF(NOT ("${CMAKE_C_COMPILER}" MATCHES "ccc-analyzer" OR
|
|
|
|
"${CMAKE_C_COMPILER}" MATCHES "gcc" OR
|
|
|
|
"${CMAKE_C_COMPILER}" MATCHES "afl-gcc"))
|
|
|
|
FIND_PROGRAM(CLANG "clang")
|
|
|
|
IF(CLANG)
|
|
|
|
SET(CMAKE_C_COMPILER "${CLANG}")
|
|
|
|
ENDIF()
|
|
|
|
ENDIF()
|
|
|
|
|
2018-03-12 22:25:01 +00:00
|
|
|
ENDIF()
|
|
|
|
|
2018-07-10 15:51:45 +00:00
|
|
|
# If using older glibc, need to link with -lrt. See clock_getres(2).
|
|
|
|
EXECUTE_PROCESS(
|
|
|
|
COMMAND ${PROJECT_SOURCE_DIR}/print-glibc-version.sh ${CMAKE_C_COMPILER}
|
|
|
|
OUTPUT_VARIABLE GLIBC_VERSION)
|
|
|
|
IF(NOT GLIBC_VERSION EQUAL "" AND GLIBC_VERSION VERSION_LESS 2.17)
|
|
|
|
SET(LIBS ${LIBS} rt)
|
|
|
|
ENDIF()
|
|
|
|
|
2018-10-16 13:03:33 +00:00
|
|
|
IF("${CMAKE_BUILD_TYPE}" STREQUAL "")
|
|
|
|
SET(CMAKE_BUILD_TYPE Debug)
|
2017-09-22 21:00:03 +00:00
|
|
|
ENDIF()
|
|
|
|
|
|
|
|
|
2018-10-16 13:03:33 +00:00
|
|
|
MESSAGE(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
|
2017-09-22 21:00:03 +00:00
|
|
|
|
2018-03-30 14:57:17 +00:00
|
|
|
|
2018-04-19 14:37:58 +00:00
|
|
|
IF (NOT MSVC)
|
2018-03-12 22:25:01 +00:00
|
|
|
|
2017-09-22 21:00:03 +00:00
|
|
|
SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Wall -Wextra -Wno-unused-parameter")
|
|
|
|
SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -fno-omit-frame-pointer")
|
|
|
|
|
2017-09-26 15:26:05 +00:00
|
|
|
IF(CMAKE_COMPILER_IS_GNUCC AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9.3)
|
2017-09-22 21:00:03 +00:00
|
|
|
SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Wno-missing-field-initializers")
|
|
|
|
ENDIF()
|
2018-10-16 13:03:33 +00:00
|
|
|
IF(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
2017-09-22 21:00:03 +00:00
|
|
|
SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -O0 -g3")
|
2018-04-23 18:13:20 +00:00
|
|
|
IF(CMAKE_C_COMPILER MATCHES "clang" AND
|
|
|
|
NOT "$ENV{TRAVIS}" MATCHES "^true$")
|
2017-09-22 21:00:03 +00:00
|
|
|
SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -fsanitize=address")
|
|
|
|
ENDIF()
|
|
|
|
# Uncomment to enable fault injection testing via libfiu:
|
|
|
|
#SET (MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DFIU_ENABLE=1")
|
2018-07-10 15:51:45 +00:00
|
|
|
#SET(LIBS ${LIBS} fiu)
|
2017-09-22 21:00:03 +00:00
|
|
|
ELSE()
|
|
|
|
SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -O3 -g0")
|
|
|
|
SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DNDEBUG")
|
|
|
|
# Comment out the following line to compile out debug messages:
|
|
|
|
#SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DLSQUIC_LOWEST_LOG_LEVEL=LSQ_LOG_INFO")
|
|
|
|
ENDIF()
|
|
|
|
|
2017-09-29 15:18:32 +00:00
|
|
|
IF(LSQUIC_PROFILE EQUAL 1)
|
|
|
|
SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -g -pg")
|
|
|
|
ENDIF()
|
|
|
|
|
2018-03-09 19:17:39 +00:00
|
|
|
IF(LSQUIC_COVERAGE EQUAL 1)
|
|
|
|
SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -fprofile-arcs -ftest-coverage")
|
|
|
|
ENDIF()
|
|
|
|
|
2017-09-22 21:00:03 +00:00
|
|
|
IF(MY_CMAKE_FLAGS MATCHES "fsanitize=address")
|
|
|
|
MESSAGE(STATUS "AddressSanitizer is ON")
|
|
|
|
ELSE()
|
|
|
|
MESSAGE(STATUS "AddressSanitizer is OFF")
|
|
|
|
ENDIF()
|
|
|
|
|
2018-03-12 22:25:01 +00:00
|
|
|
#MSVC
|
|
|
|
ELSE()
|
|
|
|
SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -W4 -WX -Zi -DWIN32_LEAN_AND_MEAN -DNOMINMAX -D_CRT_SECURE_NO_WARNINGS -I${CMAKE_CURRENT_SOURCE_DIR}/wincompat")
|
2018-10-16 13:03:33 +00:00
|
|
|
IF(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
2018-04-02 15:38:44 +00:00
|
|
|
SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Od")
|
2018-03-12 22:25:01 +00:00
|
|
|
#SET (MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DFIU_ENABLE=1")
|
2018-07-10 15:51:45 +00:00
|
|
|
#SET(LIBS ${LIBS} fiu)
|
2018-03-12 22:25:01 +00:00
|
|
|
ELSE()
|
2018-04-02 15:38:44 +00:00
|
|
|
SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Ox")
|
2018-03-12 22:25:01 +00:00
|
|
|
SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DNDEBUG")
|
|
|
|
# Comment out the following line to compile out debug messages:
|
|
|
|
#SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DLSQUIC_LOWEST_LOG_LEVEL=LSQ_LOG_INFO")
|
|
|
|
ENDIF()
|
|
|
|
|
|
|
|
SET (BORINGSSL_INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/../boringssl/include)
|
|
|
|
SET (VCPKG_INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/../vcpkg/installed/x64-windows-static/include )
|
2018-04-02 15:38:44 +00:00
|
|
|
set (BORINGSSL_BASE_LIB_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../boringssl)
|
2018-03-12 22:25:01 +00:00
|
|
|
|
2018-03-13 02:56:06 +00:00
|
|
|
SET (VCPKG_BASE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../vcpkg/installed/x64-windows-static)
|
2018-03-12 22:25:01 +00:00
|
|
|
|
|
|
|
ENDIF() #MSVC
|
|
|
|
|
2017-09-22 21:00:03 +00:00
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${MY_CMAKE_FLAGS} $ENV{EXTRA_CFLAGS}")
|
|
|
|
|
|
|
|
MESSAGE(STATUS "Compiler flags: ${CMAKE_C_FLAGS}")
|
|
|
|
|
2017-09-26 15:26:05 +00:00
|
|
|
IF(NOT DEFINED BORINGSSL_INCLUDE)
|
2017-09-27 16:01:07 +00:00
|
|
|
SET(BORINGSSL_INCLUDE /usr/local/include)
|
2017-09-26 15:26:05 +00:00
|
|
|
ENDIF()
|
|
|
|
IF(NOT DEFINED BORINGSSL_LIB)
|
2017-09-27 16:01:07 +00:00
|
|
|
SET(BORINGSSL_LIB /usr/local/lib)
|
2017-09-26 15:26:05 +00:00
|
|
|
ENDIF()
|
2017-09-22 21:00:03 +00:00
|
|
|
|
2018-03-12 22:25:01 +00:00
|
|
|
|
|
|
|
include_directories(${BORINGSSL_INCLUDE} ${VCPKG_INCLUDE} )
|
2018-03-13 02:56:06 +00:00
|
|
|
link_directories( ${BORINGSSL_LIB} )
|
2017-09-27 16:01:07 +00:00
|
|
|
|
2017-09-22 21:00:03 +00:00
|
|
|
SET(CMAKE_INCLUDE_CURRENT_DIR ON)
|
2018-09-06 18:05:15 +00:00
|
|
|
include_directories( include src/lshpack)
|
2018-07-17 07:52:42 +00:00
|
|
|
IF(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD" OR ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
2017-09-22 21:00:03 +00:00
|
|
|
# Find libevent on FreeBSD:
|
|
|
|
include_directories( /usr/local/include )
|
|
|
|
link_directories( /usr/local/lib )
|
|
|
|
ENDIF()
|
|
|
|
|
2018-03-30 14:57:17 +00:00
|
|
|
|
2018-04-19 14:37:58 +00:00
|
|
|
IF (NOT MSVC)
|
Latest changes
- [API Change] Sendfile-like functionality is gone. The stream no
longer opens files and deals with file descriptors. (Among other
things, this makes the code more portable.) Three writing functions
are provided:
lsquic_stream_write
lsquic_stream_writev
lsquic_stream_writef (NEW)
lsquic_stream_writef() is given an abstract reader that has function
pointers for size() and read() functions which the user can implement.
This is the most flexible way. lsquic_stream_write() and
lsquic_stream_writev() are now both implemented as wrappers around
lsquic_stream_writef().
- [OPTIMIZATION] When writing to stream, be it within or without the
on_write() callback, place data directly into packet buffer,
bypassing auxiliary data structures. This reduces amount of memory
required, for the amount of data that can be written is limited
by the congestion window.
To support writes outside the on_write() callback, we keep N
outgoing packet buffers per connection which can be written to
by any stream. One half of these are reserved for the highest
priority stream(s), the other half for all other streams. This way,
low-priority streams cannot write instead of high-priority streams
and, on the other hand, low-priority streams get a chance to send
their packets out.
The algorithm is as follows:
- When user writes to stream outside of the callback:
- If this is the highest priority stream, place it onto the
reserved N/2 queue or fail.
(The actual size of this queue is dynamic -- MAX(N/2, CWND) --
rather than N/2, allowing high-priority streams to write as
much as can be sent.)
- If the stream is not the highest priority, try to place the
data onto the reserved N/2 queue or fail.
- When tick occurs *and* more packets can be scheduled:
- Transfer packets from the high N/2 queue to the scheduled
queue.
- If more scheduling is allowed:
- Call on_write callbacks for highest-priority streams,
placing resulting packets directly onto the scheduled queue.
- If more scheduling is allowed:
- Transfer packets from the low N/2 queue to the scheduled
queue.
- If more scheduling is allowed:
- Call on_write callbacks for non-highest-priority streams,
placing resulting packets directly onto the scheduled queue
The number N is currently 20, but it could be varied based on
resource usage.
- If stream is created due to incoming headers, make headers readable
from on_new.
- Outgoing packets are no longer marked non-writeable to prevent placing
more than one STREAM frame from the same stream into a single packet.
This property is maintained via code flow and an explicit check.
Packets for stream data are allocated using a special function.
- STREAM frame elision is cheaper, as we only perform it if a reset
stream has outgoing packets referencing it.
- lsquic_packet_out_t is smaller, as stream_rec elements are now
inside a union.
2017-10-31 13:35:58 +00:00
|
|
|
add_executable(http_client
|
|
|
|
test/http_client.c
|
|
|
|
test/prog.c
|
|
|
|
test/test_common.c
|
|
|
|
)
|
2018-07-10 15:51:45 +00:00
|
|
|
target_link_libraries(http_client lsquic event pthread libssl.a libcrypto.a ${LIBS} z m)
|
2017-09-22 21:00:03 +00:00
|
|
|
|
2018-03-13 02:56:06 +00:00
|
|
|
#MSVC
|
2018-03-12 22:25:01 +00:00
|
|
|
ELSE()
|
|
|
|
add_executable(http_client
|
|
|
|
test/http_client.c
|
|
|
|
test/prog.c
|
2018-05-07 20:31:15 +00:00
|
|
|
test/test_common.c
|
2018-03-12 22:25:01 +00:00
|
|
|
wincompat/getopt.c
|
|
|
|
wincompat/getopt1.c
|
|
|
|
)
|
|
|
|
|
2018-03-30 14:57:17 +00:00
|
|
|
target_link_libraries(http_client
|
2018-03-13 02:56:06 +00:00
|
|
|
debug $(SolutionDir)src/liblsquic/debug/lsquic.lib
|
|
|
|
debug ${VCPKG_BASE_DIR}/debug/lib/event.lib
|
|
|
|
debug ${VCPKG_BASE_DIR}/debug/lib/zlibd.lib
|
2018-04-02 15:38:44 +00:00
|
|
|
debug ${BORINGSSL_BASE_LIB_DIR}/ssl/debug/ssl.lib
|
|
|
|
debug ${BORINGSSL_BASE_LIB_DIR}/crypto/debug/crypto.lib
|
2018-03-13 02:56:06 +00:00
|
|
|
ws2_32
|
|
|
|
optimized $(SolutionDir)src/liblsquic/release/lsquic.lib
|
|
|
|
optimized ${VCPKG_BASE_DIR}/lib/event.lib
|
|
|
|
optimized ${VCPKG_BASE_DIR}/lib/zlib.lib
|
2018-04-02 15:38:44 +00:00
|
|
|
optimized ${BORINGSSL_BASE_LIB_DIR}/ssl/release/ssl.lib
|
|
|
|
optimized ${BORINGSSL_BASE_LIB_DIR}/crypto/release/crypto.lib
|
2018-07-10 15:51:45 +00:00
|
|
|
${LIBS} )
|
2018-03-12 22:25:01 +00:00
|
|
|
|
|
|
|
ENDIF()
|
|
|
|
|
2018-07-10 15:51:45 +00:00
|
|
|
#target_link_libraries(http_client lsquic event pthread libssl.a libcrypto.a ${LIBS} z m)
|
2017-09-22 21:00:03 +00:00
|
|
|
|
|
|
|
add_subdirectory(src)
|
|
|
|
|
2018-02-26 21:01:16 +00:00
|
|
|
add_subdirectory(test)
|
2017-09-22 21:00:03 +00:00
|
|
|
|
2018-10-16 13:03:33 +00:00
|
|
|
IF(NOT (CMAKE_C_FLAGS MATCHES "-DNDEBUG"))
|
2018-02-28 19:25:21 +00:00
|
|
|
# Our test framework relies on assertions, only compile if assertions are
|
|
|
|
# enabled.
|
|
|
|
#
|
|
|
|
enable_testing()
|
|
|
|
ENDIF()
|
|
|
|
|
2017-09-22 21:00:03 +00:00
|
|
|
|
|
|
|
ADD_CUSTOM_TARGET(docs doxygen dox.cfg)
|