From: spog Date: Tue, 9 May 2006 20:51:34 +0000 (+0000) Subject: portability fixes X-Git-Tag: xonotic-v0.7.0~16^2~12^2~235 X-Git-Url: https://de.git.xonotic.org/?p=xonotic%2Fnetradiant.git;a=commitdiff_plain;h=3591d7dc01732577ebbb25f3818ccec8f440338f;hp=06eb8cc3a4046af318da7f7b9fae1c04be8c0380 portability fixes git-svn-id: svn://svn.icculus.org/gtkradiant/GtkRadiant/trunk@59 8a3a26a2-13c4-0310-b231-cf6edde360e5 --- diff --git a/SConstruct b/SConstruct index d4985c67..a8cbf68e 100644 --- a/SConstruct +++ b/SConstruct @@ -167,8 +167,10 @@ LINK = CXX # common flags warningFlags = '-W -Wall -Wcast-align -Wcast-qual -Wno-unused-parameter ' warningFlagsCXX = '-Wno-non-virtual-dtor -Wreorder ' # -Wold-style-cast -CCFLAGS = '' + warningFlags -CXXFLAGS = '-pipe -DQ_NO_STLPORT ' + warningFlags + warningFlagsCXX +# POSIX macro: platform supports posix IEEE Std 1003.1:2001 +# XWINDOWS macro: platform supports X-Windows API +CCFLAGS = '-DPOSIX -DXWINDOWS ' + warningFlags +CXXFLAGS = '-pipe -DPOSIX -DXWINDOWS ' + warningFlags + warningFlagsCXX CPPPATH = [] if (BUILD == 'debug'): CXXFLAGS += '-g -D_DEBUG ' diff --git a/contrib/bobtoolz/misc.cpp b/contrib/bobtoolz/misc.cpp index e0747965..cce40e14 100644 --- a/contrib/bobtoolz/misc.cpp +++ b/contrib/bobtoolz/misc.cpp @@ -190,7 +190,7 @@ extern char* PLUGIN_NAME; return buffer; }*/ -#if defined (__linux__) || defined (__APPLE__) +#if defined (POSIX) // the bCreateConsole parameter is ignored on linux .. bool Q_Exec( const char *pCmd, bool bCreateConsole ) { diff --git a/contrib/camera/funchandlers.cpp b/contrib/camera/funchandlers.cpp index 85af8335..f958ad96 100644 --- a/contrib/camera/funchandlers.cpp +++ b/contrib/camera/funchandlers.cpp @@ -30,10 +30,12 @@ extern GtkWidget *g_pEditModeAddRadioButton; char* Q_realpath(const char *path, char *resolved_path, size_t size) { -#if defined (__linux__) || defined (__APPLE__) +#if defined(POSIX) return realpath(path, resolved_path); +#elif defined(WIN32) + return _fullpath(resolved_path, path, size); #else - return _fullpath(resolved_path, path, size); +#error "unsupported platform" #endif } diff --git a/contrib/camera/misc.cpp b/contrib/camera/misc.cpp index 14d611a5..49148248 100644 --- a/contrib/camera/misc.cpp +++ b/contrib/camera/misc.cpp @@ -82,7 +82,7 @@ const char* ExtractFilename( const char* path ) } int Q_stricmp (const char *s1, const char *s2) { - return stricmp( s1, s2 ); + return string_equal_nocase( s1, s2 ); } /* diff --git a/contrib/hydratoolz/plugin.cpp b/contrib/hydratoolz/plugin.cpp index ef75a753..2298db60 100644 --- a/contrib/hydratoolz/plugin.cpp +++ b/contrib/hydratoolz/plugin.cpp @@ -298,7 +298,7 @@ GSList *AddToWadList(GSList *wadlist, const char *shadername, const char *wad) for (GSList *l = wadlist; l != NULL ; l = l->next) { - if (!stricmp((char *)l->data,wadname)) + if (string_equal_nocase((char *)l->data,wadname)) { free( wadname ); return wadlist; @@ -334,7 +334,7 @@ void UpdateWadKeyPair( void ) Sys_Printf("Searching for in-use wad files...\n"); for(pEpair = pEntity->epairs; pEpair != NULL; pEpair = pEpair->next) { - if (stricmp(pEpair->key,"wad") == 0) + if (string_equal_nocase(pEpair->key,"wad")) { strcpy(wads,pEpair->value); ConvertDOSToUnixName(wads,wads); @@ -415,7 +415,7 @@ void UpdateWadKeyPair( void ) wads[0] = 0; while (wadlist) { - if (stricmp((char *)wadlist->data,"common-hydra.wad") == 0) + if (string_equal_nocase((char *)wadlist->data,"common-hydra.wad")) { Sys_Printf("Skipping radiant-supplied wad file %s\n",(char *)wadlist->data); } diff --git a/libs/cmdlib/cmdlib.cpp b/libs/cmdlib/cmdlib.cpp index 23fdd5f6..a09ed9ea 100644 --- a/libs/cmdlib/cmdlib.cpp +++ b/libs/cmdlib/cmdlib.cpp @@ -32,15 +32,11 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include "os/path.h" #include "container/array.h" -#ifdef WIN32 - #include -#endif -#if defined (__linux__) || defined (__APPLE__) - #include -#endif +#if defined (POSIX) + +#include -#if defined (__linux__) || defined (__APPLE__) bool Q_Exec(const char *cmd, char *cmdline, const char *, bool) { char fullcmd[2048]; @@ -82,9 +78,11 @@ bool Q_Exec(const char *cmd, char *cmdline, const char *, bool) } return true; } -#endif -#ifdef WIN32 +#elif defined(WIN32) + +#include + // NOTE TTimo windows is VERY nitpicky about the syntax in CreateProcess bool Q_Exec(const char *cmd, char *cmdline, const char *execdir, bool bCreateConsole) { @@ -126,5 +124,6 @@ bool Q_Exec(const char *cmd, char *cmdline, const char *execdir, bool bCreateCon return true; return false; } + #endif diff --git a/libs/gtkutil/clipboard.cpp b/libs/gtkutil/clipboard.cpp index cbace0bf..f7b9466a 100644 --- a/libs/gtkutil/clipboard.cpp +++ b/libs/gtkutil/clipboard.cpp @@ -28,7 +28,69 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA /// \file /// \brief Platform-independent GTK clipboard support. /// \todo Using GDK_SELECTION_CLIPBOARD fails on win32, so we use the win32 API directly for now. -#if defined (__linux__) || defined (__APPLE__) +#if defined(WIN32) + +const char* c_clipboard_format = "RadiantClippings"; + +#include + +void clipboard_copy(ClipboardCopyFunc copy) +{ + BufferOutputStream ostream; + copy(ostream); + + bool bClipped = false; + UINT nClipboard = ::RegisterClipboardFormat(c_clipboard_format); + if (nClipboard > 0) + { + if (::OpenClipboard(0)) + { + EmptyClipboard(); + std::size_t length = ostream.size(); + HANDLE h = ::GlobalAlloc(GMEM_ZEROINIT | GMEM_MOVEABLE | GMEM_DDESHARE, length + sizeof(std::size_t)); + if (h != 0) + { + char *buffer = reinterpret_cast(::GlobalLock(h)); + *reinterpret_cast(buffer) = length; + buffer += sizeof(std::size_t); + memcpy(buffer, ostream.data(), length); + ::GlobalUnlock(h); + ::SetClipboardData(nClipboard, h); + ::CloseClipboard(); + bClipped = true; + } + } + } + + if (!bClipped) + { + globalOutputStream() << "Unable to register Windows clipboard formats, copy/paste between editors will not be possible\n"; + } +} + +void clipboard_paste(ClipboardPasteFunc paste) +{ + UINT nClipboard = ::RegisterClipboardFormat(c_clipboard_format); + if (nClipboard > 0 && ::OpenClipboard(0)) + { + if(IsClipboardFormatAvailable(nClipboard)) + { + HANDLE h = ::GetClipboardData(nClipboard); + if(h) + { + const char *buffer = reinterpret_cast(::GlobalLock(h)); + std::size_t length = *reinterpret_cast(buffer); + buffer += sizeof(std::size_t); + BufferInputStream istream(buffer, length); + paste(istream); + ::GlobalUnlock(h); + } + } + ::CloseClipboard(); + } +} + +#else #include @@ -96,67 +158,5 @@ void clipboard_paste(ClipboardPasteFunc paste) gtk_clipboard_request_contents (clipboard, gdk_atom_intern(clipboard_targets[0].target, FALSE), clipboard_received, &g_clipboardPasteFunc); } -#elif defined(WIN32) - -const char* c_clipboard_format = "RadiantClippings"; - -#include - -void clipboard_copy(ClipboardCopyFunc copy) -{ - BufferOutputStream ostream; - copy(ostream); - - bool bClipped = false; - UINT nClipboard = ::RegisterClipboardFormat(c_clipboard_format); - if (nClipboard > 0) - { - if (::OpenClipboard(0)) - { - EmptyClipboard(); - std::size_t length = ostream.size(); - HANDLE h = ::GlobalAlloc(GMEM_ZEROINIT | GMEM_MOVEABLE | GMEM_DDESHARE, length + sizeof(std::size_t)); - if (h != 0) - { - char *buffer = reinterpret_cast(::GlobalLock(h)); - *reinterpret_cast(buffer) = length; - buffer += sizeof(std::size_t); - memcpy(buffer, ostream.data(), length); - ::GlobalUnlock(h); - ::SetClipboardData(nClipboard, h); - ::CloseClipboard(); - bClipped = true; - } - } - } - - if (!bClipped) - { - globalOutputStream() << "Unable to register Windows clipboard formats, copy/paste between editors will not be possible\n"; - } -} - -void clipboard_paste(ClipboardPasteFunc paste) -{ - UINT nClipboard = ::RegisterClipboardFormat(c_clipboard_format); - if (nClipboard > 0 && ::OpenClipboard(0)) - { - if(IsClipboardFormatAvailable(nClipboard)) - { - HANDLE h = ::GetClipboardData(nClipboard); - if(h) - { - const char *buffer = reinterpret_cast(::GlobalLock(h)); - std::size_t length = *reinterpret_cast(buffer); - buffer += sizeof(std::size_t); - BufferInputStream istream(buffer, length); - paste(istream); - ::GlobalUnlock(h); - } - } - ::CloseClipboard(); - } -} - #endif diff --git a/libs/jpeglib.h b/libs/jpeglib.h index 212cc85e..f5b59010 100644 --- a/libs/jpeglib.h +++ b/libs/jpeglib.h @@ -40,7 +40,7 @@ extern "C" #endif // LZ: linux stuff -#if defined (__linux__) || defined (__APPLE__) +#if !defined (WIN32) #include #include diff --git a/libs/l_net/l_net.c b/libs/l_net/l_net.c index 7d8f404d..558ec211 100644 --- a/libs/l_net/l_net.c +++ b/libs/l_net/l_net.c @@ -83,10 +83,9 @@ void Net_SetAddressPort(address_t *address, int port) int Net_AddressCompare(address_t *addr1, address_t *addr2) { #ifdef WIN32 - return stricmp(addr1->ip, addr2->ip); -#endif -#ifdef __linux__ - return strcasecmp(addr1->ip, addr2->ip); + return _stricmp(addr1->ip, addr2->ip); +#else + return strcasecmp(addr1->ip, addr2->ip); #endif } //end of the function Net_AddressCompare //=========================================================================== diff --git a/libs/os/path.h b/libs/os/path.h index cd8b0aa7..082b56fa 100644 --- a/libs/os/path.h +++ b/libs/os/path.h @@ -93,7 +93,7 @@ inline bool path_is_absolute(const char* path) #if defined(WIN32) return path[0] == '/' || (path[0] != '\0' && path[1] == ':'); // local drive -#elif defined(__linux__) || defined(__APPLE__) +#elif defined(POSIX) return path[0] == '/'; #endif } diff --git a/libs/radiant_jpeglib.h b/libs/radiant_jpeglib.h index 1d2e74ae..b54792fe 100644 --- a/libs/radiant_jpeglib.h +++ b/libs/radiant_jpeglib.h @@ -20,7 +20,7 @@ extern "C" #endif // LZ: linux stuff -#if defined (__linux__) || defined (__APPLE__) +#if !defined (WIN32) #include #include diff --git a/libs/str.h b/libs/str.h index 1478ce7e..eacac3d6 100644 --- a/libs/str.h +++ b/libs/str.h @@ -67,7 +67,7 @@ inline char* Q_StrDup(const char* pStr) return strcpy(new char[strlen(pStr)+1], pStr); } -#if defined (__linux__) || defined (__APPLE__) +#if !defined(WIN32) #define strcmpi strcasecmp #define stricmp strcasecmp #define strnicmp strncasecmp diff --git a/plugins/textool/StdAfx.h b/plugins/textool/StdAfx.h index e11dd372..f23eeafd 100644 --- a/plugins/textool/StdAfx.h +++ b/plugins/textool/StdAfx.h @@ -28,7 +28,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include #include -#if defined(__linux__) || defined(__APPLE__) +#if !defined(WIN32) // Necessary for proper boolean type declaration #include "qertypes.h" diff --git a/radiant/GtkRadiant.vcproj b/radiant/GtkRadiant.vcproj index 1264a5b1..d020446c 100644 --- a/radiant/GtkRadiant.vcproj +++ b/radiant/GtkRadiant.vcproj @@ -548,6 +548,12 @@ copy "$(TargetDir)$(TargetName).pdb" "$(SolutionDir)install" + + + + diff --git a/radiant/environment.cpp b/radiant/environment.cpp index 67280587..a3bfd43f 100644 --- a/radiant/environment.cpp +++ b/radiant/environment.cpp @@ -72,7 +72,7 @@ const char* environment_get_app_path() } -#if defined (__linux__) || defined (__APPLE__) +#if defined(POSIX) #include #include @@ -83,7 +83,7 @@ const char* environment_get_app_path() const char* LINK_NAME = #if defined (__linux__) "/proc/self/exe" -#else +#else // FreeBSD and OSX "/proc/curproc/file" #endif ; @@ -147,9 +147,7 @@ void environment_init(int argc, char* argv[]) } } -#endif - -#ifdef WIN32 +#elif defined(WIN32) #include #include @@ -197,4 +195,6 @@ void environment_init(int argc, char* argv[]) } } +#else +#error "unsupported platform" #endif diff --git a/radiant/error.cpp b/radiant/error.cpp index 66794e7a..0ff75d1c 100644 --- a/radiant/error.cpp +++ b/radiant/error.cpp @@ -32,9 +32,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #ifdef WIN32 #define UNICODE #include -#endif - -#if defined (__linux__) || defined (__APPLE__) +#else #include #include #endif @@ -66,15 +64,6 @@ void Error (const char *error, ...) strcat( text, "\n" ); -#if defined (__linux__) || defined (__APPLE__) - if (errno != 0) - { - strcat( text, "errno: " ); - strcat( text, strerror (errno)); - strcat( text, "\n"); - } -#endif - #ifdef WIN32 if (GetLastError() != 0) { @@ -110,8 +99,16 @@ void Error (const char *error, ...) strcat( text, "\n"); LocalFree( lpMsgBuf ); } +#else + if (errno != 0) + { + strcat( text, "errno: " ); + strcat( text, strerror (errno)); + strcat( text, "\n"); + } #endif + #if 0 // we need to have a current context to call glError() if (g_glwindow_globals.d_glBase != 0) diff --git a/radiant/mainframe.cpp b/radiant/mainframe.cpp index e49d7fd9..9b36b72c 100644 --- a/radiant/mainframe.cpp +++ b/radiant/mainframe.cpp @@ -186,7 +186,7 @@ void VFS_Destroy() void HomePaths_Realise() { -#if defined (__linux__) || defined (__APPLE__) +#if defined(POSIX) const char* prefix = g_pGameDescription->getKeyValue("prefix"); if(!string_empty(prefix)) { @@ -510,10 +510,10 @@ public: const char* const c_library_extension = #if defined(WIN32) "dll" -#elif defined(__linux__) -"so" #elif defined (__APPLE__) "dylib" +#elif defined(__linux__) || defined (__FreeBSD__) +"so" #endif ; @@ -3499,7 +3499,7 @@ void MainFrame_Construct() const char* ENGINEPATH_ATTRIBUTE = #if defined(WIN32) "enginepath_win32" -#elif defined(__linux__) +#elif defined(__linux__) || defined (__FreeBSD__) "enginepath_linux" #elif defined(__APPLE__) "enginepath_macos" diff --git a/radiant/qe3.cpp b/radiant/qe3.cpp index 11c10418..a526c608 100644 --- a/radiant/qe3.cpp +++ b/radiant/qe3.cpp @@ -78,7 +78,7 @@ void QE_InitVFS() const char* gamename = gamename_get(); const char* basegame = basegame_get(); -#if defined (__linux__) || defined (__APPLE__) +#if defined(POSIX) const char* userRoot = g_qeglobals.m_userEnginePath.c_str(); #endif const char* globalRoot = EnginePath_get(); @@ -86,7 +86,7 @@ void QE_InitVFS() // if we have a mod dir if(!string_equal(gamename, basegame)) { -#if defined (__linux__) || defined (__APPLE__) +#if defined(POSIX) // ~/./ { StringOutputStream userGamePath(256); @@ -103,7 +103,7 @@ void QE_InitVFS() } } -#if defined (__linux__) || defined (__APPLE__) +#if defined(POSIX) // ~/./ { StringOutputStream userBasePath(256); @@ -172,7 +172,7 @@ bool ConfirmModified(const char* title) const char* const EXECUTABLE_TYPE = -#if defined(__linux__) +#if defined(__linux__) || defined (__FreeBSD__) "x86" #elif defined(__APPLE__) "ppc" @@ -317,20 +317,21 @@ void RunBSP(const char* name) strcat(junkpath, "junk.txt"); char batpath[PATH_MAX]; -#if defined (__linux__) || defined (__APPLE__) +#if defined(POSIX) strcpy(batpath, SettingsPath_get()); strcat(batpath, "qe3bsp.sh"); -#endif -#ifdef WIN32 +#elif defined(WIN32) strcpy(batpath, SettingsPath_get()); strcat(batpath, "qe3bsp.bat"); +#else +#error "unsupported platform" #endif bool written = false; { TextFileOutputStream batchFile(batpath); if(!batchFile.failed()) { -#if defined (__linux__) || defined (__APPLE__) +#if defined (POSIX) batchFile << "#!/bin/sh \n\n"; #endif BatchCommandListener listener(batchFile, junkpath); @@ -340,7 +341,7 @@ void RunBSP(const char* name) } if(written) { -#if defined (__linux__) || defined (__APPLE__) +#if defined (POSIX) chmod (batpath, 0744); #endif globalOutputStream() << "Writing the compile script to '" << batpath << "'\n"; diff --git a/radiant/qgl.cpp b/radiant/qgl.cpp index af7d397d..c1e6b23a 100644 --- a/radiant/qgl.cpp +++ b/radiant/qgl.cpp @@ -75,7 +75,7 @@ int ( WINAPI * qwglGetLayerPaletteEntries)(HDC, int, int, int, COLORREF *); BOOL ( WINAPI * qwglRealizeLayerPalette)(HDC, int, BOOL); BOOL ( WINAPI * qwglSwapLayerBuffers)(HDC, UINT); -#elif defined (__linux__) || defined (__APPLE__) +#elif defined (XWINDOWS) #include #include @@ -101,6 +101,8 @@ void (*qglXUseXFont)( Font font, int first, int count, int list ); void* (*qglXGetProcAddressARB) (const GLubyte *procName); typedef void* (*glXGetProcAddressARBProc) (const GLubyte *procName); +#else +#error "unsupported platform" #endif @@ -108,7 +110,7 @@ void QGL_Shutdown(OpenGLBinding& table) { globalOutputStream() << "Shutting down OpenGL module..."; -#ifdef WIN32 +#if defined(WIN32) qwglCopyContext = 0; qwglCreateContext = 0; qwglCreateLayerContext = 0; @@ -131,9 +133,7 @@ void QGL_Shutdown(OpenGLBinding& table) qwglGetPixelFormat = 0; qwglSetPixelFormat = 0; qwglSwapBuffers = 0; -#endif - -#if defined (__linux__) || defined (__APPLE__) +#elif defined(XWINDOWS) qglXChooseVisual = 0; qglXCreateContext = 0; qglXDestroyContext = 0; @@ -152,6 +152,8 @@ void QGL_Shutdown(OpenGLBinding& table) qglXWaitX = 0; qglXUseXFont = 0; qglXGetProcAddressARB = 0; +#else +#error "unsupported platform" #endif globalOutputStream() << "Done.\n"; @@ -236,7 +238,7 @@ typedef int (QGL_DLLEXPORT *QGLFunctionPointer)(); QGLFunctionPointer QGL_getExtensionFunc(const char* symbol) { -#if defined (__linux__) || defined (__APPLE__) +#if defined(XWINDOWS) //ASSERT_NOTNULL(qglXGetProcAddressARB); if (qglXGetProcAddressARB == 0) { @@ -246,9 +248,11 @@ QGLFunctionPointer QGL_getExtensionFunc(const char* symbol) { return (QGLFunctionPointer)qglXGetProcAddressARB(reinterpret_cast(symbol)); } -#else +#elif defined(WIN32) ASSERT_NOTNULL(qwglGetProcAddress); return qwglGetProcAddress(symbol); +#else +#error "unsupported platform" #endif } @@ -610,7 +614,7 @@ int QGL_Init(OpenGLBinding& table) { QGL_clear(table); -#ifdef WIN32 +#if defined(WIN32) qwglCopyContext = wglCopyContext; qwglCreateContext = wglCreateContext; qwglCreateLayerContext = wglCreateLayerContext; @@ -633,9 +637,7 @@ int QGL_Init(OpenGLBinding& table) qwglGetPixelFormat = GetPixelFormat; qwglSetPixelFormat = SetPixelFormat; qwglSwapBuffers = SwapBuffers; -#endif - -#if defined (__linux__) || defined (__APPLE__) +#elif defined(XWINDOWS) qglXChooseVisual = glXChooseVisual; qglXCreateContext = glXCreateContext; qglXDestroyContext = glXDestroyContext; @@ -654,12 +656,12 @@ int QGL_Init(OpenGLBinding& table) qglXWaitX = glXWaitX; qglXUseXFont = glXUseXFont; // qglXGetProcAddressARB = glXGetProcAddressARB; // Utah-GLX fix - qglXGetProcAddressARB = (glXGetProcAddressARBProc)dlsym(NULL, "glXGetProcAddressARB"); -#endif -#if defined (__linux__) || defined (__APPLE__) + qglXGetProcAddressARB = (glXGetProcAddressARBProc)dlsym(NULL, "glXGetProcAddressARB"); if ((qglXQueryExtension == 0) || (qglXQueryExtension(GDK_DISPLAY(),0,0) != True)) return 0; +#else +#error "unsupported platform" #endif return 1; diff --git a/radiant/server.cpp b/radiant/server.cpp index 193f3e72..28b5659d 100644 --- a/radiant/server.cpp +++ b/radiant/server.cpp @@ -160,7 +160,7 @@ public: } }; -#elif defined(__linux__) || defined (__APPLE__) +#elif defined(POSIX) #include @@ -198,6 +198,8 @@ public: } }; +#else +#error "unsupported platform" #endif class DynamicLibraryModule diff --git a/radiant/sockets.cpp b/radiant/sockets.cpp new file mode 100644 index 00000000..6f4298c9 --- /dev/null +++ b/radiant/sockets.cpp @@ -0,0 +1,47 @@ + +#include "sockets.h" + +#if defined(WIN32) +#include +#elif defined (POSIX) +#include +#define SOCKET_ERROR -1 +#else +#error "unsupported platform" +#endif + +#ifdef __APPLE__ +#include +#endif + +int Net_Wait(socket_t *sock, long sec, long usec) +{ +// used for select() +#ifdef WIN32 + TIMEVAL tout = { sec, usec }; +#endif +#if defined (POSIX) + timeval tout; + tout.tv_sec = sec; + tout.tv_usec = usec; +#endif + + // select() will identify if the socket needs an update + // if the socket is identified that means there's either a message or the connection has been closed/reset/terminated + fd_set readfds; + FD_ZERO(&readfds); + FD_SET(((unsigned int)sock->socket), &readfds); + // from select man page: + // n is the highest-numbered descriptor in any of the three sets, plus 1 + // (no use on windows) + switch( select( sock->socket + 1, &readfds, NULL, NULL, &tout ) ) + { + case SOCKET_ERROR: + return -1; + case 0: + return 0; + default: + return 1; + } +} + diff --git a/radiant/sockets.h b/radiant/sockets.h new file mode 100644 index 00000000..3bc2274d --- /dev/null +++ b/radiant/sockets.h @@ -0,0 +1,14 @@ + +#if !defined(INCLUDED_SOCKETS_H) +#define INCLUDED_SOCKETS_H + +#include "l_net/l_net.h" + +// waits for a socket to become ready +// returns +// -1: error +// 0: timeout +// 1: ready +int Net_Wait(socket_t *sock, long sec, long usec); + +#endif diff --git a/radiant/timer.cpp b/radiant/timer.cpp index bae03afb..617112e1 100644 --- a/radiant/timer.cpp +++ b/radiant/timer.cpp @@ -67,7 +67,7 @@ MillisecondTime MillisecondTime::current() -#elif defined(__linux__) || defined (__APPLE__) +#elif defined(POSIX) #include #include "sys/time.h" diff --git a/radiant/url.cpp b/radiant/url.cpp index 527643e7..382dcd90 100644 --- a/radiant/url.cpp +++ b/radiant/url.cpp @@ -33,7 +33,7 @@ bool open_url(const char* url) } #endif -#ifdef __linux__ +#if defined(__linux__) || defined(__FreeBSD__) #include bool open_url(const char* url) { diff --git a/radiant/watchbsp.cpp b/radiant/watchbsp.cpp index 8c243930..ee8912e0 100644 --- a/radiant/watchbsp.cpp +++ b/radiant/watchbsp.cpp @@ -50,21 +50,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "points.h" #include "feedback.h" #include "mainframe.h" - - -#ifdef WIN32 -//#include -#endif - -#if defined (__linux__) || defined (__APPLE__) -#include -#define SOCKET_ERROR -1 -#endif - -#ifdef __APPLE__ -#include -#endif - +#include "sockets.h" void message_flush(message_info_t* self) { @@ -93,7 +79,6 @@ void message_print(message_info_t* self, const char* characters, std::size_t len } -#include "l_net/l_net.h" #include #include #include "xmlstuff.h" @@ -614,14 +599,14 @@ void CWatchBSP::DoEBeginStep() #if defined(WIN32) #define ENGINE_ATTRIBUTE "engine_win32" #define MP_ENGINE_ATTRIBUTE "mp_engine_win32" -#elif defined(__linux__) +#elif defined(__linux__) || defined (__FreeBSD__) #define ENGINE_ATTRIBUTE "engine_linux" #define MP_ENGINE_ATTRIBUTE "mp_engine_linux" #elif defined(__APPLE__) #define ENGINE_ATTRIBUTE "engine_macos" #define MP_ENGINE_ATTRIBUTE "mp_engine_macos" #else -#error "unknown platform" +#error "unsupported platform" #endif class RunEngineConfiguration @@ -678,22 +663,8 @@ inline void GlobalGameDescription_string_write_mapparameter(StringOutputStream& } -#ifdef WIN32 -#include -#endif - void CWatchBSP::RoutineProcessing() { - // used for select() -#ifdef WIN32 - TIMEVAL tout = { 0, 0 }; -#endif -#if defined (__linux__) || defined (__APPLE__) - timeval tout; - tout.tv_sec = 0; - tout.tv_usec = 0; -#endif - switch (m_eState) { case EBeginStep: @@ -732,6 +703,7 @@ void CWatchBSP::RoutineProcessing() } break; case EWatching: + { #ifdef _DEBUG // some debug checks if (!m_pInSocket) @@ -740,33 +712,16 @@ void CWatchBSP::RoutineProcessing() return; } #endif - // select() will identify if the socket needs an update - // if the socket is identified that means there's either a message or the connection has been closed/reset/terminated - fd_set readfds; - int ret; - FD_ZERO(&readfds); - FD_SET(((unsigned int)m_pInSocket->socket), &readfds); - // from select man page: - // n is the highest-numbered descriptor in any of the three sets, plus 1 - // (no use on windows) - ret = select( m_pInSocket->socket + 1, &readfds, NULL, NULL, &tout ); - if (ret == SOCKET_ERROR) - { - globalOutputStream() << "WARNING: SOCKET_ERROR in CWatchBSP::RoutineProcessing\n"; - globalOutputStream() << "Terminating the connection.\n"; - EndMonitoringLoop(); - return; - } -#ifdef _DEBUG + + int ret = Net_Wait(m_pInSocket, 0, 0); if (ret == -1) { - // we are non-blocking?? we should never get timeout errors - globalOutputStream() << "WARNING: unexpected timeout expired in CWatchBSP::Processing\n"; + globalOutputStream() << "WARNING: SOCKET_ERROR in CWatchBSP::RoutineProcessing\n"; globalOutputStream() << "Terminating the connection.\n"; EndMonitoringLoop(); return; } -#endif + if (ret == 1) { // the socket has been identified, there's something (message or disconnection) @@ -872,6 +827,7 @@ void CWatchBSP::RoutineProcessing() } } } + } break; default: break;