Commit f048e473 authored by enet Upstream's avatar enet Upstream Committed by Atkins, Charles Vernon
Browse files

enet 2018-03-23 (c504fed3)

Code extracted from:

    https://github.com/GTkorvo/enet.git

at commit c504fed3463bd45a1dce52510a1f878405f77c35 (master).
parents
Loading
Loading
Loading
Loading

.gitignore

0 → 100644
+1 −0
Original line number Diff line number Diff line
build

CMakeLists.txt

0 → 100644
+162 −0
Original line number Diff line number Diff line
cmake_minimum_required(VERSION 3.6)

project(ENET VERSION 1.3.13 LANGUAGES C)

# Some boilerplate to setup nice output directories
set(CMAKE_INSTALL_BINDIR bin CACHE STRING "Installation runtime subdirectory")
set(CMAKE_INSTALL_LIBDIR lib CACHE STRING "Installation library subdirectory")
set(CMAKE_INSTALL_INCLUDEDIR include
  CACHE STRING "Installation include subdirectory")
set(CMAKE_INSTALL_CMAKEDIR ${CMAKE_INSTALL_LIBDIR}/cmake
  CACHE STRING "Installation CMake subdirectory")
mark_as_advanced(CMAKE_INSTALL_BINDIR)
mark_as_advanced(CMAKE_INSTALL_LIBDIR)
mark_as_advanced(CMAKE_INSTALL_INCLUDEDIR)
mark_as_advanced(CMAKE_INSTALL_CMAKEDIR)

if(NOT CMAKE_ARCHIVE_OUTPUT_DIRECTORY)
  set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY
    ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
endif()
if(NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY)
  set(CMAKE_LIBRARY_OUTPUT_DIRECTORY
    ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
endif()
if(NOT CMAKE_RUNTIME_OUTPUT_DIRECTORY)
  set(CMAKE_RUNTIME_OUTPUT_DIRECTORY
    ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_BINDIR})
endif()

# Default to a RelWithDebInfo build if not specified
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
  set_property(CACHE CMAKE_BUILD_TYPE PROPERTY VALUE RelWithDebugInfo)
endif()

include(CMakeDependentOption)

# Setup shared library defaults.  If explicitly specified somehow, then default 
# to that.  Otherwise base the default on whether or not shared libs are even
# supported.
get_property(SHARED_LIBS_SUPPORTED GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS)
cmake_dependent_option(BUILD_SHARED_LIBS
  "Build shared libraries (so/dylib/dll)." ${SHARED_LIBS_SUPPORTED}
  "SHARED_LIBS_SUPPORTED" OFF
)
mark_as_advanced(BUILD_SHARED_LIBS)

# Setup PIC defaults.  If explicitly specified somehow, then default 
# to that.  Otherwise base the default on whether or not shared libs are even
# supported.
if(DEFINED ENET_ENABLE_PIC)
  set(ENET_ENABLE_PIC_DEFAULT ${ENET_ENABLE_PIC})
elseif(DEFINED CMAKE_POSITION_INDEPENDENT_CODE)
  set(ENET_ENABLE_PIC_DEFAULT ${CMAKE_POSITION_INDEPENDENT_CODE})
else()
  set(ENET_ENABLE_PIC_DEFAULT ${SHARED_LIBS_SUPPORTED})
endif()
cmake_dependent_option(ENET_ENABLE_PIC
  "Build with Position Independent Code" ${ENET_ENABLE_PIC_DEFAULT}
  "SHARED_LIBS_SUPPORTED" OFF
)
mark_as_advanced(ENET_ENABLE_PIC)
set(CMAKE_POSITION_INDEPENDENT_CODE ${ENET_ENABLE_PIC})
mark_as_advanced(CMAKE_POSITION_INDEPENDENT_CODE)

include(CheckFunctionExists)
check_function_exists(getaddrinfo HAS_GETADDRINFO)
check_function_exists(getnameinfo HAS_GETNAMEINFO)
check_function_exists(gethostbyaddr_r HAS_GETHOSTBYADDR_R)
check_function_exists(gethostbyname_r HAS_GETHOSTBYNAME_R)
check_function_exists(poll HAS_POLL)
check_function_exists(fcntl HAS_FCNTL)
check_function_exists(inet_pton HAS_INET_PTON)
check_function_exists(inet_ntop HAS_INET_NTOP)

include(CheckStructHasMember)
check_struct_has_member("struct msghdr" msg_flags sys/socket.h HAS_MSGHDR_FLAGS)

