initial
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
/**
|
||||
* Think of this as the "Rulebook".
|
||||
* Instead of teaching Windows and Mac rules to the Server and the Client separately, we put the rules in one book.
|
||||
* Anyone who needs to know the rules just reads this book (#include "NetworkConfig.h").
|
||||
*/
|
||||
|
||||
// This is a "Do Not Duplicate" sticker.
|
||||
// It ensures this file is only read once, even if multiple files include it.
|
||||
// Can use a '#pragma once' but I prefer this old-style one.
|
||||
#ifndef IOVI_NETWORK_NETWORK_CONFIG_H
|
||||
#define IOVI_NETWORK_NETWORK_CONFIG_H
|
||||
|
||||
/**
|
||||
* THE TRANSLATOR (Cross-Platform Setup)
|
||||
* Windows and Mac/Linux speak different "socket" languages.
|
||||
* This block makes sure our code understands both
|
||||
*/
|
||||
#ifdef _WIN32
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
#define CLOSE_SOCKET closesocket
|
||||
#define SOCKET_TYPE SOCKET
|
||||
#else
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <unistd.h>
|
||||
#include <arpa/inet.h>
|
||||
#define CLOSE_SOCKET close
|
||||
#define SOCKET_TYPE int
|
||||
#define INVALID_SOCKET (-1)
|
||||
#define SOCKET_ERROR (-1)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* A helper to automatically turn on networking when the program starts.
|
||||
* For non-Windows systems does nothing.
|
||||
*/
|
||||
struct NetworkStarter {
|
||||
NetworkStarter() {
|
||||
#ifdef _WIN32
|
||||
WSADATA wsaData;
|
||||
WSAStartup(MAKEWORD(2, 2), &wsaData);
|
||||
#endif
|
||||
}
|
||||
~NetworkStarter() {
|
||||
#ifdef _WIN32
|
||||
WSACleanup();
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
#endif // IOVI_NETWORK_NETWORK_CONFIG_H
|
||||
Reference in New Issue
Block a user