Skip to content

Commit

Permalink
Update to 2.3.6
Browse files Browse the repository at this point in the history
  • Loading branch information
nxrighthere committed Mar 30, 2020
1 parent fe59115 commit 6b0f572
Show file tree
Hide file tree
Showing 13 changed files with 3,664 additions and 7,123 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ language: c
compiler: clang

script:
- cmake ./Source/Native/ -DCMAKE_BUILD_TYPE=Release -DENET_SHARED=1 -DENET_LZ4=1
- cmake ./Source/Native/ -DCMAKE_BUILD_TYPE=Release -DENET_SHARED=1
- cmake --build .

deploy:
Expand Down
2 changes: 1 addition & 1 deletion ENet-CSharp.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>ENet-CSharp</id>
<version>2.3.5</version>
<version>2.3.6</version>
<title>ENet-CSharp</title>
<authors>Stanislav Denisov</authors>
<owners>nxrighthere</owners>
Expand Down
23 changes: 12 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ Features:
- Channels
- Reliability
- Fragmentation and reassembly
- Compression
- Aggregation
- Adaptability
- Portability
Expand All @@ -37,8 +36,6 @@ For mobile platforms [NDK](https://developer.android.com/ndk/downloads/) for And

To build the library for Nintendo Switch, follow [this](https://pastebin.com/raw/rbjLgMV2) guide.

Define `ENET_LZ4` to build the library with support for an optional packet-level compression.

A managed assembly can be built using any available compiling platform that supports C# 3.0 or higher.

Compiled libraries
Expand Down Expand Up @@ -235,14 +232,18 @@ Definitions of a flags for `Peer.Send()` function:

`PacketFlags.Instant` a packet will not be bundled with other packets at a next service iteration and sent instantly instead. This delivery type trades multiplexing efficiency in favor of latency. The same packet can't be used for multiple `Peer.Send()` calls.

`PacketFlags.Crucial` a packet should not be dropped due to throttling and must be delivered if possible.

`PacketFlags.Sent` a packet was sent from all queues it has entered.

#### EventType
Definitions of event types for `Event.Type` property:

`EventType.None` no event occurred within the specified time limit.

`EventType.Connect` a connection request initiated by `Peer.Connect()` function has completed. `Event.Peer` returns a peer which successfully connected. `Event.Data` returns user-supplied data describing the connection or 0 if none is available.
`EventType.Connect` a connection request initiated by `Peer.Connect()` function has completed. `Event.Peer` returns a peer which successfully connected. `Event.Data` returns the user-supplied data describing the connection or 0 if none is available.

`EventType.Disconnect` a peer has disconnected. This event is generated on a successful completion of a disconnect initiated by `Peer.Disconnect`. `Event.Peer` returns a peer which disconnected. `Event.Data` returns user-supplied data describing the disconnection or 0 if none is available.
`EventType.Disconnect` a peer has disconnected. This event is generated on a successful completion of a disconnect initiated by `Peer.Disconnect`. `Event.Peer` returns a peer which disconnected. `Event.Data` returns the user-supplied data describing the disconnection or 0 if none is available.

`EventType.Receive` a packet has been received from a peer. `Event.Peer` returns a peer which sent the packet. `Event.ChannelID` specifies the channel number upon which the packet was received. `Event.Packet` returns a packet that was received, and this packet must be destroyed using `Event.Packet.Dispose()` function after use.

Expand Down Expand Up @@ -282,7 +283,7 @@ Provides per packet events.
#### Address
Contains structure with anonymous host data and port number.

`Address.Port` sets or gets a port number.
`Address.Port` gets or sets a port number.

`Address.GetIP()` gets an IP address.

Expand All @@ -293,15 +294,15 @@ Contains structure with anonymous host data and port number.
`Address.SetHost(string hostName)` sets host name or an IP address. Should be used for binding to a network interface or for connection to a foreign host. Returns true on success or false on failure.

#### Event
Contains structure with the event type, managed pointer to the peer, channel ID, user-supplied data, and managed pointer to the packet.
Contains structure with the event type, managed pointer to the peer, channel ID, the user-supplied data, and managed pointer to the packet.

`Event.Type` returns a type of the event.

`Event.Peer` returns a peer that generated a connect, disconnect, receive or a timeout event.

`Event.ChannelID` returns a channel ID on the peer that generated the event, if appropriate.

`Event.Data` returns user-supplied data, if appropriate.
`Event.Data` returns the user-supplied data, if appropriate.

`Event.Packet` returns a packet associated with the event, if appropriate.

Expand All @@ -314,6 +315,8 @@ Contains a managed pointer to the packet.

`Packet.Data` returns a managed pointer to the packet data.

`Packet.UserData` gets or sets the user-supplied data.

`Packet.Length` returns a length of payload in the packet.

`Packet.HasReferences` checks references to the packet.
Expand Down Expand Up @@ -395,15 +398,13 @@ Contains a managed pointer to the host.

`Host.Create(Address? address, int peerLimit, int channelLimit, uint incomingBandwidth, uint outgoingBandwidth, int bufferSize)` creates a host for communicating with peers. The bandwidth parameters determine the window size of a connection which limits the number of reliable packets that may be in transit at any given time. ENet will strategically drop packets on specific sides of a connection between hosts to ensure the host's bandwidth is not overwhelmed. The buffer size parameter is used to set the socket buffer size for sending and receiving datagrams. All the parameters are optional except the address and peer limit in cases where the function is used to create a host which will listen for incoming connections.

`Host.EnableCompression()` enables packet-level compression.

`Host.PreventConnections(bool state)` prevents access to the host for new incoming connections. This function makes the host completely invisible from outside, any peer that attempts to connect to it will be timed out.

`Host.Broadcast(byte channelID, ref Packet packet, Peer[] peers)` queues a packet to be sent to a range of peers or to all peers associated with the host if the optional peers parameter is not used. Any zeroed `Peer` structure in an array will be excluded from the broadcast. Instead of an array, a single `Peer` can be passed to function which will be excluded from the broadcast.

`Host.CheckEvents(out Event @event)` checks for any queued events on the host and dispatches one if available. Returns > 0 if an event was dispatched, 0 if no events are available, < 0 on failure.

`Host.Connect(Address address, int channelLimit, uint data)` initiates a connection to a foreign host. Returns a peer representing the foreign host on success or throws an exception on failure. The peer returned will not have completed the connection until `Host.Service()` notifies of an `EventType.Connect` event. The channel limit and user-supplied data parameters are optional.
`Host.Connect(Address address, int channelLimit, uint data)` initiates a connection to a foreign host. Returns a peer representing the foreign host on success or throws an exception on failure. The peer returned will not have completed the connection until `Host.Service()` notifies of an `EventType.Connect` event. The channel limit and the user-supplied data parameters are optional.

`Host.Service(int timeout, out Event @event)` waits for events on the specified host and shuttles packets between the host and its peers. ENet uses a polled event model to notify the user of significant events. ENet hosts are polled for events with this function, where an optional timeout value in milliseconds may be specified to control how long ENet will poll. If a timeout of 0 is specified, this function will return immediately if there are no events to dispatch. Otherwise, it will return 1 if an event was dispatched within the specified timeout. This function should be regularly called to ensure packets are sent and received, otherwise, traffic spikes will occur leading to increased latency. The timeout parameter set to 0 means non-blocking which required for cases where the function is called in a game loop.

Expand Down
1 change: 0 additions & 1 deletion Source/Managed/ENet-CSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFrameworks>netstandard2.0;netcoreapp2.0</TargetFrameworks>
<TieredCompilation>True</TieredCompilation>
<RootNamespace>ENet</RootNamespace>
<LangVersion>3</LangVersion>
</PropertyGroup>
Expand Down
37 changes: 25 additions & 12 deletions Source/Managed/ENet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ public enum PacketFlags {
Unsequenced = 1 << 1,
NoAllocate = 1 << 2,
UnreliableFragmented = 1 << 3,
Instant = 1 << 4
Instant = 1 << 4,
Crucial = 1 << 5,
Sent = 1 << 8
}

public enum EventType {
Expand Down Expand Up @@ -275,6 +277,20 @@ public IntPtr Data {
}
}

public IntPtr UserData {
get {
CheckCreated();

return Native.enet_packet_get_user_data(nativePacket);
}

set {
CheckCreated();

Native.enet_packet_set_user_data(nativePacket, value);
}
}

public int Length {
get {
CheckCreated();
Expand Down Expand Up @@ -505,12 +521,6 @@ public void Create(Address? address, int peerLimit, int channelLimit, uint incom
throw new InvalidOperationException("Host creation call failed");
}

public void EnableCompression() {
CheckCreated();

Native.enet_host_enable_compression(nativeHost);
}

public void PreventConnections(bool state) {
CheckCreated();

Expand Down Expand Up @@ -874,7 +884,7 @@ public static class Library {
public const uint timeoutLimit = 32;
public const uint timeoutMinimum = 5000;
public const uint timeoutMaximum = 30000;
public const uint version = (2 << 16) | (3 << 8) | (5);
public const uint version = (2 << 16) | (3 << 8) | (6);

public static bool Initialize() {
return Native.enet_initialize() == 0;
Expand Down Expand Up @@ -947,6 +957,12 @@ internal static class Native {
[DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
internal static extern IntPtr enet_packet_get_data(IntPtr packet);

[DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
internal static extern IntPtr enet_packet_get_user_data(IntPtr packet);

[DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
internal static extern IntPtr enet_packet_set_user_data(IntPtr packet, IntPtr userData);

[DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
internal static extern int enet_packet_get_length(IntPtr packet);

Expand Down Expand Up @@ -1007,9 +1023,6 @@ internal static class Native {
[DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
internal static extern void enet_host_destroy(IntPtr host);

[DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
internal static extern void enet_host_enable_compression(IntPtr host);

[DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
internal static extern void enet_host_prevent_connections(IntPtr host, byte state);

Expand Down Expand Up @@ -1085,4 +1098,4 @@ internal static class Native {
[DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
internal static extern void enet_peer_reset(IntPtr peer);
}
}
}
15 changes: 8 additions & 7 deletions Source/Native/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ project(enet C)
set(ENET_DEBUG "0" CACHE BOOL "Enable debug functionality")
set(ENET_STATIC "0" CACHE BOOL "Create a static library")
set(ENET_SHARED "0" CACHE BOOL "Create a shared library")
set(ENET_LZ4 "0" CACHE BOOL "Add support for an optional packet-level compression")

if (ENET_DEBUG)
add_definitions(-DENET_DEBUG)
if (MSYS OR MINGW)
set(CMAKE_C_FLAGS "-static")

add_definitions(-DWINVER=0x0601)
add_definitions(-D_WIN32_WINNT=0x0601)
endif()

if (ENET_LZ4)
add_definitions(-DENET_LZ4)
set(SOURCES lz4/lz4.c)
if (ENET_DEBUG)
add_definitions(-DENET_DEBUG)
endif()

if (ENET_STATIC)
Expand All @@ -32,4 +33,4 @@ if (ENET_SHARED)
target_link_libraries(enet winmm ws2_32)
SET_TARGET_PROPERTIES(enet PROPERTIES PREFIX "")
endif()
endif()
endif()
Loading

0 comments on commit 6b0f572

Please sign in to comment.