ENetUtil.cpp 989 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Copyright 2015 Dolphin Emulator Project
  2. // Licensed under GPLv2+
  3. // Refer to the license.txt file included.
  4. #include "ENetUtil.h"
  5. #include "Common/CommonTypes.h"
  6. namespace ENetUtil
  7. {
  8. void WakeupThread(ENetHost* host)
  9. {
  10. // Send ourselves a spurious message. This is hackier than it should be.
  11. // comex reported this as https://github.com/lsalzman/enet/issues/23, so
  12. // hopefully there will be a better way to do it in the future.
  13. ENetAddress address;
  14. if (host->address.port != 0)
  15. address.port = host->address.port;
  16. else
  17. enet_socket_get_address(host->socket, &address);
  18. address.host = 0x0100007f; // localhost
  19. u8 byte = 0;
  20. ENetBuffer buf;
  21. buf.data = &byte;
  22. buf.dataLength = 1;
  23. enet_socket_send(host->socket, &address, &buf, 1);
  24. }
  25. int ENET_CALLBACK InterceptCallback(ENetHost* host, ENetEvent* event)
  26. {
  27. // wakeup packet received
  28. if (host->receivedDataLength == 1 && host->receivedData[0] == 0)
  29. {
  30. event->type = (ENetEventType) 42;
  31. return 1;
  32. }
  33. return 0;
  34. }
  35. }