include(CheckCSourceCompiles)
check_c_source_compiles([=[
#include <sys/socket.h>
int main() { return sizeof(socklen_t); } ]=]
  HAS_SOCKLEN_T
)

add_library(enet
  callbacks.c
  compress.c
  host.c
  list.c
  packet.c
  peer.c
  protocol.c
)
add_library(enet::enet ALIAS enet)
target_compile_definitions(enet PRIVATE
  $<$<BOOL:${HAS_GETADDRINFO}>:HAS_GETADDRINFO>
  $<$<BOOL:${HAS_GETNAMEINFO}>:HAS_GETNAMEINFO>
  $<$<BOOL:${HAS_GETHOSTBYADDR_R}>:HAS_GETHOSTBYADDR_R>
  $<$<BOOL:${HAS_GETHOSTBYNAME_R}>:HAS_GETHOSTBYNAME_R>
  $<$<BOOL:${HAS_POLL}>:HAS_POLL>
  $<$<BOOL:${HAS_FCNTL}>:HAS_FCNTL>
  $<$<BOOL:${HAS_INET_PTON}>:HAS_INET_PTON>
  $<$<BOOL:${HAS_INET_NTOP}>:HAS_INET_NTOP>
  $<$<BOOL:${HAS_MSGHDR_FLAGS}>:HAS_MSGHDR_FLAGS>
  $<$<BOOL:${HAS_SOCKLEN_T}>:HAS_SOCKLEN_T>
)
set(ENET_LIBRARY_PREFIX "" CACHE STRING
  "Prefix to prepend to the output library name")
mark_as_advanced(ENET_LIBRARY_PREFIX)
if(ENET_LIBRARY_PREFIX)
  set_target_properties(enet PROPERTIES
    LIBRARY_OUTPUT_NAME ${ENET_LIBRARY_PREFIX}enet
  )
endif()

if(UNIX)
  target_sources(enet PRIVATE unix.c)
elseif(WIN32)
  target_sources(enet PRIVATE win32.c)
endif()
target_include_directories(enet PUBLIC
  $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
  $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
  $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)

set_target_properties(enet PROPERTIES
  VERSION ${ENET_VERSION}
  SOVERSION ${ENET_VERSION_MAJOR}
)
 
install(DIRECTORY include/enet
  DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
  FILES_MATCHING PATTERN "*.h"
)
install(TARGETS enet
  EXPORT enet-targets
  RUNTIME       DESTINATION "${CMAKE_INSTALL_BINDIR}"
  LIBRARY       DESTINATION "${CMAKE_INSTALL_LIBDIR}"
  ARCHIVE       DESTINATION "${CMAKE_INSTALL_LIBDIR}"
)


# Setup packaging and configs
 
# Add all targets to the build-tree export set
export(TARGETS enet NAMESPACE enet::
  FILE "${PROJECT_BINARY_DIR}/enet-targets.cmake")
configure_file(enet-config.cmake.in
  "${PROJECT_BINARY_DIR}/enet-config.cmake" @ONLY)
configure_file(enet-config-version.cmake.in
  "${PROJECT_BINARY_DIR}/enet-config-version.cmake" @ONLY)
 
# Install the enet-config.cmake and enet-config-version.cmake
install(FILES
  "${PROJECT_BINARY_DIR}/enet-config.cmake"
  "${PROJECT_BINARY_DIR}/enet-config-version.cmake"
  DESTINATION "${CMAKE_INSTALL_CMAKEDIR}/enet")
 
# Install the export set for use with the install-tree
install(EXPORT enet-targets NAMESPACE enet::
  DESTINATION "${CMAKE_INSTALL_CMAKEDIR}/enet")
+70 −0
Original line number Diff line number Diff line
cmake_minimum_required(VERSION 2.6)

project(enet)

# The "configure" step.
include(CheckFunctionExists)
include(CheckStructHasMember)
include(CheckTypeSize)
check_function_exists("fcntl" HAS_FCNTL)
check_function_exists("poll" HAS_POLL)
check_function_exists("getaddrinfo" HAS_GETADDRINFO)
check_function_exists("getnameinfo" HAS_GETNAMEINFO)
check_function_exists("gethostbyname_r" HAS_GETHOSTBYNAME_R)
check_function_exists("gethostbyaddr_r" HAS_GETHOSTBYADDR_R)
check_function_exists("inet_pton" HAS_INET_PTON)
check_function_exists("inet_ntop" HAS_INET_NTOP)
check_struct_has_member("struct msghdr" "msg_flags" "sys/types.h;sys/socket.h" HAS_MSGHDR_FLAGS)
set(CMAKE_EXTRA_INCLUDE_FILES "sys/types.h" "sys/socket.h")
check_type_size("socklen_t" HAS_SOCKLEN_T BUILTIN_TYPES_ONLY)
unset(CMAKE_EXTRA_INCLUDE_FILES)
if(MSVC)
	add_definitions(-W3)
