Updated enet to 1.3.1.

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@7976 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk 2011-03-17 21:02:22 +00:00
parent b30e770764
commit aaaa2f3b0d
30 changed files with 12229 additions and 3578 deletions

View File

@ -1,3 +1,59 @@
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.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): ENet 1.2 (February 12, 2008):
* fixed bug in VERIFY_CONNECT acknowledgement that could cause connect * fixed bug in VERIFY_CONNECT acknowledgement that could cause connect

View File

@ -1,4 +1,4 @@
Copyright (c) 2002-2007 Lee Salzman Copyright (c) 2002-2011 Lee Salzman
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

View File

@ -1,15 +1,22 @@
noinst_LIBRARIES = libenet.a pkgconfigdir = $(libdir)/pkgconfig
EXTRA_DIST = ChangeLog configure design.txt Doxyfile LICENSE tutorial.txt nodist_pkgconfig_DATA = libenet.pc
libenet_a_SOURCES = host.c list.c callbacks.c packet.c peer.c protocol.c unix.c win32.c \
include/enet/types.h \ enetincludedir=$(includedir)/enet
include/enet/list.h \ enetinclude_HEADERS = \
include/enet/utility.h \
include/enet/time.h \
include/enet/callbacks.h \ include/enet/callbacks.h \
include/enet/unix.h \ include/enet/enet.h \
include/enet/win32.h \ include/enet/list.h \
include/enet/protocol.h \ include/enet/protocol.h \
include/enet/enet.h include/enet/time.h \
include/enet/types.h \
include/enet/unix.h \
include/enet/utility.h \
include/enet/win32.h
AM_CPPFLAGS = -I$(srcdir)/include/ lib_LTLIBRARIES = libenet.la
libenet_la_SOURCES = callbacks.c compress.c host.c list.c packet.c peer.c protocol.c unix.c win32.c
# see info '(libtool) Updating version info' before making a release
libenet_la_LDFLAGS = $(AM_LDFLAGS) -version-info 1:1:0
INCLUDES = -Iinclude
ACLOCAL_AMFLAGS = -Im4

View File

@ -6,7 +6,7 @@ is:
# Generate the build system. # Generate the build system.
aclocal && automake -a -c --foreign && autoconf autoreconf -vfi
# Compile and install the library. # Compile and install the library.

436
src/enet/aclocal.m4 vendored
View File

