libnative-utilities/include/raknet/SocketIncludes.hpp
2024-08-15 18:40:30 +08:00

99 lines
2.7 KiB
C++

#ifndef RAKNET_SOCKETINCLUDES_H
#define RAKNET_SOCKETINCLUDES_H
// All this crap just to include type SOCKET
#ifdef __native_client__
#define _PP_Instance_ PP_Instance
#else
#define _PP_Instance_ int
#endif
#if defined(WINDOWS_STORE_RT)
#include <windows.h>
#include "WinRTSockAddr.hpp"
typedef Windows::Networking::Sockets::DatagramSocket^ __UDPSOCKET__;
typedef Windows::Networking::Sockets::StreamSocket^ __TCPSOCKET__;
typedef unsigned int socklen_t;
#define FORMAT_MESSAGE_ALLOCATE_BUFFER 0
#define FIONBIO 0
#define LocalFree(x)
// using Windows.Networking;
// using Windows.Networking.Sockets;
// See http://msdn.microsoft.com/en-us/library/windows/apps/windows.networking.sockets.datagramsocketcontrol
#elif defined(_WIN32)
// IP_DONTFRAGMENT is different between winsock 1 and winsock 2. Therefore, Winsock2.h must be linked againt Ws2_32.lib
// winsock.h must be linked against WSock32.lib. If these two are mixed up the flag won't work correctly
// WinRT: http://msdn.microsoft.com/en-us/library/windows/apps/windows.networking.sockets
// Sample code: http://stackoverflow.com/questions/10290945/correct-use-of-udp-datagramsocket
#include <winsock2.h>
typedef SOCKET __UDPSOCKET__;
typedef SOCKET __TCPSOCKET__;
typedef int socklen_t;
#else
#define closesocket close
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.hpp>
#include <netinet/in.hpp>
#include <arpa/inet.hpp>
#include <unistd.h>
#include <fcntl.h>
#ifdef __native_client__
#include "ppapi/cpp/private/net_address_private.hpp"
#include "ppapi/c/pp_bool.hpp"
#include "ppapi/c/pp_errors.hpp"
#include "ppapi/cpp/completion_callback.hpp"
#include "ppapi/cpp/instance_handle.hpp"
#include "ppapi/cpp/module.hpp"
#include "ppapi/cpp/module_impl.hpp"
#include "ppapi/c/pp_errors.hpp"
#include "ppapi/c/pp_module.hpp"
#include "ppapi/c/pp_var.hpp"
#include "ppapi/c/pp_resource.hpp"
#include "ppapi/c/ppb.hpp"
#include "ppapi/c/ppb_instance.hpp"
#include "ppapi/c/ppb_messaging.hpp"
#include "ppapi/c/ppb_var.hpp"
#include "ppapi/c/ppp.hpp"
#include "ppapi/c/ppb_core.hpp"
#include "ppapi/c/ppp_instance.hpp"
#include "ppapi/c/ppp_messaging.hpp"
#include "ppapi/c/pp_input_event.hpp"
#include "ppapi/c/pp_completion_callback.hpp"
//UDP specific - the 'private' folder was copied from the chromium src/ppapi/c headers folder
#include "ppapi/c/private/ppb_udp_socket_private.hpp"
#include "ppapi/cpp/private/net_address_private.hpp"
typedef PP_Resource __UDPSOCKET__;
typedef PP_Resource __TCPSOCKET__;
#else
//#include "RakMemoryOverride.hpp"
/// Unix/Linux uses ints for sockets
typedef int __UDPSOCKET__;
typedef int __TCPSOCKET__;
#endif
#endif
#endif // RAKNET_SOCKETINCLUDES_H