6 ENet
- Reliable UDP networking library
8 FreePascal DLL header
: enet
.pp
9 Copyright (c
) 2015 Dmitry D
. Chernov aka Black Doomer
12 Copyright (c
) 2002-2014 Lee Salzman
14 Version
1 for 1.3.12: 25.02.2015
16 Permission is hereby granted
, free of charge
, to any person obtaining a copy
17 of this software
and associated documentation
files (the
"Software"), to deal
18 in the Software without restriction
, including without limitation the rights
19 to use
, copy
, modify
, merge
, publish
, distribute
, sublicense
, and/or sell
20 copies of the Software
, and to permit persons to whom the Software is
21 furnished to
do so
, subject to the following conditions
:
23 The above copyright notice
and this permission notice shall be included
in all
24 copies
or substantial portions of the Software
.
26 THE SOFTWARE IS PROVIDED
"AS IS", WITHOUT WARRANTY OF ANY KIND
, EXPRESS OR
27 IMPLIED
, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY
,
28 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
. IN NO EVENT SHALL THE
29 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM
, DAMAGES OR OTHER
30 LIABILITY
, WHETHER IN AN ACTION OF CONTRACT
, TORT OR OTHERWISE
, ARISING FROM
,
31 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
38 enetplatform
, enettypes
, enetprotocol
, enetlist
, enetcallbacks
;
41 ENET_VERSION_MAJOR
= 1;
42 ENET_VERSION_MINOR
= 3;
43 ENET_VERSION_PATCH
= 12;
46 ENET_HOST_BROADCAST
: LongWord
= $FFFFFFFF;
49 ENET_BUFFER_MAXIMUM
= 1 + 2 * ENET_PROTOCOL_MAXIMUM_PACKET_COMMANDS
;
51 ENET_HOST_RECEIVE_BUFFER_SIZE
= 256 * 1024;
52 ENET_HOST_SEND_BUFFER_SIZE
= 256 * 1024;
53 ENET_HOST_BANDWIDTH_THROTTLE_INTERVAL
= 1000;
54 ENET_HOST_DEFAULT_MTU
= 1400;
55 ENET_HOST_DEFAULT_MAXIMUM_PACKET_SIZE
= 32 * 1024 * 1024;
56 ENET_HOST_DEFAULT_MAXIMUM_WAITING_DATA
= 32 * 1024 * 1024;
58 ENET_PEER_DEFAULT_ROUND_TRIP_TIME
= 500;
59 ENET_PEER_DEFAULT_PACKET_THROTTLE
= 32;
60 ENET_PEER_PACKET_THROTTLE_SCALE
= 32;
61 ENET_PEER_PACKET_THROTTLE_COUNTER
= 7;
62 ENET_PEER_PACKET_THROTTLE_ACCELERATION
= 2;
63 ENET_PEER_PACKET_THROTTLE_DECELERATION
= 2;
64 ENET_PEER_PACKET_THROTTLE_INTERVAL
= 5000;
65 ENET_PEER_PACKET_LOSS_SCALE
= 1 shl
16;
66 ENET_PEER_PACKET_LOSS_INTERVAL
= 10000;
67 ENET_PEER_WINDOW_SIZE_SCALE
= 64 * 1024;
68 ENET_PEER_TIMEOUT_LIMIT
= 32;
69 ENET_PEER_TIMEOUT_MINIMUM
= 5000;
70 ENET_PEER_TIMEOUT_MAXIMUM
= 30000;
71 ENET_PEER_PING_INTERVAL
= 500;
72 ENET_PEER_UNSEQUENCED_WINDOWS
= 64;
73 ENET_PEER_UNSEQUENCED_WINDOW_SIZE
= 1024;
74 ENET_PEER_FREE_UNSEQUENCED_WINDOWS
= 32;
75 ENET_PEER_RELIABLE_WINDOWS
= 16;
76 ENET_PEER_RELIABLE_WINDOW_SIZE
= $1000;
77 ENET_PEER_FREE_RELIABLE_WINDOWS
= 8;
81 ENetSocketType
= ( ENET_SOCKET_TYPE_STREAM
= 1,
82 ENET_SOCKET_TYPE_DATAGRAM
= 2 );
83 ENetSocketWait
= ( ENET_SOCKET_WAIT_NONE
= 0,
84 ENET_SOCKET_WAIT_SEND
= 1,
85 ENET_SOCKET_WAIT_RECEIVE
= 2,
86 ENET_SOCKET_WAIT_INTERRUPT
= 4 );
87 ENetSocketOption
= ( ENET_SOCKOPT_NONBLOCK
= 1,
88 ENET_SOCKOPT_BROADCAST
= 2,
89 ENET_SOCKOPT_RCVBUF
= 3,
90 ENET_SOCKOPT_SNDBUF
= 4,
91 ENET_SOCKOPT_REUSEADDR
= 5,
92 ENET_SOCKOPT_RCVTIMEO
= 6,
93 ENET_SOCKOPT_SNDTIMEO
= 7,
94 ENET_SOCKOPT_ERROR
= 8,
95 ENET_SOCKOPT_NODELAY
= 9 );
96 ENetSocketShutdown
= ( ENET_SOCKET_SHUTDOWN_READ
,
97 ENET_SOCKET_SHUTDOWN_WRITE
,
98 ENET_SOCKET_SHUTDOWN_READ_WRITE
);
101 ENET_PACKET_FLAG_RELIABLE
= 1;
102 ENET_PACKET_FLAG_UNSEQUENCED
= 2;
103 ENET_PACKET_FLAG_NO_ALLOCATE
= 4;
104 ENET_PACKET_FLAG_UNRELIABLE_FRAGMENT
= 8;
105 ENET_PACKET_FLAG_SENT
= 256;
108 ENetPeerState
= ( ENET_PEER_STATE_DISCONNECTED
,
109 ENET_PEER_STATE_CONNECTING
,
110 ENET_PEER_STATE_ACKNOWLEDGING_CONNECT
,
111 ENET_PEER_STATE_CONNECTION_PENDING
,
112 ENET_PEER_STATE_CONNECTION_SUCCEEDED
,
113 ENET_PEER_STATE_CONNECTED
,
114 ENET_PEER_STATE_DISCONNECT_LATER
,
115 ENET_PEER_STATE_DISCONNECTING
,
116 ENET_PEER_STATE_ACKNOWLEDGING_DISCONNECT
,
117 ENET_PEER_STATE_ZOMBIE
);
119 ENetEventType
= ( ENET_EVENT_TYPE_NONE
,
120 ENET_EVENT_TYPE_CONNECT
,
121 ENET_EVENT_TYPE_DISCONNECT
,
122 ENET_EVENT_TYPE_RECEIVE
);
125 ENetVersion
= enet_uint32
;
128 pENetAddress
= ^ENetAddress
;
129 pENetPacket
= ^ENetPacket
;
130 pENetAcknowledgement
= ^ENetAcknowledgement
;
131 pENetOutgoingCommand
= ^ENetOutgoingCommand
;
132 pENetIncomingCommand
= ^ENetIncomingCommand
;
133 pENetChannel
= ^ENetChannel
;
134 pENetPeer
= ^ENetPeer
;
135 pENetCompressor
= ^ENetCompressor
;
136 pENetHost
= ^ENetHost
;
137 pENetEvent
= ^ENetEvent
;
140 ENetPacketFreeCallback
= procedure( packet
: pENetPacket
); cdecl
;
141 ENetChecksumCallback
= function( const buffers
: pENetBuffer
; bufferCount
: enet_size_t
): enet_uint32
; cdecl
;
142 ENetInterceptCallback
= function( host
: pENetHost
; event
: pENetEvent
): enet_int
; cdecl
;
152 referenceCount
: enet_size_t
;
155 dataLength
: enet_size_t
;
156 freeCallback
: ENetPacketFreeCallback
;
159 ENetAcknowledgement
= record
160 acknowledgementList
: ENetListNode
;
161 sentTime
: enet_uint32
;
162 command
: TENetProtocol
;
164 ENetOutgoingCommand
= record
165 outgoingCommandList
: ENetListNode
;
166 reliableSequenceNumber
: enet_uint16
;
167 unreliableSequenceNumber
: enet_uint16
;
168 sentTime
: enet_uint32
;
169 roundTripTimeout
: enet_uint32
;
170 roundTripTimeoutLimit
: enet_uint32
;
171 fragmentOffset
: enet_uint32
;
172 fragmentLength
: enet_uint16
;
173 sendAttempts
: enet_uint16
;
174 command
: TENetProtocol
;
175 packet
: pENetPacket
;
177 ENetIncomingCommand
= record
178 incomingCommandList
: ENetListNode
;
179 reliableSequenceNumber
: enet_uint16
;
180 unreliableSequenceNumber
: enet_uint16
;
181 command
: TENetProtocol
;
182 fragmentCount
: enet_uint32
;
183 fragmentsRemaining
: enet_uint32
;
184 fragments
: penet_uint32
;
185 packet
: pENetPacket
;
188 outgoingReliableSequenceNumber
: enet_uint16
;
189 outgoingUnreliableSequenceNumber
: enet_uint16
;
190 usedReliableWindows
: enet_uint16
;
191 reliableWindows
: array
[ 0..ENET_PEER_RELIABLE_WINDOWS-1
] of enet_uint16
;
192 incomingReliableSequenceNumber
: enet_uint16
;
193 incomingUnreliableSequenceNumber
: enet_uint16
;
194 incomingReliableCommands
: TENetList
;
195 incomingUnreliableCommands
: TENetList
;
198 dispatchList
: ENetListNode
;
200 outgoingPeerID
: enet_uint16
;
201 incomingPeerID
: enet_uint16
;
202 connectID
: enet_uint32
;
203 outgoingSessionID
: enet_uint8
;
204 incomingSessionID
: enet_uint8
;
205 address
: ENetAddress
;
207 state
: ENetPeerState
;
208 channels
: pENetChannel
;
209 channelCount
: enet_size_t
;
210 incomingBandwidth
: enet_uint32
;
211 outgoingBandwidth
: enet_uint32
;
212 incomingBandwidthThrottleEpoch
: enet_uint32
;
213 outgoingBandwidthThrottleEpoch
: enet_uint32
;
214 incomingDataTotal
: enet_uint32
;
215 outgoingDataTotal
: enet_uint32
;
216 lastSendTime
: enet_uint32
;
217 lastReceiveTime
: enet_uint32
;
218 nextTimeout
: enet_uint32
;
219 earliestTimeout
: enet_uint32
;
220 packetLossEpoch
: enet_uint32
;
221 packetsSent
: enet_uint32
;
222 packetsLost
: enet_uint32
;
223 packetLoss
: enet_uint32
;
224 packetLossVariance
: enet_uint32
;
225 packetThrottle
: enet_uint32
;
226 packetThrottleLimit
: enet_uint32
;
227 packetThrottleCounter
: enet_uint32
;
228 packetThrottleEpoch
: enet_uint32
;
229 packetThrottleAcceleration
: enet_uint32
;
230 packetThrottleDeceleration
: enet_uint32
;
231 packetThrottleInterval
: enet_uint32
;
232 pingInterval
: enet_uint32
;
233 timeoutLimit
: enet_uint32
;
234 timeoutMinimum
: enet_uint32
;
235 timeoutMaximum
: enet_uint32
;
236 lastRoundTripTime
: enet_uint32
;
237 lowestRoundTripTime
: enet_uint32
;
238 lastRoundTripTimeVariance
: enet_uint32
;
239 highestRoundTripTimeVariance
: enet_uint32
;
240 roundTripTime
: enet_uint32
;
241 roundTripTimeVariance
: enet_uint32
;
243 windowSize
: enet_uint32
;
244 reliableDataInTransit
: enet_uint32
;
245 outgoingReliableSequenceNumber
: enet_uint16
;
246 acknowledgements
: TENetList
;
247 sentReliableCommands
: TENetList
;
248 sentUnreliableCommands
: TENetList
;
249 outgoingReliableCommands
: TENetList
;
250 outgoingUnreliableCommands
: TENetList
;
251 dispatchedCommands
: TENetList
;
252 needsDispatch
: enet_int
;
253 incomingUnsequencedGroup
: enet_uint16
;
254 outgoingUnsequencedGroup
: enet_uint16
;
255 unsequencedWindow
: array
[ 0..(ENET_PEER_UNSEQUENCED_WINDOW_SIZE div
32)-1 ] of enet_uint32
;
256 eventData
: enet_uint32
;
257 totalWaitingData
: enet_size_t
;
259 ENetCompressor
= record
261 compress
: function( context
: Pointer
; const inBuffers
: pENetBuffer
; inBufferCount
, inLimit
: enet_size_t
; outData
: penet_uint8
; outLimit
: enet_size_t
): enet_size_t
; cdecl
;
262 decompress
: function( context
: Pointer
; const inData
: penet_uint8
; inLimit
: enet_size_t
; outData
: penet_uint8
; outLimit
: enet_size_t
): enet_size_t
; cdecl
;
263 destroy
: procedure( context
: Pointer
); cdecl
;
267 address
: ENetAddress
;
268 incomingBandwidth
: enet_uint32
;
269 outgoingBandwidth
: enet_uint32
;
270 bandwidthThrottleEpoch
: enet_uint32
;
272 randomSeed
: enet_uint32
;
273 recalculateBandwidthLimits
: enet_int
;
275 peerCount
: enet_size_t
;
276 channelLimit
: enet_size_t
;
277 serviceTime
: enet_uint32
;
278 dispatchQueue
: TENetList
;
279 continueSending
: enet_int
;
280 packetSize
: enet_size_t
;
281 headerFlags
: enet_uint16
;
282 commands
: array
[ 0..ENET_PROTOCOL_MAXIMUM_PACKET_COMMANDS-1
] of TENetProtocol
;
283 commandCount
: enet_size_t
;
284 buffers
: array
[ 0..ENET_BUFFER_MAXIMUM-1
] of ENetBuffer
;
285 bufferCount
: enet_size_t
;
286 checksum
: ENetChecksumCallback
;
287 compressor
: ENetCompressor
;
288 packetData
: array
[ 0..1, 0..ENET_PROTOCOL_MAXIMUM_MTU-1
] of enet_uint8
;
289 receivedAddress
: ENetAddress
;
290 receivedData
: penet_uint8
;
291 receivedDataLength
: enet_size_t
;
292 totalSentData
: enet_uint32
;
293 totalSentPackets
: enet_uint32
;
294 totalReceivedData
: enet_uint32
;
295 totalReceivedPackets
: enet_uint32
;
296 intercept
: ENetInterceptCallback
;
297 connectedPeers
: enet_size_t
;
298 bandwidthLimitedPeers
: enet_size_t
;
299 duplicatePeers
: enet_size_t
;
300 maximumPacketSize
: enet_size_t
;
301 maximumWaitingData
: enet_size_t
;
304 kind
: ENetEventType
; //originally
"type", which conflicts
306 channelID
: enet_uint8
;
308 packet
: pENetPacket
;
311 {$PACKRECORDS DEFAULT
}
314 function
ENET_VERSION_CREATE( const major
, minor
, patch
: LongInt
): ENetVersion
; inline
;
315 function
ENET_VERSION_GET_MAJOR( const
version: ENetVersion
): LongInt
; inline
;
316 function
ENET_VERSION_GET_MINOR( const
version: ENetVersion
): LongInt
; inline
;
317 function
ENET_VERSION_GET_PATCH( const
version: ENetVersion
): LongInt
; inline
;
318 function
ENET_VERSION(): ENetVersion
; inline
;
322 {$DEFINE libraryENet
:= cdecl
; external
'enet'}
324 function
enet_initialize(): enet_int
; libraryENet
;
325 function
enet_initialize_with_callbacks( version: ENetVersion
; const inits
: pENetCallbacks
): enet_int
; libraryENet
;
326 procedure
enet_deinitialize(); libraryENet
;
327 function
enet_linked_version(): ENetVersion
; libraryENet
;
329 function
enet_time_get(): enet_uint32
; libraryENet
;
330 procedure
enet_time_set( newTimeBase
: enet_uint32
); libraryENet
;
332 function
enet_socket_create( kind
: ENetSocketType
): ENetSocket
; libraryENet
;
333 function
enet_socket_bind( socket
: ENetSocket
; const address
: pENetAddress
): enet_int
; libraryENet
;
334 function
enet_socket_get_address( socket
: ENetSocket
; address
: pENetAddress
): enet_int
; libraryENet
;
335 function
enet_socket_listen( socket
: ENetSocket
; backlog
: enet_int
): enet_int
; libraryENet
;
336 function
enet_socket_accept( socket
: ENetSocket
; address
: pENetAddress
): ENetSocket
; libraryENet
;
337 function
enet_socket_connect( socket
: ENetSocket
; const address
: pENetAddress
): enet_int
; libraryENet
;
338 function
enet_socket_send( socket
: ENetSocket
; const address
: pENetAddress
; const buffers
: pENetBuffer
; bufferCount
: enet_size_t
): enet_int
; libraryENet
;
339 function
enet_socket_receive( socket
: ENetSocket
; address
: pENetAddress
; buffers
: pENetBuffer
; bufferCount
: enet_size_t
): enet_int
; libraryENet
;
340 function
enet_socket_wait( socket
: ENetSocket
; condition
: penet_uint32
; timeout
: enet_uint32
): enet_int
; libraryENet
;
341 function
enet_socket_set_option( socket
: ENetSocket
; option
: ENetSocketOption
; value
: enet_int
): enet_int
; libraryENet
;
342 function
enet_socket_get_option( socket
: ENetSocket
; option
: ENetSocketOption
; value
: penet_int
): enet_int
; libraryENet
;
343 function
enet_socket_shutdown( socket
: ENetSocket
; how
: ENetSocketShutdown
): enet_int
; libraryENet
;
344 procedure
enet_socket_destroy( socket
: ENetSocket
); libraryENet
;
345 function
enet_socketset_select( maxSocket
: ENetSocket
; readSet
: pENetSocketSet
; writeSet
: pENetSocketSet
; timeout
: enet_uint32
): enet_int
; libraryENet
;
347 function
enet_address_set_host( address
: pENetAddress
; const hostName
: PChar
): enet_int
; libraryENet
;
348 function
enet_address_get_host_ip( const address
: pENetAddress
; hostName
: PChar
; nameLength
: enet_size_t
): enet_int
; libraryENet
;
349 function
enet_address_get_host( const address
: pENetAddress
; hostName
: PChar
; nameLength
: enet_size_t
): enet_int
; libraryENet
;
351 function
enet_packet_create( const
data: Pointer
; dataLength
: enet_size_t
; flags
: enet_uint32
): pENetPacket
; libraryENet
;
352 procedure
enet_packet_destroy( packet
: pENetPacket
); libraryENet
;
353 function
enet_packet_resize( packet
: pENetPacket
; dataLength
: enet_size_t
): enet_int
; libraryENet
;
354 function
enet_crc32( const buffers
: pENetBuffer
; bufferCount
: enet_size_t
): enet_uint32
; libraryENet
;
356 function
enet_host_create( const address
: pENetAddress
; peerCount
, channelLimit
: enet_size_t
; incomingBandwidth
, outgoingBandwidth
: enet_uint32
): pENetHost
; libraryENet
;
357 procedure
enet_host_destroy( host
: pENetHost
); libraryENet
;
358 function
enet_host_connect( host
: pENetHost
; const address
: pENetAddress
; channelCount
: enet_size_t
; data: enet_uint32
): pENetPeer
; libraryENet
;
359 function
enet_host_check_events( host
: pENetHost
; event
: pENetEvent
): enet_int
; libraryENet
;
360 function
enet_host_service( host
: pENetHost
; event
: pENetEvent
; timeout
: enet_uint32
): enet_int
; libraryENet
;
361 procedure
enet_host_flush( host
: pENetHost
); libraryENet
;
362 procedure
enet_host_widecast( host
: pENetHost
; channelID
: enet_uint8
; packet
: pENetPacket
); libraryENet name
'enet_host_broadcast'; //renamed due to names conflict
363 procedure
enet_host_compress( host
: pENetHost
; const compressor
: pENetCompressor
); libraryENet
;
364 function
enet_host_compress_with_range_coder( host
: pENetHost
): enet_int
; libraryENet
;
365 procedure
enet_host_channel_limit( host
: pENetHost
; channelLimit
: enet_size_t
); libraryENet
;
366 procedure
enet_host_bandwidth_limit( host
: pENetHost
; incomingBandwidth
, outgoingBandwidth
: enet_uint32
); libraryENet
;
368 function
enet_peer_send( peer
: pENetPeer
; channelID
: enet_uint8
; packet
: pENetPacket
): enet_int
; libraryENet
;
369 function
enet_peer_receive( peer
: pENetPeer
; channelID
: penet_uint8
): pENetPacket
; libraryENet
;
370 procedure
enet_peer_ping( peer
: pENetPeer
); libraryENet
;
371 procedure
enet_peer_ping_frequency( peer
: pENetPeer
; pingInterval
: enet_uint32
); libraryENet name
'enet_peer_ping_interval'; //renamed due to names conflict
372 procedure
enet_peer_timeout( peer
: pENetPeer
; timeoutLimit
, timeoutMinimum
, timeoutMaximum
: enet_uint32
); libraryENet
;
373 procedure
enet_peer_reset( peer
: pENetPeer
); libraryENet
;
374 procedure
enet_peer_disconnect( peer
: pENetPeer
; data: enet_uint32
); libraryENet
;
375 procedure
enet_peer_disconnect_now( peer
: pENetPeer
; data: enet_uint32
); libraryENet
;
376 procedure
enet_peer_disconnect_later( peer
: pENetPeer
; data: enet_uint32
); libraryENet
;
377 procedure
enet_peer_throttle_configure( peer
: pENetPeer
; interval
, acceleration
, deceleration
: enet_uint32
); libraryENet
;
379 function
enet_range_coder_create(): Pointer
; libraryENet
;
380 procedure
enet_range_coder_destroy( context
: Pointer
); libraryENet
;
381 function
enet_range_coder_compress( context
: Pointer
; const inBuffers
: pENetBuffer
; inBufferCount
, inLiit
: enet_size_t
; outData
: penet_uint8
; outLimit
: enet_size_t
): enet_size_t
; libraryENet
;
382 function
enet_range_coder_decompress( context
: Pointer
; const inData
: penet_uint8
; inLimit
: enet_size_t
; outData
: penet_uint8
; outLimit
: enet_size_t
): enet_size_t
; libraryENet
;
386 function
ENET_VERSION_CREATE( const major
, minor
, patch
: LongInt
): ENetVersion
; inline
;
387 begin Result
:= (major shl
16) or (minor shl
8) or patch
;
390 function
ENET_VERSION_GET_MAJOR( const
version: ENetVersion
): LongInt
; inline
;
391 begin Result
:= (version shr
16) and $FF;
394 function
ENET_VERSION_GET_MINOR( const
version: ENetVersion
): LongInt
; inline
;
395 begin Result
:= (version shr
8) and $FF;
398 function
ENET_VERSION_GET_PATCH( const
version: ENetVersion
): LongInt
; inline
;
399 begin Result
:= version and $FF;
402 function
ENET_VERSION(): ENetVersion
; inline
;
403 begin Result
:= ENET_VERSION_CREATE( ENET_VERSION_MAJOR
, ENET_VERSION_MINOR
, ENET_VERSION_PATCH
);