else()
	add_definitions(-Wno-error)
endif()
 
if(HAS_FCNTL)
    add_definitions(-DHAS_FCNTL=1)
endif()
if(HAS_POLL)
    add_definitions(-DHAS_POLL=1)
endif()
if(HAS_GETNAMEINFO)
    add_definitions(-DHAS_GETNAMEINFO=1)
endif()
if(HAS_GETADDRINFO)
    add_definitions(-DHAS_GETADDRINFO=1)
endif()
if(HAS_GETHOSTBYNAME_R)
    add_definitions(-DHAS_GETHOSTBYNAME_R=1)
endif()
if(HAS_GETHOSTBYADDR_R)
    add_definitions(-DHAS_GETHOSTBYADDR_R=1)
endif()
if(HAS_INET_PTON)
    add_definitions(-DHAS_INET_PTON=1)
endif()
if(HAS_INET_NTOP)
    add_definitions(-DHAS_INET_NTOP=1)
endif()
if(HAS_MSGHDR_FLAGS)
    add_definitions(-DHAS_MSGHDR_FLAGS=1)
endif()
if(HAS_SOCKLEN_T)
    add_definitions(-DHAS_SOCKLEN_T=1)
endif()
 
include_directories(${PROJECT_SOURCE_DIR}/include)
 
add_library(enet STATIC
        callbacks.c
        compress.c
        host.c
        list.c
        packet.c
        peer.c
        protocol.c
        unix.c
        win32.c
    )

ChangeLog

0 → 100644
+179 −0
Original line number Diff line number Diff line
* use getaddrinfo and getnameinfo where available

ENet 1.3.13 (April 30, 2015):

* miscellaneous bug fixes
* added premake and cmake support
* miscellaneous documentation cleanups

ENet 1.3.12 (April 24, 2014):

* added maximumPacketSize and maximumWaitingData fields to ENetHost to limit the amount of 
data waiting to be delivered on a peer (beware that the default maximumPacketSize is
32MB and should be set higher if desired as should maximumWaitingData)

ENet 1.3.11 (December 26, 2013):

* allow an ENetHost to connect to itself
* fixed possible bug with disconnect notifications during connect attempts
* fixed some preprocessor definition bugs

ENet 1.3.10 (October 23, 2013);

* doubled maximum reliable window size
* fixed RCVTIMEO/SNDTIMEO socket options and also added NODELAY

ENet 1.3.9 (August 19, 2013):

* added duplicatePeers option to ENetHost which can limit the number of peers from duplicate IPs
* added enet_socket_get_option() and ENET_SOCKOPT_ERROR
* added enet_host_random_seed() platform stub

ENet 1.3.8 (June 2, 2013):

* added enet_linked_version() for checking the linked version 
* added enet_socket_get_address() for querying the local address of a socket
* silenced some debugging prints unless ENET_DEBUG is defined during compilation
* handle EINTR in enet_socket_wait() so that enet_host_service() doesn't propagate errors from signals
* optimized enet_host_bandwidth_throttle() to be less expensive for large numbers of peers

ENet 1.3.7 (March 6, 2013):

* added ENET_PACKET_FLAG_SENT to indicate that a packet is being freed because it has been sent
* added userData field to ENetPacket
* changed how random seed is generated on Windows to avoid import warnings
* fixed case where disconnects could be generated with no preceding connect event

ENet 1.3.6 (December 11, 2012):

* added support for intercept callback in ENetHost that can be used to process raw packets before ENet
* added enet_socket_shutdown() for issuing shutdown on a socket
* fixed enet_socket_connect() to not error on non-blocking connects
* fixed bug in MTU negotiation during connections
 
ENet 1.3.5 (July 31, 2012):

* fixed bug in unreliable packet fragment queuing

ENet 1.3.4 (May 29, 2012):

* added enet_peer_ping_interval() for configuring per-peer ping intervals
* added enet_peer_timeout() for configuring per-peer timeouts
* added protocol packet size limits

ENet 1.3.3 (June 28, 2011):