@ -1,7 +1,7 @@
# generated automatically by aclocal 1.9.6 -*- Autoconf -*- # generated automatically by aclocal 1.11.1 -*- Autoconf -*-
# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, # Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
# 2005 Free Software Foundation, Inc. # 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
# This file is free software; the Free Software Foundation # This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it, # gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved. # with or without modifications, as long as this notice is preserved.
@ -11,7 +11,15 @@
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A # even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE. # PARTICULAR PURPOSE.
# Copyright (C) 2002, 2003, 2005 Free Software Foundation, Inc. m4_ifndef([AC_AUTOCONF_VERSION],
[m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl
m4_if(m4_defn([AC_AUTOCONF_VERSION]), [2.67],,
[m4_warning([this file was generated for autoconf 2.67.
You have another version of autoconf. It may work, but is not guaranteed to.
If you have problems, you may need to regenerate the build system entirely.
To do so, use the procedure documented by the package, typically `autoreconf'.])])
# Copyright (C) 2002, 2003, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
# #
# This file is free software; the Free Software Foundation # This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it, # gives unlimited permission to copy and/or distribute it,
@ -21,14 +29,31 @@
# ---------------------------- # ----------------------------
# Automake X.Y traces this macro to ensure aclocal.m4 has been # Automake X.Y traces this macro to ensure aclocal.m4 has been
# generated from the m4 files accompanying Automake X.Y. # generated from the m4 files accompanying Automake X.Y.
AC_DEFUN([AM_AUTOMAKE_VERSION], [am__api_version="1.9"]) # (This private macro should not be called outside this file.)
AC_DEFUN([AM_AUTOMAKE_VERSION],
[am__api_version='1.11'
dnl Some users find AM_AUTOMAKE_VERSION and mistake it for a way to
dnl require some minimum version. Point them to the right macro.
m4_if([$1], [1.11.1], [],
[AC_FATAL([Do not call $0, use AM_INIT_AUTOMAKE([$1]).])])dnl
])
# _AM_AUTOCONF_VERSION(VERSION)
# -----------------------------
# aclocal traces this macro to find the Autoconf version.
# This is a private macro too. Using m4_define simplifies
# the logic in aclocal, which can simply ignore this definition.
m4_define([_AM_AUTOCONF_VERSION], [])
# AM_SET_CURRENT_AUTOMAKE_VERSION # AM_SET_CURRENT_AUTOMAKE_VERSION
# ------------------------------- # -------------------------------
# Call AM_AUTOMAKE_VERSION so it can be traced. # Call AM_AUTOMAKE_VERSION and AM_AUTOMAKE_VERSION so they can be traced.
# This function is AC_REQUIREd by AC_INIT_AUTOMAKE. # This function is AC_REQUIREd by AM_INIT_AUTOMAKE.
AC_DEFUN([AM_SET_CURRENT_AUTOMAKE_VERSION], AC_DEFUN([AM_SET_CURRENT_AUTOMAKE_VERSION],
[AM_AUTOMAKE_VERSION([1.9.6])]) [AM_AUTOMAKE_VERSION([1.11.1])dnl
m4_ifndef([AC_AUTOCONF_VERSION],
[m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl
_AM_AUTOCONF_VERSION(m4_defn([AC_AUTOCONF_VERSION]))])
# AM_AUX_DIR_EXPAND -*- Autoconf -*- # AM_AUX_DIR_EXPAND -*- Autoconf -*-
@ -85,14 +110,14 @@ am_aux_dir=`cd $ac_aux_dir && pwd`
# AM_CONDITIONAL -*- Autoconf -*- # AM_CONDITIONAL -*- Autoconf -*-
# Copyright (C) 1997, 2000, 2001, 2003, 2004, 2005 # Copyright (C) 1997, 2000, 2001, 2003, 2004, 2005, 2006, 2008
# Free Software Foundation, Inc. # Free Software Foundation, Inc.
# #
# This file is free software; the Free Software Foundation # This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it, # gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved. # with or without modifications, as long as this notice is preserved.
# serial 7 # serial 9
# AM_CONDITIONAL(NAME, SHELL-CONDITION) # AM_CONDITIONAL(NAME, SHELL-CONDITION)
# ------------------------------------- # -------------------------------------
@ -101,8 +126,11 @@ AC_DEFUN([AM_CONDITIONAL],
[AC_PREREQ(2.52)dnl [AC_PREREQ(2.52)dnl
ifelse([$1], [TRUE], [AC_FATAL([$0: invalid condition: $1])], ifelse([$1], [TRUE], [AC_FATAL([$0: invalid condition: $1])],
[$1], [FALSE], [AC_FATAL([$0: invalid condition: $1])])dnl [$1], [FALSE], [AC_FATAL([$0: invalid condition: $1])])dnl
AC_SUBST([$1_TRUE]) AC_SUBST([$1_TRUE])dnl
AC_SUBST([$1_FALSE]) AC_SUBST([$1_FALSE])dnl
_AM_SUBST_NOTMAKE([$1_TRUE])dnl
_AM_SUBST_NOTMAKE([$1_FALSE])dnl
m4_define([_AM_COND_VALUE_$1], [$2])dnl
if $2; then if $2; then
$1_TRUE= $1_TRUE=
$1_FALSE='#' $1_FALSE='#'
@ -116,15 +144,14 @@ AC_CONFIG_COMMANDS_PRE(
Usually this means the macro was only invoked conditionally.]]) Usually this means the macro was only invoked conditionally.]])
fi])]) fi])])
# Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2009
# Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005
# Free Software Foundation, Inc. # Free Software Foundation, Inc.
# #
# This file is free software; the Free Software Foundation # This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it, # gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved. # with or without modifications, as long as this notice is preserved.
# serial 8 # serial 10
# There are a few dirty hacks below to avoid letting `AC_PROG_CC' be # There are a few dirty hacks below to avoid letting `AC_PROG_CC' be
# written in clear, in which case automake, when reading aclocal.m4, # written in clear, in which case automake, when reading aclocal.m4,
@ -152,6 +179,7 @@ AC_REQUIRE([AM_DEP_TRACK])dnl
ifelse([$1], CC, [depcc="$CC" am_compiler_list=], ifelse([$1], CC, [depcc="$CC" am_compiler_list=],
[$1], CXX, [depcc="$CXX" am_compiler_list=], [$1], CXX, [depcc="$CXX" am_compiler_list=],
[$1], OBJC, [depcc="$OBJC" am_compiler_list='gcc3 gcc'], [$1], OBJC, [depcc="$OBJC" am_compiler_list='gcc3 gcc'],
[$1], UPC, [depcc="$UPC" am_compiler_list=],
[$1], GCJ, [depcc="$GCJ" am_compiler_list='gcc3 gcc'], [$1], GCJ, [depcc="$GCJ" am_compiler_list='gcc3 gcc'],
[depcc="$$1" am_compiler_list=]) [depcc="$$1" am_compiler_list=])
@ -180,6 +208,16 @@ AC_CACHE_CHECK([dependency style of $depcc],
if test "$am_compiler_list" = ""; then if test "$am_compiler_list" = ""; then
am_compiler_list=`sed -n ['s/^#*\([a-zA-Z0-9]*\))$/\1/p'] < ./depcomp` am_compiler_list=`sed -n ['s/^#*\([a-zA-Z0-9]*\))$/\1/p'] < ./depcomp`
fi fi
am__universal=false
m4_case([$1], [CC],
[case " $depcc " in #(
*\ -arch\ *\ -arch\ *) am__universal=true ;;
esac],
[CXX],
[case " $depcc " in #(
*\ -arch\ *\ -arch\ *) am__universal=true ;;
esac])
for depmode in $am_compiler_list; do for depmode in $am_compiler_list; do
# Setup a source with many dependencies, because some compilers # Setup a source with many dependencies, because some compilers
# like to wrap large dependency lists on column 80 (with \), and # like to wrap large dependency lists on column 80 (with \), and
@ -197,7 +235,17 @@ AC_CACHE_CHECK([dependency style of $depcc],
done done
echo "${am__include} ${am__quote}sub/conftest.Po${am__quote}" > confmf echo "${am__include} ${am__quote}sub/conftest.Po${am__quote}" > confmf
# We check with `-c' and `-o' for the sake of the "dashmstdout"
# mode. It turns out that the SunPro C++ compiler does not properly
# handle `-M -o', and we need to detect this. Also, some Intel
# versions had trouble with output in subdirs
am__obj=sub/conftest.${OBJEXT-o}
am__minus_obj="-o $am__obj"
case $depmode in case $depmode in
gcc)
# This depmode causes a compiler race in universal mode.
test "$am__universal" = false || continue
;;
nosideeffect) nosideeffect)
# after this tag, mechanisms are not by side-effect, so they'll # after this tag, mechanisms are not by side-effect, so they'll
# only be used when explicitly requested # only be used when explicitly requested
@ -207,18 +255,23 @@ AC_CACHE_CHECK([dependency style of $depcc],
break break
fi fi
;; ;;
msvisualcpp | msvcmsys)
# This compiler won't grok `-c -o', but also, the minuso test has
# not run yet. These depmodes are late enough in the game, and
# so weak that their functioning should not be impacted.
am__obj=conftest.${OBJEXT-o}
am__minus_obj=
;;
none) break ;; none) break ;;
esac esac
# We check with `-c' and `-o' for the sake of the "dashmstdout"
# mode. It turns out that the SunPro C++ compiler does not properly
# handle `-M -o', and we need to detect this.
if depmode=$depmode \ if depmode=$depmode \
source=sub/conftest.c object=sub/conftest.${OBJEXT-o} \ source=sub/conftest.c object=$am__obj \
depfile=sub/conftest.Po tmpdepfile=sub/conftest.TPo \ depfile=sub/conftest.Po tmpdepfile=sub/conftest.TPo \
$SHELL ./depcomp $depcc -c -o sub/conftest.${OBJEXT-o} sub/conftest.c \ $SHELL ./depcomp $depcc -c $am__minus_obj sub/conftest.c \
>/dev/null 2>conftest.err && >/dev/null 2>conftest.err &&
grep sub/conftst1.h sub/conftest.Po > /dev/null 2>&1 &&
grep sub/conftst6.h sub/conftest.Po > /dev/null 2>&1 && grep sub/conftst6.h sub/conftest.Po > /dev/null 2>&1 &&
grep sub/conftest.${OBJEXT-o} sub/conftest.Po > /dev/null 2>&1 && grep $am__obj sub/conftest.Po > /dev/null 2>&1 &&
${MAKE-make} -s -f confmf > /dev/null 2>&1; then ${MAKE-make} -s -f confmf > /dev/null 2>&1; then
# icc doesn't choke on unknown options, it will just issue warnings # icc doesn't choke on unknown options, it will just issue warnings
# or remarks (even with -Werror). So we grep stderr for any message # or remarks (even with -Werror). So we grep stderr for any message
@ -269,61 +322,74 @@ if test "x$enable_dependency_tracking" != xno; then
AMDEPBACKSLASH='\' AMDEPBACKSLASH='\'
fi fi
AM_CONDITIONAL([AMDEP], [test "x$enable_dependency_tracking" != xno]) AM_CONDITIONAL([AMDEP], [test "x$enable_dependency_tracking" != xno])
AC_SUBST([AMDEPBACKSLASH]) AC_SUBST([AMDEPBACKSLASH])dnl
_AM_SUBST_NOTMAKE([AMDEPBACKSLASH])dnl
]) ])
# Generate code to set up dependency tracking. -*- Autoconf -*- # Generate code to set up dependency tracking. -*- Autoconf -*-
# Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005 # Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2008
# Free Software Foundation, Inc. # Free Software Foundation, Inc.
# #
# This file is free software; the Free Software Foundation # This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it, # gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved. # with or without modifications, as long as this notice is preserved.
#serial 3 #serial 5
# _AM_OUTPUT_DEPENDENCY_COMMANDS # _AM_OUTPUT_DEPENDENCY_COMMANDS
# ------------------------------ # ------------------------------
AC_DEFUN([_AM_OUTPUT_DEPENDENCY_COMMANDS], AC_DEFUN([_AM_OUTPUT_DEPENDENCY_COMMANDS],
[for mf in $CONFIG_FILES; do [{
# Strip MF so we end up with the name of the file. # Autoconf 2.62 quotes --file arguments for eval, but not when files
mf=`echo "$mf" | sed -e 's/:.*$//'` # are listed without --file. Let's play safe and only enable the eval
# Check whether this is an Automake generated Makefile or not. # if we detect the quoting.
# We used to match only the files named `Makefile.in', but case $CONFIG_FILES in
# some people rename them; so instead we look at the file content. *\'*) eval set x "$CONFIG_FILES" ;;
# Grep'ing the first line is not enough: some people post-process *) set x $CONFIG_FILES ;;
# each Makefile.in and add a new line on top of each file to say so. esac
# So let's grep whole file. shift
if grep '^#.*generated by automake' $mf > /dev/null 2>&1; then for mf
dirpart=`AS_DIRNAME("$mf")` do
else # Strip MF so we end up with the name of the file.
continue mf=`echo "$mf" | sed -e 's/:.*$//'`
fi # Check whether this is an Automake generated Makefile or not.
# Extract the definition of DEPDIR, am__include, and am__quote # We used to match only the files named `Makefile.in', but
# from the Makefile without running `make'. # some people rename them; so instead we look at the file content.
DEPDIR=`sed -n 's/^DEPDIR = //p' < "$mf"` # Grep'ing the first line is not enough: some people post-process
test -z "$DEPDIR" && continue # each Makefile.in and add a new line on top of each file to say so.
am__include=`sed -n 's/^am__include = //p' < "$mf"` # Grep'ing the whole file is not good either: AIX grep has a line
test -z "am__include" && continue # limit of 2048, but all sed's we know have understand at least 4000.
am__quote=`sed -n 's/^am__quote = //p' < "$mf"` if sed -n 's,^#.*generated by automake.*,X,p' "$mf" | grep X >/dev/null 2>&1; then
# When using ansi2knr, U may be empty or an underscore; expand it dirpart=`AS_DIRNAME("$mf")`
U=`sed -n 's/^U = //p' < "$mf"` else
# Find all dependency output files, they are included files with continue
# $(DEPDIR) in their names. We invoke sed twice because it is the fi
# simplest approach to changing $(DEPDIR) to its actual value in the # Extract the definition of DEPDIR, am__include, and am__quote
# expansion. # from the Makefile without running `make'.
for file in `sed -n " DEPDIR=`sed -n 's/^DEPDIR = //p' < "$mf"`
s/^$am__include $am__quote\(.*(DEPDIR).*\)$am__quote"'$/\1/p' <"$mf" | \ test -z "$DEPDIR" && continue
sed -e 's/\$(DEPDIR)/'"$DEPDIR"'/g' -e 's/\$U/'"$U"'/g'`; do am__include=`sed -n 's/^am__include = //p' < "$mf"`
# Make sure the directory exists. test -z "am__include" && continue
test -f "$dirpart/$file" && continue am__quote=`sed -n 's/^am__quote = //p' < "$mf"`
fdir=`AS_DIRNAME(["$file"])` # When using ansi2knr, U may be empty or an underscore; expand it
AS_MKDIR_P([$dirpart/$fdir]) U=`sed -n 's/^U = //p' < "$mf"`
# echo "creating $dirpart/$file" # Find all dependency output files, they are included files with
echo '# dummy' > "$dirpart/$file" # $(DEPDIR) in their names. We invoke sed twice because it is the
# simplest approach to changing $(DEPDIR) to its actual value in the
# expansion.
for file in `sed -n "
s/^$am__include $am__quote\(.*(DEPDIR).*\)$am__quote"'$/\1/p' <"$mf" | \
sed -e 's/\$(DEPDIR)/'"$DEPDIR"'/g' -e 's/\$U/'"$U"'/g'`; do
# Make sure the directory exists.
test -f "$dirpart/$file" && continue
fdir=`AS_DIRNAME(["$file"])`
AS_MKDIR_P([$dirpart/$fdir])
# echo "creating $dirpart/$file"
echo '# dummy' > "$dirpart/$file"
done
done done
done }
])# _AM_OUTPUT_DEPENDENCY_COMMANDS ])# _AM_OUTPUT_DEPENDENCY_COMMANDS
@ -342,14 +408,14 @@ AC_DEFUN([AM_OUTPUT_DEPENDENCY_COMMANDS],
# Do all the work for Automake. -*- Autoconf -*- # Do all the work for Automake. -*- Autoconf -*-
# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 # Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
# Free Software Foundation, Inc. # 2005, 2006, 2008, 2009 Free Software Foundation, Inc.
# #
# This file is free software; the Free Software Foundation # This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it, # gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved. # with or without modifications, as long as this notice is preserved.
# serial 12 # serial 16
# This macro actually does too much. Some checks are only needed if # This macro actually does too much. Some checks are only needed if
# your package does certain things. But this isn't really a big deal. # your package does certain things. But this isn't really a big deal.
@ -366,16 +432,20 @@ AC_DEFUN([AM_OUTPUT_DEPENDENCY_COMMANDS],
# arguments mandatory, and then we can depend on a new Autoconf # arguments mandatory, and then we can depend on a new Autoconf
# release and drop the old call support. # release and drop the old call support.
AC_DEFUN([AM_INIT_AUTOMAKE], AC_DEFUN([AM_INIT_AUTOMAKE],
[AC_PREREQ([2.58])dnl [AC_PREREQ([2.62])dnl
dnl Autoconf wants to disallow AM_ names. We explicitly allow dnl Autoconf wants to disallow AM_ names. We explicitly allow
dnl the ones we care about. dnl the ones we care about.
m4_pattern_allow([^AM_[A-Z]+FLAGS$])dnl m4_pattern_allow([^AM_[A-Z]+FLAGS$])dnl
AC_REQUIRE([AM_SET_CURRENT_AUTOMAKE_VERSION])dnl AC_REQUIRE([AM_SET_CURRENT_AUTOMAKE_VERSION])dnl
AC_REQUIRE([AC_PROG_INSTALL])dnl AC_REQUIRE([AC_PROG_INSTALL])dnl
# test to see if srcdir already configured if test "`cd $srcdir && pwd`" != "`pwd`"; then
if test "`cd $srcdir && pwd`" != "`pwd`" && # Use -I$(srcdir) only when $(srcdir) != ., so that make's output
test -f $srcdir/config.status; then # is not polluted with repeated "-I."
AC_MSG_ERROR([source directory already configured; run "make distclean" there first]) AC_SUBST([am__isrc], [' -I$(srcdir)'])_AM_SUBST_NOTMAKE([am__isrc])dnl
# test to see if srcdir already configured
if test -f $srcdir/config.status; then
AC_MSG_ERROR([source directory already configured; run "make distclean" there first])
fi
fi fi
# test whether we have cygpath # test whether we have cygpath
@ -395,6 +465,9 @@ m4_ifval([$2],
AC_SUBST([PACKAGE], [$1])dnl AC_SUBST([PACKAGE], [$1])dnl
AC_SUBST([VERSION], [$2])], AC_SUBST([VERSION], [$2])],
[_AM_SET_OPTIONS([$1])dnl [_AM_SET_OPTIONS([$1])dnl
dnl Diagnose old-style AC_INIT with new-style AM_AUTOMAKE_INIT.
m4_if(m4_ifdef([AC_PACKAGE_NAME], 1)m4_ifdef([AC_PACKAGE_VERSION], 1), 11,,
[m4_fatal([AC_INIT should be called with package and version arguments])])dnl
AC_SUBST([PACKAGE], ['AC_PACKAGE_TARNAME'])dnl AC_SUBST([PACKAGE], ['AC_PACKAGE_TARNAME'])dnl
AC_SUBST([VERSION], ['AC_PACKAGE_VERSION'])])dnl AC_SUBST([VERSION], ['AC_PACKAGE_VERSION'])])dnl
@ -410,8 +483,8 @@ AM_MISSING_PROG(AUTOCONF, autoconf)
AM_MISSING_PROG(AUTOMAKE, automake-${am__api_version}) AM_MISSING_PROG(AUTOMAKE, automake-${am__api_version})
AM_MISSING_PROG(AUTOHEADER, autoheader) AM_MISSING_PROG(AUTOHEADER, autoheader)
AM_MISSING_PROG(MAKEINFO, makeinfo) AM_MISSING_PROG(MAKEINFO, makeinfo)
AM_PROG_INSTALL_SH AC_REQUIRE([AM_PROG_INSTALL_SH])dnl
AM_PROG_INSTALL_STRIP AC_REQUIRE([AM_PROG_INSTALL_STRIP])dnl
AC_REQUIRE([AM_PROG_MKDIR_P])dnl AC_REQUIRE([AM_PROG_MKDIR_P])dnl
# We need awk for the "check" target. The system "awk" is bad on # We need awk for the "check" target. The system "awk" is bad on
# some platforms. # some platforms.
@ -419,20 +492,37 @@ AC_REQUIRE([AC_PROG_AWK])dnl
AC_REQUIRE([AC_PROG_MAKE_SET])dnl AC_REQUIRE([AC_PROG_MAKE_SET])dnl
AC_REQUIRE([AM_SET_LEADING_DOT])dnl AC_REQUIRE([AM_SET_LEADING_DOT])dnl
_AM_IF_OPTION([tar-ustar], [_AM_PROG_TAR([ustar])], _AM_IF_OPTION([tar-ustar], [_AM_PROG_TAR([ustar])],
[_AM_IF_OPTION([tar-pax], [_AM_PROG_TAR([pax])], [_AM_IF_OPTION([tar-pax], [_AM_PROG_TAR([pax])],
[_AM_PROG_TAR([v7])])]) [_AM_PROG_TAR([v7])])])
_AM_IF_OPTION([no-dependencies],, _AM_IF_OPTION([no-dependencies],,
[AC_PROVIDE_IFELSE([AC_PROG_CC], [AC_PROVIDE_IFELSE([AC_PROG_CC],
[_AM_DEPENDENCIES(CC)], [_AM_DEPENDENCIES(CC)],
[define([AC_PROG_CC], [define([AC_PROG_CC],
defn([AC_PROG_CC])[_AM_DEPENDENCIES(CC)])])dnl defn([AC_PROG_CC])[_AM_DEPENDENCIES(CC)])])dnl
AC_PROVIDE_IFELSE([AC_PROG_CXX], AC_PROVIDE_IFELSE([AC_PROG_CXX],
[_AM_DEPENDENCIES(CXX)], [_AM_DEPENDENCIES(CXX)],
[define([AC_PROG_CXX], [define([AC_PROG_CXX],
defn([AC_PROG_CXX])[_AM_DEPENDENCIES(CXX)])])dnl defn([AC_PROG_CXX])[_AM_DEPENDENCIES(CXX)])])dnl
AC_PROVIDE_IFELSE([AC_PROG_OBJC],
[_AM_DEPENDENCIES(OBJC)],
[define([AC_PROG_OBJC],
defn([AC_PROG_OBJC])[_AM_DEPENDENCIES(OBJC)])])dnl
]) ])
_AM_IF_OPTION([silent-rules], [AC_REQUIRE([AM_SILENT_RULES])])dnl
dnl The `parallel-tests' driver may need to know about EXEEXT, so add the
dnl `am__EXEEXT' conditional if _AM_COMPILER_EXEEXT was seen. This macro
dnl is hooked onto _AC_COMPILER_EXEEXT early, see below.
AC_CONFIG_COMMANDS_PRE(dnl
[m4_provide_if([_AM_COMPILER_EXEEXT],
[AM_CONDITIONAL([am__EXEEXT], [test -n "$EXEEXT"])])])dnl
]) ])
dnl Hook into `_AC_COMPILER_EXEEXT' early to learn its expansion. Do not
dnl add the conditional right here, as _AC_COMPILER_EXEEXT may be further
dnl mangled by Autoconf and run in a shell conditional statement.
m4_define([_AC_COMPILER_EXEEXT],
m4_defn([_AC_COMPILER_EXEEXT])[m4_provide([_AM_COMPILER_EXEEXT])])
# When config.status generates a header, we must update the stamp-h file. # When config.status generates a header, we must update the stamp-h file.
# This file resides in the same directory as the config header # This file resides in the same directory as the config header
@ -443,18 +533,19 @@ AC_PROVIDE_IFELSE([AC_PROG_CXX],
# our stamp files there. # our stamp files there.
AC_DEFUN([_AC_AM_CONFIG_HEADER_HOOK], AC_DEFUN([_AC_AM_CONFIG_HEADER_HOOK],
[# Compute $1's index in $config_headers. [# Compute $1's index in $config_headers.
_am_arg=$1
_am_stamp_count=1 _am_stamp_count=1
for _am_header in $config_headers :; do for _am_header in $config_headers :; do
case $_am_header in case $_am_header in
$1 | $1:* ) $_am_arg | $_am_arg:* )
break ;; break ;;
* ) * )
_am_stamp_count=`expr $_am_stamp_count + 1` ;; _am_stamp_count=`expr $_am_stamp_count + 1` ;;
esac esac
done done
echo "timestamp for $1" >`AS_DIRNAME([$1])`/stamp-h[]$_am_stamp_count]) echo "timestamp for $_am_arg" >`AS_DIRNAME(["$_am_arg"])`/stamp-h[]$_am_stamp_count])
# Copyright (C) 2001, 2003, 2005 Free Software Foundation, Inc. # Copyright (C) 2001, 2003, 2005, 2008 Free Software Foundation, Inc.
# #
# This file is free software; the Free Software Foundation # This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it, # gives unlimited permission to copy and/or distribute it,
@ -465,7 +556,14 @@ echo "timestamp for $1" >`AS_DIRNAME([$1])`/stamp-h[]$_am_stamp_count])
# Define $install_sh. # Define $install_sh.
AC_DEFUN([AM_PROG_INSTALL_SH], AC_DEFUN([AM_PROG_INSTALL_SH],
[AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl [AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl
install_sh=${install_sh-"$am_aux_dir/install-sh"} if test x"${install_sh}" != xset; then
case $am_aux_dir in
*\ * | *\ *)
install_sh="\${SHELL} '$am_aux_dir/install-sh'" ;;
*)
install_sh="\${SHELL} $am_aux_dir/install-sh"
esac
fi
AC_SUBST(install_sh)]) AC_SUBST(install_sh)])
# Copyright (C) 2003, 2005 Free Software Foundation, Inc. # Copyright (C) 2003, 2005 Free Software Foundation, Inc.
@ -491,13 +589,13 @@ AC_SUBST([am__leading_dot])])
# Check to see how 'make' treats includes. -*- Autoconf -*- # Check to see how 'make' treats includes. -*- Autoconf -*-
# Copyright (C) 2001, 2002, 2003, 2005 Free Software Foundation, Inc. # Copyright (C) 2001, 2002, 2003, 2005, 2009 Free Software Foundation, Inc.
# #
# This file is free software; the Free Software Foundation # This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it, # gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved. # with or without modifications, as long as this notice is preserved.
# serial 3 # serial 4
# AM_MAKE_INCLUDE() # AM_MAKE_INCLUDE()
# ----------------- # -----------------
@ -506,7 +604,7 @@ AC_DEFUN([AM_MAKE_INCLUDE],
[am_make=${MAKE-make} [am_make=${MAKE-make}
cat > confinc << 'END' cat > confinc << 'END'
am__doit: am__doit:
@echo done @echo this is the am__doit target
.PHONY: am__doit .PHONY: am__doit
END END
# If we don't find an include directive, just comment out the code. # If we don't find an include directive, just comment out the code.
@ -516,24 +614,24 @@ am__quote=
_am_result=none _am_result=none
# First try GNU make style include. # First try GNU make style include.
echo "include confinc" > confmf echo "include confinc" > confmf
# We grep out `Entering directory' and `Leaving directory' # Ignore all kinds of additional output from `make'.
# messages which can occur if `w' ends up in MAKEFLAGS. case `$am_make -s -f confmf 2> /dev/null` in #(
# In particular we don't look at `^make:' because GNU make might *the\ am__doit\ target*)
# be invoked under some other name (usually "gmake"), in which am__include=include
# case it prints its new name instead of `make'. am__quote=
if test "`$am_make -s -f confmf 2> /dev/null | grep -v 'ing directory'`" = "done"; then _am_result=GNU
am__include=include ;;
am__quote= esac
_am_result=GNU
fi
# Now try BSD make style include. # Now try BSD make style include.
if test "$am__include" = "#"; then if test "$am__include" = "#"; then
echo '.include "confinc"' > confmf echo '.include "confinc"' > confmf
if test "`$am_make -s -f confmf 2> /dev/null`" = "done"; then case `$am_make -s -f confmf 2> /dev/null` in #(
am__include=.include *the\ am__doit\ target*)
am__quote="\"" am__include=.include
_am_result=BSD am__quote="\""
fi _am_result=BSD
;;
esac
fi fi
AC_SUBST([am__include]) AC_SUBST([am__include])
AC_SUBST([am__quote]) AC_SUBST([am__quote])
@ -543,14 +641,14 @@ rm -f confinc confmf
# Fake the existence of programs that GNU maintainers use. -*- Autoconf -*- # Fake the existence of programs that GNU maintainers use. -*- Autoconf -*-
# Copyright (C) 1997, 1999, 2000, 2001, 2003, 2005 # Copyright (C) 1997, 1999, 2000, 2001, 2003, 2004, 2005, 2008
# Free Software Foundation, Inc. # Free Software Foundation, Inc.
# #
# This file is free software; the Free Software Foundation # This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it, # gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved. # with or without modifications, as long as this notice is preserved.
# serial 4 # serial 6
# AM_MISSING_PROG(NAME, PROGRAM) # AM_MISSING_PROG(NAME, PROGRAM)
# ------------------------------ # ------------------------------
@ -566,7 +664,15 @@ AC_SUBST($1)])
# If it does, set am_missing_run to use it, otherwise, to nothing. # If it does, set am_missing_run to use it, otherwise, to nothing.
AC_DEFUN([AM_MISSING_HAS_RUN], AC_DEFUN([AM_MISSING_HAS_RUN],
[AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl [AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl
test x"${MISSING+set}" = xset || MISSING="\${SHELL} $am_aux_dir/missing" AC_REQUIRE_AUX_FILE([missing])dnl
if test x"${MISSING+set}" != xset; then
case $am_aux_dir in
*\ * | *\ *)
MISSING="\${SHELL} \"$am_aux_dir/missing\"" ;;
*)
MISSING="\${SHELL} $am_aux_dir/missing" ;;
esac
fi
# Use eval to expand $SHELL # Use eval to expand $SHELL
if eval "$MISSING --run true"; then if eval "$MISSING --run true"; then
am_missing_run="$MISSING --run " am_missing_run="$MISSING --run "
@ -576,7 +682,7 @@ else
fi fi
]) ])
# Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc. # Copyright (C) 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
# #
# This file is free software; the Free Software Foundation # This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it, # gives unlimited permission to copy and/or distribute it,
@ -584,70 +690,33 @@ fi
# AM_PROG_MKDIR_P # AM_PROG_MKDIR_P
# --------------- # ---------------
# Check whether `mkdir -p' is supported, fallback to mkinstalldirs otherwise. # Check for `mkdir -p'.
#
# Automake 1.8 used `mkdir -m 0755 -p --' to ensure that directories
# created by `make install' are always world readable, even if the
# installer happens to have an overly restrictive umask (e.g. 077).
# This was a mistake. There are at least two reasons why we must not
# use `-m 0755':
# - it causes special bits like SGID to be ignored,
# - it may be too restrictive (some setups expect 775 directories).
#
# Do not use -m 0755 and let people choose whatever they expect by
# setting umask.
#
# We cannot accept any implementation of `mkdir' that recognizes `-p'.
# Some implementations (such as Solaris 8's) are not thread-safe: if a
# parallel make tries to run `mkdir -p a/b' and `mkdir -p a/c'
# concurrently, both version can detect that a/ is missing, but only
# one can create it and the other will error out. Consequently we
# restrict ourselves to GNU make (using the --version option ensures
# this.)
AC_DEFUN([AM_PROG_MKDIR_P], AC_DEFUN([AM_PROG_MKDIR_P],
[if mkdir -p --version . >/dev/null 2>&1 && test ! -d ./--version; then [AC_PREREQ([2.60])dnl
# We used to keeping the `.' as first argument, in order to AC_REQUIRE([AC_PROG_MKDIR_P])dnl
# allow $(mkdir_p) to be used without argument. As in dnl Automake 1.8 to 1.9.6 used to define mkdir_p. We now use MKDIR_P,
# $(mkdir_p) $(somedir) dnl while keeping a definition of mkdir_p for backward compatibility.
# where $(somedir) is conditionally defined. However this is wrong dnl @MKDIR_P@ is magic: AC_OUTPUT adjusts its value for each Makefile.
# for two reasons: dnl However we cannot define mkdir_p as $(MKDIR_P) for the sake of
# 1. if the package is installed by a user who cannot write `.' dnl Makefile.ins that do not define MKDIR_P, so we do our own
# make install will fail, dnl adjustment using top_builddir (which is defined more often than
# 2. the above comment should most certainly read dnl MKDIR_P).
# $(mkdir_p) $(DESTDIR)$(somedir) AC_SUBST([mkdir_p], ["$MKDIR_P"])dnl
# so it does not work when $(somedir) is undefined and case $mkdir_p in
# $(DESTDIR) is not. [[\\/$]]* | ?:[[\\/]]*) ;;
# To support the latter case, we have to write */*) mkdir_p="\$(top_builddir)/$mkdir_p" ;;
# test -z "$(somedir)" || $(mkdir_p) $(DESTDIR)$(somedir), esac
# so the `.' trick is pointless. ])
mkdir_p='mkdir -p --'
else
# On NextStep and OpenStep, the `mkdir' command does not
# recognize any option. It will interpret all options as
# directories to create, and then abort because `.' already
# exists.
for d in ./-p ./--version;
do
test -d $d && rmdir $d
done
# $(mkinstalldirs) is defined by Automake if mkinstalldirs exists.
if test -f "$ac_aux_dir/mkinstalldirs"; then
mkdir_p='$(mkinstalldirs)'
else
mkdir_p='$(install_sh) -d'
fi
fi
AC_SUBST([mkdir_p])])
# Helper functions for option handling. -*- Autoconf -*- # Helper functions for option handling. -*- Autoconf -*-
# Copyright (C) 2001, 2002, 2003, 2005 Free Software Foundation, Inc. # Copyright (C) 2001, 2002, 2003, 2005, 2008 Free Software Foundation, Inc.
# #
# This file is free software; the Free Software Foundation # This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it, # gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved. # with or without modifications, as long as this notice is preserved.
# serial 3 # serial 4
# _AM_MANGLE_OPTION(NAME) # _AM_MANGLE_OPTION(NAME)
# ----------------------- # -----------------------
@ -664,7 +733,7 @@ AC_DEFUN([_AM_SET_OPTION],
# ---------------------------------- # ----------------------------------
# OPTIONS is a space-separated list of Automake options. # OPTIONS is a space-separated list of Automake options.
AC_DEFUN([_AM_SET_OPTIONS], AC_DEFUN([_AM_SET_OPTIONS],
[AC_FOREACH([_AM_Option], [$1], [_AM_SET_OPTION(_AM_Option)])]) [m4_foreach_w([_AM_Option], [$1], [_AM_SET_OPTION(_AM_Option)])])
# _AM_IF_OPTION(OPTION, IF-SET, [IF-NOT-SET]) # _AM_IF_OPTION(OPTION, IF-SET, [IF-NOT-SET])
# ------------------------------------------- # -------------------------------------------
@ -674,14 +743,14 @@ AC_DEFUN([_AM_IF_OPTION],
# Check to make sure that the build environment is sane. -*- Autoconf -*- # Check to make sure that the build environment is sane. -*- Autoconf -*-
# Copyright (C) 1996, 1997, 2000, 2001, 2003, 2005 # Copyright (C) 1996, 1997, 2000, 2001, 2003, 2005, 2008
# Free Software Foundation, Inc. # Free Software Foundation, Inc.
# #
# This file is free software; the Free Software Foundation # This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it, # gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved. # with or without modifications, as long as this notice is preserved.
# serial 4 # serial 5
# AM_SANITY_CHECK # AM_SANITY_CHECK
# --------------- # ---------------
@ -690,16 +759,29 @@ AC_DEFUN([AM_SANITY_CHECK],
# Just in case # Just in case
sleep 1 sleep 1
echo timestamp > conftest.file echo timestamp > conftest.file
# Reject unsafe characters in $srcdir or the absolute working directory
# name. Accept space and tab only in the latter.
am_lf='
'
case `pwd` in
*[[\\\"\#\$\&\'\`$am_lf]]*)
AC_MSG_ERROR([unsafe absolute working directory name]);;
esac
case $srcdir in
*[[\\\"\#\$\&\'\`$am_lf\ \ ]]*)
AC_MSG_ERROR([unsafe srcdir value: `$srcdir']);;
esac
# Do `set' in a subshell so we don't clobber the current shell's # Do `set' in a subshell so we don't clobber the current shell's
# arguments. Must try -L first in case configure is actually a # arguments. Must try -L first in case configure is actually a
# symlink; some systems play weird games with the mod time of symlinks # symlink; some systems play weird games with the mod time of symlinks
# (eg FreeBSD returns the mod time of the symlink's containing # (eg FreeBSD returns the mod time of the symlink's containing
# directory). # directory).
if ( if (
set X `ls -Lt $srcdir/configure conftest.file 2> /dev/null` set X `ls -Lt "$srcdir/configure" conftest.file 2> /dev/null`
if test "$[*]" = "X"; then if test "$[*]" = "X"; then
# -L didn't work. # -L didn't work.
set X `ls -t $srcdir/configure conftest.file` set X `ls -t "$srcdir/configure" conftest.file`
fi fi
rm -f conftest.file rm -f conftest.file
if test "$[*]" != "X $srcdir/configure conftest.file" \ if test "$[*]" != "X $srcdir/configure conftest.file" \
@ -749,9 +831,28 @@ dnl Don't test for $cross_compiling = yes, because it might be `maybe'.
if test "$cross_compiling" != no; then if test "$cross_compiling" != no; then
AC_CHECK_TOOL([STRIP], [strip], :) AC_CHECK_TOOL([STRIP], [strip], :)
fi fi
INSTALL_STRIP_PROGRAM="\${SHELL} \$(install_sh) -c -s" INSTALL_STRIP_PROGRAM="\$(install_sh) -c -s"
AC_SUBST([INSTALL_STRIP_PROGRAM])]) AC_SUBST([INSTALL_STRIP_PROGRAM])])
# Copyright (C) 2006, 2008 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# serial 2
# _AM_SUBST_NOTMAKE(VARIABLE)
# ---------------------------
# Prevent Automake from outputting VARIABLE = @VARIABLE@ in Makefile.in.
# This macro is traced by Automake.
AC_DEFUN([_AM_SUBST_NOTMAKE])
# AM_SUBST_NOTMAKE(VARIABLE)
# ---------------------------
# Public sister of _AM_SUBST_NOTMAKE.
AC_DEFUN([AM_SUBST_NOTMAKE], [_AM_SUBST_NOTMAKE($@)])
# Check how to create a tarball. -*- Autoconf -*- # Check how to create a tarball. -*- Autoconf -*-
# Copyright (C) 2004, 2005 Free Software Foundation, Inc. # Copyright (C) 2004, 2005 Free Software Foundation, Inc.
@ -848,3 +949,8 @@ AC_SUBST([am__tar])
AC_SUBST([am__untar]) AC_SUBST([am__untar])
]) # _AM_PROG_TAR ]) # _AM_PROG_TAR
m4_include([m4/libtool.m4])
m4_include([m4/ltoptions.m4])
m4_include([m4/ltsugar.m4])
m4_include([m4/ltversion.m4])
m4_include([m4/lt~obsolete.m4])

View File

@ -5,12 +5,12 @@
#define ENET_BUILDING_LIB 1 #define ENET_BUILDING_LIB 1
#include "enet/enet.h" #include "enet/enet.h"
static ENetCallbacks callbacks = { malloc, free, rand }; static ENetCallbacks callbacks = { malloc, free, abort };
int int
enet_initialize_with_callbacks (ENetVersion version, const ENetCallbacks * inits) enet_initialize_with_callbacks (ENetVersion version, const ENetCallbacks * inits)
{ {
if (version != ENET_VERSION) if (version < ENET_VERSION_CREATE (1, 3, 0))
return -1; return -1;
if (inits -> malloc != NULL || inits -> free != NULL) if (inits -> malloc != NULL || inits -> free != NULL)
@ -22,8 +22,8 @@ enet_initialize_with_callbacks (ENetVersion version, const ENetCallbacks * inits
callbacks.free = inits -> free; callbacks.free = inits -> free;
} }
if (inits -> rand != NULL) if (inits -> no_memory != NULL)
callbacks.rand = inits -> rand; callbacks.no_memory = inits -> no_memory;
return enet_initialize (); return enet_initialize ();
} }
@ -34,7 +34,7 @@ enet_malloc (size_t size)
void * memory = callbacks.malloc (size); void * memory = callbacks.malloc (size);
if (memory == NULL) if (memory == NULL)
abort (); callbacks.no_memory ();
return memory; return memory;
} }
@ -45,9 +45,3 @@ enet_free (void * memory)
callbacks.free (memory); callbacks.free (memory);
} }
int
enet_rand (void)
{
return callbacks.rand ();
}

654
src/enet/compress.c Normal file
View File

@ -0,0 +1,654 @@
/**
@file compress.c
@brief An adaptive order-2 PPM range coder
*/
#define ENET_BUILDING_LIB 1
#include <string.h>
#include "enet/enet.h"
typedef struct _ENetSymbol
{
/* binary indexed tree of symbols */
enet_uint8 value;
enet_uint8 count;
enet_uint16 under;
enet_uint16 left, right;
/* context defined by this symbol */
enet_uint16 symbols;
enet_uint16 escapes;
enet_uint16 total;
enet_uint16 parent;
} ENetSymbol;
/* adaptation constants tuned aggressively for small packet sizes rather than large file compression */
enum
{
ENET_RANGE_CODER_TOP = 1<<24,
ENET_RANGE_CODER_BOTTOM = 1<<16,
ENET_CONTEXT_SYMBOL_DELTA = 3,
ENET_CONTEXT_SYMBOL_MINIMUM = 1,
ENET_CONTEXT_ESCAPE_MINIMUM = 1,
ENET_SUBCONTEXT_ORDER = 2,
ENET_SUBCONTEXT_SYMBOL_DELTA = 2,
ENET_SUBCONTEXT_ESCAPE_DELTA = 5
};
/* context exclusion roughly halves compression speed, so disable for now */
#undef ENET_CONTEXT_EXCLUSION
typedef struct _ENetRangeCoder
{
/* only allocate enough symbols for reasonable MTUs, would need to be larger for large file compression */
ENetSymbol symbols[4096];
} ENetRangeCoder;
void *
enet_range_coder_create (void)
{
ENetRangeCoder * rangeCoder = (ENetRangeCoder *) enet_malloc (sizeof (ENetRangeCoder));
if (rangeCoder == NULL)
return NULL;
return rangeCoder;
}
void
enet_range_coder_destroy (void * context)
{
ENetRangeCoder * rangeCoder = (ENetRangeCoder *) context;
if (rangeCoder == NULL)
return;
enet_free (rangeCoder);
}
#define ENET_SYMBOL_CREATE(symbol, value_, count_) \
{ \
symbol = & rangeCoder -> symbols [nextSymbol ++]; \
symbol -> value = value_; \
symbol -> count = count_; \
symbol -> under = count_; \
symbol -> left = 0; \
symbol -> right = 0; \
symbol -> symbols = 0; \
symbol -> escapes = 0; \
symbol -> total = 0; \
symbol -> parent = 0; \
}
#define ENET_CONTEXT_CREATE(context, escapes_, minimum) \
{ \
ENET_SYMBOL_CREATE (context, 0, 0); \
(context) -> escapes = escapes_; \
(context) -> total = escapes_ + 256*minimum; \
(context) -> symbols = 0; \
}
static enet_uint16
enet_symbol_rescale (ENetSymbol * symbol)
{
enet_uint16 total = 0;
for (;;)
{
symbol -> count -= symbol->count >> 1;
symbol -> under = symbol -> count;
if (symbol -> left)
symbol -> under += enet_symbol_rescale (symbol + symbol -> left);
total += symbol -> under;
if (! symbol -> right) break;
symbol += symbol -> right;
}
return total;
}
#define ENET_CONTEXT_RESCALE(context, minimum) \
{ \
(context) -> total = (context) -> symbols ? enet_symbol_rescale ((context) + (context) -> symbols) : 0; \
(context) -> escapes -= (context) -> escapes >> 1; \
(context) -> total += (context) -> escapes + 256*minimum; \
}
#define ENET_RANGE_CODER_OUTPUT(value) \
{ \
if (outData >= outEnd) \
return 0; \
* outData ++ = value; \
}
#define ENET_RANGE_CODER_ENCODE(under, count, total) \
{ \
encodeRange /= (total); \
encodeLow += (under) * encodeRange; \
encodeRange *= (count); \
for (;;) \
{ \
if((encodeLow ^ (encodeLow + encodeRange)) >= ENET_RANGE_CODER_TOP) \
{ \
if(encodeRange >= ENET_RANGE_CODER_BOTTOM) break; \
encodeRange = -encodeLow & (ENET_RANGE_CODER_BOTTOM - 1); \
} \
ENET_RANGE_CODER_OUTPUT (encodeLow >> 24); \
encodeRange <<= 8; \
encodeLow <<= 8; \
} \
}
#define ENET_RANGE_CODER_FLUSH \
{ \
while (encodeLow) \
{ \
ENET_RANGE_CODER_OUTPUT (encodeLow >> 24); \
encodeLow <<= 8; \
} \
}
#define ENET_RANGE_CODER_FREE_SYMBOLS \
{ \
if (nextSymbol >= sizeof (rangeCoder -> symbols) / sizeof (ENetSymbol) - ENET_SUBCONTEXT_ORDER ) \
{ \
nextSymbol = 0; \
ENET_CONTEXT_CREATE (root, ENET_CONTEXT_ESCAPE_MINIMUM, ENET_CONTEXT_SYMBOL_MINIMUM); \
predicted = 0; \
order = 0; \
} \
}
#define ENET_CONTEXT_ENCODE(context, symbol_, value_, under_, count_, update, minimum) \
{ \
under_ = value*minimum; \
count_ = minimum; \
if (! (context) -> symbols) \
{ \
ENET_SYMBOL_CREATE (symbol_, value_, update); \
(context) -> symbols = symbol_ - (context); \
} \
else \
{ \
ENetSymbol * node = (context) + (context) -> symbols; \
for (;;) \
{ \
if (value_ < node -> value) \
{ \
node -> under += update; \
if (node -> left) { node += node -> left; continue; } \
ENET_SYMBOL_CREATE (symbol_, value_, update); \
node -> left = symbol_ - node; \
} \
else \
if (value_ > node -> value) \
{ \
under_ += node -> under; \
if (node -> right) { node += node -> right; continue; } \
ENET_SYMBOL_CREATE (symbol_, value_, update); \
node -> right = symbol_ - node; \
} \
else \
{ \
count_ += node -> count; \
under_ += node -> under - node -> count; \
node -> under += update; \
node -> count += update; \
symbol_ = node; \
} \
break; \
} \
} \
}
#ifdef ENET_CONTEXT_EXCLUSION
static const ENetSymbol emptyContext = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
#define ENET_CONTEXT_WALK(context, body) \
{ \
const ENetSymbol * node = (context) + (context) -> symbols; \
const ENetSymbol * stack [256]; \
size_t stackSize = 0; \
while (node -> left) \
{ \
stack [stackSize ++] = node; \
node += node -> left; \
} \
for (;;) \
{ \
body; \
if (node -> right) \
{ \
node += node -> right; \
while (node -> left) \
{ \
stack [stackSize ++] = node; \
node += node -> left; \
} \
} \
else \
if (stackSize <= 0) \
break; \
else \
node = stack [-- stackSize]; \
} \
}
#define ENET_CONTEXT_ENCODE_EXCLUDE(context, value_, under, total, minimum) \
ENET_CONTEXT_WALK(context, { \
if (node -> value != value_) \
{ \
enet_uint16 parentCount = rangeCoder -> symbols [node -> parent].count + minimum; \
if (node -> value < value_) \
under -= parentCount; \
total -= parentCount; \
} \
})
#endif
size_t
enet_range_coder_compress (void * context, const ENetBuffer * inBuffers, size_t inBufferCount, size_t inLimit, enet_uint8 * outData, size_t outLimit)
{
ENetRangeCoder * rangeCoder = (ENetRangeCoder *) context;
enet_uint8 * outStart = outData, * outEnd = & outData [outLimit];
const enet_uint8 * inData, * inEnd;
enet_uint32 encodeLow = 0, encodeRange = ~0;
ENetSymbol * root;
enet_uint16 predicted = 0;
size_t order = 0, nextSymbol = 0;
if (rangeCoder == NULL || inBufferCount <= 0 || inLimit <= 0)
return 0;
inData = (const enet_uint8 *) inBuffers -> data;
inEnd = & inData [inBuffers -> dataLength];
inBuffers ++;
inBufferCount --;
ENET_CONTEXT_CREATE (root, ENET_CONTEXT_ESCAPE_MINIMUM, ENET_CONTEXT_SYMBOL_MINIMUM);
for (;;)
{
ENetSymbol * subcontext, * symbol;
#ifdef ENET_CONTEXT_EXCLUSION
const ENetSymbol * childContext = & emptyContext;
#endif
enet_uint8 value;
enet_uint16 count, under, * parent = & predicted, total;
if (inData >= inEnd)
{
if (inBufferCount <= 0)
break;
inData = (const enet_uint8 *) inBuffers -> data;
inEnd = & inData [inBuffers -> dataLength];
inBuffers ++;
inBufferCount --;
}
value = * inData ++;
for (subcontext = & rangeCoder -> symbols [predicted];
subcontext != root;
#ifdef ENET_CONTEXT_EXCLUSION
childContext = subcontext,
#endif
subcontext = & rangeCoder -> symbols [subcontext -> parent])
{
ENET_CONTEXT_ENCODE (subcontext, symbol, value, under, count, ENET_SUBCONTEXT_SYMBOL_DELTA, 0);
* parent = symbol - rangeCoder -> symbols;
parent = & symbol -> parent;
total = subcontext -> total;
#ifdef ENET_CONTEXT_EXCLUSION
if (childContext -> total > ENET_SUBCONTEXT_SYMBOL_DELTA + ENET_SUBCONTEXT_ESCAPE_DELTA)
ENET_CONTEXT_ENCODE_EXCLUDE (childContext, value, under, total, 0);
#endif
if (count > 0)
{
ENET_RANGE_CODER_ENCODE (subcontext -> escapes + under, count, total);
}
else
{
if (subcontext -> escapes > 0 && subcontext -> escapes < total)
ENET_RANGE_CODER_ENCODE (0, subcontext -> escapes, total);
subcontext -> escapes += ENET_SUBCONTEXT_ESCAPE_DELTA;
subcontext -> total += ENET_SUBCONTEXT_ESCAPE_DELTA;
}
subcontext -> total += ENET_SUBCONTEXT_SYMBOL_DELTA;
if (count > 0xFF - 2*ENET_SUBCONTEXT_SYMBOL_DELTA || subcontext -> total > ENET_RANGE_CODER_BOTTOM - 0x100)
ENET_CONTEXT_RESCALE (subcontext, 0);
if (count > 0) goto nextInput;
}
ENET_CONTEXT_ENCODE (root, symbol, value, under, count, ENET_CONTEXT_SYMBOL_DELTA, ENET_CONTEXT_SYMBOL_MINIMUM);
* parent = symbol - rangeCoder -> symbols;
parent = & symbol -> parent;
total = root -> total;
#ifdef ENET_CONTEXT_EXCLUSION
if (childContext -> total > ENET_SUBCONTEXT_SYMBOL_DELTA + ENET_SUBCONTEXT_ESCAPE_DELTA)
ENET_CONTEXT_ENCODE_EXCLUDE (childContext, value, under, total, ENET_CONTEXT_SYMBOL_MINIMUM);
#endif
ENET_RANGE_CODER_ENCODE (root -> escapes + under, count, total);
root -> total += ENET_CONTEXT_SYMBOL_DELTA;
if (count > 0xFF - 2*ENET_CONTEXT_SYMBOL_DELTA + ENET_CONTEXT_SYMBOL_MINIMUM || root -> total > ENET_RANGE_CODER_BOTTOM - 0x100)
ENET_CONTEXT_RESCALE (root, ENET_CONTEXT_SYMBOL_MINIMUM);
nextInput:
if (order >= ENET_SUBCONTEXT_ORDER)
predicted = rangeCoder -> symbols [predicted].parent;
else
order ++;
ENET_RANGE_CODER_FREE_SYMBOLS;
}
ENET_RANGE_CODER_FLUSH;
return (size_t) (outData - outStart);
}
#define ENET_RANGE_CODER_SEED \
{ \
if (inData < inEnd) decodeCode |= * inData ++ << 24; \
if (inData < inEnd) decodeCode |= * inData ++ << 16; \
if (inData < inEnd) decodeCode |= * inData ++ << 8; \
if (inData < inEnd) decodeCode |= * inData ++; \
}
#define ENET_RANGE_CODER_READ(total) ((decodeCode - decodeLow) / (decodeRange /= (total)))
#define ENET_RANGE_CODER_DECODE(under, count, total) \
{ \
decodeLow += (under) * decodeRange; \
decodeRange *= (count); \
for (;;) \
{ \
if((decodeLow ^ (decodeLow + decodeRange)) >= ENET_RANGE_CODER_TOP) \
{ \
if(decodeRange >= ENET_RANGE_CODER_BOTTOM) break; \
decodeRange = -decodeLow & (ENET_RANGE_CODER_BOTTOM - 1); \
} \
decodeCode <<= 8; \
if (inData < inEnd) \
decodeCode |= * inData ++; \
decodeRange <<= 8; \
decodeLow <<= 8; \
} \
}
#define ENET_CONTEXT_DECODE(context, symbol_, code, value_, under_, count_, update, minimum, createRoot, visitNode, createRight, createLeft) \
{ \
under_ = 0; \
count_ = minimum; \
if (! (context) -> symbols) \
{ \
createRoot; \
} \
else \
{ \
ENetSymbol * node = (context) + (context) -> symbols; \
for (;;) \
{ \
enet_uint16 after = under_ + node -> under + (node -> value + 1)*minimum, before = node -> count + minimum; \
visitNode; \
if (code >= after) \
{ \
under_ += node -> under; \
if (node -> right) { node += node -> right; continue; } \
createRight; \
} \
else \
if (code < after - before) \
{ \
node -> under += update; \
if (node -> left) { node += node -> left; continue; } \
createLeft; \
} \
else \
{ \
value_ = node -> value; \
count_ += node -> count; \
under_ = after - before; \
node -> under += update; \
node -> count += update; \
symbol_ = node; \
} \
break; \
} \
} \
}
#define ENET_CONTEXT_TRY_DECODE(context, symbol_, code, value_, under_, count_, update, minimum, exclude) \
ENET_CONTEXT_DECODE (context, symbol_, code, value_, under_, count_, update, minimum, return 0, exclude (node -> value, after, before), return 0, return 0)
#define ENET_CONTEXT_ROOT_DECODE(context, symbol_, code, value_, under_, count_, update, minimum, exclude) \
ENET_CONTEXT_DECODE (context, symbol_, code, value_, under_, count_, update, minimum, \
{ \
value_ = code / minimum; \
under_ = code - code%minimum; \
ENET_SYMBOL_CREATE (symbol_, value_, update); \
(context) -> symbols = symbol_ - (context); \
}, \
exclude (node -> value, after, before), \
{ \
value_ = node->value + 1 + (code - after)/minimum; \
under_ = code - (code - after)%minimum; \
ENET_SYMBOL_CREATE (symbol_, value_, update); \
node -> right = symbol_ - node; \
}, \
{ \
value_ = node->value - 1 - (after - before - code - 1)/minimum; \
under_ = code - (after - before - code - 1)%minimum; \
ENET_SYMBOL_CREATE (symbol_, value_, update); \
node -> left = symbol_ - node; \
}) \
#ifdef ENET_CONTEXT_EXCLUSION
typedef struct _ENetExclude
{
enet_uint8 value;
enet_uint16 under;
} ENetExclude;
#define ENET_CONTEXT_DECODE_EXCLUDE(context, total, minimum) \
{ \
enet_uint16 under = 0; \
nextExclude = excludes; \
ENET_CONTEXT_WALK (context, { \
under += rangeCoder -> symbols [node -> parent].count + minimum; \
nextExclude -> value = node -> value; \
nextExclude -> under = under; \
nextExclude ++; \
}); \
total -= under; \
}
#define ENET_CONTEXT_EXCLUDED(value_, after, before) \
{ \
size_t low = 0, high = nextExclude - excludes; \
for(;;) \
{ \
size_t mid = (low + high) >> 1; \
const ENetExclude * exclude = & excludes [mid]; \
if (value_ < exclude -> value) \
{ \
if (low + 1 < high) \
{ \
high = mid; \
continue; \
} \
if (exclude > excludes) \
after -= exclude [-1].under; \
} \
else \
{ \
if (value_ > exclude -> value) \
{ \
if (low + 1 < high) \
{ \
low = mid; \
continue; \
} \
} \
else \
before = 0; \
after -= exclude -> under; \
} \
break; \
} \
}
#endif
#define ENET_CONTEXT_NOT_EXCLUDED(value_, after, before)
size_t
enet_range_coder_decompress (void * context, const enet_uint8 * inData, size_t inLimit, enet_uint8 * outData, size_t outLimit)
{
ENetRangeCoder * rangeCoder = (ENetRangeCoder *) context;
enet_uint8 * outStart = outData, * outEnd = & outData [outLimit];
const enet_uint8 * inEnd = & inData [inLimit];
enet_uint32 decodeLow = 0, decodeCode = 0, decodeRange = ~0;
ENetSymbol * root;
enet_uint16 predicted = 0;
size_t order = 0, nextSymbol = 0;
#ifdef ENET_CONTEXT_EXCLUSION
ENetExclude excludes [256];
ENetExclude * nextExclude = excludes;
#endif
if (rangeCoder == NULL || inLimit <= 0)
return 0;
ENET_CONTEXT_CREATE (root, ENET_CONTEXT_ESCAPE_MINIMUM, ENET_CONTEXT_SYMBOL_MINIMUM);
ENET_RANGE_CODER_SEED;
for (;;)
{
ENetSymbol * subcontext, * symbol, * patch;
#ifdef ENET_CONTEXT_EXCLUSION
const ENetSymbol * childContext = & emptyContext;
#endif
enet_uint8 value = 0;
enet_uint16 code, under, count, bottom, * parent = & predicted, total;
for (subcontext = & rangeCoder -> symbols [predicted];
subcontext != root;
#ifdef ENET_CONTEXT_EXCLUSION
childContext = subcontext,
#endif
subcontext = & rangeCoder -> symbols [subcontext -> parent])
{
if (subcontext -> escapes <= 0)
continue;
total = subcontext -> total;
#ifdef ENET_CONTEXT_EXCLUSION
if (childContext -> total > 0)
ENET_CONTEXT_DECODE_EXCLUDE (childContext, total, 0);
#endif
if (subcontext -> escapes >= total)
continue;
code = ENET_RANGE_CODER_READ (total);
if (code < subcontext -> escapes)
{
ENET_RANGE_CODER_DECODE (0, subcontext -> escapes, total);
continue;
}
code -= subcontext -> escapes;
#ifdef ENET_CONTEXT_EXCLUSION
if (childContext -> total > 0)
{
ENET_CONTEXT_TRY_DECODE (subcontext, symbol, code, value, under, count, ENET_SUBCONTEXT_SYMBOL_DELTA, 0, ENET_CONTEXT_EXCLUDED);
}
else
#endif
{
ENET_CONTEXT_TRY_DECODE (subcontext, symbol, code, value, under, count, ENET_SUBCONTEXT_SYMBOL_DELTA, 0, ENET_CONTEXT_NOT_EXCLUDED);
}
bottom = symbol - rangeCoder -> symbols;
ENET_RANGE_CODER_DECODE (subcontext -> escapes + under, count, total);
subcontext -> total += ENET_SUBCONTEXT_SYMBOL_DELTA;
if (count > 0xFF - 2*ENET_SUBCONTEXT_SYMBOL_DELTA || subcontext -> total > ENET_RANGE_CODER_BOTTOM - 0x100)
ENET_CONTEXT_RESCALE (subcontext, 0);
goto patchContexts;
}
total = root -> total;
#ifdef ENET_CONTEXT_EXCLUSION
if (childContext -> total > 0)
ENET_CONTEXT_DECODE_EXCLUDE (childContext, total, ENET_CONTEXT_SYMBOL_MINIMUM);
#endif
code = ENET_RANGE_CODER_READ (total);
if (code < root -> escapes)
{
ENET_RANGE_CODER_DECODE (0, root -> escapes, total);
break;
}
code -= root -> escapes;
#ifdef ENET_CONTEXT_EXCLUSION
if (childContext -> total > 0)
{
ENET_CONTEXT_ROOT_DECODE (root, symbol, code, value, under, count, ENET_CONTEXT_SYMBOL_DELTA, ENET_CONTEXT_SYMBOL_MINIMUM, ENET_CONTEXT_EXCLUDED);
}
else
#endif
{
ENET_CONTEXT_ROOT_DECODE (root, symbol, code, value, under, count, ENET_CONTEXT_SYMBOL_DELTA, ENET_CONTEXT_SYMBOL_MINIMUM, ENET_CONTEXT_NOT_EXCLUDED);
}
bottom = symbol - rangeCoder -> symbols;
ENET_RANGE_CODER_DECODE (root -> escapes + under, count, total);
root -> total += ENET_CONTEXT_SYMBOL_DELTA;
if (count > 0xFF - 2*ENET_CONTEXT_SYMBOL_DELTA + ENET_CONTEXT_SYMBOL_MINIMUM || root -> total > ENET_RANGE_CODER_BOTTOM - 0x100)
ENET_CONTEXT_RESCALE (root, ENET_CONTEXT_SYMBOL_MINIMUM);
patchContexts:
for (patch = & rangeCoder -> symbols [predicted];
patch != subcontext;
patch = & rangeCoder -> symbols [patch -> parent])
{
ENET_CONTEXT_ENCODE (patch, symbol, value, under, count, ENET_SUBCONTEXT_SYMBOL_DELTA, 0);
* parent = symbol - rangeCoder -> symbols;
parent = & symbol -> parent;
if (count <= 0)
{
patch -> escapes += ENET_SUBCONTEXT_ESCAPE_DELTA;
patch -> total += ENET_SUBCONTEXT_ESCAPE_DELTA;
}
patch -> total += ENET_SUBCONTEXT_SYMBOL_DELTA;
if (count > 0xFF - 2*ENET_SUBCONTEXT_SYMBOL_DELTA || patch -> total > ENET_RANGE_CODER_BOTTOM - 0x100)
ENET_CONTEXT_RESCALE (patch, 0);
}
* parent = bottom;
ENET_RANGE_CODER_OUTPUT (value);
if (order >= ENET_SUBCONTEXT_ORDER)
predicted = rangeCoder -> symbols [predicted].parent;
else
order ++;
ENET_RANGE_CODER_FREE_SYMBOLS;
}
return (size_t) (outData - outStart);
}
/** @defgroup host ENet host functions
@{
*/
/** Sets the packet compressor the host should use to the default range coder.
@param host host to enable the range coder for
@returns 0 on success, < 0 on failure
*/
int
enet_host_compress_with_range_coder (ENetHost * host)
{
ENetCompressor compressor;
memset (& compressor, 0, sizeof (compressor));
compressor.context = enet_range_coder_create();
if (compressor.context == NULL)
return -1;
compressor.compress = enet_range_coder_compress;
compressor.decompress = enet_range_coder_decompress;
compressor.destroy = enet_range_coder_destroy;
enet_host_compress (host, & compressor);
return 0;
}
/** @} */

12560
src/enet/configure vendored

File diff suppressed because it is too large Load Diff

View File

@ -1,9 +1,10 @@
#! /bin/sh #! /bin/sh
# depcomp - compile a program generating dependencies as side-effects # depcomp - compile a program generating dependencies as side-effects
scriptversion=2005-07-09.11 scriptversion=2009-04-28.21; # UTC
# Copyright (C) 1999, 2000, 2003, 2004, 2005 Free Software Foundation, Inc. # Copyright (C) 1999, 2000, 2003, 2004, 2005, 2006, 2007, 2009 Free
# Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@ -16,9 +17,7 @@ scriptversion=2005-07-09.11
# GNU General Public License for more details. # GNU General Public License for more details.
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software # along with this program. If not, see <http://www.gnu.org/licenses/>.
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
# As a special exception to the GNU General Public License, if you # As a special exception to the GNU General Public License, if you
# distribute this file as part of a program that contains a # distribute this file as part of a program that contains a
@ -86,12 +85,34 @@ if test "$depmode" = dashXmstdout; then
depmode=dashmstdout depmode=dashmstdout
fi fi
cygpath_u="cygpath -u -f -"
if test "$depmode" = msvcmsys; then
# This is just like msvisualcpp but w/o cygpath translation.
# Just convert the backslash-escaped backslashes to single forward
# slashes to satisfy depend.m4
cygpath_u="sed s,\\\\\\\\,/,g"
depmode=msvisualcpp
fi
case "$depmode" in case "$depmode" in
gcc3) gcc3)
## gcc 3 implements dependency tracking that does exactly what ## gcc 3 implements dependency tracking that does exactly what
## we want. Yay! Note: for some reason libtool 1.4 doesn't like ## we want. Yay! Note: for some reason libtool 1.4 doesn't like
## it if -MD -MP comes after the -MF stuff. Hmm. ## it if -MD -MP comes after the -MF stuff. Hmm.
"$@" -MT "$object" -MD -MP -MF "$tmpdepfile" ## Unfortunately, FreeBSD c89 acceptance of flags depends upon
## the command line argument order; so add the flags where they
## appear in depend2.am. Note that the slowdown incurred here
## affects only configure: in makefiles, %FASTDEP% shortcuts this.
for arg
do
case $arg in
-c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
*) set fnord "$@" "$arg" ;;
esac
shift # fnord
shift # $arg
done
"$@"
stat=$? stat=$?
if test $stat -eq 0; then : if test $stat -eq 0; then :
else else
@ -178,14 +199,14 @@ sgi)
' < "$tmpdepfile" \ ' < "$tmpdepfile" \
| sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \ | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \
tr ' tr '
' ' ' >> $depfile ' ' ' >> "$depfile"
echo >> $depfile echo >> "$depfile"
# The second pass generates a dummy entry for each header file. # The second pass generates a dummy entry for each header file.
tr ' ' ' tr ' ' '
' < "$tmpdepfile" \ ' < "$tmpdepfile" \
| sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \ | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
>> $depfile >> "$depfile"
else else
# The sourcefile does not contain any dependencies, so just # The sourcefile does not contain any dependencies, so just
# store a dummy comment line, to avoid errors with the Makefile # store a dummy comment line, to avoid errors with the Makefile
@ -201,34 +222,39 @@ aix)
# current directory. Also, the AIX compiler puts `$object:' at the # current directory. Also, the AIX compiler puts `$object:' at the
# start of each line; $object doesn't have directory information. # start of each line; $object doesn't have directory information.
# Version 6 uses the directory in both cases. # Version 6 uses the directory in both cases.
stripped=`echo "$object" | sed 's/\(.*\)\..*$/\1/'` dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
tmpdepfile="$stripped.u" test "x$dir" = "x$object" && dir=
base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
if test "$libtool" = yes; then if test "$libtool" = yes; then
tmpdepfile1=$dir$base.u
tmpdepfile2=$base.u
tmpdepfile3=$dir.libs/$base.u
"$@" -Wc,-M "$@" -Wc,-M
else else
tmpdepfile1=$dir$base.u
tmpdepfile2=$dir$base.u
tmpdepfile3=$dir$base.u
"$@" -M "$@" -M
fi fi
stat=$? stat=$?
if test -f "$tmpdepfile"; then :
else
stripped=`echo "$stripped" | sed 's,^.*/,,'`
tmpdepfile="$stripped.u"
fi
if test $stat -eq 0; then : if test $stat -eq 0; then :
else else
rm -f "$tmpdepfile" rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
exit $stat exit $stat
fi fi
for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
do
test -f "$tmpdepfile" && break
done
if test -f "$tmpdepfile"; then if test -f "$tmpdepfile"; then
outname="$stripped.o"
# Each line is of the form `foo.o: dependent.h'. # Each line is of the form `foo.o: dependent.h'.
# Do two passes, one to just change these to # Do two passes, one to just change these to
# `$object: dependent.h' and one to simply `dependent.h:'. # `$object: dependent.h' and one to simply `dependent.h:'.
sed -e "s,^$outname:,$object :," < "$tmpdepfile" > "$depfile" sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
sed -e "s,^$outname: \(.*\)$,\1:," < "$tmpdepfile" >> "$depfile" # That's a tab and a space in the [].
sed -e 's,^.*\.[a-z]*:[ ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
else else
# The sourcefile does not contain any dependencies, so just # The sourcefile does not contain any dependencies, so just
# store a dummy comment line, to avoid errors with the Makefile # store a dummy comment line, to avoid errors with the Makefile
@ -276,6 +302,51 @@ icc)
rm -f "$tmpdepfile" rm -f "$tmpdepfile"
;; ;;
hp2)
# The "hp" stanza above does not work with aCC (C++) and HP's ia64
# compilers, which have integrated preprocessors. The correct option
# to use with these is +Maked; it writes dependencies to a file named
# 'foo.d', which lands next to the object file, wherever that
# happens to be.
# Much of this is similar to the tru64 case; see comments there.
dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
test "x$dir" = "x$object" && dir=
base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
if test "$libtool" = yes; then
tmpdepfile1=$dir$base.d
tmpdepfile2=$dir.libs/$base.d
"$@" -Wc,+Maked
else
tmpdepfile1=$dir$base.d
tmpdepfile2=$dir$base.d
"$@" +Maked
fi
stat=$?
if test $stat -eq 0; then :
else
rm -f "$tmpdepfile1" "$tmpdepfile2"
exit $stat
fi
for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
do
test -f "$tmpdepfile" && break
done
if test -f "$tmpdepfile"; then
sed -e "s,^.*\.[a-z]*:,$object:," "$tmpdepfile" > "$depfile"
# Add `dependent.h:' lines.
sed -ne '2,${
s/^ *//
s/ \\*$//
s/$/:/
p
}' "$tmpdepfile" >> "$depfile"
else
echo "#dummy" > "$depfile"
fi
rm -f "$tmpdepfile" "$tmpdepfile2"
;;
tru64) tru64)
# The Tru64 compiler uses -MD to generate dependencies as a side # The Tru64 compiler uses -MD to generate dependencies as a side
# effect. `cc -MD -o foo.o ...' puts the dependencies into `foo.o.d'. # effect. `cc -MD -o foo.o ...' puts the dependencies into `foo.o.d'.
@ -288,13 +359,13 @@ tru64)
if test "$libtool" = yes; then if test "$libtool" = yes; then
# With Tru64 cc, shared objects can also be used to make a # With Tru64 cc, shared objects can also be used to make a
# static library. This mecanism is used in libtool 1.4 series to # static library. This mechanism is used in libtool 1.4 series to
# handle both shared and static libraries in a single compilation. # handle both shared and static libraries in a single compilation.
# With libtool 1.4, dependencies were output in $dir.libs/$base.lo.d. # With libtool 1.4, dependencies were output in $dir.libs/$base.lo.d.
# #
# With libtool 1.5 this exception was removed, and libtool now # With libtool 1.5 this exception was removed, and libtool now
# generates 2 separate objects for the 2 libraries. These two # generates 2 separate objects for the 2 libraries. These two
# compilations output dependencies in in $dir.libs/$base.o.d and # compilations output dependencies in $dir.libs/$base.o.d and
# in $dir$base.o.d. We have to check for both files, because # in $dir$base.o.d. We have to check for both files, because
# one of the two compilations can be disabled. We should prefer # one of the two compilations can be disabled. We should prefer
# $dir$base.o.d over $dir.libs/$base.o.d because the latter is # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
@ -345,7 +416,7 @@ dashmstdout)
# Remove the call to Libtool. # Remove the call to Libtool.
if test "$libtool" = yes; then if test "$libtool" = yes; then
while test $1 != '--mode=compile'; do while test "X$1" != 'X--mode=compile'; do
shift shift
done done
shift shift
@ -396,32 +467,39 @@ makedepend)
"$@" || exit $? "$@" || exit $?
# Remove any Libtool call # Remove any Libtool call
if test "$libtool" = yes; then if test "$libtool" = yes; then
while test $1 != '--mode=compile'; do while test "X$1" != 'X--mode=compile'; do
shift shift
done done
shift shift
fi fi
# X makedepend # X makedepend
shift shift
cleared=no cleared=no eat=no
for arg in "$@"; do for arg
do
case $cleared in case $cleared in
no) no)
set ""; shift set ""; shift
cleared=yes ;; cleared=yes ;;
esac esac
if test $eat = yes; then
eat=no
continue
fi
case "$arg" in case "$arg" in
-D*|-I*) -D*|-I*)
set fnord "$@" "$arg"; shift ;; set fnord "$@" "$arg"; shift ;;
# Strip any option that makedepend may not understand. Remove # Strip any option that makedepend may not understand. Remove
# the object too, otherwise makedepend will parse it as a source file. # the object too, otherwise makedepend will parse it as a source file.
-arch)
eat=yes ;;
-*|$object) -*|$object)
;; ;;
*) *)
set fnord "$@" "$arg"; shift ;; set fnord "$@" "$arg"; shift ;;
esac esac
done done
obj_suffix="`echo $object | sed 's/^.*\././'`" obj_suffix=`echo "$object" | sed 's/^.*\././'`
touch "$tmpdepfile" touch "$tmpdepfile"
${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@" ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
rm -f "$depfile" rm -f "$depfile"
@ -441,7 +519,7 @@ cpp)
# Remove the call to Libtool. # Remove the call to Libtool.
if test "$libtool" = yes; then if test "$libtool" = yes; then
while test $1 != '--mode=compile'; do while test "X$1" != 'X--mode=compile'; do
shift shift
done done
shift shift
@ -479,13 +557,27 @@ cpp)
msvisualcpp) msvisualcpp)
# Important note: in order to support this mode, a compiler *must* # Important note: in order to support this mode, a compiler *must*
# always write the preprocessed file to stdout, regardless of -o, # always write the preprocessed file to stdout.
# because we must use -o when running libtool.
"$@" || exit $? "$@" || exit $?
# Remove the call to Libtool.
if test "$libtool" = yes; then
while test "X$1" != 'X--mode=compile'; do
shift
done
shift
fi
IFS=" " IFS=" "
for arg for arg
do do
case "$arg" in case "$arg" in
-o)
shift
;;
$object)
shift
;;
"-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI") "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
set fnord "$@" set fnord "$@"
shift shift
@ -498,16 +590,23 @@ msvisualcpp)
;; ;;
esac esac
done done
"$@" -E | "$@" -E 2>/dev/null |
sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::echo "`cygpath -u \\"\1\\"`":p' | sort | uniq > "$tmpdepfile" sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
rm -f "$depfile" rm -f "$depfile"
echo "$object : \\" > "$depfile" echo "$object : \\" > "$depfile"
. "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s:: \1 \\:p' >> "$depfile" sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s:: \1 \\:p' >> "$depfile"
echo " " >> "$depfile" echo " " >> "$depfile"
. "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s::\1\::p' >> "$depfile" sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
rm -f "$tmpdepfile" rm -f "$tmpdepfile"
;; ;;
msvcmsys)
# This case exists only to let depend.m4 do its work. It works by
# looking at the text of this script. This case will never be run,
# since it is checked for above.
exit 1
;;
none) none)
exec "$@" exec "$@"
;; ;;
@ -526,5 +625,6 @@ exit 0
# eval: (add-hook 'write-file-hooks 'time-stamp) # eval: (add-hook 'write-file-hooks 'time-stamp)
# time-stamp-start: "scriptversion=" # time-stamp-start: "scriptversion="
# time-stamp-format: "%:y-%02m-%02d.%02H" # time-stamp-format: "%:y-%02m-%02d.%02H"
# time-stamp-end: "$" # time-stamp-time-zone: "UTC"
# time-stamp-end: "; # UTC"
# End: # End:

