|
@@ -222,15 +222,21 @@ extern "C" {
|
|
typedef uint64_t enet_uint64; /**< unsigned 64-bit type */
|
|
typedef uint64_t enet_uint64; /**< unsigned 64-bit type */
|
|
|
|
|
|
typedef enet_uint32 ENetVersion;
|
|
typedef enet_uint32 ENetVersion;
|
|
|
|
+ typedef struct _ENetPacket ENetPacket;
|
|
|
|
|
|
typedef struct _ENetCallbacks {
|
|
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);
|
|
void (ENET_CALLBACK *no_memory) (void);
|
|
void (ENET_CALLBACK *no_memory) (void);
|
|
|
|
+
|
|
|
|
+ ENetPacket *(ENET_CALLBACK *packet_create) (const void *data, size_t dataLength, enet_uint32 flags);
|
|
|
|
+ void (ENET_CALLBACK *packet_destroy) (ENetPacket *packet);
|
|
} ENetCallbacks;
|
|
} ENetCallbacks;
|
|
|
|
|
|
extern void *enet_malloc(size_t);
|
|
extern void *enet_malloc(size_t);
|
|
extern void enet_free(void *);
|
|
extern void enet_free(void *);
|
|
|
|
+ extern ENetPacket* enet_packet_create(const void*,size_t,enet_uint32);
|
|
|
|
+ extern void enet_packet_destroy(ENetPacket*);
|
|
|
|
|
|
// =======================================================================//
|
|
// =======================================================================//
|
|
// !
|
|
// !
|
|
@@ -937,9 +943,6 @@ extern "C" {
|
|
ENET_API enet_uint32 enet_packet_get_length(ENetPacket *);
|
|
ENET_API enet_uint32 enet_packet_get_length(ENetPacket *);
|
|
ENET_API void enet_packet_set_free_callback(ENetPacket *, void *);
|
|
ENET_API void enet_packet_set_free_callback(ENetPacket *, void *);
|
|
|
|
|
|
- ENET_API ENetPacket * enet_packet_create(const void *, size_t, enet_uint32);
|
|
|
|
- ENET_API ENetPacket * enet_packet_create_offset(const void *, size_t, size_t, enet_uint32);
|
|
|
|
- ENET_API void enet_packet_destroy(ENetPacket *);
|
|
|
|
ENET_API enet_uint32 enet_crc32(const ENetBuffer *, size_t);
|
|
ENET_API enet_uint32 enet_crc32(const ENetBuffer *, size_t);
|
|
|
|
|
|
ENET_API ENetHost * enet_host_create(const ENetAddress *, size_t, size_t, enet_uint32, enet_uint32);
|
|
ENET_API ENetHost * enet_host_create(const ENetAddress *, size_t, size_t, enet_uint32, enet_uint32);
|
|
@@ -1200,7 +1203,7 @@ extern "C" {
|
|
// !
|
|
// !
|
|
// =======================================================================//
|
|
// =======================================================================//
|
|
|
|
|
|
- static ENetCallbacks callbacks = { malloc, free, abort };
|
|
|
|
|
|
+ static ENetCallbacks callbacks = { malloc, free, abort, enet_packet_create, enet_packet_destroy };
|
|
|
|
|
|
int enet_initialize_with_callbacks(ENetVersion version, const ENetCallbacks *inits) {
|
|
int enet_initialize_with_callbacks(ENetVersion version, const ENetCallbacks *inits) {
|
|
if (version < ENET_VERSION_CREATE(1, 3, 0)) {
|
|
if (version < ENET_VERSION_CREATE(1, 3, 0)) {
|
|
@@ -1220,6 +1223,15 @@ extern "C" {
|
|
callbacks.no_memory = inits->no_memory;
|
|
callbacks.no_memory = inits->no_memory;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ if (inits->packet_create != NULL || inits->packet_destroy != NULL) {
|
|
|
|
+ if (inits->packet_create == NULL || inits->packet_destroy == NULL) {
|
|
|
|
+ return -1;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ callbacks.packet_create = inits->packet_create;
|
|
|
|
+ callbacks.packet_destroy = inits->packet_destroy;
|
|
|
|
+ }
|
|
|
|
+
|
|
return enet_initialize();
|
|
return enet_initialize();
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1618,7 +1630,7 @@ extern "C" {
|
|
|
|
|
|
if (outgoingCommand->packet->referenceCount == 0) {
|
|
if (outgoingCommand->packet->referenceCount == 0) {
|
|
outgoingCommand->packet->flags |= ENET_PACKET_FLAG_SENT;
|
|
outgoingCommand->packet->flags |= ENET_PACKET_FLAG_SENT;
|
|
- enet_packet_destroy(outgoingCommand->packet);
|
|
|
|
|
|
+ callbacks.packet_destroy(outgoingCommand->packet);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1690,7 +1702,7 @@ extern "C" {
|
|
|
|
|
|
if (outgoingCommand->packet->referenceCount == 0) {
|
|
if (outgoingCommand->packet->referenceCount == 0) {
|
|
outgoingCommand->packet->flags |= ENET_PACKET_FLAG_SENT;
|
|
outgoingCommand->packet->flags |= ENET_PACKET_FLAG_SENT;
|
|
- enet_packet_destroy(outgoingCommand->packet);
|
|
|
|
|
|
+ callbacks.packet_destroy(outgoingCommand->packet);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -2775,7 +2787,7 @@ extern "C" {
|
|
--outgoingCommand->packet->referenceCount;
|
|
--outgoingCommand->packet->referenceCount;
|
|
|
|
|
|
if (outgoingCommand->packet->referenceCount == 0) {
|
|
if (outgoingCommand->packet->referenceCount == 0) {
|
|
- enet_packet_destroy(outgoingCommand->packet);
|
|
|
|
|
|
+ callbacks.packet_destroy(outgoingCommand->packet);
|
|
}
|
|
}
|
|
|
|
|
|
enet_list_remove(&outgoingCommand->outgoingCommandList);
|
|
enet_list_remove(&outgoingCommand->outgoingCommandList);
|
|
@@ -3621,7 +3633,7 @@ extern "C" {
|
|
--outgoingCommand->packet->referenceCount;
|
|
--outgoingCommand->packet->referenceCount;
|
|
|
|
|
|
if (outgoingCommand->packet->referenceCount == 0) {
|
|
if (outgoingCommand->packet->referenceCount == 0) {
|
|
- enet_packet_destroy(outgoingCommand->packet);
|
|
|
|
|
|
+ callbacks.packet_destroy(outgoingCommand->packet);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -3644,7 +3656,7 @@ extern "C" {
|
|
--incomingCommand->packet->referenceCount;
|
|
--incomingCommand->packet->referenceCount;
|
|
|
|
|
|
if (incomingCommand->packet->referenceCount == 0) {
|
|
if (incomingCommand->packet->referenceCount == 0) {
|
|
- enet_packet_destroy(incomingCommand->packet);
|
|
|
|
|
|
+ callbacks.packet_destroy(incomingCommand->packet);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -4248,7 +4260,7 @@ extern "C" {
|
|
goto notifyError;
|
|
goto notifyError;
|
|
}
|
|
}
|
|
|
|
|
|
- packet = enet_packet_create(data, dataLength, flags);
|
|
|
|
|
|
+ packet = callbacks.packet_create(data, dataLength, flags);
|
|
if (packet == NULL) {
|
|
if (packet == NULL) {
|
|
goto notifyError;
|
|
goto notifyError;
|
|
}
|
|
}
|
|
@@ -4306,14 +4318,14 @@ extern "C" {
|
|
}
|
|
}
|
|
|
|
|
|
if (packet != NULL && packet->referenceCount == 0) {
|
|
if (packet != NULL && packet->referenceCount == 0) {
|
|
- enet_packet_destroy(packet);
|
|
|
|
|
|
+ callbacks.packet_destroy(packet);
|
|
}
|
|
}
|
|
|
|
|
|
return &dummyCommand;
|
|
return &dummyCommand;
|
|
|
|
|
|
notifyError:
|
|
notifyError:
|
|
if (packet != NULL && packet->referenceCount == 0) {
|
|
if (packet != NULL && packet->referenceCount == 0) {
|
|
- enet_packet_destroy(packet);
|
|
|
|
|
|
+ callbacks.packet_destroy(packet);
|
|
}
|
|
}
|
|
|
|
|
|
return NULL;
|
|
return NULL;
|
|
@@ -4572,7 +4584,7 @@ extern "C" {
|
|
}
|
|
}
|
|
|
|
|
|
if (packet->referenceCount == 0) {
|
|
if (packet->referenceCount == 0) {
|
|
- enet_packet_destroy(packet);
|
|
|
|
|
|
+ callbacks.packet_destroy(packet);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|