* fixed bug with simultaneous disconnects not dispatching events

ENet 1.3.2 (May 31, 2011):

* added support for unreliable packet fragmenting via the packet flag
ENET_PACKET_FLAG_UNRELIABLE_FRAGMENT
* fixed regression in unreliable packet queuing
* added check against received port to limit some forms of IP-spoofing

ENet 1.3.1 (February 10, 2011):

* fixed bug in tracking of reliable data in transit
* reliable data window size now scales with the throttle
* fixed bug in fragment length calculation when checksums are used

ENet 1.3.0 (June 5, 2010):

* enet_host_create() now requires the channel limit to be specified as
a parameter
* enet_host_connect() now accepts a data parameter which is supplied 
to the receiving receiving host in the event data field for a connect event
* added an adaptive order-2 PPM range coder as a built-in compressor option
which can be set with enet_host_compress_with_range_coder()
* added support for packet compression configurable with a callback
* improved session number handling to not rely on the packet checksum
field, saving 4 bytes per packet unless the checksum option is used
* removed the dependence on the rand callback for session number handling

Caveats: This version is not protocol compatible with the 1.2 series or 
earlier. The enet_host_connect and enet_host_create API functions require
supplying additional parameters.

ENet 1.2.5 (June 28, 2011):

* fixed bug with simultaneous disconnects not dispatching events

ENet 1.2.4 (May 31, 2011):

* fixed regression in unreliable packet queuing
* added check against received port to limit some forms of IP-spoofing

ENet 1.2.3 (February 10, 2011):

* fixed bug in tracking reliable data in transit

ENet 1.2.2 (June 5, 2010):

* checksum functionality is now enabled by setting a checksum callback
inside ENetHost instead of being a configure script option
* added totalSentData, totalSentPackets, totalReceivedData, and
totalReceivedPackets counters inside ENetHost for getting usage
statistics
* added enet_host_channel_limit() for limiting the maximum number of
channels allowed by connected peers
* now uses dispatch queues for event dispatch rather than potentially
unscalable array walking
* added no_memory callback that is called when a malloc attempt fails,
such that if no_memory returns rather than aborts (the default behavior),
then the error is propagated to the return value of the API calls
* now uses packed attribute for protocol structures on platforms with 
strange alignment rules
* improved autoconf build system contributed by Nathan Brink allowing 
for easier building as a shared library

Caveats: If you were using the compile-time option that enabled checksums,
make sure to set the checksum callback inside ENetHost to enet_crc32 to
regain the old behavior. The ENetCallbacks structure has added new fields,
so make sure to clear the structure to zero before use if 
using enet_initialize_with_callbacks().

ENet 1.2.1 (November 12, 2009):

* fixed bug that could cause disconnect events to be dropped
* added thin wrapper around select() for portable usage
* added ENET_SOCKOPT_REUSEADDR socket option
* factored enet_socket_bind()/enet_socket_listen() out of enet_socket_create()
* added contributed Code::Blocks build file

ENet 1.2 (February 12, 2008):

* fixed bug in VERIFY_CONNECT acknowledgement that could cause connect
attempts to occasionally timeout
* fixed acknowledgements to check both the outgoing and sent queues
when removing acknowledged packets
* fixed accidental bit rot in the MSVC project file
* revised sequence number overflow handling to address some possible
disconnect bugs
* added enet_host_check_events() for getting only local queued events
* factored out socket option setting into enet_socket_set_option() so
that socket options are now set separately from enet_socket_create()

Caveats: While this release is superficially protocol compatible with 1.1,
differences in the sequence number overflow handling can potentially cause
random disconnects.

ENet 1.1 (June 6, 2007):

* optional CRC32 just in case someone needs a stronger checksum than UDP 
provides (--enable-crc32 configure option)
* the size of packet headers are half the size they used to be (so less 
overhead when sending small packets)
* enet_peer_disconnect_later() that waits till all queued outgoing 
packets get sent before issuing an actual disconnect
* freeCallback field in individual packets for notification of when a 
packet is about to be freed
* ENET_PACKET_FLAG_NO_ALLOCATE for supplying pre-allocated data to a 
packet (can be used in concert with freeCallback to support some custom 
allocation schemes that the normal memory allocation callbacks would 
normally not allow)
* enet_address_get_host_ip() for printing address numbers
* promoted the enet_socket_*() functions to be part of the API now
* a few stability/crash fixes

Doxyfile

0 → 100644
+0 −0

File added.

Preview size limit exceeded, changes collapsed.