View File

@ -16,7 +16,7 @@ If you obtained the package from CVS, you must have automake and autoconf
available to generate the build system first by doing the following command available to generate the build system first by doing the following command
before using the above mentioned build procedure: before using the above mentioned build procedure:
aclocal && automake -a -c --foreign && autoconf autoreconf -vfi
@subsection SolarisBSD Solaris and BSD @subsection SolarisBSD Solaris and BSD
@ -32,7 +32,7 @@ build a suitable library file. Alternatively, you may simply drag all
the ENet source files into your main project. the ENet source files into your main project.
You will have to link to the Winsock2 libraries, so make sure to add You will have to link to the Winsock2 libraries, so make sure to add
ws2_32.lib to your library list (Project Settings | Link | ws2_32.lib and winmm.lib to your library list (Project Settings | Link |
Object/library modules). Object/library modules).
@subsection enet.dsp Building with the included enet.dsp @subsection enet.dsp Building with the included enet.dsp
@ -46,8 +46,8 @@ selected to build. By default, it should produce "Debug/enet.lib".
You may then copy the resulting "enet.lib" file and the header files You may then copy the resulting "enet.lib" file and the header files
found in the "include/" directory to your other projects and add it to found in the "include/" directory to your other projects and add it to
their library lists. Make sure to also link against "ws2_32.lib" as their library lists. Make sure to also link against "ws2_32.lib" and
described above. "winmm.lib" as described above.
@subsection DLL DLL @subsection DLL DLL

View File

@ -1,7 +1,7 @@
/** /**
@page License License @page License License
Copyright (c) 2002 Lee Salzman Copyright (c) 2002-2010 Lee Salzman
Permission is hereby granted, free of charge, to any person obtaining Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the a copy of this software and associated documentation files (the

View File

@ -7,10 +7,10 @@ network communication layer on top of UDP (User Datagram Protocol).
The primary feature it provides is optional reliable, in-order The primary feature it provides is optional reliable, in-order
delivery of packets. delivery of packets.
ENet is NOT intended to be a general purpose high level networking ENet omits certain higher level networking features such as authentication,
library that handles authentication, lobbying, server discovery, lobbying, server discovery, encryption, or other similar tasks that are
compression, encryption and other high level, often application level particularly application specific so that the library remains flexible,
or dependent tasks. portable, and easily embeddable.
@ref Features @ref Features
@ -22,6 +22,8 @@ or dependent tasks.
@ref MailingList @ref MailingList
@ref IRCChannel
@ref FAQ @ref FAQ
@ref License @ref License
@ -34,7 +36,8 @@ or dependent tasks.
You can retrieve the source to ENet by downloading it in either .tar.gz form You can retrieve the source to ENet by downloading it in either .tar.gz form
or accessing the cvs distribution directly. or accessing the cvs distribution directly.
The most recent stable release (1.2) can be downloaded <a href="http://enet.bespin.org/download/enet-1.2.tar.gz">here</a>. The most recent stable release (1.3.1) can be downloaded <a href="http://enet.bespin.org/download/enet-1.3.1.tar.gz">here</a>.
The last release that is protocol compatible with the 1.2 series or earlier (1.2.3) can be downloaded <a href="http://enet.bespin.org/download/enet-1.2.3.tar.gz">here</a>
To access ENet via anonymous CVS, you must use the CVSROOT To access ENet via anonymous CVS, you must use the CVSROOT
:pserver:anonymous\@bespin.org:/var/lib/cvs/enet with an empty :pserver:anonymous\@bespin.org:/var/lib/cvs/enet with an empty
@ -62,3 +65,11 @@ sent via email to @ref MailingList.
The <a href="http://lists.cubik.org/mailman/listinfo/enet-discuss">enet-discuss</a> list is for discussion of ENet, including bug reports or feature requests. The <a href="http://lists.cubik.org/mailman/listinfo/enet-discuss">enet-discuss</a> list is for discussion of ENet, including bug reports or feature requests.
*/ */
/**
@page IRCChannel ENet IRC Channel
Join the \#enet channel on the freenode IRC network (irc.freenode.net) for real-time discussion about the ENet library.
*/

View File

