MPMA Framework 0.4
PlatformSockets.h
00001 //includes whatever files are needed to access the platform's socket implementation and provides helpers for platform-specific socket operations.
00002 //this is meant for internal framework use only.
00003 //Luke Lenhart, 2008
00004 //See /docs/License.txt for details on how this code may be used.
00005 
00006 #pragma once
00007 
00008 #include "../base/Setup.h"
00009 
00010 #ifdef MPMA_COMPILE_NET
00011 
00012 #include <string>
00013 #include "../base/Types.h"
00014 
00015 // -- do platform includes and typedefs
00016 
00017 #if defined(_WIN32) || defined(_WIN64) // msvc
00018 
00019 #include <Winsock2.h>
00020 #undef SetPort //wow
00021 
00022 typedef int socklen_t;
00023 
00024 #elif defined(linux)  // g++ linux
00025 
00026 #include <sys/socket.h>
00027 #include <arpa/inet.h>
00028 #include <netdb.h>
00029 #include <netinet/tcp.h>
00030 
00031 #else // ?
00032 
00033     #error Unknown platform in PlatformSockets.h
00034 
00035 #endif
00036 
00037 // -- functions we have to abstract
00038 
00039 namespace NET_INTERNAL
00040 {
00041     //sets a socket to be blocking or nonblocking
00042     bool Internal_SetSocketBlocking(nsint sock, bool block);
00043 
00044     //clears any previous error codes set
00045     void Internal_ClearLastError();
00046 
00047     //gets a string that represents a socket error for the most recent operation
00048     std::string Internal_GetLastError();
00049 
00050     //closes a socket
00051     void Internal_CloseSocket(nsint sock);
00052 
00053     //returns whether the error from the most recent socket operations indicates a loss of connection, or whether the socket was nicely closed
00054     bool Internal_IsLastSocketErrorADisconnect();
00055 
00056     //gets our subnet mask and subnet address
00057     bool Internal_GetSubnet(uint32 &mask, uint32 &net, uint32 &localIp);
00058 }
00059 
00060 #endif //#ifdef MPMA_COMPILE_NET
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends