You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-12-04 17:04:49 +00:00
Allow non blocking UDP put_packet in C++.
- Add blocking mode option to PacketPeerUDP. - put_packet returns ERR_UNAVAILABLE when operation would block. - ENet module uses non-blocking UDP.
This commit is contained in:
10
thirdparty/enet/godot.cpp
vendored
10
thirdparty/enet/godot.cpp
vendored
@@ -79,7 +79,10 @@ int enet_socket_bind(ENetSocket socket, const ENetAddress *address) {
|
||||
|
||||
ENetSocket enet_socket_create(ENetSocketType type) {
|
||||
|
||||
return PacketPeerUDP::create();
|
||||
PacketPeerUDP *socket = PacketPeerUDP::create();
|
||||
socket->set_blocking_mode(false);
|
||||
|
||||
return socket;
|
||||
}
|
||||
|
||||
void enet_socket_destroy(ENetSocket socket) {
|
||||
@@ -118,6 +121,11 @@ int enet_socket_send(ENetSocket socket, const ENetAddress *address, const ENetBu
|
||||
|
||||
err = sock->put_packet((const uint8_t *)&w[0], size);
|
||||
if (err != OK) {
|
||||
|
||||
if (err == ERR_UNAVAILABLE) { // blocking call
|
||||
return 0;
|
||||
}
|
||||
|
||||
WARN_PRINT("Sending failed!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user