@ -17,11 +17,17 @@
@section Initialization Initialization @section Initialization Initialization
You should include the file <enet/enet.h> when using ENet. Do not
include <enet.h> without the directory prefix, as this may cause
file name conflicts on some systems.
Before using ENet, you must call enet_initialize() to initialize the Before using ENet, you must call enet_initialize() to initialize the
library. Upon program exit, you should call enet_deinitialize() so library. Upon program exit, you should call enet_deinitialize() so
that the library may clean up any used resources. that the library may clean up any used resources.
@code @code
#include <enet/enet.h>
int int
main (int argc, char ** argv) main (int argc, char ** argv)
{ {
@ -67,6 +73,7 @@ and the resources used by the host will be freed.
server = enet_host_create (& address /* the address to bind the server host to */, server = enet_host_create (& address /* the address to bind the server host to */,
32 /* allow up to 32 clients and/or outgoing connections */, 32 /* allow up to 32 clients and/or outgoing connections */,
2 /* allow up to 2 channels to be used, 0 and 1 */,
0 /* assume any amount of incoming bandwidth */, 0 /* assume any amount of incoming bandwidth */,
0 /* assume any amount of outgoing bandwidth */); 0 /* assume any amount of outgoing bandwidth */);
if (server == NULL) if (server == NULL)
@ -94,6 +101,7 @@ may be simultaneously open.
client = enet_host_create (NULL /* create a client host */, client = enet_host_create (NULL /* create a client host */,
1 /* only allow 1 outgoing connection */, 1 /* only allow 1 outgoing connection */,
2 /* allow up 2 channels to be used, 0 and 1 */,
57600 / 8 /* 56K modem with 56 Kbps downstream bandwidth */, 57600 / 8 /* 56K modem with 56 Kbps downstream bandwidth */,
14400 / 8 /* 56K modem with 14 Kbps upstream bandwidth */); 14400 / 8 /* 56K modem with 14 Kbps upstream bandwidth */);
@ -315,7 +323,7 @@ ENET_EVENT_TYPE_DISCONNECT will be generated.
address.port = 1234; address.port = 1234;
/* Initiate the connection, allocating the two channels 0 and 1. */ /* Initiate the connection, allocating the two channels 0 and 1. */
peer = enet_host_connect (client, & address, 2); peer = enet_host_connect (client, & address, 2, 0);
if (peer == NULL) if (peer == NULL)
{ {

View File

@ -101,6 +101,10 @@ SOURCE=.\callbacks.c
# End Source File # End Source File
# Begin Source File # Begin Source File
SOURCE=.\compress.c
# End Source File
# Begin Source File
SOURCE=.\packet.c SOURCE=.\packet.c
# End Source File # End Source File
# Begin Source File # Begin Source File

View File

@ -4,6 +4,7 @@
*/ */
#define ENET_BUILDING_LIB 1 #define ENET_BUILDING_LIB 1
#include <string.h> #include <string.h>
#include <time.h>
#include "enet/enet.h" #include "enet/enet.h"
/** @defgroup host ENet host functions /** @defgroup host ENet host functions
@ -14,6 +15,7 @@
@param address the address at which other peers may connect to this host. If NULL, then no peers may connect to the host. @param address the address at which other peers may connect to this host. If NULL, then no peers may connect to the host.
@param peerCount the maximum number of peers that should be allocated for the host. @param peerCount the maximum number of peers that should be allocated for the host.
@param channelLimit the maximum number of channels allowed; if 0, then this is equivalent to ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT
@param incomingBandwidth downstream bandwidth of the host in bytes/second; if 0, ENet will assume unlimited bandwidth. @param incomingBandwidth downstream bandwidth of the host in bytes/second; if 0, ENet will assume unlimited bandwidth.
@param outgoingBandwidth upstream bandwidth of the host in bytes/second; if 0, ENet will assume unlimited bandwidth. @param outgoingBandwidth upstream bandwidth of the host in bytes/second; if 0, ENet will assume unlimited bandwidth.
@ -25,20 +27,33 @@
at any given time. at any given time.
*/ */
ENetHost * ENetHost *
enet_host_create (const ENetAddress * address, size_t peerCount, enet_uint32 incomingBandwidth, enet_uint32 outgoingBandwidth) enet_host_create (const ENetAddress * address, size_t peerCount, size_t channelLimit, enet_uint32 incomingBandwidth, enet_uint32 outgoingBandwidth)
{ {
ENetHost * host = (ENetHost *) enet_malloc (sizeof (ENetHost)); ENetHost * host;
ENetPeer * currentPeer; ENetPeer * currentPeer;
if (peerCount > ENET_PROTOCOL_MAXIMUM_PEER_ID) if (peerCount > ENET_PROTOCOL_MAXIMUM_PEER_ID)
return NULL; return NULL;
host = (ENetHost *) enet_malloc (sizeof (ENetHost));
if (host == NULL)
return NULL;
host -> peers = (ENetPeer *) enet_malloc (peerCount * sizeof (ENetPeer)); host -> peers = (ENetPeer *) enet_malloc (peerCount * sizeof (ENetPeer));
if (host -> peers == NULL)
{
enet_free (host);
return NULL;
}
memset (host -> peers, 0, peerCount * sizeof (ENetPeer)); memset (host -> peers, 0, peerCount * sizeof (ENetPeer));
host -> socket = enet_socket_create (ENET_SOCKET_TYPE_DATAGRAM, address); host -> socket = enet_socket_create (ENET_SOCKET_TYPE_DATAGRAM);
if (host -> socket == ENET_SOCKET_NULL) if (host -> socket == ENET_SOCKET_NULL || (address != NULL && enet_socket_bind (host -> socket, address) < 0))
{ {
if (host -> socket != ENET_SOCKET_NULL)
enet_socket_destroy (host -> socket);
enet_free (host -> peers); enet_free (host -> peers);
enet_free (host); enet_free (host);
@ -53,25 +68,48 @@ enet_host_create (const ENetAddress * address, size_t peerCount, enet_uint32 inc
if (address != NULL) if (address != NULL)
host -> address = * address; host -> address = * address;
if (! channelLimit || channelLimit > ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT)
channelLimit = ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT;
else
if (channelLimit < ENET_PROTOCOL_MINIMUM_CHANNEL_COUNT)
channelLimit = ENET_PROTOCOL_MINIMUM_CHANNEL_COUNT;
host -> randomSeed = (enet_uint32) time(NULL) + (enet_uint32) (size_t) host;
host -> randomSeed = (host -> randomSeed << 16) | (host -> randomSeed >> 16);
host -> channelLimit = channelLimit;
host -> incomingBandwidth = incomingBandwidth; host -> incomingBandwidth = incomingBandwidth;
host -> outgoingBandwidth = outgoingBandwidth; host -> outgoingBandwidth = outgoingBandwidth;
host -> bandwidthThrottleEpoch = 0; host -> bandwidthThrottleEpoch = 0;
host -> recalculateBandwidthLimits = 0; host -> recalculateBandwidthLimits = 0;
host -> mtu = ENET_HOST_DEFAULT_MTU; host -> mtu = ENET_HOST_DEFAULT_MTU;
host -> peerCount = peerCount; host -> peerCount = peerCount;
host -> lastServicedPeer = host -> peers;
host -> commandCount = 0; host -> commandCount = 0;
host -> bufferCount = 0; host -> bufferCount = 0;
host -> checksum = NULL;
host -> receivedAddress.host = ENET_HOST_ANY; host -> receivedAddress.host = ENET_HOST_ANY;
host -> receivedAddress.port = 0; host -> receivedAddress.port = 0;
host -> receivedData = NULL;
host -> receivedDataLength = 0; host -> receivedDataLength = 0;
host -> totalSentData = 0;
host -> totalSentPackets = 0;
host -> totalReceivedData = 0;
host -> totalReceivedPackets = 0;
host -> compressor.context = NULL;
host -> compressor.compress = NULL;
host -> compressor.decompress = NULL;
host -> compressor.destroy = NULL;
enet_list_clear (& host -> dispatchQueue);
for (currentPeer = host -> peers; for (currentPeer = host -> peers;
currentPeer < & host -> peers [host -> peerCount]; currentPeer < & host -> peers [host -> peerCount];
++ currentPeer) ++ currentPeer)
{ {
currentPeer -> host = host; currentPeer -> host = host;
currentPeer -> incomingPeerID = currentPeer - host -> peers; currentPeer -> incomingPeerID = currentPeer - host -> peers;
currentPeer -> outgoingSessionID = currentPeer -> incomingSessionID = 0xFF;
currentPeer -> data = NULL; currentPeer -> data = NULL;
enet_list_clear (& currentPeer -> acknowledgements); enet_list_clear (& currentPeer -> acknowledgements);
@ -79,10 +117,11 @@ enet_host_create (const ENetAddress * address, size_t peerCount, enet_uint32 inc
enet_list_clear (& currentPeer -> sentUnreliableCommands); enet_list_clear (& currentPeer -> sentUnreliableCommands);
enet_list_clear (& currentPeer -> outgoingReliableCommands); enet_list_clear (& currentPeer -> outgoingReliableCommands);
enet_list_clear (& currentPeer -> outgoingUnreliableCommands); enet_list_clear (& currentPeer -> outgoingUnreliableCommands);
enet_list_clear (& currentPeer -> dispatchedCommands);
enet_peer_reset (currentPeer); enet_peer_reset (currentPeer);
} }
return host; return host;
} }
@ -103,6 +142,9 @@ enet_host_destroy (ENetHost * host)
enet_peer_reset (currentPeer); enet_peer_reset (currentPeer);
} }
if (host -> compressor.context != NULL && host -> compressor.destroy)
(* host -> compressor.destroy) (host -> compressor.context);
enet_free (host -> peers); enet_free (host -> peers);
enet_free (host); enet_free (host);
} }
@ -111,12 +153,13 @@ enet_host_destroy (ENetHost * host)
@param host host seeking the connection @param host host seeking the connection
@param address destination for the connection @param address destination for the connection
@param channelCount number of channels to allocate @param channelCount number of channels to allocate
@param data user data supplied to the receiving host
@returns a peer representing the foreign host on success, NULL on failure @returns a peer representing the foreign host on success, NULL on failure
@remarks The peer returned will have not completed the connection until enet_host_service() @remarks The peer returned will have not completed the connection until enet_host_service()
notifies of an ENET_EVENT_TYPE_CONNECT event for the peer. notifies of an ENET_EVENT_TYPE_CONNECT event for the peer.
*/ */
ENetPeer * ENetPeer *
enet_host_connect (ENetHost * host, const ENetAddress * address, size_t channelCount) enet_host_connect (ENetHost * host, const ENetAddress * address, size_t channelCount, enet_uint32 data)
{ {
ENetPeer * currentPeer; ENetPeer * currentPeer;
ENetChannel * channel; ENetChannel * channel;
@ -139,11 +182,13 @@ enet_host_connect (ENetHost * host, const ENetAddress * address, size_t channelC
if (currentPeer >= & host -> peers [host -> peerCount]) if (currentPeer >= & host -> peers [host -> peerCount])
return NULL; return NULL;
currentPeer -> channels = (ENetChannel *) enet_malloc (channelCount * sizeof (ENetChannel));
if (currentPeer -> channels == NULL)
return NULL;
currentPeer -> channelCount = channelCount;
currentPeer -> state = ENET_PEER_STATE_CONNECTING; currentPeer -> state = ENET_PEER_STATE_CONNECTING;
currentPeer -> address = * address; currentPeer -> address = * address;
currentPeer -> channels = (ENetChannel *) enet_malloc (channelCount * sizeof (ENetChannel)); currentPeer -> connectID = ++ host -> randomSeed;
currentPeer -> channelCount = channelCount;
currentPeer -> sessionID = (enet_uint32) enet_rand ();
if (host -> outgoingBandwidth == 0) if (host -> outgoingBandwidth == 0)
currentPeer -> windowSize = ENET_PROTOCOL_MAXIMUM_WINDOW_SIZE; currentPeer -> windowSize = ENET_PROTOCOL_MAXIMUM_WINDOW_SIZE;
@ -176,7 +221,9 @@ enet_host_connect (ENetHost * host, const ENetAddress * address, size_t channelC
command.header.command = ENET_PROTOCOL_COMMAND_CONNECT | ENET_PROTOCOL_COMMAND_FLAG_ACKNOWLEDGE; command.header.command = ENET_PROTOCOL_COMMAND_CONNECT | ENET_PROTOCOL_COMMAND_FLAG_ACKNOWLEDGE;
command.header.channelID = 0xFF; command.header.channelID = 0xFF;
command.connect.outgoingPeerID = ENET_HOST_TO_NET_16 (currentPeer -> incomingPeerID); command.connect.outgoingPeerID = ENET_HOST_TO_NET_16 (currentPeer -> incomingPeerID);
command.connect.mtu = ENET_HOST_TO_NET_16 (currentPeer -> mtu); command.connect.incomingSessionID = currentPeer -> incomingSessionID;
command.connect.outgoingSessionID = currentPeer -> outgoingSessionID;
command.connect.mtu = ENET_HOST_TO_NET_32 (currentPeer -> mtu);
command.connect.windowSize = ENET_HOST_TO_NET_32 (currentPeer -> windowSize); command.connect.windowSize = ENET_HOST_TO_NET_32 (currentPeer -> windowSize);
command.connect.channelCount = ENET_HOST_TO_NET_32 (channelCount); command.connect.channelCount = ENET_HOST_TO_NET_32 (channelCount);
command.connect.incomingBandwidth = ENET_HOST_TO_NET_32 (host -> incomingBandwidth); command.connect.incomingBandwidth = ENET_HOST_TO_NET_32 (host -> incomingBandwidth);
@ -184,8 +231,9 @@ enet_host_connect (ENetHost * host, const ENetAddress * address, size_t channelC
command.connect.packetThrottleInterval = ENET_HOST_TO_NET_32 (currentPeer -> packetThrottleInterval); command.connect.packetThrottleInterval = ENET_HOST_TO_NET_32 (currentPeer -> packetThrottleInterval);
command.connect.packetThrottleAcceleration = ENET_HOST_TO_NET_32 (currentPeer -> packetThrottleAcceleration); command.connect.packetThrottleAcceleration = ENET_HOST_TO_NET_32 (currentPeer -> packetThrottleAcceleration);
command.connect.packetThrottleDeceleration = ENET_HOST_TO_NET_32 (currentPeer -> packetThrottleDeceleration); command.connect.packetThrottleDeceleration = ENET_HOST_TO_NET_32 (currentPeer -> packetThrottleDeceleration);
command.connect.sessionID = currentPeer -> sessionID; command.connect.connectID = currentPeer -> connectID;
command.connect.data = ENET_HOST_TO_NET_32 (data);
enet_peer_queue_outgoing_command (currentPeer, & command, NULL, 0, 0); enet_peer_queue_outgoing_command (currentPeer, & command, NULL, 0, 0);
return currentPeer; return currentPeer;
@ -215,6 +263,39 @@ enet_host_broadcast (ENetHost * host, enet_uint8 channelID, ENetPacket * packet)
enet_packet_destroy (packet); enet_packet_destroy (packet);
} }
/** Sets the packet compressor the host should use to compress and decompress packets.
@param host host to enable or disable compression for
@param compressor callbacks for for the packet compressor; if NULL, then compression is disabled
*/
void
enet_host_compress (ENetHost * host, const ENetCompressor * compressor)
{
if (host -> compressor.context != NULL && host -> compressor.destroy)
(* host -> compressor.destroy) (host -> compressor.context);
if (compressor)
host -> compressor = * compressor;
else
host -> compressor.context = NULL;
}
/** Limits the maximum allowed channels of future incoming connections.
@param host host to limit
@param channelLimit the maximum number of channels allowed; if 0, then this is equivalent to ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT
*/
void
enet_host_channel_limit (ENetHost * host, size_t channelLimit)
{
if (! channelLimit || channelLimit > ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT)
channelLimit = ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT;
else
if (channelLimit < ENET_PROTOCOL_MINIMUM_CHANNEL_COUNT)
channelLimit = ENET_PROTOCOL_MINIMUM_CHANNEL_COUNT;
host -> channelLimit = channelLimit;
}
/** Adjusts the bandwidth limits of a host. /** Adjusts the bandwidth limits of a host.
@param host host to adjust @param host host to adjust
@param incomingBandwidth new incoming bandwidth @param incomingBandwidth new incoming bandwidth

View File

@ -7,11 +7,11 @@
#include <stdlib.h> #include <stdlib.h>
typedef struct typedef struct _ENetCallbacks
{ {
void * (ENET_CALLBACK * malloc) (size_t size); void * (ENET_CALLBACK * malloc) (size_t size);
void (ENET_CALLBACK * free) (void * memory); void (ENET_CALLBACK * free) (void * memory);
int (ENET_CALLBACK * rand) (void); void (ENET_CALLBACK * no_memory) (void);
} ENetCallbacks; } ENetCallbacks;
/** @defgroup callbacks ENet internal callbacks /** @defgroup callbacks ENet internal callbacks
@ -20,7 +20,6 @@ typedef struct
*/ */
extern void * enet_malloc (size_t); extern void * enet_malloc (size_t);
extern void enet_free (void *); extern void enet_free (void *);
extern int enet_rand (void);
/** @} */ /** @} */

View File

@ -23,30 +23,34 @@ extern "C"
#include "enet/list.h" #include "enet/list.h"
#include "enet/callbacks.h" #include "enet/callbacks.h"
typedef enum #define ENET_VERSION_MAJOR 1
{ #define ENET_VERSION_MINOR 3
ENET_VERSION = 1 #define ENET_VERSION_PATCH 1
} ENetVersion; #define ENET_VERSION_CREATE(major, minor, patch) (((major)<<16) | ((minor)<<8) | (patch))
#define ENET_VERSION ENET_VERSION_CREATE(ENET_VERSION_MAJOR, ENET_VERSION_MINOR, ENET_VERSION_PATCH)
typedef enum typedef enet_uint32 ENetVersion;
typedef enum _ENetSocketType
{ {
ENET_SOCKET_TYPE_STREAM = 1, ENET_SOCKET_TYPE_STREAM = 1,
ENET_SOCKET_TYPE_DATAGRAM = 2 ENET_SOCKET_TYPE_DATAGRAM = 2
} ENetSocketType; } ENetSocketType;
typedef enum typedef enum _ENetSocketWait
{ {
ENET_SOCKET_WAIT_NONE = 0, ENET_SOCKET_WAIT_NONE = 0,
ENET_SOCKET_WAIT_SEND = (1 << 0), ENET_SOCKET_WAIT_SEND = (1 << 0),
ENET_SOCKET_WAIT_RECEIVE = (1 << 1) ENET_SOCKET_WAIT_RECEIVE = (1 << 1)
} ENetSocketWait; } ENetSocketWait;
typedef enum typedef enum _ENetSocketOption
{ {
ENET_SOCKOPT_NONBLOCK = 1, ENET_SOCKOPT_NONBLOCK = 1,
ENET_SOCKOPT_BROADCAST = 2, ENET_SOCKOPT_BROADCAST = 2,
ENET_SOCKOPT_RCVBUF = 3, ENET_SOCKOPT_RCVBUF = 3,
ENET_SOCKOPT_SNDBUF = 4 ENET_SOCKOPT_SNDBUF = 4,
ENET_SOCKOPT_REUSEADDR = 5
} ENetSocketOption; } ENetSocketOption;
enum enum
@ -82,7 +86,7 @@ typedef struct _ENetAddress
@sa ENetPacket @sa ENetPacket
*/ */
typedef enum typedef enum _ENetPacketFlag
{ {
/** packet must be received by the target peer and resend attempts should be /** packet must be received by the target peer and resend attempts should be
* made until the packet is delivered */ * made until the packet is delivered */
@ -160,7 +164,7 @@ typedef struct _ENetIncomingCommand
ENetPacket * packet; ENetPacket * packet;
} ENetIncomingCommand; } ENetIncomingCommand;
typedef enum typedef enum _ENetPeerState
{ {
ENET_PEER_STATE_DISCONNECTED = 0, ENET_PEER_STATE_DISCONNECTED = 0,
ENET_PEER_STATE_CONNECTING = 1, ENET_PEER_STATE_CONNECTING = 1,
@ -225,10 +229,13 @@ typedef struct _ENetChannel
*/ */
typedef struct _ENetPeer typedef struct _ENetPeer
{ {
ENetListNode dispatchList;
struct _ENetHost * host; struct _ENetHost * host;
enet_uint16 outgoingPeerID; enet_uint16 outgoingPeerID;
enet_uint16 incomingPeerID; enet_uint16 incomingPeerID;
enet_uint32 sessionID; enet_uint32 connectID;
enet_uint8 outgoingSessionID;
enet_uint8 incomingSessionID;
ENetAddress address; /**< Internet address of the peer */ ENetAddress address; /**< Internet address of the peer */
void * data; /**< Application private data, may be freely modified */ void * data; /**< Application private data, may be freely modified */
ENetPeerState state; ENetPeerState state;
@ -262,7 +269,7 @@ typedef struct _ENetPeer
enet_uint32 highestRoundTripTimeVariance; enet_uint32 highestRoundTripTimeVariance;
enet_uint32 roundTripTime; /**< mean round trip time (RTT), in milliseconds, between sending a reliable packet and receiving its acknowledgement */ enet_uint32 roundTripTime; /**< mean round trip time (RTT), in milliseconds, between sending a reliable packet and receiving its acknowledgement */
enet_uint32 roundTripTimeVariance; enet_uint32 roundTripTimeVariance;
enet_uint16 mtu; enet_uint32 mtu;
enet_uint32 windowSize; enet_uint32 windowSize;
enet_uint32 reliableDataInTransit; enet_uint32 reliableDataInTransit;
enet_uint16 outgoingReliableSequenceNumber; enet_uint16 outgoingReliableSequenceNumber;
@ -271,15 +278,34 @@ typedef struct _ENetPeer
ENetList sentUnreliableCommands; ENetList sentUnreliableCommands;
ENetList outgoingReliableCommands; ENetList outgoingReliableCommands;
ENetList outgoingUnreliableCommands; ENetList outgoingUnreliableCommands;
ENetList dispatchedCommands;
int needsDispatch;
enet_uint16 incomingUnsequencedGroup; enet_uint16 incomingUnsequencedGroup;
enet_uint16 outgoingUnsequencedGroup; enet_uint16 outgoingUnsequencedGroup;
enet_uint32 unsequencedWindow [ENET_PEER_UNSEQUENCED_WINDOW_SIZE / 32]; enet_uint32 unsequencedWindow [ENET_PEER_UNSEQUENCED_WINDOW_SIZE / 32];
enet_uint32 disconnectData; enet_uint32 eventData;
} ENetPeer; } ENetPeer;
/** An ENet packet compressor for compressing UDP packets before socket sends or receives.
*/
typedef struct _ENetCompressor
{
/** Context data for the compressor. Must be non-NULL. */
void * context;
/** Compresses from inBuffers[0:inBufferCount-1], containing inLimit bytes, to outData, outputting at most outLimit bytes. Should return 0 on failure. */
size_t (ENET_CALLBACK * compress) (void * context, const ENetBuffer * inBuffers, size_t inBufferCount, size_t inLimit, enet_uint8 * outData, size_t outLimit);
/** Decompresses from inData, containing inLimit bytes, to outData, outputting at most outLimit bytes. Should return 0 on failure. */
size_t (ENET_CALLBACK * decompress) (void * context, const enet_uint8 * inData, size_t inLimit, enet_uint8 * outData, size_t outLimit);
/** Destroys the context when compression is disabled or the host is destroyed. May be NULL. */
void (ENET_CALLBACK * destroy) (void * context);
} ENetCompressor;
/** Callback that computes the checksum of the data held in buffers[0:bufferCount-1] */
typedef enet_uint32 (ENET_CALLBACK * ENetChecksumCallback) (const ENetBuffer * buffers, size_t bufferCount);
/** An ENet host for communicating with peers. /** An ENet host for communicating with peers.
* *
* No fields should be modified. * No fields should be modified unless otherwise stated.
@sa enet_host_create() @sa enet_host_create()
@sa enet_host_destroy() @sa enet_host_destroy()
@ -287,38 +313,50 @@ typedef struct _ENetPeer
@sa enet_host_service() @sa enet_host_service()
@sa enet_host_flush() @sa enet_host_flush()
@sa enet_host_broadcast() @sa enet_host_broadcast()
@sa enet_host_compress()
@sa enet_host_compress_with_range_coder()
@sa enet_host_channel_limit()
@sa enet_host_bandwidth_limit() @sa enet_host_bandwidth_limit()
@sa enet_host_bandwidth_throttle() @sa enet_host_bandwidth_throttle()
*/ */
typedef struct _ENetHost typedef struct _ENetHost
{ {
ENetSocket socket; ENetSocket socket;
ENetAddress address; /**< Internet address of the host */ ENetAddress address; /**< Internet address of the host */
enet_uint32 incomingBandwidth; /**< downstream bandwidth of the host */ enet_uint32 incomingBandwidth; /**< downstream bandwidth of the host */
enet_uint32 outgoingBandwidth; /**< upstream bandwidth of the host */ enet_uint32 outgoingBandwidth; /**< upstream bandwidth of the host */
enet_uint32 bandwidthThrottleEpoch; enet_uint32 bandwidthThrottleEpoch;
enet_uint32 mtu; enet_uint32 mtu;
int recalculateBandwidthLimits; enet_uint32 randomSeed;
ENetPeer * peers; /**< array of peers allocated for this host */ int recalculateBandwidthLimits;
size_t peerCount; /**< number of peers allocated for this host */ ENetPeer * peers; /**< array of peers allocated for this host */
enet_uint32 serviceTime; size_t peerCount; /**< number of peers allocated for this host */
ENetPeer * lastServicedPeer; size_t channelLimit; /**< maximum number of channels allowed for connected peers */
int continueSending; enet_uint32 serviceTime;
size_t packetSize; ENetList dispatchQueue;
enet_uint16 headerFlags; int continueSending;
ENetProtocol commands [ENET_PROTOCOL_MAXIMUM_PACKET_COMMANDS]; size_t packetSize;
size_t commandCount; enet_uint16 headerFlags;
ENetBuffer buffers [ENET_BUFFER_MAXIMUM]; ENetProtocol commands [ENET_PROTOCOL_MAXIMUM_PACKET_COMMANDS];
size_t bufferCount; size_t commandCount;
ENetAddress receivedAddress; ENetBuffer buffers [ENET_BUFFER_MAXIMUM];
enet_uint8 receivedData [ENET_PROTOCOL_MAXIMUM_MTU]; size_t bufferCount;
size_t receivedDataLength; ENetChecksumCallback checksum; /**< callback the user can set to enable packet checksums for this host */
ENetCompressor compressor;
enet_uint8 packetData [2][ENET_PROTOCOL_MAXIMUM_MTU];
ENetAddress receivedAddress;
enet_uint8 * receivedData;
size_t receivedDataLength;
enet_uint32 totalSentData; /**< total data sent, user should reset to 0 as needed to prevent overflow */
enet_uint32 totalSentPackets; /**< total UDP packets sent, user should reset to 0 as needed to prevent overflow */
enet_uint32 totalReceivedData; /**< total data received, user should reset to 0 as needed to prevent overflow */
enet_uint32 totalReceivedPackets; /**< total UDP packets received, user should reset to 0 as needed to prevent overflow */
} ENetHost; } ENetHost;
/** /**
* An ENet event type, as specified in @ref ENetEvent. * An ENet event type, as specified in @ref ENetEvent.
*/ */
typedef enum typedef enum _ENetEventType
{ {
/** no event occurred within the specified time limit */ /** no event occurred within the specified time limit */
ENET_EVENT_TYPE_NONE = 0, ENET_EVENT_TYPE_NONE = 0,
@ -372,7 +410,7 @@ typedef struct _ENetEvent
ENET_API int enet_initialize (void); ENET_API int enet_initialize (void);
/** /**
Initializes ENet globally and supplies user-overridden callbacks. Must be called prior to using any functions in ENet. Do not use enet_initialize() if you use this variant. Initializes ENet globally and supplies user-overridden callbacks. Must be called prior to using any functions in ENet. Do not use enet_initialize() if you use this variant. Make sure the ENetCallbacks structure is zeroed out so that any additional callbacks added in future versions will be properly ignored.
@param version the constant ENET_VERSION should be supplied so ENet knows which version of ENetCallbacks struct to use @param version the constant ENET_VERSION should be supplied so ENet knows which version of ENetCallbacks struct to use
@param inits user-overriden callbacks where any NULL callbacks will use ENet's defaults @param inits user-overriden callbacks where any NULL callbacks will use ENet's defaults
@ -403,7 +441,9 @@ ENET_API void enet_time_set (enet_uint32);
/** @defgroup socket ENet socket functions /** @defgroup socket ENet socket functions
@{ @{
*/ */
ENET_API ENetSocket enet_socket_create (ENetSocketType, const ENetAddress *); ENET_API ENetSocket enet_socket_create (ENetSocketType);
ENET_API int enet_socket_bind (ENetSocket, const ENetAddress *);
ENET_API int enet_socket_listen (ENetSocket, int);
ENET_API ENetSocket enet_socket_accept (ENetSocket, ENetAddress *); ENET_API ENetSocket enet_socket_accept (ENetSocket, ENetAddress *);
ENET_API int enet_socket_connect (ENetSocket, const ENetAddress *); ENET_API int enet_socket_connect (ENetSocket, const ENetAddress *);
ENET_API int enet_socket_send (ENetSocket, const ENetAddress *, const ENetBuffer *, size_t); ENET_API int enet_socket_send (ENetSocket, const ENetAddress *, const ENetBuffer *, size_t);
@ -411,6 +451,7 @@ ENET_API int enet_socket_receive (ENetSocket, ENetAddress *, ENetBuffer *
ENET_API int enet_socket_wait (ENetSocket, enet_uint32 *, enet_uint32); ENET_API int enet_socket_wait (ENetSocket, enet_uint32 *, enet_uint32);
ENET_API int enet_socket_set_option (ENetSocket, ENetSocketOption, int); ENET_API int enet_socket_set_option (ENetSocket, ENetSocketOption, int);
ENET_API void enet_socket_destroy (ENetSocket); ENET_API void enet_socket_destroy (ENetSocket);
ENET_API int enet_socketset_select (ENetSocket, ENetSocketSet *, ENetSocketSet *, enet_uint32);
/** @} */ /** @} */
@ -454,18 +495,21 @@ ENET_API void enet_packet_destroy (ENetPacket *);
ENET_API int enet_packet_resize (ENetPacket *, size_t); ENET_API int enet_packet_resize (ENetPacket *, size_t);
extern enet_uint32 enet_crc32 (const ENetBuffer *, size_t); extern enet_uint32 enet_crc32 (const ENetBuffer *, size_t);
ENET_API ENetHost * enet_host_create (const ENetAddress *, size_t, enet_uint32, enet_uint32); ENET_API ENetHost * enet_host_create (const ENetAddress *, size_t, size_t, enet_uint32, enet_uint32);
ENET_API void enet_host_destroy (ENetHost *); ENET_API void enet_host_destroy (ENetHost *);
ENET_API ENetPeer * enet_host_connect (ENetHost *, const ENetAddress *, size_t); ENET_API ENetPeer * enet_host_connect (ENetHost *, const ENetAddress *, size_t, enet_uint32);
ENET_API int enet_host_check_events (ENetHost *, ENetEvent *); ENET_API int enet_host_check_events (ENetHost *, ENetEvent *);
ENET_API int enet_host_service (ENetHost *, ENetEvent *, enet_uint32); ENET_API int enet_host_service (ENetHost *, ENetEvent *, enet_uint32);
ENET_API void enet_host_flush (ENetHost *); ENET_API void enet_host_flush (ENetHost *);
ENET_API void enet_host_broadcast (ENetHost *, enet_uint8, ENetPacket *); ENET_API void enet_host_broadcast (ENetHost *, enet_uint8, ENetPacket *);
ENET_API void enet_host_compress (ENetHost *, const ENetCompressor *);
ENET_API int enet_host_compress_with_range_coder (ENetHost * host);
ENET_API void enet_host_channel_limit (ENetHost *, size_t);
ENET_API void enet_host_bandwidth_limit (ENetHost *, enet_uint32, enet_uint32); ENET_API void enet_host_bandwidth_limit (ENetHost *, enet_uint32, enet_uint32);
extern void enet_host_bandwidth_throttle (ENetHost *); extern void enet_host_bandwidth_throttle (ENetHost *);
ENET_API int enet_peer_send (ENetPeer *, enet_uint8, ENetPacket *); ENET_API int enet_peer_send (ENetPeer *, enet_uint8, ENetPacket *);
ENET_API ENetPacket * enet_peer_receive (ENetPeer *, enet_uint8); ENET_API ENetPacket * enet_peer_receive (ENetPeer *, enet_uint8 * channelID);
ENET_API void enet_peer_ping (ENetPeer *); ENET_API void enet_peer_ping (ENetPeer *);
ENET_API void enet_peer_reset (ENetPeer *); ENET_API void enet_peer_reset (ENetPeer *);
ENET_API void enet_peer_disconnect (ENetPeer *, enet_uint32); ENET_API void enet_peer_disconnect (ENetPeer *, enet_uint32);
@ -474,10 +518,18 @@ ENET_API void enet_peer_disconnect_later (ENetPeer *, enet_uint32
ENET_API void enet_peer_throttle_configure (ENetPeer *, enet_uint32, enet_uint32, enet_uint32); ENET_API void enet_peer_throttle_configure (ENetPeer *, enet_uint32, enet_uint32, enet_uint32);
extern int enet_peer_throttle (ENetPeer *, enet_uint32); extern int enet_peer_throttle (ENetPeer *, enet_uint32);
extern void enet_peer_reset_queues (ENetPeer *); extern void enet_peer_reset_queues (ENetPeer *);
extern void enet_peer_setup_outgoing_command (ENetPeer *, ENetOutgoingCommand *);
extern ENetOutgoingCommand * enet_peer_queue_outgoing_command (ENetPeer *, const ENetProtocol *, ENetPacket *, enet_uint32, enet_uint16); extern ENetOutgoingCommand * enet_peer_queue_outgoing_command (ENetPeer *, const ENetProtocol *, ENetPacket *, enet_uint32, enet_uint16);
extern ENetIncomingCommand * enet_peer_queue_incoming_command (ENetPeer *, const ENetProtocol *, ENetPacket *, enet_uint32); extern ENetIncomingCommand * enet_peer_queue_incoming_command (ENetPeer *, const ENetProtocol *, ENetPacket *, enet_uint32);
extern ENetAcknowledgement * enet_peer_queue_acknowledgement (ENetPeer *, const ENetProtocol *, enet_uint16); extern ENetAcknowledgement * enet_peer_queue_acknowledgement (ENetPeer *, const ENetProtocol *, enet_uint16);
extern void enet_peer_dispatch_incoming_unreliable_commands (ENetPeer *, ENetChannel *);
extern void enet_peer_dispatch_incoming_reliable_commands (ENetPeer *, ENetChannel *);
ENET_API void * enet_range_coder_create (void);
ENET_API void enet_range_coder_destroy (void *);
ENET_API size_t enet_range_coder_compress (void *, const ENetBuffer *, size_t, size_t, enet_uint8 *, size_t);
ENET_API size_t enet_range_coder_decompress (void *, const enet_uint8 *, size_t, enet_uint8 *, size_t);
extern size_t enet_protocol_command_size (enet_uint8); extern size_t enet_protocol_command_size (enet_uint8);
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -24,6 +24,7 @@ extern void enet_list_clear (ENetList *);
extern ENetListIterator enet_list_insert (ENetListIterator, void *); extern ENetListIterator enet_list_insert (ENetListIterator, void *);
extern void * enet_list_remove (ENetListIterator); extern void * enet_list_remove (ENetListIterator);
extern ENetListIterator enet_list_move (ENetListIterator, void *, void *);
extern size_t enet_list_size (ENetList *); extern size_t enet_list_size (ENetList *);

View File

@ -16,10 +16,10 @@ enum
ENET_PROTOCOL_MAXIMUM_WINDOW_SIZE = 32768, ENET_PROTOCOL_MAXIMUM_WINDOW_SIZE = 32768,
ENET_PROTOCOL_MINIMUM_CHANNEL_COUNT = 1, ENET_PROTOCOL_MINIMUM_CHANNEL_COUNT = 1,
ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT = 255, ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT = 255,
ENET_PROTOCOL_MAXIMUM_PEER_ID = 0x7FFF ENET_PROTOCOL_MAXIMUM_PEER_ID = 0xFFF
}; };
typedef enum typedef enum _ENetProtocolCommand
{ {
ENET_PROTOCOL_COMMAND_NONE = 0, ENET_PROTOCOL_COMMAND_NONE = 0,
ENET_PROTOCOL_COMMAND_ACKNOWLEDGE = 1, ENET_PROTOCOL_COMMAND_ACKNOWLEDGE = 1,
@ -38,41 +38,55 @@ typedef enum
ENET_PROTOCOL_COMMAND_MASK = 0x0F ENET_PROTOCOL_COMMAND_MASK = 0x0F
} ENetProtocolCommand; } ENetProtocolCommand;
typedef enum typedef enum _ENetProtocolFlag
{ {
ENET_PROTOCOL_COMMAND_FLAG_ACKNOWLEDGE = (1 << 7), ENET_PROTOCOL_COMMAND_FLAG_ACKNOWLEDGE = (1 << 7),
ENET_PROTOCOL_COMMAND_FLAG_UNSEQUENCED = (1 << 6), ENET_PROTOCOL_COMMAND_FLAG_UNSEQUENCED = (1 << 6),
ENET_PROTOCOL_HEADER_FLAG_SENT_TIME = (1 << 15), ENET_PROTOCOL_HEADER_FLAG_COMPRESSED = (1 << 14),
ENET_PROTOCOL_HEADER_FLAG_MASK = 0x8000 ENET_PROTOCOL_HEADER_FLAG_SENT_TIME = (1 << 15),
ENET_PROTOCOL_HEADER_FLAG_MASK = ENET_PROTOCOL_HEADER_FLAG_COMPRESSED | ENET_PROTOCOL_HEADER_FLAG_SENT_TIME,
ENET_PROTOCOL_HEADER_SESSION_MASK = (3 << 12),
ENET_PROTOCOL_HEADER_SESSION_SHIFT = 12
} ENetProtocolFlag; } ENetProtocolFlag;
typedef struct #ifdef _MSC_VER_
#pragma pack(push, 1)
#define ENET_PACKED
#elif defined(__GNUC__)
#define ENET_PACKED __attribute__ ((packed))
#else
#define ENET_PACKED
#endif
typedef struct _ENetProtocolHeader
{ {
enet_uint32 checksum;
enet_uint16 peerID; enet_uint16 peerID;
enet_uint16 sentTime; enet_uint16 sentTime;
} ENetProtocolHeader; } ENET_PACKED ENetProtocolHeader;
typedef struct typedef struct _ENetProtocolCommandHeader
{ {
enet_uint8 command; enet_uint8 command;
enet_uint8 channelID; enet_uint8 channelID;
enet_uint16 reliableSequenceNumber; enet_uint16 reliableSequenceNumber;
} ENetProtocolCommandHeader; } ENET_PACKED ENetProtocolCommandHeader;
typedef struct typedef struct _ENetProtocolAcknowledge
{ {
ENetProtocolCommandHeader header; ENetProtocolCommandHeader header;
enet_uint16 receivedReliableSequenceNumber; enet_uint16 receivedReliableSequenceNumber;
enet_uint16 receivedSentTime; enet_uint16 receivedSentTime;
} ENetProtocolAcknowledge; } ENET_PACKED ENetProtocolAcknowledge;
typedef struct typedef struct _ENetProtocolConnect
{ {
ENetProtocolCommandHeader header; ENetProtocolCommandHeader header;
enet_uint16 outgoingPeerID; enet_uint16 outgoingPeerID;
enet_uint16 mtu; enet_uint8 incomingSessionID;
enet_uint8 outgoingSessionID;
enet_uint32 mtu;
enet_uint32 windowSize; enet_uint32 windowSize;
enet_uint32 channelCount; enet_uint32 channelCount;
enet_uint32 incomingBandwidth; enet_uint32 incomingBandwidth;
@ -80,14 +94,17 @@ typedef struct
enet_uint32 packetThrottleInterval; enet_uint32 packetThrottleInterval;
enet_uint32 packetThrottleAcceleration; enet_uint32 packetThrottleAcceleration;
enet_uint32 packetThrottleDeceleration; enet_uint32 packetThrottleDeceleration;
enet_uint32 sessionID; enet_uint32 connectID;
} ENetProtocolConnect; enet_uint32 data;
} ENET_PACKED ENetProtocolConnect;
typedef struct typedef struct _ENetProtocolVerifyConnect
{ {
ENetProtocolCommandHeader header; ENetProtocolCommandHeader header;
enet_uint16 outgoingPeerID; enet_uint16 outgoingPeerID;
enet_uint16 mtu; enet_uint8 incomingSessionID;
enet_uint8 outgoingSessionID;
enet_uint32 mtu;
enet_uint32 windowSize; enet_uint32 windowSize;
enet_uint32 channelCount; enet_uint32 channelCount;
enet_uint32 incomingBandwidth; enet_uint32 incomingBandwidth;
@ -95,55 +112,56 @@ typedef struct
enet_uint32 packetThrottleInterval; enet_uint32 packetThrottleInterval;
enet_uint32 packetThrottleAcceleration; enet_uint32 packetThrottleAcceleration;
enet_uint32 packetThrottleDeceleration; enet_uint32 packetThrottleDeceleration;
} ENetProtocolVerifyConnect; enet_uint32 connectID;
} ENET_PACKED ENetProtocolVerifyConnect;
typedef struct typedef struct _ENetProtocolBandwidthLimit
{ {
ENetProtocolCommandHeader header; ENetProtocolCommandHeader header;
enet_uint32 incomingBandwidth; enet_uint32 incomingBandwidth;
enet_uint32 outgoingBandwidth; enet_uint32 outgoingBandwidth;
} ENetProtocolBandwidthLimit; } ENET_PACKED ENetProtocolBandwidthLimit;
typedef struct typedef struct _ENetProtocolThrottleConfigure
{ {
ENetProtocolCommandHeader header; ENetProtocolCommandHeader header;
enet_uint32 packetThrottleInterval; enet_uint32 packetThrottleInterval;
enet_uint32 packetThrottleAcceleration; enet_uint32 packetThrottleAcceleration;
enet_uint32 packetThrottleDeceleration; enet_uint32 packetThrottleDeceleration;
} ENetProtocolThrottleConfigure; } ENET_PACKED ENetProtocolThrottleConfigure;
typedef struct typedef struct _ENetProtocolDisconnect
{ {
ENetProtocolCommandHeader header; ENetProtocolCommandHeader header;
enet_uint32 data; enet_uint32 data;
} ENetProtocolDisconnect; } ENET_PACKED ENetProtocolDisconnect;
typedef struct typedef struct _ENetProtocolPing
{ {
ENetProtocolCommandHeader header; ENetProtocolCommandHeader header;
} ENetProtocolPing; } ENET_PACKED ENetProtocolPing;
typedef struct typedef struct _ENetProtocolSendReliable
{ {
ENetProtocolCommandHeader header; ENetProtocolCommandHeader header;
enet_uint16 dataLength; enet_uint16 dataLength;
} ENetProtocolSendReliable; } ENET_PACKED ENetProtocolSendReliable;
typedef struct typedef struct _ENetProtocolSendUnreliable
{ {
ENetProtocolCommandHeader header; ENetProtocolCommandHeader header;
enet_uint16 unreliableSequenceNumber; enet_uint16 unreliableSequenceNumber;
enet_uint16 dataLength; enet_uint16 dataLength;
} ENetProtocolSendUnreliable; } ENET_PACKED ENetProtocolSendUnreliable;
typedef struct typedef struct _ENetProtocolSendUnsequenced
{ {
ENetProtocolCommandHeader header; ENetProtocolCommandHeader header;
enet_uint16 unsequencedGroup; enet_uint16 unsequencedGroup;
enet_uint16 dataLength; enet_uint16 dataLength;
} ENetProtocolSendUnsequenced; } ENET_PACKED ENetProtocolSendUnsequenced;
typedef struct typedef struct _ENetProtocolSendFragment
{ {
ENetProtocolCommandHeader header; ENetProtocolCommandHeader header;
enet_uint16 startSequenceNumber; enet_uint16 startSequenceNumber;
@ -152,9 +170,9 @@ typedef struct
enet_uint32 fragmentNumber; enet_uint32 fragmentNumber;
enet_uint32 totalLength; enet_uint32 totalLength;
enet_uint32 fragmentOffset; enet_uint32 fragmentOffset;
} ENetProtocolSendFragment; } ENET_PACKED ENetProtocolSendFragment;
typedef union typedef union _ENetProtocol
{ {
ENetProtocolCommandHeader header; ENetProtocolCommandHeader header;
ENetProtocolAcknowledge acknowledge; ENetProtocolAcknowledge acknowledge;
@ -168,7 +186,11 @@ typedef union
ENetProtocolSendFragment sendFragment; ENetProtocolSendFragment sendFragment;
ENetProtocolBandwidthLimit bandwidthLimit; ENetProtocolBandwidthLimit bandwidthLimit;
ENetProtocolThrottleConfigure throttleConfigure; ENetProtocolThrottleConfigure throttleConfigure;
} ENetProtocol; } ENET_PACKED ENetProtocol;
#ifdef _MSC_VER_
#pragma pack(pop)
#endif
#endif /* __ENET_PROTOCOL_H__ */ #endif /* __ENET_PROTOCOL_H__ */

View File

@ -6,8 +6,10 @@
#define __ENET_UNIX_H__ #define __ENET_UNIX_H__
#include <stdlib.h> #include <stdlib.h>
#include <sys/time.h>
#include <sys/types.h> #include <sys/types.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <unistd.h>
typedef int ENetSocket; typedef int ENetSocket;
@ -32,5 +34,12 @@ typedef struct
#define ENET_API extern #define ENET_API extern
typedef fd_set ENetSocketSet;
#define ENET_SOCKETSET_EMPTY(sockset) FD_ZERO (& (sockset))
#define ENET_SOCKETSET_ADD(sockset, socket) FD_SET (socket, & (sockset))
#define ENET_SOCKETSET_REMOVE(sockset, socket) FD_CLEAR (socket, & (sockset))
#define ENET_SOCKETSET_CHECK(sockset, socket) FD_ISSET (socket, & (sockset))
#endif /* __ENET_UNIX_H__ */ #endif /* __ENET_UNIX_H__ */

View File

@ -46,6 +46,13 @@ typedef struct
#define ENET_API extern #define ENET_API extern
#endif /* ENET_DLL */ #endif /* ENET_DLL */
typedef fd_set ENetSocketSet;
#define ENET_SOCKETSET_EMPTY(sockset) FD_ZERO (& (sockset))
#define ENET_SOCKETSET_ADD(sockset, socket) FD_SET (socket, & (sockset))
#define ENET_SOCKETSET_REMOVE(sockset, socket) FD_CLEAR (socket, & (sockset))
#define ENET_SOCKETSET_CHECK(sockset, socket) FD_ISSET (socket, & (sockset))
#endif /* __ENET_WIN32_H__ */ #endif /* __ENET_WIN32_H__ */

View File

@ -1,7 +1,7 @@
#!/bin/sh #!/bin/sh
# install - install a program, script, or datafile # install - install a program, script, or datafile
scriptversion=2005-05-14.22 scriptversion=2009-04-28.21; # UTC
# This originates from X11R5 (mit/util/scripts/install.sh), which was # This originates from X11R5 (mit/util/scripts/install.sh), which was
# later released in X11R6 (xc/config/util/install.sh) with the # later released in X11R6 (xc/config/util/install.sh) with the
@ -39,38 +39,68 @@ scriptversion=2005-05-14.22
# when there is no Makefile. # when there is no Makefile.
# #
# This script is compatible with the BSD install script, but was written # This script is compatible with the BSD install script, but was written
# from scratch. It can only install one file at a time, a restriction # from scratch.
# shared with many OS's install programs.
nl='
'
IFS=" "" $nl"
# set DOITPROG to echo to test this script # set DOITPROG to echo to test this script
# Don't use :- since 4.3BSD and earlier shells don't like it. # Don't use :- since 4.3BSD and earlier shells don't like it.
doit="${DOITPROG-}" doit=${DOITPROG-}
if test -z "$doit"; then
doit_exec=exec
else
doit_exec=$doit
fi
# put in absolute paths if you don't have them in your path; or use env. vars. # Put in absolute file names if you don't have them in your path;
# or use environment vars.
mvprog="${MVPROG-mv}" chgrpprog=${CHGRPPROG-chgrp}
cpprog="${CPPROG-cp}" chmodprog=${CHMODPROG-chmod}
chmodprog="${CHMODPROG-chmod}" chownprog=${CHOWNPROG-chown}
chownprog="${CHOWNPROG-chown}" cmpprog=${CMPPROG-cmp}
chgrpprog="${CHGRPPROG-chgrp}" cpprog=${CPPROG-cp}
stripprog="${STRIPPROG-strip}" mkdirprog=${MKDIRPROG-mkdir}
rmprog="${RMPROG-rm}" mvprog=${MVPROG-mv}
mkdirprog="${MKDIRPROG-mkdir}" rmprog=${RMPROG-rm}
stripprog=${STRIPPROG-strip}
posix_glob='?'
initialize_posix_glob='
test "$posix_glob" != "?" || {
if (set -f) 2>/dev/null; then
posix_glob=
else
posix_glob=:
fi
}
'
posix_mkdir=
# Desired mode of installed file.
mode=0755
chmodcmd="$chmodprog 0755"
chowncmd=
chgrpcmd= chgrpcmd=
stripcmd= chmodcmd=$chmodprog
chowncmd=
mvcmd=$mvprog
rmcmd="$rmprog -f" rmcmd="$rmprog -f"
mvcmd="$mvprog" stripcmd=
src= src=
dst= dst=
dir_arg= dir_arg=
dstarg= dst_arg=
copy_on_change=false
no_target_directory= no_target_directory=
usage="Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE usage="\
Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE
or: $0 [OPTION]... SRCFILES... DIRECTORY or: $0 [OPTION]... SRCFILES... DIRECTORY
or: $0 [OPTION]... -t DIRECTORY SRCFILES... or: $0 [OPTION]... -t DIRECTORY SRCFILES...
or: $0 [OPTION]... -d DIRECTORIES... or: $0 [OPTION]... -d DIRECTORIES...
@ -80,81 +110,86 @@ In the 2nd and 3rd, copy all SRCFILES to DIRECTORY.
In the 4th, create DIRECTORIES. In the 4th, create DIRECTORIES.
Options: Options:
-c (ignored) --help display this help and exit.
-d create directories instead of installing files. --version display version info and exit.
-g GROUP $chgrpprog installed files to GROUP.
-m MODE $chmodprog installed files to MODE. -c (ignored)
-o USER $chownprog installed files to USER. -C install only if different (preserve the last data modification time)
-s $stripprog installed files. -d create directories instead of installing files.
-t DIRECTORY install into DIRECTORY. -g GROUP $chgrpprog installed files to GROUP.
-T report an error if DSTFILE is a directory. -m MODE $chmodprog installed files to MODE.
--help display this help and exit. -o USER $chownprog installed files to USER.
--version display version info and exit. -s $stripprog installed files.
-t DIRECTORY install into DIRECTORY.
-T report an error if DSTFILE is a directory.
Environment variables override the default commands: Environment variables override the default commands:
CHGRPPROG CHMODPROG CHOWNPROG CPPROG MKDIRPROG MVPROG RMPROG STRIPPROG CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG
RMPROG STRIPPROG
" "
while test -n "$1"; do while test $# -ne 0; do
case $1 in case $1 in
-c) shift -c) ;;
continue;;
-d) dir_arg=true -C) copy_on_change=true;;
shift
continue;; -d) dir_arg=true;;
-g) chgrpcmd="$chgrpprog $2" -g) chgrpcmd="$chgrpprog $2"
shift shift;;
shift
continue;;
--help) echo "$usage"; exit $?;; --help) echo "$usage"; exit $?;;
-m) chmodcmd="$chmodprog $2" -m) mode=$2
shift case $mode in
shift *' '* | *' '* | *'
continue;; '* | *'*'* | *'?'* | *'['*)
echo "$0: invalid mode: $mode" >&2
exit 1;;
esac
shift;;
-o) chowncmd="$chownprog $2" -o) chowncmd="$chownprog $2"
shift shift;;
shift
continue;;
-s) stripcmd=$stripprog -s) stripcmd=$stripprog;;
shift
continue;;
-t) dstarg=$2 -t) dst_arg=$2
shift shift;;
shift
continue;;
-T) no_target_directory=true -T) no_target_directory=true;;
shift
continue;;
--version) echo "$0 $scriptversion"; exit $?;; --version) echo "$0 $scriptversion"; exit $?;;
*) # When -d is used, all remaining arguments are directories to create. --) shift
# When -t is used, the destination is already specified.
test -n "$dir_arg$dstarg" && break
# Otherwise, the last argument is the destination. Remove it from $@.
for arg
do
if test -n "$dstarg"; then
# $@ is not empty: it contains at least $arg.
set fnord "$@" "$dstarg"
shift # fnord
fi
shift # arg
dstarg=$arg
done
break;; break;;
-*) echo "$0: invalid option: $1" >&2
exit 1;;
*) break;;
esac esac
shift
done done
if test -z "$1"; then if test $# -ne 0 && test -z "$dir_arg$dst_arg"; then
# When -d is used, all remaining arguments are directories to create.
# When -t is used, the destination is already specified.
# Otherwise, the last argument is the destination. Remove it from $@.
for arg
do
if test -n "$dst_arg"; then
# $@ is not empty: it contains at least $arg.
set fnord "$@" "$dst_arg"
shift # fnord
fi
shift # arg
dst_arg=$arg
done
fi
if test $# -eq 0; then
if test -z "$dir_arg"; then if test -z "$dir_arg"; then
echo "$0: no input file specified." >&2 echo "$0: no input file specified." >&2
exit 1 exit 1
@ -164,24 +199,47 @@ if test -z "$1"; then
exit 0 exit 0
fi fi
if test -z "$dir_arg"; then
trap '(exit $?); exit' 1 2 13 15
# Set umask so as not to create temps with too-generous modes.
# However, 'strip' requires both read and write access to temps.
case $mode in
# Optimize common cases.
*644) cp_umask=133;;
*755) cp_umask=22;;
*[0-7])
if test -z "$stripcmd"; then
u_plus_rw=
else
u_plus_rw='% 200'
fi
cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;;
*)
if test -z "$stripcmd"; then
u_plus_rw=
else
u_plus_rw=,u+rw
fi
cp_umask=$mode$u_plus_rw;;
esac
fi
for src for src
do do
# Protect names starting with `-'. # Protect names starting with `-'.
case $src in case $src in
-*) src=./$src ;; -*) src=./$src;;
esac esac
if test -n "$dir_arg"; then if test -n "$dir_arg"; then
dst=$src dst=$src
src= dstdir=$dst
test -d "$dstdir"
if test -d "$dst"; then dstdir_status=$?
mkdircmd=:
chmodcmd=
else
mkdircmd=$mkdirprog
fi
else else
# Waiting for this to be detected by the "$cpprog $src $dsttmp" command # Waiting for this to be detected by the "$cpprog $src $dsttmp" command
# might cause directories to be created, which would be especially bad # might cause directories to be created, which would be especially bad
# if $src (and thus $dsttmp) contains '*'. # if $src (and thus $dsttmp) contains '*'.
@ -190,71 +248,199 @@ do
exit 1 exit 1
fi fi
if test -z "$dstarg"; then if test -z "$dst_arg"; then
echo "$0: no destination specified." >&2 echo "$0: no destination specified." >&2
exit 1 exit 1
fi fi
dst=$dstarg dst=$dst_arg
# Protect names starting with `-'. # Protect names starting with `-'.
case $dst in case $dst in
-*) dst=./$dst ;; -*) dst=./$dst;;
esac esac
# If destination is a directory, append the input filename; won't work # If destination is a directory, append the input filename; won't work
# if double slashes aren't ignored. # if double slashes aren't ignored.
if test -d "$dst"; then if test -d "$dst"; then
if test -n "$no_target_directory"; then if test -n "$no_target_directory"; then
echo "$0: $dstarg: Is a directory" >&2 echo "$0: $dst_arg: Is a directory" >&2
exit 1 exit 1
fi fi
dst=$dst/`basename "$src"` dstdir=$dst
dst=$dstdir/`basename "$src"`
dstdir_status=0
else
# Prefer dirname, but fall back on a substitute if dirname fails.
dstdir=`
(dirname "$dst") 2>/dev/null ||
expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
X"$dst" : 'X\(//\)[^/]' \| \
X"$dst" : 'X\(//\)$' \| \
X"$dst" : 'X\(/\)' \| . 2>/dev/null ||
echo X"$dst" |
sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
s//\1/
q
}
/^X\(\/\/\)[^/].*/{
s//\1/
q
}
/^X\(\/\/\)$/{
s//\1/
q
}
/^X\(\/\).*/{
s//\1/
q
}
s/.*/./; q'
`
test -d "$dstdir"
dstdir_status=$?
fi fi
fi fi
# This sed command emulates the dirname command. obsolete_mkdir_used=false
dstdir=`echo "$dst" | sed -e 's,/*$,,;s,[^/]*$,,;s,/*$,,;s,^$,.,'`
# Make sure that the destination directory exists. if test $dstdir_status != 0; then
case $posix_mkdir in
'')
# Create intermediate dirs using mode 755 as modified by the umask.
# This is like FreeBSD 'install' as of 1997-10-28.
umask=`umask`
case $stripcmd.$umask in
# Optimize common cases.
*[2367][2367]) mkdir_umask=$umask;;
.*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;;
# Skip lots of stat calls in the usual case. *[0-7])
if test ! -d "$dstdir"; then mkdir_umask=`expr $umask + 22 \
defaultIFS=' - $umask % 100 % 40 + $umask % 20 \
' - $umask % 10 % 4 + $umask % 2
IFS="${IFS-$defaultIFS}" `;;
*) mkdir_umask=$umask,go-w;;
esac
oIFS=$IFS # With -d, create the new directory with the user-specified mode.
# Some sh's can't handle IFS=/ for some reason. # Otherwise, rely on $mkdir_umask.
IFS='%' if test -n "$dir_arg"; then
set x `echo "$dstdir" | sed -e 's@/@%@g' -e 's@^%@/@'` mkdir_mode=-m$mode
shift else
IFS=$oIFS mkdir_mode=
fi
pathcomp= posix_mkdir=false
case $umask in
*[123567][0-7][0-7])
# POSIX mkdir -p sets u+wx bits regardless of umask, which
# is incompatible with FreeBSD 'install' when (umask & 300) != 0.
;;
*)
tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$
trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0
while test $# -ne 0 ; do if (umask $mkdir_umask &&
pathcomp=$pathcomp$1 exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1
then
if test -z "$dir_arg" || {
# Check for POSIX incompatibilities with -m.
# HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or
# other-writeable bit of parent directory when it shouldn't.
# FreeBSD 6.1 mkdir -m -p sets mode of existing directory.
ls_ld_tmpdir=`ls -ld "$tmpdir"`
case $ls_ld_tmpdir in
d????-?r-*) different_mode=700;;
d????-?--*) different_mode=755;;
*) false;;
esac &&
$mkdirprog -m$different_mode -p -- "$tmpdir" && {
ls_ld_tmpdir_1=`ls -ld "$tmpdir"`
test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1"
}
}
then posix_mkdir=:
fi
rmdir "$tmpdir/d" "$tmpdir"
else
# Remove any dirs left behind by ancient mkdir implementations.
rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null
fi
trap '' 0;;
esac;;
esac
if
$posix_mkdir && (
umask $mkdir_umask &&
$doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir"
)
then :
else
# The umask is ridiculous, or mkdir does not conform to POSIX,
# or it failed possibly due to a race condition. Create the
# directory the slow way, step by step, checking for races as we go.
case $dstdir in
/*) prefix='/';;
-*) prefix='./';;
*) prefix='';;
esac
eval "$initialize_posix_glob"
oIFS=$IFS
IFS=/
$posix_glob set -f
set fnord $dstdir
shift shift
if test ! -d "$pathcomp"; then $posix_glob set +f
$mkdirprog "$pathcomp" IFS=$oIFS
# mkdir can fail with a `File exist' error in case several
# install-sh are creating the directory concurrently. This prefixes=
# is OK.
test -d "$pathcomp" || exit for d
do
test -z "$d" && continue
prefix=$prefix$d
if test -d "$prefix"; then
prefixes=
else
if $posix_mkdir; then
(umask=$mkdir_umask &&
$doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break
# Don't fail if two instances are running concurrently.
test -d "$prefix" || exit 1
else
case $prefix in
*\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;;
*) qprefix=$prefix;;
esac
prefixes="$prefixes '$qprefix'"
fi
fi
prefix=$prefix/
done
if test -n "$prefixes"; then
# Don't fail if two instances are running concurrently.
(umask $mkdir_umask &&
eval "\$doit_exec \$mkdirprog $prefixes") ||
test -d "$dstdir" || exit 1
obsolete_mkdir_used=true
fi fi
pathcomp=$pathcomp/ fi
done
fi fi
if test -n "$dir_arg"; then if test -n "$dir_arg"; then
$doit $mkdircmd "$dst" \ { test -z "$chowncmd" || $doit $chowncmd "$dst"; } &&
&& { test -z "$chowncmd" || $doit $chowncmd "$dst"; } \ { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } &&
&& { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } \ { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false ||
&& { test -z "$stripcmd" || $doit $stripcmd "$dst"; } \ test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1
&& { test -z "$chmodcmd" || $doit $chmodcmd "$dst"; }
else else
dstfile=`basename "$dst"`
# Make a couple of temp file names in the proper directory. # Make a couple of temp file names in the proper directory.
dsttmp=$dstdir/_inst.$$_ dsttmp=$dstdir/_inst.$$_
@ -262,10 +448,9 @@ do
# Trap to clean up those temp files at exit. # Trap to clean up those temp files at exit.
trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0
trap '(exit $?); exit' 1 2 13 15
# Copy the file name to the temp name. # Copy the file name to the temp name.
$doit $cpprog "$src" "$dsttmp" && (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") &&
# and set any options; do chmod last to preserve setuid bits. # and set any options; do chmod last to preserve setuid bits.
# #
@ -273,51 +458,63 @@ do
# ignore errors from any of these, just make sure not to ignore # ignore errors from any of these, just make sure not to ignore
# errors from the above "$doit $cpprog $src $dsttmp" command. # errors from the above "$doit $cpprog $src $dsttmp" command.
# #
{ test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } \ { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } &&
&& { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } \ { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } &&
&& { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } \ { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } &&
&& { test -z "$chmodcmd" || $doit $chmodcmd "$dsttmp"; } && { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } &&
# Now rename the file to the real destination. # If -C, don't bother to copy if it wouldn't change the file.
{ $doit $mvcmd -f "$dsttmp" "$dstdir/$dstfile" 2>/dev/null \ if $copy_on_change &&
|| { old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` &&
# The rename failed, perhaps because mv can't rename something else new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` &&
# to itself, or perhaps because mv is so ancient that it does not
# support -f.
# Now remove or move aside any old file at destination location. eval "$initialize_posix_glob" &&
# We try this two ways since rm can't unlink itself on some $posix_glob set -f &&
# systems and the destination file might be busy for other set X $old && old=:$2:$4:$5:$6 &&
# reasons. In this case, the final cleanup might fail but the new set X $new && new=:$2:$4:$5:$6 &&
# file should still install successfully. $posix_glob set +f &&
{
if test -f "$dstdir/$dstfile"; then
$doit $rmcmd -f "$dstdir/$dstfile" 2>/dev/null \
|| $doit $mvcmd -f "$dstdir/$dstfile" "$rmtmp" 2>/dev/null \
|| {
echo "$0: cannot unlink or rename $dstdir/$dstfile" >&2
(exit 1); exit 1
}
else
:
fi
} &&
# Now rename the file to the real destination. test "$old" = "$new" &&
$doit $mvcmd "$dsttmp" "$dstdir/$dstfile" $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1
} then
} rm -f "$dsttmp"
fi || { (exit 1); exit 1; } else
# Rename the file to the real destination.
$doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null ||
# The rename failed, perhaps because mv can't rename something else
# to itself, or perhaps because mv is so ancient that it does not
# support -f.
{
# Now remove or move aside any old file at destination location.
# We try this two ways since rm can't unlink itself on some
# systems and the destination file might be busy for other
# reasons. In this case, the final cleanup might fail but the new
# file should still install successfully.
{
test ! -f "$dst" ||
$doit $rmcmd -f "$dst" 2>/dev/null ||
{ $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null &&
{ $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; }
} ||
{ echo "$0: cannot unlink or rename $dst" >&2
(exit 1); exit 1
}
} &&
# Now rename the file to the real destination.
$doit $mvcmd "$dsttmp" "$dst"
}
fi || exit 1
trap '' 0
fi
done done
# The final little trick to "correctly" pass the exit status to the exit trap.
{
(exit 0); exit 0
}
# Local variables: # Local variables:
# eval: (add-hook 'write-file-hooks 'time-stamp) # eval: (add-hook 'write-file-hooks 'time-stamp)
# time-stamp-start: "scriptversion=" # time-stamp-start: "scriptversion="
# time-stamp-format: "%:y-%02m-%02d.%02H" # time-stamp-format: "%:y-%02m-%02d.%02H"
# time-stamp-end: "$" # time-stamp-time-zone: "UTC"
# time-stamp-end: "; # UTC"
# End: # End:

View File

@ -3,7 +3,7 @@
@brief ENet linked list functions @brief ENet linked list functions
*/ */
#define ENET_BUILDING_LIB 1 #define ENET_BUILDING_LIB 1
#include "enet/list.h" #include "enet/enet.h"
/** /**
@defgroup list ENet linked list utility functions @defgroup list ENet linked list utility functions
@ -40,6 +40,24 @@ enet_list_remove (ENetListIterator position)
return position; return position;
} }
ENetListIterator
enet_list_move (ENetListIterator position, void * dataFirst, void * dataLast)
{
ENetListIterator first = (ENetListIterator) dataFirst,
last = (ENetListIterator) dataLast;
first -> previous -> next = last -> next;
last -> next -> previous = first -> previous;
first -> previous = position -> previous;
last -> next = position;
first -> previous -> next = first;
position -> previous = last;
return first;
}
size_t size_t
enet_list_size (ENetList * list) enet_list_size (ENetList * list)
{ {

View File

@ -1,10 +1,10 @@
#! /bin/sh #! /bin/sh
# Common stub for a few missing GNU programs while installing. # Common stub for a few missing GNU programs while installing.
scriptversion=2005-06-08.21 scriptversion=2009-04-28.21; # UTC
# Copyright (C) 1996, 1997, 1999, 2000, 2002, 2003, 2004, 2005 # Copyright (C) 1996, 1997, 1999, 2000, 2002, 2003, 2004, 2005, 2006,
# Free Software Foundation, Inc. # 2008, 2009 Free Software Foundation, Inc.
# Originally by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996. # Originally by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
@ -18,9 +18,7 @@ scriptversion=2005-06-08.21
# GNU General Public License for more details. # GNU General Public License for more details.
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software # along with this program. If not, see <http://www.gnu.org/licenses/>.
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
# As a special exception to the GNU General Public License, if you # As a special exception to the GNU General Public License, if you
# distribute this file as part of a program that contains a # distribute this file as part of a program that contains a
@ -33,6 +31,8 @@ if test $# -eq 0; then
fi fi
run=: run=:
sed_output='s/.* --output[ =]\([^ ]*\).*/\1/p'
sed_minuso='s/.* -o \([^ ]*\).*/\1/p'
# In the cases where this matters, `missing' is being run in the # In the cases where this matters, `missing' is being run in the
# srcdir already. # srcdir already.
@ -44,7 +44,7 @@ fi
msg="missing on your system" msg="missing on your system"
case "$1" in case $1 in
--run) --run)
# Try to run requested program, and just exit if it succeeds. # Try to run requested program, and just exit if it succeeds.
run= run=
@ -77,6 +77,7 @@ Supported PROGRAM values:
aclocal touch file \`aclocal.m4' aclocal touch file \`aclocal.m4'
autoconf touch file \`configure' autoconf touch file \`configure'
autoheader touch file \`config.h.in' autoheader touch file \`config.h.in'
autom4te touch the output file, or create a stub one
automake touch all \`Makefile.in' files automake touch all \`Makefile.in' files
bison create \`y.tab.[ch]', if possible, from existing .[ch] bison create \`y.tab.[ch]', if possible, from existing .[ch]
flex create \`lex.yy.c', if possible, from existing .c flex create \`lex.yy.c', if possible, from existing .c
@ -86,6 +87,9 @@ Supported PROGRAM values:
tar try tar, gnutar, gtar, then tar without non-portable flags tar try tar, gnutar, gtar, then tar without non-portable flags
yacc create \`y.tab.[ch]', if possible, from existing .[ch] yacc create \`y.tab.[ch]', if possible, from existing .[ch]
Version suffixes to PROGRAM as well as the prefixes \`gnu-', \`gnu', and
\`g' are ignored when checking the name.
Send bug reports to <bug-automake@gnu.org>." Send bug reports to <bug-automake@gnu.org>."
exit $? exit $?
;; ;;
@ -103,15 +107,22 @@ Send bug reports to <bug-automake@gnu.org>."
esac esac
# normalize program name to check for.
program=`echo "$1" | sed '
s/^gnu-//; t
s/^gnu//; t
s/^g//; t'`
# Now exit if we have it, but it failed. Also exit now if we # Now exit if we have it, but it failed. Also exit now if we
# don't have it and --version was passed (most likely to detect # don't have it and --version was passed (most likely to detect
# the program). # the program). This is about non-GNU programs, so use $1 not
case "$1" in # $program.
lex|yacc) case $1 in
lex*|yacc*)
# Not GNU programs, they don't have --version. # Not GNU programs, they don't have --version.
;; ;;
tar) tar*)
if test -n "$run"; then if test -n "$run"; then
echo 1>&2 "ERROR: \`tar' requires --run" echo 1>&2 "ERROR: \`tar' requires --run"
exit 1 exit 1
@ -135,7 +146,7 @@ esac
# If it does not exist, or fails to run (possibly an outdated version), # If it does not exist, or fails to run (possibly an outdated version),
# try to emulate it. # try to emulate it.
case "$1" in case $program in
aclocal*) aclocal*)
echo 1>&2 "\ echo 1>&2 "\
WARNING: \`$1' is $msg. You should only need it if WARNING: \`$1' is $msg. You should only need it if
@ -145,7 +156,7 @@ WARNING: \`$1' is $msg. You should only need it if
touch aclocal.m4 touch aclocal.m4
;; ;;
autoconf) autoconf*)
echo 1>&2 "\ echo 1>&2 "\
WARNING: \`$1' is $msg. You should only need it if WARNING: \`$1' is $msg. You should only need it if
you modified \`${configure_ac}'. You might want to install the you modified \`${configure_ac}'. You might want to install the
@ -154,7 +165,7 @@ WARNING: \`$1' is $msg. You should only need it if
touch configure touch configure
;; ;;
autoheader) autoheader*)
echo 1>&2 "\ echo 1>&2 "\
WARNING: \`$1' is $msg. You should only need it if WARNING: \`$1' is $msg. You should only need it if
you modified \`acconfig.h' or \`${configure_ac}'. You might want you modified \`acconfig.h' or \`${configure_ac}'. You might want
@ -164,7 +175,7 @@ WARNING: \`$1' is $msg. You should only need it if
test -z "$files" && files="config.h" test -z "$files" && files="config.h"
touch_files= touch_files=
for f in $files; do for f in $files; do
case "$f" in case $f in
*:*) touch_files="$touch_files "`echo "$f" | *:*) touch_files="$touch_files "`echo "$f" |
sed -e 's/^[^:]*://' -e 's/:.*//'`;; sed -e 's/^[^:]*://' -e 's/:.*//'`;;
*) touch_files="$touch_files $f.in";; *) touch_files="$touch_files $f.in";;
@ -184,7 +195,7 @@ WARNING: \`$1' is $msg. You should only need it if
while read f; do touch "$f"; done while read f; do touch "$f"; done
;; ;;
autom4te) autom4te*)
echo 1>&2 "\ echo 1>&2 "\
WARNING: \`$1' is needed, but is $msg. WARNING: \`$1' is needed, but is $msg.
You might have modified some files without having the You might have modified some files without having the
@ -192,8 +203,8 @@ WARNING: \`$1' is needed, but is $msg.
You can get \`$1' as part of \`Autoconf' from any GNU You can get \`$1' as part of \`Autoconf' from any GNU
archive site." archive site."
file=`echo "$*" | sed -n 's/.*--output[ =]*\([^ ]*\).*/\1/p'` file=`echo "$*" | sed -n "$sed_output"`
test -z "$file" && file=`echo "$*" | sed -n 's/.*-o[ ]*\([^ ]*\).*/\1/p'` test -z "$file" && file=`echo "$*" | sed -n "$sed_minuso"`
if test -f "$file"; then if test -f "$file"; then
touch $file touch $file
else else
@ -207,80 +218,78 @@ WARNING: \`$1' is needed, but is $msg.
fi fi
;; ;;
bison|yacc) bison*|yacc*)
echo 1>&2 "\ echo 1>&2 "\
WARNING: \`$1' $msg. You should only need it if WARNING: \`$1' $msg. You should only need it if
you modified a \`.y' file. You may need the \`Bison' package you modified a \`.y' file. You may need the \`Bison' package
in order for those modifications to take effect. You can get in order for those modifications to take effect. You can get
\`Bison' from any GNU archive site." \`Bison' from any GNU archive site."
rm -f y.tab.c y.tab.h rm -f y.tab.c y.tab.h
if [ $# -ne 1 ]; then if test $# -ne 1; then
eval LASTARG="\${$#}" eval LASTARG="\${$#}"
case "$LASTARG" in case $LASTARG in
*.y) *.y)
SRCFILE=`echo "$LASTARG" | sed 's/y$/c/'` SRCFILE=`echo "$LASTARG" | sed 's/y$/c/'`
if [ -f "$SRCFILE" ]; then if test -f "$SRCFILE"; then
cp "$SRCFILE" y.tab.c cp "$SRCFILE" y.tab.c
fi fi
SRCFILE=`echo "$LASTARG" | sed 's/y$/h/'` SRCFILE=`echo "$LASTARG" | sed 's/y$/h/'`
if [ -f "$SRCFILE" ]; then if test -f "$SRCFILE"; then
cp "$SRCFILE" y.tab.h cp "$SRCFILE" y.tab.h
fi fi
;; ;;
esac esac
fi fi
if [ ! -f y.tab.h ]; then if test ! -f y.tab.h; then
echo >y.tab.h echo >y.tab.h
fi fi
if [ ! -f y.tab.c ]; then if test ! -f y.tab.c; then
echo 'main() { return 0; }' >y.tab.c echo 'main() { return 0; }' >y.tab.c
fi fi
;; ;;
lex|flex) lex*|flex*)
echo 1>&2 "\ echo 1>&2 "\
WARNING: \`$1' is $msg. You should only need it if WARNING: \`$1' is $msg. You should only need it if
you modified a \`.l' file. You may need the \`Flex' package you modified a \`.l' file. You may need the \`Flex' package
in order for those modifications to take effect. You can get in order for those modifications to take effect. You can get
\`Flex' from any GNU archive site." \`Flex' from any GNU archive site."
rm -f lex.yy.c rm -f lex.yy.c
if [ $# -ne 1 ]; then if test $# -ne 1; then
eval LASTARG="\${$#}" eval LASTARG="\${$#}"
case "$LASTARG" in case $LASTARG in
*.l) *.l)
SRCFILE=`echo "$LASTARG" | sed 's/l$/c/'` SRCFILE=`echo "$LASTARG" | sed 's/l$/c/'`
if [ -f "$SRCFILE" ]; then if test -f "$SRCFILE"; then
cp "$SRCFILE" lex.yy.c cp "$SRCFILE" lex.yy.c
fi fi
;; ;;
esac esac
fi fi
if [ ! -f lex.yy.c ]; then if test ! -f lex.yy.c; then
echo 'main() { return 0; }' >lex.yy.c echo 'main() { return 0; }' >lex.yy.c
fi fi
;; ;;
help2man) help2man*)
echo 1>&2 "\ echo 1>&2 "\
WARNING: \`$1' is $msg. You should only need it if WARNING: \`$1' is $msg. You should only need it if
you modified a dependency of a manual page. You may need the you modified a dependency of a manual page. You may need the
\`Help2man' package in order for those modifications to take \`Help2man' package in order for those modifications to take
effect. You can get \`Help2man' from any GNU archive site." effect. You can get \`Help2man' from any GNU archive site."
file=`echo "$*" | sed -n 's/.*-o \([^ ]*\).*/\1/p'` file=`echo "$*" | sed -n "$sed_output"`
if test -z "$file"; then test -z "$file" && file=`echo "$*" | sed -n "$sed_minuso"`
file=`echo "$*" | sed -n 's/.*--output=\([^ ]*\).*/\1/p'` if test -f "$file"; then
fi
if [ -f "$file" ]; then
touch $file touch $file
else else
test -z "$file" || exec >$file test -z "$file" || exec >$file
echo ".ab help2man is required to generate this page" echo ".ab help2man is required to generate this page"
exit 1 exit $?
fi fi
;; ;;
makeinfo) makeinfo*)
echo 1>&2 "\ echo 1>&2 "\
WARNING: \`$1' is $msg. You should only need it if WARNING: \`$1' is $msg. You should only need it if
you modified a \`.texi' or \`.texinfo' file, or any other file you modified a \`.texi' or \`.texinfo' file, or any other file
@ -289,11 +298,17 @@ WARNING: \`$1' is $msg. You should only need it if
DU, IRIX). You might want to install the \`Texinfo' package or DU, IRIX). You might want to install the \`Texinfo' package or
the \`GNU make' package. Grab either from any GNU archive site." the \`GNU make' package. Grab either from any GNU archive site."
# The file to touch is that specified with -o ... # The file to touch is that specified with -o ...
file=`echo "$*" | sed -n 's/.*-o \([^ ]*\).*/\1/p'` file=`echo "$*" | sed -n "$sed_output"`
test -z "$file" && file=`echo "$*" | sed -n "$sed_minuso"`
if test -z "$file"; then if test -z "$file"; then
# ... or it is the one specified with @setfilename ... # ... or it is the one specified with @setfilename ...
infile=`echo "$*" | sed 's/.* \([^ ]*\) *$/\1/'` infile=`echo "$*" | sed 's/.* \([^ ]*\) *$/\1/'`
file=`sed -n '/^@setfilename/ { s/.* \([^ ]*\) *$/\1/; p; q; }' $infile` file=`sed -n '
/^@setfilename/{
s/.* \([^ ]*\) *$/\1/
p
q
}' $infile`
# ... or it is derived from the source name (dir/f.texi becomes f.info) # ... or it is derived from the source name (dir/f.texi becomes f.info)
test -z "$file" && file=`echo "$infile" | sed 's,.*/,,;s,.[^.]*$,,'`.info test -z "$file" && file=`echo "$infile" | sed 's,.*/,,;s,.[^.]*$,,'`.info
fi fi
@ -303,7 +318,7 @@ WARNING: \`$1' is $msg. You should only need it if
touch $file touch $file
;; ;;
tar) tar*)
shift shift
# We have already tried tar in the generic part. # We have already tried tar in the generic part.
@ -317,13 +332,13 @@ WARNING: \`$1' is $msg. You should only need it if
fi fi
firstarg="$1" firstarg="$1"
if shift; then if shift; then
case "$firstarg" in case $firstarg in
*o*) *o*)
firstarg=`echo "$firstarg" | sed s/o//` firstarg=`echo "$firstarg" | sed s/o//`
tar "$firstarg" "$@" && exit 0 tar "$firstarg" "$@" && exit 0
;; ;;
esac esac
case "$firstarg" in case $firstarg in
*h*) *h*)
firstarg=`echo "$firstarg" | sed s/h//` firstarg=`echo "$firstarg" | sed s/h//`
tar "$firstarg" "$@" && exit 0 tar "$firstarg" "$@" && exit 0
@ -356,5 +371,6 @@ exit 0
# eval: (add-hook 'write-file-hooks 'time-stamp) # eval: (add-hook 'write-file-hooks 'time-stamp)
# time-stamp-start: "scriptversion=" # time-stamp-start: "scriptversion="
# time-stamp-format: "%:y-%02m-%02d.%02H" # time-stamp-format: "%:y-%02m-%02d.%02H"
# time-stamp-end: "$" # time-stamp-time-zone: "UTC"
# time-stamp-end: "; # UTC"
# End: # End:

View File

@ -20,6 +20,8 @@ ENetPacket *
enet_packet_create (const void * data, size_t dataLength, enet_uint32 flags) enet_packet_create (const void * data, size_t dataLength, enet_uint32 flags)
{ {
ENetPacket * packet = (ENetPacket *) enet_malloc (sizeof (ENetPacket)); ENetPacket * packet = (ENetPacket *) enet_malloc (sizeof (ENetPacket));
if (packet == NULL)
return NULL;
if (flags & ENET_PACKET_FLAG_NO_ALLOCATE) if (flags & ENET_PACKET_FLAG_NO_ALLOCATE)
packet -> data = (enet_uint8 *) data; packet -> data = (enet_uint8 *) data;
@ -91,13 +93,28 @@ enet_packet_resize (ENetPacket * packet, size_t dataLength)
static int initializedCRC32 = 0; static int initializedCRC32 = 0;
static enet_uint32 crcTable [256]; static enet_uint32 crcTable [256];
static void initialize_crc32 () static enet_uint32
reflect_crc (int val, int bits)
{
int result = 0, bit;
for (bit = 0; bit < bits; bit ++)
{
if(val & 1) result |= 1 << (bits - 1 - bit);
val >>= 1;
}
return result;
}
static void
initialize_crc32 ()
{ {
int byte; int byte;
for (byte = 0; byte < 256; ++ byte) for (byte = 0; byte < 256; ++ byte)
{ {
enet_uint32 crc = byte << 24; enet_uint32 crc = reflect_crc (byte, 8) << 24;
int offset; int offset;
for(offset = 0; offset < 8; ++ offset) for(offset = 0; offset < 8; ++ offset)
@ -108,7 +125,7 @@ static void initialize_crc32 ()
crc <<= 1; crc <<= 1;
} }
crcTable [byte] = crc; crcTable [byte] = reflect_crc (crc, 32);
} }
initializedCRC32 = 1; initializedCRC32 = 1;
@ -128,7 +145,7 @@ enet_crc32 (const ENetBuffer * buffers, size_t bufferCount)
while (data < dataEnd) while (data < dataEnd)
{ {
crc = ((crc << 8) | * data ++) ^ crcTable [crc >> 24]; crc = (crc >> 8) ^ crcTable [(crc & 0xFF) ^ *data++];
} }
++ buffers; ++ buffers;

View File

@ -108,6 +108,8 @@ enet_peer_send (ENetPeer * peer, enet_uint8 channelID, ENetPacket * packet)
return -1; return -1;
fragmentLength = peer -> mtu - sizeof (ENetProtocolHeader) - sizeof (ENetProtocolSendFragment); fragmentLength = peer -> mtu - sizeof (ENetProtocolHeader) - sizeof (ENetProtocolSendFragment);
if (peer -> host -> checksum != NULL)
fragmentLength -= sizeof(enet_uint32);
if (packet -> dataLength > fragmentLength) if (packet -> dataLength > fragmentLength)
{ {
@ -115,9 +117,10 @@ enet_peer_send (ENetPeer * peer, enet_uint8 channelID, ENetPacket * packet)
enet_uint32 fragmentCount = ENET_HOST_TO_NET_32 ((packet -> dataLength + fragmentLength - 1) / fragmentLength), enet_uint32 fragmentCount = ENET_HOST_TO_NET_32 ((packet -> dataLength + fragmentLength - 1) / fragmentLength),
fragmentNumber, fragmentNumber,
fragmentOffset; fragmentOffset;
ENetList fragments;
ENetOutgoingCommand * fragment;
packet -> flags |= ENET_PACKET_FLAG_RELIABLE; enet_list_clear (& fragments);
packet -> flags &= ~ENET_PACKET_FLAG_UNSEQUENCED;
for (fragmentNumber = 0, for (fragmentNumber = 0,
fragmentOffset = 0; fragmentOffset = 0;
@ -128,16 +131,41 @@ enet_peer_send (ENetPeer * peer, enet_uint8 channelID, ENetPacket * packet)
if (packet -> dataLength - fragmentOffset < fragmentLength) if (packet -> dataLength - fragmentOffset < fragmentLength)
fragmentLength = packet -> dataLength - fragmentOffset; fragmentLength = packet -> dataLength - fragmentOffset;
command.header.command = ENET_PROTOCOL_COMMAND_SEND_FRAGMENT | ENET_PROTOCOL_COMMAND_FLAG_ACKNOWLEDGE; fragment = (ENetOutgoingCommand *) enet_malloc (sizeof (ENetOutgoingCommand));
command.header.channelID = channelID; if (fragment == NULL)
command.sendFragment.startSequenceNumber = startSequenceNumber; {
command.sendFragment.dataLength = ENET_HOST_TO_NET_16 (fragmentLength); while (! enet_list_empty (& fragments))
command.sendFragment.fragmentCount = fragmentCount; {
command.sendFragment.fragmentNumber = ENET_HOST_TO_NET_32 (fragmentNumber); fragment = (ENetOutgoingCommand *) enet_list_remove (enet_list_begin (& fragments));
command.sendFragment.totalLength = ENET_HOST_TO_NET_32 (packet -> dataLength);
command.sendFragment.fragmentOffset = ENET_NET_TO_HOST_32 (fragmentOffset); enet_free (fragment);
}
return -1;
}
fragment -> fragmentOffset = fragmentOffset;
fragment -> fragmentLength = fragmentLength;
fragment -> packet = packet;
fragment -> command.header.command = ENET_PROTOCOL_COMMAND_SEND_FRAGMENT | ENET_PROTOCOL_COMMAND_FLAG_ACKNOWLEDGE;
fragment -> command.header.channelID = channelID;
fragment -> command.sendFragment.startSequenceNumber = startSequenceNumber;
fragment -> command.sendFragment.dataLength = ENET_HOST_TO_NET_16 (fragmentLength);
fragment -> command.sendFragment.fragmentCount = fragmentCount;
fragment -> command.sendFragment.fragmentNumber = ENET_HOST_TO_NET_32 (fragmentNumber);
fragment -> command.sendFragment.totalLength = ENET_HOST_TO_NET_32 (packet -> dataLength);
fragment -> command.sendFragment.fragmentOffset = ENET_NET_TO_HOST_32 (fragmentOffset);
enet_list_insert (enet_list_end (& fragments), fragment);
}
enet_peer_queue_outgoing_command (peer, & command, packet, fragmentOffset, fragmentLength); packet -> referenceCount += fragmentNumber;
while (! enet_list_empty (& fragments))
{
fragment = (ENetOutgoingCommand *) enet_list_remove (enet_list_begin (& fragments));
enet_peer_setup_outgoing_command (peer, fragment);
} }
return 0; return 0;
@ -145,9 +173,6 @@ enet_peer_send (ENetPeer * peer, enet_uint8 channelID, ENetPacket * packet)
command.header.channelID = channelID; command.header.channelID = channelID;
if (! (packet -> flags & (ENET_PACKET_FLAG_RELIABLE | ENET_PACKET_FLAG_UNSEQUENCED)) && channel -> outgoingUnreliableSequenceNumber >= 0xFFFF)
packet -> flags |= ENET_PACKET_FLAG_RELIABLE;
if (packet -> flags & ENET_PACKET_FLAG_RELIABLE) if (packet -> flags & ENET_PACKET_FLAG_RELIABLE)
{ {
command.header.command = ENET_PROTOCOL_COMMAND_SEND_RELIABLE | ENET_PROTOCOL_COMMAND_FLAG_ACKNOWLEDGE; command.header.command = ENET_PROTOCOL_COMMAND_SEND_RELIABLE | ENET_PROTOCOL_COMMAND_FLAG_ACKNOWLEDGE;
@ -160,6 +185,12 @@ enet_peer_send (ENetPeer * peer, enet_uint8 channelID, ENetPacket * packet)
command.sendUnsequenced.unsequencedGroup = ENET_HOST_TO_NET_16 (peer -> outgoingUnsequencedGroup + 1); command.sendUnsequenced.unsequencedGroup = ENET_HOST_TO_NET_16 (peer -> outgoingUnsequencedGroup + 1);
command.sendUnsequenced.dataLength = ENET_HOST_TO_NET_16 (packet -> dataLength); command.sendUnsequenced.dataLength = ENET_HOST_TO_NET_16 (packet -> dataLength);
} }
else
if (channel -> outgoingUnreliableSequenceNumber >= 0xFFFF)
{
command.header.command = ENET_PROTOCOL_COMMAND_SEND_RELIABLE | ENET_PROTOCOL_COMMAND_FLAG_ACKNOWLEDGE;
command.sendReliable.dataLength = ENET_HOST_TO_NET_16 (packet -> dataLength);
}
else else
{ {
command.header.command = ENET_PROTOCOL_COMMAND_SEND_UNRELIABLE; command.header.command = ENET_PROTOCOL_COMMAND_SEND_UNRELIABLE;
@ -167,53 +198,30 @@ enet_peer_send (ENetPeer * peer, enet_uint8 channelID, ENetPacket * packet)
command.sendUnreliable.dataLength = ENET_HOST_TO_NET_16 (packet -> dataLength); command.sendUnreliable.dataLength = ENET_HOST_TO_NET_16 (packet -> dataLength);
} }
enet_peer_queue_outgoing_command (peer, & command, packet, 0, packet -> dataLength); if (enet_peer_queue_outgoing_command (peer, & command, packet, 0, packet -> dataLength) == NULL)
return -1;
return 0; return 0;
} }
/** Attempts to dequeue any incoming queued packet. /** Attempts to dequeue any incoming queued packet.
@param peer peer to dequeue packets from @param peer peer to dequeue packets from
@param channelID channel on which to receive @param channelID holds the channel ID of the channel the packet was received on success
@returns a pointer to the packet, or NULL if there are no available incoming queued packets @returns a pointer to the packet, or NULL if there are no available incoming queued packets
*/ */
ENetPacket * ENetPacket *
enet_peer_receive (ENetPeer * peer, enet_uint8 channelID) enet_peer_receive (ENetPeer * peer, enet_uint8 * channelID)
{ {
ENetChannel * channel = & peer -> channels [channelID]; ENetIncomingCommand * incomingCommand;
ENetIncomingCommand * incomingCommand = NULL;
ENetPacket * packet; ENetPacket * packet;
if (! enet_list_empty (& channel -> incomingUnreliableCommands)) if (enet_list_empty (& peer -> dispatchedCommands))
{
incomingCommand = (ENetIncomingCommand *) enet_list_front (& channel -> incomingUnreliableCommands);
if ((incomingCommand -> command.header.command & ENET_PROTOCOL_COMMAND_MASK) == ENET_PROTOCOL_COMMAND_SEND_UNRELIABLE)
{
if (incomingCommand -> reliableSequenceNumber != channel -> incomingReliableSequenceNumber)
incomingCommand = NULL;
}
}
if (incomingCommand == NULL &&
! enet_list_empty (& channel -> incomingReliableCommands))
{
incomingCommand = (ENetIncomingCommand *) enet_list_front (& channel -> incomingReliableCommands);
if (incomingCommand -> fragmentsRemaining > 0 ||
incomingCommand -> reliableSequenceNumber != (enet_uint16) (channel -> incomingReliableSequenceNumber + 1))
return NULL;
channel -> incomingReliableSequenceNumber = incomingCommand -> reliableSequenceNumber;
if (incomingCommand -> fragmentCount > 0)
channel -> incomingReliableSequenceNumber += incomingCommand -> fragmentCount - 1;
}
if (incomingCommand == NULL)
return NULL; return NULL;
enet_list_remove (& incomingCommand -> incomingCommandList); incomingCommand = (ENetIncomingCommand *) enet_list_remove (enet_list_begin (& peer -> dispatchedCommands));
if (channelID != NULL)
* channelID = incomingCommand -> command.header.channelID;
packet = incomingCommand -> packet; packet = incomingCommand -> packet;
@ -277,6 +285,13 @@ enet_peer_reset_queues (ENetPeer * peer)
{ {
ENetChannel * channel; ENetChannel * channel;
if (peer -> needsDispatch)
{
enet_list_remove (& peer -> dispatchList);
peer -> needsDispatch = 0;
}
while (! enet_list_empty (& peer -> acknowledgements)) while (! enet_list_empty (& peer -> acknowledgements))
enet_free (enet_list_remove (enet_list_begin (& peer -> acknowledgements))); enet_free (enet_list_remove (enet_list_begin (& peer -> acknowledgements)));
@ -284,6 +299,7 @@ enet_peer_reset_queues (ENetPeer * peer)
enet_peer_reset_outgoing_commands (& peer -> sentUnreliableCommands); enet_peer_reset_outgoing_commands (& peer -> sentUnreliableCommands);
enet_peer_reset_outgoing_commands (& peer -> outgoingReliableCommands); enet_peer_reset_outgoing_commands (& peer -> outgoingReliableCommands);
enet_peer_reset_outgoing_commands (& peer -> outgoingUnreliableCommands); enet_peer_reset_outgoing_commands (& peer -> outgoingUnreliableCommands);
enet_peer_reset_incoming_commands (& peer -> dispatchedCommands);
if (peer -> channels != NULL && peer -> channelCount > 0) if (peer -> channels != NULL && peer -> channelCount > 0)
{ {
@ -311,7 +327,7 @@ void
enet_peer_reset (ENetPeer * peer) enet_peer_reset (ENetPeer * peer)
{ {
peer -> outgoingPeerID = ENET_PROTOCOL_MAXIMUM_PEER_ID; peer -> outgoingPeerID = ENET_PROTOCOL_MAXIMUM_PEER_ID;
peer -> sessionID = 0; peer -> connectID = 0;
peer -> state = ENET_PEER_STATE_DISCONNECTED; peer -> state = ENET_PEER_STATE_DISCONNECTED;
@ -349,7 +365,7 @@ enet_peer_reset (ENetPeer * peer)
peer -> windowSize = ENET_PROTOCOL_MAXIMUM_WINDOW_SIZE; peer -> windowSize = ENET_PROTOCOL_MAXIMUM_WINDOW_SIZE;
peer -> incomingUnsequencedGroup = 0; peer -> incomingUnsequencedGroup = 0;
peer -> outgoingUnsequencedGroup = 0; peer -> outgoingUnsequencedGroup = 0;
peer -> disconnectData = 0; peer -> eventData = 0;
memset (peer -> unsequencedWindow, 0, sizeof (peer -> unsequencedWindow)); memset (peer -> unsequencedWindow, 0, sizeof (peer -> unsequencedWindow));
@ -422,6 +438,7 @@ enet_peer_disconnect (ENetPeer * peer, enet_uint32 data)
if (peer -> state == ENET_PEER_STATE_DISCONNECTING || if (peer -> state == ENET_PEER_STATE_DISCONNECTING ||
peer -> state == ENET_PEER_STATE_DISCONNECTED || peer -> state == ENET_PEER_STATE_DISCONNECTED ||
peer -> state == ENET_PEER_STATE_ACKNOWLEDGING_DISCONNECT ||
peer -> state == ENET_PEER_STATE_ZOMBIE) peer -> state == ENET_PEER_STATE_ZOMBIE)
return; return;
@ -462,7 +479,7 @@ enet_peer_disconnect_later (ENetPeer * peer, enet_uint32 data)
enet_list_empty (& peer -> sentReliableCommands))) enet_list_empty (& peer -> sentReliableCommands)))
{ {
peer -> state = ENET_PEER_STATE_DISCONNECT_LATER; peer -> state = ENET_PEER_STATE_DISCONNECT_LATER;
peer -> disconnectData = data; peer -> eventData = data;
} }
else else
enet_peer_disconnect (peer, data); enet_peer_disconnect (peer, data);
@ -486,9 +503,11 @@ enet_peer_queue_acknowledgement (ENetPeer * peer, const ENetProtocol * command,
return NULL; return NULL;
} }
peer -> outgoingDataTotal += sizeof (ENetProtocolAcknowledge);
acknowledgement = (ENetAcknowledgement *) enet_malloc (sizeof (ENetAcknowledgement)); acknowledgement = (ENetAcknowledgement *) enet_malloc (sizeof (ENetAcknowledgement));
if (acknowledgement == NULL)
return NULL;
peer -> outgoingDataTotal += sizeof (ENetProtocolAcknowledge);
acknowledgement -> sentTime = sentTime; acknowledgement -> sentTime = sentTime;
acknowledgement -> command = * command; acknowledgement -> command = * command;
@ -498,17 +517,14 @@ enet_peer_queue_acknowledgement (ENetPeer * peer, const ENetProtocol * command,
return acknowledgement; return acknowledgement;
} }
ENetOutgoingCommand * void
enet_peer_queue_outgoing_command (ENetPeer * peer, const ENetProtocol * command, ENetPacket * packet, enet_uint32 offset, enet_uint16 length) enet_peer_setup_outgoing_command (ENetPeer * peer, ENetOutgoingCommand * outgoingCommand)
{ {
ENetChannel * channel = & peer -> channels [command -> header.channelID]; ENetChannel * channel = & peer -> channels [outgoingCommand -> command.header.channelID];
ENetOutgoingCommand * outgoingCommand;
peer -> outgoingDataTotal += enet_protocol_command_size (command -> header.command) + length; peer -> outgoingDataTotal += enet_protocol_command_size (outgoingCommand -> command.header.command) + outgoingCommand -> fragmentLength;
outgoingCommand = (ENetOutgoingCommand *) enet_malloc (sizeof (ENetOutgoingCommand)); if (outgoingCommand -> command.header.channelID == 0xFF)
if (command -> header.channelID == 0xFF)
{ {
++ peer -> outgoingReliableSequenceNumber; ++ peer -> outgoingReliableSequenceNumber;
@ -516,7 +532,7 @@ enet_peer_queue_outgoing_command (ENetPeer * peer, const ENetProtocol * command,
outgoingCommand -> unreliableSequenceNumber = 0; outgoingCommand -> unreliableSequenceNumber = 0;
} }
else else
if (command -> header.command & ENET_PROTOCOL_COMMAND_FLAG_ACKNOWLEDGE) if (outgoingCommand -> command.header.command & ENET_PROTOCOL_COMMAND_FLAG_ACKNOWLEDGE)
{ {
++ channel -> outgoingReliableSequenceNumber; ++ channel -> outgoingReliableSequenceNumber;
channel -> outgoingUnreliableSequenceNumber = 0; channel -> outgoingUnreliableSequenceNumber = 0;
@ -525,7 +541,7 @@ enet_peer_queue_outgoing_command (ENetPeer * peer, const ENetProtocol * command,
outgoingCommand -> unreliableSequenceNumber = 0; outgoingCommand -> unreliableSequenceNumber = 0;
} }
else else
if (command -> header.command & ENET_PROTOCOL_COMMAND_FLAG_UNSEQUENCED) if (outgoingCommand -> command.header.command & ENET_PROTOCOL_COMMAND_FLAG_UNSEQUENCED)
{ {
++ peer -> outgoingUnsequencedGroup; ++ peer -> outgoingUnsequencedGroup;
@ -544,26 +560,103 @@ enet_peer_queue_outgoing_command (ENetPeer * peer, const ENetProtocol * command,
outgoingCommand -> sentTime = 0; outgoingCommand -> sentTime = 0;
outgoingCommand -> roundTripTimeout = 0; outgoingCommand -> roundTripTimeout = 0;
outgoingCommand -> roundTripTimeoutLimit = 0; outgoingCommand -> roundTripTimeoutLimit = 0;
outgoingCommand -> fragmentOffset = offset;
outgoingCommand -> fragmentLength = length;
outgoingCommand -> packet = packet;
outgoingCommand -> command = * command;
outgoingCommand -> command.header.reliableSequenceNumber = ENET_HOST_TO_NET_16 (outgoingCommand -> reliableSequenceNumber); outgoingCommand -> command.header.reliableSequenceNumber = ENET_HOST_TO_NET_16 (outgoingCommand -> reliableSequenceNumber);
if (packet != NULL) if (outgoingCommand -> command.header.command & ENET_PROTOCOL_COMMAND_FLAG_ACKNOWLEDGE)
++ packet -> referenceCount;
if (command -> header.command & ENET_PROTOCOL_COMMAND_FLAG_ACKNOWLEDGE)
enet_list_insert (enet_list_end (& peer -> outgoingReliableCommands), outgoingCommand); enet_list_insert (enet_list_end (& peer -> outgoingReliableCommands), outgoingCommand);
else else
enet_list_insert (enet_list_end (& peer -> outgoingUnreliableCommands), outgoingCommand); enet_list_insert (enet_list_end (& peer -> outgoingUnreliableCommands), outgoingCommand);
}
ENetOutgoingCommand *
enet_peer_queue_outgoing_command (ENetPeer * peer, const ENetProtocol * command, ENetPacket * packet, enet_uint32 offset, enet_uint16 length)
{
ENetOutgoingCommand * outgoingCommand = (ENetOutgoingCommand *) enet_malloc (sizeof (ENetOutgoingCommand));
if (outgoingCommand == NULL)
return NULL;
outgoingCommand -> command = * command;
outgoingCommand -> fragmentOffset = offset;
outgoingCommand -> fragmentLength = length;
outgoingCommand -> packet = packet;
if (packet != NULL)
++ packet -> referenceCount;
enet_peer_setup_outgoing_command (peer, outgoingCommand);
return outgoingCommand; return outgoingCommand;
} }
void
enet_peer_dispatch_incoming_unreliable_commands (ENetPeer * peer, ENetChannel * channel)
{
ENetListIterator currentCommand;
for (currentCommand = enet_list_begin (& channel -> incomingUnreliableCommands);
currentCommand != enet_list_end (& channel -> incomingUnreliableCommands);
currentCommand = enet_list_next (currentCommand))
{
ENetIncomingCommand * incomingCommand = (ENetIncomingCommand *) currentCommand;
if ((incomingCommand -> command.header.command & ENET_PROTOCOL_COMMAND_MASK) == ENET_PROTOCOL_COMMAND_SEND_UNRELIABLE &&
incomingCommand -> reliableSequenceNumber != channel -> incomingReliableSequenceNumber)
break;
}
if (currentCommand == enet_list_begin (& channel -> incomingUnreliableCommands))
return;
enet_list_move (enet_list_end (& peer -> dispatchedCommands), enet_list_begin (& channel -> incomingUnreliableCommands), enet_list_previous (currentCommand));
if (! peer -> needsDispatch)
{
enet_list_insert (enet_list_end (& peer -> host -> dispatchQueue), & peer -> dispatchList);
peer -> needsDispatch = 1;
}
}
void
enet_peer_dispatch_incoming_reliable_commands (ENetPeer * peer, ENetChannel * channel)
{
ENetListIterator currentCommand;
for (currentCommand = enet_list_begin (& channel -> incomingReliableCommands);
currentCommand != enet_list_end (& channel -> incomingReliableCommands);
currentCommand = enet_list_next (currentCommand))
{
ENetIncomingCommand * incomingCommand = (ENetIncomingCommand *) currentCommand;
if (incomingCommand -> fragmentsRemaining > 0 ||
incomingCommand -> reliableSequenceNumber != (enet_uint16) (channel -> incomingReliableSequenceNumber + 1))
break;
channel -> incomingReliableSequenceNumber = incomingCommand -> reliableSequenceNumber;
if (incomingCommand -> fragmentCount > 0)
channel -> incomingReliableSequenceNumber += incomingCommand -> fragmentCount - 1;
}
if (currentCommand == enet_list_begin (& channel -> incomingReliableCommands))
return;
enet_list_move (enet_list_end (& peer -> dispatchedCommands), enet_list_begin (& channel -> incomingReliableCommands), enet_list_previous (currentCommand));
if (! peer -> needsDispatch)
{
enet_list_insert (enet_list_end (& peer -> host -> dispatchQueue), & peer -> dispatchList);
peer -> needsDispatch = 1;
}
enet_peer_dispatch_incoming_unreliable_commands (peer, channel);
}
ENetIncomingCommand * ENetIncomingCommand *
enet_peer_queue_incoming_command (ENetPeer * peer, const ENetProtocol * command, ENetPacket * packet, enet_uint32 fragmentCount) enet_peer_queue_incoming_command (ENetPeer * peer, const ENetProtocol * command, ENetPacket * packet, enet_uint32 fragmentCount)
{ {
static ENetIncomingCommand dummyCommand;
ENetChannel * channel = & peer -> channels [command -> header.channelID]; ENetChannel * channel = & peer -> channels [command -> header.channelID];
enet_uint32 unreliableSequenceNumber = 0, reliableSequenceNumber; enet_uint32 unreliableSequenceNumber = 0, reliableSequenceNumber;
enet_uint16 reliableWindow, currentWindow; enet_uint16 reliableWindow, currentWindow;
@ -664,6 +757,8 @@ enet_peer_queue_incoming_command (ENetPeer * peer, const ENetProtocol * command,
} }
incomingCommand = (ENetIncomingCommand *) enet_malloc (sizeof (ENetIncomingCommand)); incomingCommand = (ENetIncomingCommand *) enet_malloc (sizeof (ENetIncomingCommand));
if (incomingCommand == NULL)
goto notifyError;
incomingCommand -> reliableSequenceNumber = command -> header.reliableSequenceNumber; incomingCommand -> reliableSequenceNumber = command -> header.reliableSequenceNumber;
incomingCommand -> unreliableSequenceNumber = unreliableSequenceNumber & 0xFFFF; incomingCommand -> unreliableSequenceNumber = unreliableSequenceNumber & 0xFFFF;
@ -676,6 +771,12 @@ enet_peer_queue_incoming_command (ENetPeer * peer, const ENetProtocol * command,
if (fragmentCount > 0) if (fragmentCount > 0)
{ {
incomingCommand -> fragments = (enet_uint32 *) enet_malloc ((fragmentCount + 31) / 32 * sizeof (enet_uint32)); incomingCommand -> fragments = (enet_uint32 *) enet_malloc ((fragmentCount + 31) / 32 * sizeof (enet_uint32));
if (incomingCommand -> fragments == NULL)
{
enet_free (incomingCommand);
goto notifyError;
}
memset (incomingCommand -> fragments, 0, (fragmentCount + 31) / 32 * sizeof (enet_uint32)); memset (incomingCommand -> fragments, 0, (fragmentCount + 31) / 32 * sizeof (enet_uint32));
} }
@ -684,14 +785,32 @@ enet_peer_queue_incoming_command (ENetPeer * peer, const ENetProtocol * command,
enet_list_insert (enet_list_next (currentCommand), incomingCommand); enet_list_insert (enet_list_next (currentCommand), incomingCommand);
switch (command -> header.command & ENET_PROTOCOL_COMMAND_MASK)
{
case ENET_PROTOCOL_COMMAND_SEND_FRAGMENT:
case ENET_PROTOCOL_COMMAND_SEND_RELIABLE:
enet_peer_dispatch_incoming_reliable_commands (peer, channel);
break;
default:
enet_peer_dispatch_incoming_unreliable_commands (peer, channel);
break;
}
return incomingCommand; return incomingCommand;
freePacket: freePacket:
if (packet != NULL) if (fragmentCount > 0)
{ goto notifyError;
if (packet -> referenceCount == 0)
enet_packet_destroy (packet); if (packet != NULL && packet -> referenceCount == 0)
} enet_packet_destroy (packet);
return & dummyCommand;
notifyError:
if (packet != NULL && packet -> referenceCount == 0)
enet_packet_destroy (packet);
return NULL; return NULL;
} }

View File

@ -34,24 +34,21 @@ enet_protocol_command_size (enet_uint8 commandNumber)
static int static int
enet_protocol_dispatch_incoming_commands (ENetHost * host, ENetEvent * event) enet_protocol_dispatch_incoming_commands (ENetHost * host, ENetEvent * event)
{ {
ENetPeer * currentPeer = host -> lastServicedPeer; while (! enet_list_empty (& host -> dispatchQueue))
ENetChannel * channel;
do
{ {
++ currentPeer; ENetPeer * peer = (ENetPeer *) enet_list_remove (enet_list_begin (& host -> dispatchQueue));
if (currentPeer >= & host -> peers [host -> peerCount])
currentPeer = host -> peers;
switch (currentPeer -> state) peer -> needsDispatch = 0;
switch (peer -> state)
{ {
case ENET_PEER_STATE_CONNECTION_PENDING: case ENET_PEER_STATE_CONNECTION_PENDING:
case ENET_PEER_STATE_CONNECTION_SUCCEEDED: case ENET_PEER_STATE_CONNECTION_SUCCEEDED:
currentPeer -> state = ENET_PEER_STATE_CONNECTED; peer -> state = ENET_PEER_STATE_CONNECTED;
event -> type = ENET_EVENT_TYPE_CONNECT; event -> type = ENET_EVENT_TYPE_CONNECT;
event -> peer = currentPeer; event -> peer = peer;
event -> data = peer -> eventData;
return 1; return 1;
@ -59,72 +56,78 @@ enet_protocol_dispatch_incoming_commands (ENetHost * host, ENetEvent * event)
host -> recalculateBandwidthLimits = 1; host -> recalculateBandwidthLimits = 1;
event -> type = ENET_EVENT_TYPE_DISCONNECT; event -> type = ENET_EVENT_TYPE_DISCONNECT;
event -> peer = currentPeer; event -> peer = peer;
event -> data = currentPeer -> disconnectData; event -> data = peer -> eventData;
enet_peer_reset (currentPeer); enet_peer_reset (peer);
host -> lastServicedPeer = currentPeer;
return 1; return 1;
}
if (currentPeer -> state != ENET_PEER_STATE_CONNECTED) case ENET_PEER_STATE_CONNECTED:
continue; if (enet_list_empty (& peer -> dispatchedCommands))
for (channel = currentPeer -> channels;
channel < & currentPeer -> channels [currentPeer -> channelCount];
++ channel)
{
if (enet_list_empty (& channel -> incomingReliableCommands) &&
enet_list_empty (& channel -> incomingUnreliableCommands))
continue; continue;
event -> packet = enet_peer_receive (currentPeer, channel - currentPeer -> channels); event -> packet = enet_peer_receive (peer, & event -> channelID);
if (event -> packet == NULL) if (event -> packet == NULL)
continue; continue;
event -> type = ENET_EVENT_TYPE_RECEIVE; event -> type = ENET_EVENT_TYPE_RECEIVE;
event -> peer = currentPeer; event -> peer = peer;
event -> channelID = (enet_uint8) (channel - currentPeer -> channels);
host -> lastServicedPeer = currentPeer; if (! enet_list_empty (& peer -> dispatchedCommands))
{
peer -> needsDispatch = 1;
enet_list_insert (enet_list_end (& host -> dispatchQueue), & peer -> dispatchList);
}
return 1; return 1;
} }
} while (currentPeer != host -> lastServicedPeer); }
return 0; return 0;
} }
static void
enet_protocol_dispatch_state (ENetHost * host, ENetPeer * peer, ENetPeerState state)
{
peer -> state = state;
if (! peer -> needsDispatch)
{
enet_list_insert (enet_list_end (& host -> dispatchQueue), & peer -> dispatchList);
peer -> needsDispatch = 1;
}
}
static void static void
enet_protocol_notify_connect (ENetHost * host, ENetPeer * peer, ENetEvent * event) enet_protocol_notify_connect (ENetHost * host, ENetPeer * peer, ENetEvent * event)
{ {
host -> recalculateBandwidthLimits = 1; host -> recalculateBandwidthLimits = 1;
if (event == NULL) if (event != NULL)
peer -> state = (peer -> state == ENET_PEER_STATE_CONNECTING ? ENET_PEER_STATE_CONNECTION_SUCCEEDED : ENET_PEER_STATE_CONNECTION_PENDING);
else
{ {
peer -> state = ENET_PEER_STATE_CONNECTED; peer -> state = ENET_PEER_STATE_CONNECTED;
event -> type = ENET_EVENT_TYPE_CONNECT; event -> type = ENET_EVENT_TYPE_CONNECT;
event -> peer = peer; event -> peer = peer;
event -> data = peer -> eventData;
} }
else
enet_protocol_dispatch_state (host, peer, peer -> state == ENET_PEER_STATE_CONNECTING ? ENET_PEER_STATE_CONNECTION_SUCCEEDED : ENET_PEER_STATE_CONNECTION_PENDING);
} }
static void static void
enet_protocol_notify_disconnect (ENetHost * host, ENetPeer * peer, ENetEvent * event) enet_protocol_notify_disconnect (ENetHost * host, ENetPeer * peer, ENetEvent * event)
{ {
if (peer -> state >= ENET_PEER_STATE_CONNECTION_PENDING) if (peer -> state >= ENET_PEER_STATE_CONNECTION_PENDING)
host -> recalculateBandwidthLimits = 1; host -> recalculateBandwidthLimits = 1;
if (peer -> state != ENET_PEER_STATE_CONNECTING && peer -> state < ENET_PEER_STATE_CONNECTION_SUCCEEDED) if (peer -> state != ENET_PEER_STATE_CONNECTING && peer -> state < ENET_PEER_STATE_CONNECTION_SUCCEEDED)
enet_peer_reset (peer); enet_peer_reset (peer);
else else
if (event == NULL) if (event != NULL)
peer -> state = ENET_PEER_STATE_ZOMBIE;
else
{ {
event -> type = ENET_EVENT_TYPE_DISCONNECT; event -> type = ENET_EVENT_TYPE_DISCONNECT;
event -> peer = peer; event -> peer = peer;
@ -132,6 +135,12 @@ enet_protocol_notify_disconnect (ENetHost * host, ENetPeer * peer, ENetEvent * e
enet_peer_reset (peer); enet_peer_reset (peer);
} }
else
{
peer -> eventData = 0;
enet_protocol_dispatch_state (host, peer, ENET_PEER_STATE_ZOMBIE);
}
} }
static void static void
@ -163,6 +172,7 @@ enet_protocol_remove_sent_reliable_command (ENetPeer * peer, enet_uint16 reliabl
ENetOutgoingCommand * outgoingCommand; ENetOutgoingCommand * outgoingCommand;
ENetListIterator currentCommand; ENetListIterator currentCommand;
ENetProtocolCommand commandNumber; ENetProtocolCommand commandNumber;
int wasSent = 1;
for (currentCommand = enet_list_begin (& peer -> sentReliableCommands); for (currentCommand = enet_list_begin (& peer -> sentReliableCommands);
currentCommand != enet_list_end (& peer -> sentReliableCommands); currentCommand != enet_list_end (& peer -> sentReliableCommands);
@ -192,6 +202,8 @@ enet_protocol_remove_sent_reliable_command (ENetPeer * peer, enet_uint16 reliabl
if (currentCommand == enet_list_end (& peer -> outgoingReliableCommands)) if (currentCommand == enet_list_end (& peer -> outgoingReliableCommands))
return ENET_PROTOCOL_COMMAND_NONE; return ENET_PROTOCOL_COMMAND_NONE;
wasSent = 0;
} }
if (channelID < peer -> channelCount) if (channelID < peer -> channelCount)
@ -212,7 +224,8 @@ enet_protocol_remove_sent_reliable_command (ENetPeer * peer, enet_uint16 reliabl
if (outgoingCommand -> packet != NULL) if (outgoingCommand -> packet != NULL)
{ {
peer -> reliableDataInTransit -= outgoingCommand -> fragmentLength; if (wasSent)
peer -> reliableDataInTransit -= outgoingCommand -> fragmentLength;
-- outgoingCommand -> packet -> referenceCount; -- outgoingCommand -> packet -> referenceCount;
@ -235,32 +248,13 @@ enet_protocol_remove_sent_reliable_command (ENetPeer * peer, enet_uint16 reliabl
static ENetPeer * static ENetPeer *
enet_protocol_handle_connect (ENetHost * host, ENetProtocolHeader * header, ENetProtocol * command) enet_protocol_handle_connect (ENetHost * host, ENetProtocolHeader * header, ENetProtocol * command)
{ {
enet_uint16 mtu; enet_uint8 incomingSessionID, outgoingSessionID;
enet_uint32 windowSize; enet_uint32 mtu, windowSize;
ENetChannel * channel; ENetChannel * channel;
size_t channelCount; size_t channelCount;
ENetPeer * currentPeer; ENetPeer * currentPeer;
ENetProtocol verifyCommand; ENetProtocol verifyCommand;
#ifdef USE_CRC32
{
enet_uint32 crc = header -> checksum;
ENetBuffer buffer;
command -> header.reliableSequenceNumber = ENET_HOST_TO_NET_16 (command -> header.reliableSequenceNumber);
header -> checksum = command -> connect.sessionID;
buffer.data = host -> receivedData;
buffer.dataLength = host -> receivedDataLength;
if (enet_crc32 (& buffer, 1) != crc)
return NULL;
command -> header.reliableSequenceNumber = ENET_NET_TO_HOST_16 (command -> header.reliableSequenceNumber);
}
#endif
channelCount = ENET_NET_TO_HOST_32 (command -> connect.channelCount); channelCount = ENET_NET_TO_HOST_32 (command -> connect.channelCount);
if (channelCount < ENET_PROTOCOL_MINIMUM_CHANNEL_COUNT || if (channelCount < ENET_PROTOCOL_MINIMUM_CHANNEL_COUNT ||
@ -274,7 +268,7 @@ enet_protocol_handle_connect (ENetHost * host, ENetProtocolHeader * header, ENet
if (currentPeer -> state != ENET_PEER_STATE_DISCONNECTED && if (currentPeer -> state != ENET_PEER_STATE_DISCONNECTED &&
currentPeer -> address.host == host -> receivedAddress.host && currentPeer -> address.host == host -> receivedAddress.host &&
currentPeer -> address.port == host -> receivedAddress.port && currentPeer -> address.port == host -> receivedAddress.port &&
currentPeer -> sessionID == command -> connect.sessionID) currentPeer -> connectID == command -> connect.connectID)
return NULL; return NULL;
} }
@ -289,8 +283,14 @@ enet_protocol_handle_connect (ENetHost * host, ENetProtocolHeader * header, ENet
if (currentPeer >= & host -> peers [host -> peerCount]) if (currentPeer >= & host -> peers [host -> peerCount])
return NULL; return NULL;
if (channelCount > host -> channelLimit)
channelCount = host -> channelLimit;
currentPeer -> channels = (ENetChannel *) enet_malloc (channelCount * sizeof (ENetChannel));
if (currentPeer -> channels == NULL)
return NULL;
currentPeer -> channelCount = channelCount;
currentPeer -> state = ENET_PEER_STATE_ACKNOWLEDGING_CONNECT; currentPeer -> state = ENET_PEER_STATE_ACKNOWLEDGING_CONNECT;
currentPeer -> sessionID = command -> connect.sessionID; currentPeer -> connectID = command -> connect.connectID;
currentPeer -> address = host -> receivedAddress; currentPeer -> address = host -> receivedAddress;
currentPeer -> outgoingPeerID = ENET_NET_TO_HOST_16 (command -> connect.outgoingPeerID); currentPeer -> outgoingPeerID = ENET_NET_TO_HOST_16 (command -> connect.outgoingPeerID);
currentPeer -> incomingBandwidth = ENET_NET_TO_HOST_32 (command -> connect.incomingBandwidth); currentPeer -> incomingBandwidth = ENET_NET_TO_HOST_32 (command -> connect.incomingBandwidth);
@ -298,8 +298,19 @@ enet_protocol_handle_connect (ENetHost * host, ENetProtocolHeader * header, ENet
currentPeer -> packetThrottleInterval = ENET_NET_TO_HOST_32 (command -> connect.packetThrottleInterval); currentPeer -> packetThrottleInterval = ENET_NET_TO_HOST_32 (command -> connect.packetThrottleInterval);
currentPeer -> packetThrottleAcceleration = ENET_NET_TO_HOST_32 (command -> connect.packetThrottleAcceleration); currentPeer -> packetThrottleAcceleration = ENET_NET_TO_HOST_32 (command -> connect.packetThrottleAcceleration);
currentPeer -> packetThrottleDeceleration = ENET_NET_TO_HOST_32 (command -> connect.packetThrottleDeceleration); currentPeer -> packetThrottleDeceleration = ENET_NET_TO_HOST_32 (command -> connect.packetThrottleDeceleration);
currentPeer -> channels = (ENetChannel *) enet_malloc (channelCount * sizeof (ENetChannel)); currentPeer -> eventData = ENET_NET_TO_HOST_32 (command -> connect.data);
currentPeer -> channelCount = channelCount;
incomingSessionID = command -> connect.incomingSessionID == 0xFF ? currentPeer -> outgoingSessionID : command -> connect.incomingSessionID;
incomingSessionID = (incomingSessionID + 1) & (ENET_PROTOCOL_HEADER_SESSION_MASK >> ENET_PROTOCOL_HEADER_SESSION_SHIFT);
if (incomingSessionID == currentPeer -> outgoingSessionID)
incomingSessionID = (incomingSessionID + 1) & (ENET_PROTOCOL_HEADER_SESSION_MASK >> ENET_PROTOCOL_HEADER_SESSION_SHIFT);
currentPeer -> outgoingSessionID = incomingSessionID;
outgoingSessionID = command -> connect.outgoingSessionID == 0xFF ? currentPeer -> incomingSessionID : command -> connect.outgoingSessionID;
outgoingSessionID = (outgoingSessionID + 1) & (ENET_PROTOCOL_HEADER_SESSION_MASK >> ENET_PROTOCOL_HEADER_SESSION_SHIFT);
if (outgoingSessionID == currentPeer -> incomingSessionID)
outgoingSessionID = (outgoingSessionID + 1) & (ENET_PROTOCOL_HEADER_SESSION_MASK >> ENET_PROTOCOL_HEADER_SESSION_SHIFT);
currentPeer -> incomingSessionID = outgoingSessionID;
for (channel = currentPeer -> channels; for (channel = currentPeer -> channels;
channel < & currentPeer -> channels [channelCount]; channel < & currentPeer -> channels [channelCount];
@ -316,7 +327,7 @@ enet_protocol_handle_connect (ENetHost * host, ENetProtocolHeader * header, ENet
memset (channel -> reliableWindows, 0, sizeof (channel -> reliableWindows)); memset (channel -> reliableWindows, 0, sizeof (channel -> reliableWindows));
} }
mtu = ENET_NET_TO_HOST_16 (command -> connect.mtu); mtu = ENET_NET_TO_HOST_32 (command -> connect.mtu);
if (mtu < ENET_PROTOCOL_MINIMUM_MTU) if (mtu < ENET_PROTOCOL_MINIMUM_MTU)
mtu = ENET_PROTOCOL_MINIMUM_MTU; mtu = ENET_PROTOCOL_MINIMUM_MTU;
@ -364,6 +375,8 @@ enet_protocol_handle_connect (ENetHost * host, ENetProtocolHeader * header, ENet
verifyCommand.header.command = ENET_PROTOCOL_COMMAND_VERIFY_CONNECT | ENET_PROTOCOL_COMMAND_FLAG_ACKNOWLEDGE; verifyCommand.header.command = ENET_PROTOCOL_COMMAND_VERIFY_CONNECT | ENET_PROTOCOL_COMMAND_FLAG_ACKNOWLEDGE;
verifyCommand.header.channelID = 0xFF; verifyCommand.header.channelID = 0xFF;
verifyCommand.verifyConnect.outgoingPeerID = ENET_HOST_TO_NET_16 (currentPeer -> incomingPeerID); verifyCommand.verifyConnect.outgoingPeerID = ENET_HOST_TO_NET_16 (currentPeer -> incomingPeerID);
verifyCommand.verifyConnect.incomingSessionID = incomingSessionID;
verifyCommand.verifyConnect.outgoingSessionID = outgoingSessionID;
verifyCommand.verifyConnect.mtu = ENET_HOST_TO_NET_16 (currentPeer -> mtu); verifyCommand.verifyConnect.mtu = ENET_HOST_TO_NET_16 (currentPeer -> mtu);
verifyCommand.verifyConnect.windowSize = ENET_HOST_TO_NET_32 (windowSize); verifyCommand.verifyConnect.windowSize = ENET_HOST_TO_NET_32 (windowSize);
verifyCommand.verifyConnect.channelCount = ENET_HOST_TO_NET_32 (channelCount); verifyCommand.verifyConnect.channelCount = ENET_HOST_TO_NET_32 (channelCount);
@ -372,6 +385,7 @@ enet_protocol_handle_connect (ENetHost * host, ENetProtocolHeader * header, ENet
verifyCommand.verifyConnect.packetThrottleInterval = ENET_HOST_TO_NET_32 (currentPeer -> packetThrottleInterval); verifyCommand.verifyConnect.packetThrottleInterval = ENET_HOST_TO_NET_32 (currentPeer -> packetThrottleInterval);
verifyCommand.verifyConnect.packetThrottleAcceleration = ENET_HOST_TO_NET_32 (currentPeer -> packetThrottleAcceleration); verifyCommand.verifyConnect.packetThrottleAcceleration = ENET_HOST_TO_NET_32 (currentPeer -> packetThrottleAcceleration);
verifyCommand.verifyConnect.packetThrottleDeceleration = ENET_HOST_TO_NET_32 (currentPeer -> packetThrottleDeceleration); verifyCommand.verifyConnect.packetThrottleDeceleration = ENET_HOST_TO_NET_32 (currentPeer -> packetThrottleDeceleration);
verifyCommand.verifyConnect.connectID = currentPeer -> connectID;
enet_peer_queue_outgoing_command (currentPeer, & verifyCommand, NULL, 0, 0); enet_peer_queue_outgoing_command (currentPeer, & verifyCommand, NULL, 0, 0);
@ -396,10 +410,10 @@ enet_protocol_handle_send_reliable (ENetHost * host, ENetPeer * peer, const ENet
packet = enet_packet_create ((const enet_uint8 *) command + sizeof (ENetProtocolSendReliable), packet = enet_packet_create ((const enet_uint8 *) command + sizeof (ENetProtocolSendReliable),
dataLength, dataLength,
ENET_PACKET_FLAG_RELIABLE); ENET_PACKET_FLAG_RELIABLE);
if (packet == NULL) if (packet == NULL ||
enet_peer_queue_incoming_command (peer, command, packet, 0) == NULL)
return -1; return -1;
enet_peer_queue_incoming_command (peer, command, packet, 0);
return 0; return 0;
} }
@ -440,16 +454,15 @@ enet_protocol_handle_send_unsequenced (ENetHost * host, ENetPeer * peer, const E
if (peer -> unsequencedWindow [index / 32] & (1 << (index % 32))) if (peer -> unsequencedWindow [index / 32] & (1 << (index % 32)))
return 0; return 0;
peer -> unsequencedWindow [index / 32] |= 1 << (index % 32);
packet = enet_packet_create ((const enet_uint8 *) command + sizeof (ENetProtocolSendUnsequenced), packet = enet_packet_create ((const enet_uint8 *) command + sizeof (ENetProtocolSendUnsequenced),
dataLength, dataLength,
ENET_PACKET_FLAG_UNSEQUENCED); ENET_PACKET_FLAG_UNSEQUENCED);
if (packet == NULL) if (packet == NULL ||
enet_peer_queue_incoming_command (peer, command, packet, 0) == NULL)
return -1; return -1;
enet_peer_queue_incoming_command (peer, command, packet, 0); peer -> unsequencedWindow [index / 32] |= 1 << (index % 32);
return 0; return 0;
} }
@ -471,10 +484,10 @@ enet_protocol_handle_send_unreliable (ENetHost * host, ENetPeer * peer, const EN
packet = enet_packet_create ((const enet_uint8 *) command + sizeof (ENetProtocolSendUnreliable), packet = enet_packet_create ((const enet_uint8 *) command + sizeof (ENetProtocolSendUnreliable),
dataLength, dataLength,
0); 0);
if (packet == NULL) if (packet == NULL ||
enet_peer_queue_incoming_command (peer, command, packet, 0) == NULL)
return -1; return -1;
enet_peer_queue_incoming_command (peer, command, packet, 0);
return 0; return 0;
} }
@ -584,6 +597,9 @@ enet_protocol_handle_send_fragment (ENetHost * host, ENetPeer * peer, const ENet
memcpy (startCommand -> packet -> data + fragmentOffset, memcpy (startCommand -> packet -> data + fragmentOffset,
(enet_uint8 *) command + sizeof (ENetProtocolSendFragment), (enet_uint8 *) command + sizeof (ENetProtocolSendFragment),
fragmentLength); fragmentLength);
if (startCommand -> fragmentsRemaining <= 0)
enet_peer_dispatch_incoming_reliable_commands (peer, channel);
} }
return 0; return 0;
@ -629,10 +645,13 @@ enet_protocol_handle_throttle_configure (ENetHost * host, ENetPeer * peer, const
static int static int
enet_protocol_handle_disconnect (ENetHost * host, ENetPeer * peer, const ENetProtocol * command) enet_protocol_handle_disconnect (ENetHost * host, ENetPeer * peer, const ENetProtocol * command)
{ {
if (peer -> state == ENET_PEER_STATE_ZOMBIE || peer -> state == ENET_PEER_STATE_ACKNOWLEDGING_DISCONNECT)
return 0;
enet_peer_reset_queues (peer); enet_peer_reset_queues (peer);
if (peer -> state == ENET_PEER_STATE_CONNECTION_SUCCEEDED) if (peer -> state == ENET_PEER_STATE_CONNECTION_SUCCEEDED)
peer -> state = ENET_PEER_STATE_ZOMBIE; enet_protocol_dispatch_state (host, peer, ENET_PEER_STATE_ZOMBIE);
else else
if (peer -> state != ENET_PEER_STATE_CONNECTED && peer -> state != ENET_PEER_STATE_DISCONNECT_LATER) if (peer -> state != ENET_PEER_STATE_CONNECTED && peer -> state != ENET_PEER_STATE_DISCONNECT_LATER)
{ {
@ -644,9 +663,11 @@ enet_protocol_handle_disconnect (ENetHost * host, ENetPeer * peer, const ENetPro
if (command -> header.command & ENET_PROTOCOL_COMMAND_FLAG_ACKNOWLEDGE) if (command -> header.command & ENET_PROTOCOL_COMMAND_FLAG_ACKNOWLEDGE)
peer -> state = ENET_PEER_STATE_ACKNOWLEDGING_DISCONNECT; peer -> state = ENET_PEER_STATE_ACKNOWLEDGING_DISCONNECT;
else else
peer -> state = ENET_PEER_STATE_ZOMBIE; enet_protocol_dispatch_state (host, peer, ENET_PEER_STATE_ZOMBIE);
if (peer -> state != ENET_PEER_STATE_DISCONNECTED)
peer -> eventData = ENET_NET_TO_HOST_32 (command -> disconnect.data);
peer -> disconnectData = ENET_NET_TO_HOST_32 (command -> disconnect.data);
return 0; return 0;
} }
@ -726,7 +747,7 @@ enet_protocol_handle_acknowledge (ENetHost * host, ENetEvent * event, ENetPeer *
if (enet_list_empty (& peer -> outgoingReliableCommands) && if (enet_list_empty (& peer -> outgoingReliableCommands) &&
enet_list_empty (& peer -> outgoingUnreliableCommands) && enet_list_empty (& peer -> outgoingUnreliableCommands) &&
enet_list_empty (& peer -> sentReliableCommands)) enet_list_empty (& peer -> sentReliableCommands))
enet_peer_disconnect (peer, peer -> disconnectData); enet_peer_disconnect (peer, peer -> eventData);
break; break;
} }
@ -736,27 +757,37 @@ enet_protocol_handle_acknowledge (ENetHost * host, ENetEvent * event, ENetPeer *
static int static int
enet_protocol_handle_verify_connect (ENetHost * host, ENetEvent * event, ENetPeer * peer, const ENetProtocol * command) enet_protocol_handle_verify_connect (ENetHost * host, ENetEvent * event, ENetPeer * peer, const ENetProtocol * command)
{ {
enet_uint16 mtu; enet_uint32 mtu, windowSize;
enet_uint32 windowSize; size_t channelCount;
if (peer -> state != ENET_PEER_STATE_CONNECTING) if (peer -> state != ENET_PEER_STATE_CONNECTING)
return 0; return 0;
if (ENET_NET_TO_HOST_32 (command -> verifyConnect.channelCount) != peer -> channelCount || channelCount = ENET_NET_TO_HOST_32 (command -> verifyConnect.channelCount);
if (channelCount < ENET_PROTOCOL_MINIMUM_CHANNEL_COUNT || channelCount > ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT ||
ENET_NET_TO_HOST_32 (command -> verifyConnect.packetThrottleInterval) != peer -> packetThrottleInterval || ENET_NET_TO_HOST_32 (command -> verifyConnect.packetThrottleInterval) != peer -> packetThrottleInterval ||
ENET_NET_TO_HOST_32 (command -> verifyConnect.packetThrottleAcceleration) != peer -> packetThrottleAcceleration || ENET_NET_TO_HOST_32 (command -> verifyConnect.packetThrottleAcceleration) != peer -> packetThrottleAcceleration ||
ENET_NET_TO_HOST_32 (command -> verifyConnect.packetThrottleDeceleration) != peer -> packetThrottleDeceleration) ENET_NET_TO_HOST_32 (command -> verifyConnect.packetThrottleDeceleration) != peer -> packetThrottleDeceleration ||
command -> verifyConnect.connectID != peer -> connectID)
{ {
peer -> state = ENET_PEER_STATE_ZOMBIE; peer -> eventData = 0;
enet_protocol_dispatch_state (host, peer, ENET_PEER_STATE_ZOMBIE);
return -1; return -1;
} }
enet_protocol_remove_sent_reliable_command (peer, 1, 0xFF); enet_protocol_remove_sent_reliable_command (peer, 1, 0xFF);
peer -> outgoingPeerID = ENET_NET_TO_HOST_16 (command -> verifyConnect.outgoingPeerID); if (channelCount < peer -> channelCount)
peer -> channelCount = channelCount;
mtu = ENET_NET_TO_HOST_16 (command -> verifyConnect.mtu); peer -> outgoingPeerID = ENET_NET_TO_HOST_16 (command -> verifyConnect.outgoingPeerID);
peer -> incomingSessionID = command -> verifyConnect.incomingSessionID;
peer -> outgoingSessionID = command -> verifyConnect.outgoingSessionID;
mtu = ENET_NET_TO_HOST_32 (command -> verifyConnect.mtu);
if (mtu < ENET_PROTOCOL_MINIMUM_MTU) if (mtu < ENET_PROTOCOL_MINIMUM_MTU)
mtu = ENET_PROTOCOL_MINIMUM_MTU; mtu = ENET_PROTOCOL_MINIMUM_MTU;
@ -794,15 +825,21 @@ enet_protocol_handle_incoming_commands (ENetHost * host, ENetEvent * event)
enet_uint8 * currentData; enet_uint8 * currentData;
size_t headerSize; size_t headerSize;
enet_uint16 peerID, flags; enet_uint16 peerID, flags;
enet_uint8 sessionID;
if (host -> receivedDataLength < sizeof (ENetProtocolHeader)) if (host -> receivedDataLength < (size_t) & ((ENetProtocolHeader *) 0) -> sentTime)
return 0; return 0;
header = (ENetProtocolHeader *) host -> receivedData; header = (ENetProtocolHeader *) host -> receivedData;
peerID = ENET_NET_TO_HOST_16 (header -> peerID); peerID = ENET_NET_TO_HOST_16 (header -> peerID);
sessionID = (peerID & ENET_PROTOCOL_HEADER_SESSION_MASK) >> ENET_PROTOCOL_HEADER_SESSION_SHIFT;
flags = peerID & ENET_PROTOCOL_HEADER_FLAG_MASK; flags = peerID & ENET_PROTOCOL_HEADER_FLAG_MASK;
peerID &= ~ ENET_PROTOCOL_HEADER_FLAG_MASK; peerID &= ~ (ENET_PROTOCOL_HEADER_FLAG_MASK | ENET_PROTOCOL_HEADER_SESSION_MASK);
headerSize = (flags & ENET_PROTOCOL_HEADER_FLAG_SENT_TIME ? sizeof (ENetProtocolHeader) : (size_t) & ((ENetProtocolHeader *) 0) -> sentTime);
if (host -> checksum != NULL)
headerSize += sizeof (enet_uint32);
if (peerID == ENET_PROTOCOL_MAXIMUM_PEER_ID) if (peerID == ENET_PROTOCOL_MAXIMUM_PEER_ID)
peer = NULL; peer = NULL;
@ -814,35 +851,55 @@ enet_protocol_handle_incoming_commands (ENetHost * host, ENetEvent * event)
peer = & host -> peers [peerID]; peer = & host -> peers [peerID];
if (peer -> state == ENET_PEER_STATE_DISCONNECTED || if (peer -> state == ENET_PEER_STATE_DISCONNECTED ||
peer -> state == ENET_PEER_STATE_ZOMBIE || peer -> state == ENET_PEER_STATE_ZOMBIE ||
(host -> receivedAddress.host != peer -> address.host && (host -> receivedAddress.host != peer -> address.host &&
peer -> address.host != ENET_HOST_BROADCAST)) peer -> address.host != ENET_HOST_BROADCAST) ||
(peer -> outgoingPeerID < ENET_PROTOCOL_MAXIMUM_PEER_ID &&
sessionID != peer -> incomingSessionID))
return 0; return 0;
}
if (flags & ENET_PROTOCOL_HEADER_FLAG_COMPRESSED)
{
size_t originalSize;
if (host -> compressor.context == NULL || host -> compressor.decompress == NULL)
return 0;
#ifdef USE_CRC32 originalSize = host -> compressor.decompress (host -> compressor.context,
{ host -> receivedData + headerSize,
enet_uint32 crc = header -> checksum; host -> receivedDataLength - headerSize,
ENetBuffer buffer; host -> packetData [1] + headerSize,
sizeof (host -> packetData [1]) - headerSize);
if (originalSize <= 0 || originalSize > sizeof (host -> packetData [1]) - headerSize)
return 0;
header -> checksum = peer -> sessionID; memcpy (host -> packetData [1], header, headerSize);
host -> receivedData = host -> packetData [1];
host -> receivedDataLength = headerSize + originalSize;
}
buffer.data = host -> receivedData; if (host -> checksum != NULL)
buffer.dataLength = host -> receivedDataLength; {
enet_uint32 * checksum = (enet_uint32 *) & host -> receivedData [headerSize - sizeof (enet_uint32)],
desiredChecksum = * checksum;
ENetBuffer buffer;
if (enet_crc32 (& buffer, 1) != crc) * checksum = peer != NULL ? peer -> connectID : 0;
return 0;
}
#else
if (header -> checksum != peer -> sessionID)
return 0;
#endif
buffer.data = host -> receivedData;
buffer.dataLength = host -> receivedDataLength;
if (host -> checksum (& buffer, 1) != desiredChecksum)
return 0;
}
if (peer != NULL)
{
peer -> address.host = host -> receivedAddress.host; peer -> address.host = host -> receivedAddress.host;
peer -> address.port = host -> receivedAddress.port; peer -> address.port = host -> receivedAddress.port;
peer -> incomingDataTotal += host -> receivedDataLength; peer -> incomingDataTotal += host -> receivedDataLength;
} }
headerSize = (flags & ENET_PROTOCOL_HEADER_FLAG_SENT_TIME ? sizeof (ENetProtocolHeader) : (size_t) & ((ENetProtocolHeader *) 0) -> sentTime);
currentData = host -> receivedData + headerSize; currentData = host -> receivedData + headerSize;
while (currentData < & host -> receivedData [host -> receivedDataLength]) while (currentData < & host -> receivedData [host -> receivedDataLength])
@ -975,8 +1032,8 @@ enet_protocol_receive_incoming_commands (ENetHost * host, ENetEvent * event)
int receivedLength; int receivedLength;
ENetBuffer buffer; ENetBuffer buffer;
buffer.data = host -> receivedData; buffer.data = host -> packetData [0];
buffer.dataLength = sizeof (host -> receivedData); buffer.dataLength = sizeof (host -> packetData [0]);
receivedLength = enet_socket_receive (host -> socket, receivedLength = enet_socket_receive (host -> socket,
& host -> receivedAddress, & host -> receivedAddress,
@ -989,8 +1046,12 @@ enet_protocol_receive_incoming_commands (ENetHost * host, ENetEvent * event)
if (receivedLength == 0) if (receivedLength == 0)
return 0; return 0;
host -> receivedData = host -> packetData [0];
host -> receivedDataLength = receivedLength; host -> receivedDataLength = receivedLength;
host -> totalReceivedData += receivedLength;
host -> totalReceivedPackets ++;
switch (enet_protocol_handle_incoming_commands (host, event)) switch (enet_protocol_handle_incoming_commands (host, event))
{ {
case 1: case 1:
@ -1043,7 +1104,7 @@ enet_protocol_send_acknowledgements (ENetHost * host, ENetPeer * peer)
command -> acknowledge.receivedSentTime = ENET_HOST_TO_NET_16 (acknowledgement -> sentTime); command -> acknowledge.receivedSentTime = ENET_HOST_TO_NET_16 (acknowledgement -> sentTime);
if ((acknowledgement -> command.header.command & ENET_PROTOCOL_COMMAND_MASK) == ENET_PROTOCOL_COMMAND_DISCONNECT) if ((acknowledgement -> command.header.command & ENET_PROTOCOL_COMMAND_MASK) == ENET_PROTOCOL_COMMAND_DISCONNECT)
peer -> state = ENET_PEER_STATE_ZOMBIE; enet_protocol_dispatch_state (host, peer, ENET_PEER_STATE_ZOMBIE);
enet_list_remove (& acknowledgement -> acknowledgementList); enet_list_remove (& acknowledgement -> acknowledgementList);
enet_free (acknowledgement); enet_free (acknowledgement);
@ -1139,7 +1200,7 @@ enet_protocol_send_unreliable_outgoing_commands (ENetHost * host, ENetPeer * pee
enet_list_empty (& peer -> outgoingReliableCommands) && enet_list_empty (& peer -> outgoingReliableCommands) &&
enet_list_empty (& peer -> outgoingUnreliableCommands) && enet_list_empty (& peer -> outgoingUnreliableCommands) &&
enet_list_empty (& peer -> sentReliableCommands)) enet_list_empty (& peer -> sentReliableCommands))
enet_peer_disconnect (peer, peer -> disconnectData); enet_peer_disconnect (peer, peer -> eventData);
} }
static int static int
@ -1195,7 +1256,7 @@ enet_protocol_check_timeouts (ENetHost * host, ENetPeer * peer, ENetEvent * even
return 0; return 0;
} }
static void static int
enet_protocol_send_reliable_outgoing_commands (ENetHost * host, ENetPeer * peer) enet_protocol_send_reliable_outgoing_commands (ENetHost * host, ENetPeer * peer)
{ {
ENetProtocol * command = & host -> commands [host -> commandCount]; ENetProtocol * command = & host -> commands [host -> commandCount];
@ -1205,6 +1266,7 @@ enet_protocol_send_reliable_outgoing_commands (ENetHost * host, ENetPeer * peer)
ENetChannel *channel; ENetChannel *channel;
enet_uint16 reliableWindow; enet_uint16 reliableWindow;
size_t commandSize; size_t commandSize;
int windowExceeded = 0, windowWrap = 0, canPing = 1;
currentCommand = enet_list_begin (& peer -> outgoingReliableCommands); currentCommand = enet_list_begin (& peer -> outgoingReliableCommands);
@ -1214,37 +1276,54 @@ enet_protocol_send_reliable_outgoing_commands (ENetHost * host, ENetPeer * peer)
channel = outgoingCommand -> command.header.channelID < peer -> channelCount ? & peer -> channels [outgoingCommand -> command.header.channelID] : NULL; channel = outgoingCommand -> command.header.channelID < peer -> channelCount ? & peer -> channels [outgoingCommand -> command.header.channelID] : NULL;
reliableWindow = outgoingCommand -> reliableSequenceNumber / ENET_PEER_RELIABLE_WINDOW_SIZE; reliableWindow = outgoingCommand -> reliableSequenceNumber / ENET_PEER_RELIABLE_WINDOW_SIZE;
if (channel != NULL && if (channel != NULL)
outgoingCommand -> sendAttempts < 1 && {
! (outgoingCommand -> reliableSequenceNumber % ENET_PEER_RELIABLE_WINDOW_SIZE) && if (! windowWrap &&
(channel -> reliableWindows [(reliableWindow + ENET_PEER_RELIABLE_WINDOWS - 1) % ENET_PEER_RELIABLE_WINDOWS] >= ENET_PEER_RELIABLE_WINDOW_SIZE || outgoingCommand -> sendAttempts < 1 &&
channel -> usedReliableWindows & ((((1 << ENET_PEER_FREE_RELIABLE_WINDOWS) - 1) << reliableWindow) | ! (outgoingCommand -> reliableSequenceNumber % ENET_PEER_RELIABLE_WINDOW_SIZE) &&
(((1 << ENET_PEER_FREE_RELIABLE_WINDOWS) - 1) >> (ENET_PEER_RELIABLE_WINDOW_SIZE - reliableWindow))))) (channel -> reliableWindows [(reliableWindow + ENET_PEER_RELIABLE_WINDOWS - 1) % ENET_PEER_RELIABLE_WINDOWS] >= ENET_PEER_RELIABLE_WINDOW_SIZE ||
break; channel -> usedReliableWindows & ((((1 << ENET_PEER_FREE_RELIABLE_WINDOWS) - 1) << reliableWindow) |
(((1 << ENET_PEER_FREE_RELIABLE_WINDOWS) - 1) >> (ENET_PEER_RELIABLE_WINDOW_SIZE - reliableWindow)))))
windowWrap = 1;
if (windowWrap)
{
currentCommand = enet_list_next (currentCommand);
continue;
}
}
if (outgoingCommand -> packet != NULL)
{
if (! windowExceeded)
{
enet_uint32 windowSize = (peer -> packetThrottle * peer -> windowSize) / ENET_PEER_PACKET_THROTTLE_SCALE;
if (peer -> reliableDataInTransit + outgoingCommand -> fragmentLength > ENET_MAX (windowSize, peer -> mtu))
windowExceeded = 1;
}
if (windowExceeded)
{
currentCommand = enet_list_next (currentCommand);
continue;
}
}
canPing = 0;
commandSize = commandSizes [outgoingCommand -> command.header.command & ENET_PROTOCOL_COMMAND_MASK]; commandSize = commandSizes [outgoingCommand -> command.header.command & ENET_PROTOCOL_COMMAND_MASK];
if (command >= & host -> commands [sizeof (host -> commands) / sizeof (ENetProtocol)] || if (command >= & host -> commands [sizeof (host -> commands) / sizeof (ENetProtocol)] ||
buffer + 1 >= & host -> buffers [sizeof (host -> buffers) / sizeof (ENetBuffer)] || buffer + 1 >= & host -> buffers [sizeof (host -> buffers) / sizeof (ENetBuffer)] ||
peer -> mtu - host -> packetSize < commandSize) peer -> mtu - host -> packetSize < commandSize ||
(outgoingCommand -> packet != NULL &&
(enet_uint16) (peer -> mtu - host -> packetSize) < (enet_uint16) (commandSize + outgoingCommand -> fragmentLength)))
{ {
host -> continueSending = 1; host -> continueSending = 1;
break; break;
} }
if (outgoingCommand -> packet != NULL)
{
if (peer -> reliableDataInTransit + outgoingCommand -> fragmentLength > peer -> windowSize)
break;
if ((enet_uint16) (peer -> mtu - host -> packetSize) < (enet_uint16) (commandSize + outgoingCommand -> fragmentLength))
{
host -> continueSending = 1;
break;
}
}
currentCommand = enet_list_next (currentCommand); currentCommand = enet_list_next (currentCommand);
if (channel != NULL && outgoingCommand -> sendAttempts < 1) if (channel != NULL && outgoingCommand -> sendAttempts < 1)
@ -1297,15 +1376,19 @@ enet_protocol_send_reliable_outgoing_commands (ENetHost * host, ENetPeer * peer)
host -> commandCount = command - host -> commands; host -> commandCount = command - host -> commands;
host -> bufferCount = buffer - host -> buffers; host -> bufferCount = buffer - host -> buffers;
return canPing;
} }
static int static int
enet_protocol_send_outgoing_commands (ENetHost * host, ENetEvent * event, int checkForTimeouts) enet_protocol_send_outgoing_commands (ENetHost * host, ENetEvent * event, int checkForTimeouts)
{ {
ENetProtocolHeader header; enet_uint8 headerData [sizeof (ENetProtocolHeader) + sizeof (enet_uint32)];
ENetProtocolHeader * header = (ENetProtocolHeader *) headerData;
ENetPeer * currentPeer; ENetPeer * currentPeer;
int sentLength; int sentLength;
size_t shouldCompress = 0;
host -> continueSending = 1; host -> continueSending = 1;
while (host -> continueSending) while (host -> continueSending)
@ -1332,10 +1415,9 @@ enet_protocol_send_outgoing_commands (ENetHost * host, ENetEvent * event, int ch
enet_protocol_check_timeouts (host, currentPeer, event) == 1) enet_protocol_check_timeouts (host, currentPeer, event) == 1)
return 1; return 1;
if (! enet_list_empty (& currentPeer -> outgoingReliableCommands)) if ((enet_list_empty (& currentPeer -> outgoingReliableCommands) ||
enet_protocol_send_reliable_outgoing_commands (host, currentPeer); enet_protocol_send_reliable_outgoing_commands (host, currentPeer)) &&
else enet_list_empty (& currentPeer -> sentReliableCommands) &&
if (enet_list_empty (& currentPeer -> sentReliableCommands) &&
ENET_TIME_DIFFERENCE (host -> serviceTime, currentPeer -> lastReceiveTime) >= ENET_PEER_PING_INTERVAL && ENET_TIME_DIFFERENCE (host -> serviceTime, currentPeer -> lastReceiveTime) >= ENET_PEER_PING_INTERVAL &&
currentPeer -> mtu - host -> packetSize >= sizeof (ENetProtocolPing)) currentPeer -> mtu - host -> packetSize >= sizeof (ENetProtocolPing))
{ {
@ -1384,22 +1466,57 @@ enet_protocol_send_outgoing_commands (ENetHost * host, ENetEvent * event, int ch
currentPeer -> packetsLost = 0; currentPeer -> packetsLost = 0;
} }
header.checksum = currentPeer -> sessionID; host -> buffers -> data = headerData;
header.peerID = ENET_HOST_TO_NET_16 (currentPeer -> outgoingPeerID | host -> headerFlags);
host -> buffers -> data = & header;
if (host -> headerFlags & ENET_PROTOCOL_HEADER_FLAG_SENT_TIME) if (host -> headerFlags & ENET_PROTOCOL_HEADER_FLAG_SENT_TIME)
{ {
header.sentTime = ENET_HOST_TO_NET_16 (host -> serviceTime & 0xFFFF); header -> sentTime = ENET_HOST_TO_NET_16 (host -> serviceTime & 0xFFFF);
host -> buffers -> dataLength = sizeof (ENetProtocolHeader); host -> buffers -> dataLength = sizeof (ENetProtocolHeader);
} }
else else
host -> buffers -> dataLength = (size_t) & ((ENetProtocolHeader *) 0) -> sentTime; host -> buffers -> dataLength = (size_t) & ((ENetProtocolHeader *) 0) -> sentTime;
#ifdef USE_CRC32 shouldCompress = 0;
header.checksum = enet_crc32 (host -> buffers, host -> bufferCount); if (host -> compressor.context != NULL && host -> compressor.compress != NULL)
{
size_t originalSize = host -> packetSize - sizeof(ENetProtocolHeader),
compressedSize = host -> compressor.compress (host -> compressor.context,
& host -> buffers [1], host -> bufferCount - 1,
originalSize,
host -> packetData [1],
originalSize);
if (compressedSize > 0 && compressedSize < originalSize)
{
host -> headerFlags |= ENET_PROTOCOL_HEADER_FLAG_COMPRESSED;
shouldCompress = compressedSize;
#ifdef ENET_DEBUG_COMPRESS
#ifdef WIN32
printf (
#else
fprintf (stderr,
#endif #endif
"peer %u: compressed %u -> %u (%u%%)\n", currentPeer -> incomingPeerID, originalSize, compressedSize, (compressedSize * 100) / originalSize);
#endif
}
}
if (currentPeer -> outgoingPeerID < ENET_PROTOCOL_MAXIMUM_PEER_ID)
host -> headerFlags |= currentPeer -> outgoingSessionID << ENET_PROTOCOL_HEADER_SESSION_SHIFT;
header -> peerID = ENET_HOST_TO_NET_16 (currentPeer -> outgoingPeerID | host -> headerFlags);
if (host -> checksum != NULL)
{
enet_uint32 * checksum = (enet_uint32 *) & headerData [host -> buffers -> dataLength];
* checksum = currentPeer -> outgoingPeerID < ENET_PROTOCOL_MAXIMUM_PEER_ID ? currentPeer -> connectID : 0;
host -> buffers -> dataLength += sizeof (enet_uint32);
* checksum = host -> checksum (host -> buffers, host -> bufferCount);
}
if (shouldCompress > 0)
{
host -> buffers [1].data = host -> packetData [1];
host -> buffers [1].dataLength = shouldCompress;
host -> bufferCount = 2;
}
currentPeer -> lastSendTime = host -> serviceTime; currentPeer -> lastSendTime = host -> serviceTime;
@ -1409,6 +1526,9 @@ enet_protocol_send_outgoing_commands (ENetHost * host, ENetEvent * event, int ch
if (sentLength < 0) if (sentLength < 0)
return -1; return -1;
host -> totalSentData += sentLength;
host -> totalSentPackets ++;
} }
return 0; return 0;

View File

@ -80,7 +80,7 @@ enet_address_set_host (ENetAddress * address, const char * name)
char buffer [2048]; char buffer [2048];
int errnum; int errnum;
#if defined(linux) || defined(__FreeBSD__) #if defined(linux) || defined(__linux) || defined(__linux__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
gethostbyname_r (name, & hostData, buffer, sizeof (buffer), & hostEntry, & errnum); gethostbyname_r (name, & hostData, buffer, sizeof (buffer), & hostEntry, & errnum);
#else #else
hostEntry = gethostbyname_r (name, & hostData, buffer, sizeof (buffer), & errnum); hostEntry = gethostbyname_r (name, & hostData, buffer, sizeof (buffer), & errnum);
@ -133,7 +133,7 @@ enet_address_get_host (const ENetAddress * address, char * name, size_t nameLeng
in.s_addr = address -> host; in.s_addr = address -> host;
#if defined(linux) || defined(__FreeBSD__) #if defined(linux) || defined(__linux) || defined(__linux__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
gethostbyaddr_r ((char *) & in, sizeof (struct in_addr), AF_INET, & hostData, buffer, sizeof (buffer), & hostEntry, & errnum); gethostbyaddr_r ((char *) & in, sizeof (struct in_addr), AF_INET, & hostData, buffer, sizeof (buffer), & hostEntry, & errnum);
#else #else
hostEntry = gethostbyaddr_r ((char *) & in, sizeof (struct in_addr), AF_INET, & hostData, buffer, sizeof (buffer), & errnum); hostEntry = gethostbyaddr_r ((char *) & in, sizeof (struct in_addr), AF_INET, & hostData, buffer, sizeof (buffer), & errnum);
@ -152,37 +152,41 @@ enet_address_get_host (const ENetAddress * address, char * name, size_t nameLeng
return 0; return 0;
} }
ENetSocket int
enet_socket_create (ENetSocketType type, const ENetAddress * address) enet_socket_bind (ENetSocket socket, const ENetAddress * address)
{ {
ENetSocket newSocket = socket (PF_INET, type == ENET_SOCKET_TYPE_DATAGRAM ? SOCK_DGRAM : SOCK_STREAM, 0);
struct sockaddr_in sin; struct sockaddr_in sin;
if (newSocket == ENET_SOCKET_NULL)
return ENET_SOCKET_NULL;
if (address == NULL)
return newSocket;
memset (& sin, 0, sizeof (struct sockaddr_in)); memset (& sin, 0, sizeof (struct sockaddr_in));
sin.sin_family = AF_INET; sin.sin_family = AF_INET;
sin.sin_port = ENET_HOST_TO_NET_16 (address -> port);
sin.sin_addr.s_addr = address -> host;
if (bind (newSocket, if (address != NULL)
(struct sockaddr *) & sin,
sizeof (struct sockaddr_in)) == -1 ||
(type == ENET_SOCKET_TYPE_STREAM &&
address -> port != ENET_PORT_ANY &&
listen (newSocket, SOMAXCONN) == -1))
{ {
close (newSocket); sin.sin_port = ENET_HOST_TO_NET_16 (address -> port);
sin.sin_addr.s_addr = address -> host;
return ENET_SOCKET_NULL; }
else
{
sin.sin_port = 0;
sin.sin_addr.s_addr = INADDR_ANY;
} }
return newSocket; return bind (socket,
(struct sockaddr *) & sin,
sizeof (struct sockaddr_in));
}
int
enet_socket_listen (ENetSocket socket, int backlog)
{
return listen (socket, backlog < 0 ? SOMAXCONN : backlog);
}
ENetSocket
enet_socket_create (ENetSocketType type)
{
return socket (PF_INET, type == ENET_SOCKET_TYPE_DATAGRAM ? SOCK_DGRAM : SOCK_STREAM, 0);
} }
int int
@ -203,6 +207,10 @@ enet_socket_set_option (ENetSocket socket, ENetSocketOption option, int value)
result = setsockopt (socket, SOL_SOCKET, SO_BROADCAST, (char *) & value, sizeof (int)); result = setsockopt (socket, SOL_SOCKET, SO_BROADCAST, (char *) & value, sizeof (int));
break; break;
case ENET_SOCKOPT_REUSEADDR:
result = setsockopt (socket, SOL_SOCKET, SO_REUSEADDR, (char *) & value, sizeof (int));
break;
case ENET_SOCKOPT_RCVBUF: case ENET_SOCKOPT_RCVBUF:
result = setsockopt (socket, SOL_SOCKET, SO_RCVBUF, (char *) & value, sizeof (int)); result = setsockopt (socket, SOL_SOCKET, SO_RCVBUF, (char *) & value, sizeof (int));
break; break;
@ -274,6 +282,8 @@ enet_socket_send (ENetSocket socket,
if (address != NULL) if (address != NULL)
{ {
memset (& sin, 0, sizeof (struct sockaddr_in));
sin.sin_family = AF_INET; sin.sin_family = AF_INET;
sin.sin_port = ENET_HOST_TO_NET_16 (address -> port); sin.sin_port = ENET_HOST_TO_NET_16 (address -> port);
sin.sin_addr.s_addr = address -> host; sin.sin_addr.s_addr = address -> host;
@ -343,6 +353,17 @@ enet_socket_receive (ENetSocket socket,
return recvLength; return recvLength;
} }
int
enet_socketset_select (ENetSocket maxSocket, ENetSocketSet * readSet, ENetSocketSet * writeSet, enet_uint32 timeout)
{
struct timeval timeVal;
timeVal.tv_sec = timeout / 1000;
timeVal.tv_usec = (timeout % 1000) * 1000;
return select (maxSocket + 1, readSet, writeSet, NULL, & timeVal);
}
int int
enet_socket_wait (ENetSocket socket, enet_uint32 * condition, enet_uint32 timeout) enet_socket_wait (ENetSocket socket, enet_uint32 * condition, enet_uint32 timeout)
{ {

View File

@ -100,19 +100,15 @@ enet_address_get_host (const ENetAddress * address, char * name, size_t nameLeng
return 0; return 0;
} }
ENetSocket int
enet_socket_create (ENetSocketType type, const ENetAddress * address) enet_socket_bind (ENetSocket socket, const ENetAddress * address)
{ {
ENetSocket newSocket = socket (PF_INET, type == ENET_SOCKET_TYPE_DATAGRAM ? SOCK_DGRAM : SOCK_STREAM, 0);
struct sockaddr_in sin; struct sockaddr_in sin;
if (newSocket == ENET_SOCKET_NULL)
return ENET_SOCKET_NULL;
memset (& sin, 0, sizeof (struct sockaddr_in)); memset (& sin, 0, sizeof (struct sockaddr_in));
sin.sin_family = AF_INET; sin.sin_family = AF_INET;
if (address != NULL) if (address != NULL)
{ {
sin.sin_port = ENET_HOST_TO_NET_16 (address -> port); sin.sin_port = ENET_HOST_TO_NET_16 (address -> port);
@ -124,20 +120,21 @@ enet_socket_create (ENetSocketType type, const ENetAddress * address)
sin.sin_addr.s_addr = INADDR_ANY; sin.sin_addr.s_addr = INADDR_ANY;
} }
if (bind (newSocket, return bind (socket,
(struct sockaddr *) & sin, (struct sockaddr *) & sin,
sizeof (struct sockaddr_in)) == SOCKET_ERROR || sizeof (struct sockaddr_in)) == SOCKET_ERROR ? -1 : 0;
(type == ENET_SOCKET_TYPE_STREAM && }
address != NULL &&
address -> port != ENET_PORT_ANY &&
listen (newSocket, SOMAXCONN) == SOCKET_ERROR))
{
closesocket (newSocket);
return ENET_SOCKET_NULL; int
} enet_socket_listen (ENetSocket socket, int backlog)
{
return listen (socket, backlog < 0 ? SOMAXCONN : backlog) == SOCKET_ERROR ? -1 : 0;
}
return newSocket; ENetSocket
enet_socket_create (ENetSocketType type)
{
return socket (PF_INET, type == ENET_SOCKET_TYPE_DATAGRAM ? SOCK_DGRAM : SOCK_STREAM, 0);
} }
int int
@ -157,6 +154,10 @@ enet_socket_set_option (ENetSocket socket, ENetSocketOption option, int value)
result = setsockopt (socket, SOL_SOCKET, SO_BROADCAST, (char *) & value, sizeof (int)); result = setsockopt (socket, SOL_SOCKET, SO_BROADCAST, (char *) & value, sizeof (int));
break; break;
case ENET_SOCKOPT_REUSEADDR:
result = setsockopt (socket, SOL_SOCKET, SO_REUSEADDR, (char *) & value, sizeof (int));
break;
case ENET_SOCKOPT_RCVBUF: case ENET_SOCKOPT_RCVBUF:
result = setsockopt (socket, SOL_SOCKET, SO_RCVBUF, (char *) & value, sizeof (int)); result = setsockopt (socket, SOL_SOCKET, SO_RCVBUF, (char *) & value, sizeof (int));
break; break;
@ -182,7 +183,7 @@ enet_socket_connect (ENetSocket socket, const ENetAddress * address)
sin.sin_port = ENET_HOST_TO_NET_16 (address -> port); sin.sin_port = ENET_HOST_TO_NET_16 (address -> port);
sin.sin_addr.s_addr = address -> host; sin.sin_addr.s_addr = address -> host;
return connect (socket, (struct sockaddr *) & sin, sizeof (struct sockaddr_in)); return connect (socket, (struct sockaddr *) & sin, sizeof (struct sockaddr_in)) == SOCKET_ERROR ? -1 : 0;
} }
ENetSocket ENetSocket
@ -225,6 +226,8 @@ enet_socket_send (ENetSocket socket,
if (address != NULL) if (address != NULL)
{ {
memset (& sin, 0, sizeof (struct sockaddr_in));
sin.sin_family = AF_INET; sin.sin_family = AF_INET;
sin.sin_port = ENET_HOST_TO_NET_16 (address -> port); sin.sin_port = ENET_HOST_TO_NET_16 (address -> port);
sin.sin_addr.s_addr = address -> host; sin.sin_addr.s_addr = address -> host;
@ -292,6 +295,17 @@ enet_socket_receive (ENetSocket socket,
return (int) recvLength; return (int) recvLength;
} }
int
enet_socketset_select (ENetSocket maxSocket, ENetSocketSet * readSet, ENetSocketSet * writeSet, enet_uint32 timeout)
{
struct timeval timeVal;
timeVal.tv_sec = timeout / 1000;
timeVal.tv_usec = (timeout % 1000) * 1000;
return select (maxSocket + 1, readSet, writeSet, NULL, & timeVal);
}
int int
enet_socket_wait (ENetSocket socket, enet_uint32 * condition, enet_uint32 timeout) enet_socket_wait (ENetSocket socket, enet_uint32 * condition, enet_uint32 timeout)
{ {

View File

@ -219,6 +219,10 @@
RelativePath="..\..\enet\callbacks.c" RelativePath="..\..\enet\callbacks.c"
> >
</File> </File>
<File
RelativePath="..\..\enet\compress.c"
>
</File>
<File <File
RelativePath="..\..\enet\host.c" RelativePath="..\..\enet\host.c"
> >