Skip to content
This repository
Browse code

Windows: In-depth cleanup (see details)

-Fix x64 builds for Windows. Now all configurations compile.
-Remove the non-working rebase stuff.
-Remove the Windows fork hack and instead use FreeConsole() to emulate the behavior. This directly allows us to compile with ASLR, which is turned on now.
-Remove the old IPC mechanism for the removed GUI. This is not needed anymore as the GUI wasn't ever supported on anything newer than 1.2
-Remove the WIN32/WINDOWS macros. _WIN32 is supported on all x86-based VC++ targets, so that's what we need.
-Enable optimizations for release builds.
-De-duplicate printf_c(), it was previously copy-pasted into colors.h for configure
-Add the VC++ specific bad files in .gitignore
-Disable PID writing on Windows. This is only making sense for *nix builds.
-Replace the CPU usage retrieval with an algorithm analogous to the *nix behavior. Also supports separated now/total values. (Tested with a dummy busy loop - seems working)
-Removed certain unused functions and variables
-Remove stdint defines from the windows wrapper
-Remove CRT debug alloc. This is a bad idea as it would define a macro to replace free which breaks builds.
-Re-evaluated the warnings list, commented it.
-Moved inspircd_config/_version to include/ to match *nix
-Removed the creation of inspircd_se_config, as it isn't used at all.
-Made non-git builds show as "r0" instead of "r" (thanks to @SaberUK for pointing this out)
-Fixed up m_spanningtree's project paths. Now all configurations (debug/release x86/x64) have been tested and build properly.
-Moved FindDNS out of the wrapper and matched its log behavior with *nix. (It's pointless having it in the wrapper after the recent slimming down)
-Replaced random/srandom wrappers with a mechanism that tries to use Windows' Random API first is no SSL module is loaded.
-Removed more old junk from support for compilers older than VC++ 2010 (we don't have project files for these, so compiling them would be hard anyways)
-Removed the unused ClearConsole()
-Removed unused includes from the wrapper. Also, do not include psapi.h here if we don't link psapi.lib. This should be done where appropriate.
-Made inet_aton an inline function for increased performance
-C4800, performance warning about bool forcing, resolved at all occurrences.
-C4701, uninitialized variable 'cached', resolved at all occurrences.
-dlerror() was migrated out of the wrapper for more thread safety (no global buffer being shared) and increased performance.
-Removed the wrong CRT debug flags. This drains a lot of performance.
-Removed the clock_gettime/gettimeofday wrappers
-Replaced all TCHAR/ANSI mix-ups of functions with the correct respective function.
-Added a block of C4355 for < VS2012
-Update project files for c870714
  • Loading branch information...
commit 5b9682275e384635a1fd9f7320cf4d9a604a43b4 1 parent 152bf49
ChrisTX authored

Showing 55 changed files with 533 additions and 1,287 deletions. Show diff stats Hide diff stats

  1. +25 0 .gitignore
  2. +0 4 include/bancache.h
  3. +2 2 include/base.h
  4. +1 1  include/configparser.h
  5. +0 4 include/dns.h
  6. +6 0 include/dynamic.h
  7. +4 14 include/hash_map.h
  8. +1 1  include/hashcomp.h
  9. +14 6 include/inspircd.h
  10. +1 1  include/modules.h
  11. +1 1  include/socket.h
  12. +0 4 include/threadengine.h
  13. +4 1 include/threadengines/threadengine_win32.h
  14. +5 10 include/typedefs.h
  15. +1 1  include/users.h
  16. +30 4 src/commands/cmd_stats.cpp
  17. +35 5 src/configreader.cpp
  18. +1 1  src/dns.cpp
  19. +23 1 src/dynamic.cpp
  20. +5 12 src/hashcomp.cpp
  21. +17 0 src/helperfuncs.cpp
  22. +56 51 src/inspircd.cpp
  23. +1 1  src/modmanager_dynamic.cpp
  24. +2 2 src/modules.cpp
  25. +1 1  src/modules/extra/m_geoip.cpp
  26. +1 1  src/modules/extra/m_ldapauth.cpp
  27. +1 1  src/modules/extra/m_ldapoper.cpp
  28. +1 1  src/modules/extra/m_mysql.cpp
  29. +1 1  src/modules/extra/m_regex_pcre.cpp
  30. +1 1  src/modules/extra/m_sqlite3.cpp
  31. +1 1  src/modules/extra/m_ssl_gnutls.cpp
  32. +1 1  src/modules/extra/m_ssl_openssl.cpp
  33. +1 1  src/modules/m_spanningtree/main.cpp
  34. +2 2 src/modules/m_spanningtree/resolvers.cpp
  35. +1 1  src/modules/m_spanningtree/utils.cpp
  36. +3 7 src/modules/m_spanningtree/utils.h
  37. +2 5 src/modules/m_watch.cpp
  38. +1 1  src/modules/ssl.h
  39. +5 3 src/server.cpp
  40. +6 6 src/socketengine.cpp
  41. +1 1  src/socketengines/socketengine_poll.cpp
  42. +2 2 src/socketengines/socketengine_select.cpp
  43. +10 1 src/threadengines/threadengine_win32.cpp
  44. +1 3 win/{colours.h → colors.h}
  45. +64 129 win/configure.cpp
  46. +28 23 win/configure.vcxproj
  47. +47 47 win/inspircd.vcxproj
  48. +2 2 win/inspircd_memory_functions.cpp
  49. +0 196 win/inspircd_namedpipe.cpp
  50. +0 55 win/inspircd_namedpipe.h
  51. +13 496 win/inspircd_win32wrapper.cpp
  52. +49 122 win/inspircd_win32wrapper.h
  53. +28 30 win/m_spanningtree.vcxproj
  54. +0 3  win/rebase.bat
  55. +24 16 win/win32service.cpp
25 .gitignore
@@ -9,6 +9,7 @@
9 9 /inspircd
10 10 /org.inspircd.plist
11 11 /run
  12 +/bin
12 13
13 14 /include/inspircd_config.h
14 15 /include/inspircd_version.h
@@ -26,3 +27,27 @@
26 27 /src/modules/m_sqlite3.cpp
27 28 /src/modules/m_ssl_gnutls.cpp
28 29 /src/modules/m_ssl_openssl.cpp
  30 +
  31 +*.ilk
  32 +*.lib
  33 +*.pdb
  34 +*.exp
  35 +*.dll
  36 +*.exe
  37 +/src/commands/debug
  38 +/src/commands/release
  39 +/src/commands/debug_x64
  40 +/src/commands/release_x64
  41 +/src/commands/commands.mak
  42 +/src/modules/debug
  43 +/src/modules/release
  44 +/src/modules/debug_x64
  45 +/src/modules/release_x64
  46 +/src/modules/modules.mak
  47 +/win/x64*
  48 +/win/debug*
  49 +/win/release*
  50 +/win/*.suo
  51 +/win/*.sdf
  52 +/win/*.user
  53 +/win/*.opensdf
4 include/bancache.h
@@ -65,11 +65,7 @@ class CoreExport BanCacheHit
65 65 /* A container of ban cache items.
66 66 * must be defined after class BanCacheHit.
67 67 */
68   -#if defined(WINDOWS) && !defined(HASHMAP_DEPRECATED)
69   -typedef nspace::hash_map<std::string, BanCacheHit*, nspace::hash_compare<std::string, std::less<std::string> > > BanCacheHash;
70   -#else
71 68 typedef nspace::hash_map<std::string, BanCacheHit*, nspace::hash<std::string> > BanCacheHash;
72   -#endif
73 69
74 70 /** A manager for ban cache, which allocates and deallocates and checks cached bans.
75 71 */
4 include/base.h
@@ -157,7 +157,7 @@ class CoreExport reference
157 157 return *this;
158 158 }
159 159
160   - inline operator bool() const { return value; }
  160 + inline operator bool() const { return (value != NULL); }
161 161 inline operator T*() const { return value; }
162 162 inline T* operator->() const { return value; }
163 163 inline T& operator*() const { return *value; }
@@ -165,7 +165,7 @@ class CoreExport reference
165 165 inline bool operator>(const reference<T>& other) const { return value > other.value; }
166 166 static inline void* operator new(size_t, void* m) { return m; }
167 167 private:
168   -#ifndef WIN32
  168 +#ifndef _WIN32
169 169 static void* operator new(size_t);
170 170 static void operator delete(void*);
171 171 #endif
2  include/configparser.h
@@ -63,7 +63,7 @@ struct FileWrapper
63 63 FILE* const f;
64 64 bool close_with_pclose;
65 65 FileWrapper(FILE* file, bool use_pclose = false) : f(file), close_with_pclose(use_pclose) {}
66   - operator bool() { return f; }
  66 + operator bool() { return (f != NULL); }
67 67 operator FILE*() { return f; }
68 68 ~FileWrapper()
69 69 {
4 include/dns.h
@@ -102,11 +102,7 @@ class CoreExport CachedQuery
102 102
103 103 /** DNS cache information. Holds IPs mapped to hostnames, and hostnames mapped to IPs.
104 104 */
105   -#if defined(WINDOWS) && !defined(HASHMAP_DEPRECATED)
106   -typedef nspace::hash_map<irc::string, CachedQuery, nspace::hash_compare<irc::string> > dnscache;
107   -#else
108 105 typedef nspace::hash_map<irc::string, CachedQuery, irc::hash> dnscache;
109   -#endif
110 106
111 107 /**
112 108 * Error types that class Resolver can emit to its error method.
6 include/dynamic.h
@@ -33,6 +33,12 @@ class CoreExport DLLManager : public classbase
33 33 */
34 34 std::string err;
35 35
  36 +#ifdef _WIN32
  37 + /** Sets the last error string
  38 + */
  39 + void RetrieveLastError();
  40 +#endif
  41 +
36 42 public:
37 43 /** This constructor loads the module using dlopen()
38 44 * @param fname The filename to load. This should be within
18 include/hash_map.h
@@ -28,7 +28,7 @@
28 28 /** Where hash_map is varies from compiler to compiler
29 29 * as it is not standard unless we have tr1.
30 30 */
31   - #ifndef WIN32
  31 + #ifndef _WIN32
32 32 #ifdef HASHMAP_DEPRECATED
33 33 // GCC4+ has deprecated hash_map and uses tr1. But of course, uses a different include to MSVC. FOR FUCKS SAKE.
34 34 #include <tr1/unordered_map>
@@ -41,19 +41,9 @@
41 41 #define END_HASHMAP_NAMESPACE }
42 42 #endif
43 43 #else
44   - #if _MSC_VER >= 1600
45   - // New MSVC has tr1. Just to make things fucked up, though, MSVC and GCC use different includes! FFS.
46   - #include <unordered_map>
47   - #define HAS_TR1_UNORDERED
48   - #define HASHMAP_DEPRECATED
49   - #else
50   - /** Oddball windows namespace for hash_map */
51   - #include <hash_map>
52   - #define nspace stdext
53   - using stdext::hash_map;
54   - #define BEGIN_HASHMAP_NAMESPACE namespace nspace {
55   - #define END_HASHMAP_NAMESPACE }
56   - #endif
  44 + #include <unordered_map>
  45 + #define HAS_TR1_UNORDERED
  46 + #define HASHMAP_DEPRECATED
57 47 #endif
58 48
59 49 // tr1: restoring sanity to our headers. now if only compiler vendors could agree on a FUCKING INCLUDE FILE.
2  include/hashcomp.h
@@ -598,7 +598,7 @@ BEGIN_HASHMAP_NAMESPACE
598 598
599 599 /** Hashing function to hash irc::string
600 600 */
601   -#if defined(WINDOWS) && !defined(HAS_TR1_UNORDERED)
  601 +#if defined(_WIN32) && !defined(HAS_TR1_UNORDERED)
602 602 template<> class CoreExport hash_compare<irc::string, std::less<irc::string> >
603 603 {
604 604 public:
20 include/inspircd.h
@@ -31,7 +31,7 @@
31 31 #define _LARGEFILE_SOURCE
32 32 #endif
33 33
34   -#ifndef WIN32
  34 +#ifndef _WIN32
35 35 #define DllExport
36 36 #define CoreExport
37 37 #define printf_c printf
@@ -55,7 +55,7 @@
55 55 #include <cstring>
56 56 #include <climits>
57 57 #include <cstdio>
58   -#ifndef WIN32
  58 +#ifndef _WIN32
59 59 #include <unistd.h>
60 60 #endif
61 61
@@ -232,12 +232,24 @@ class serverstats
232 232 /** Total bytes of data received
233 233 */
234 234 unsigned long statsRecv;
  235 +#ifdef _WIN32
  236 + /** Cpu usage at last sample
  237 + */
  238 + FILETIME LastCPU;
  239 + /** Time QP sample was read
  240 + */
  241 + LARGE_INTEGER LastSampled;
  242 + /** QP frequency
  243 + */
  244 + LARGE_INTEGER QPFrequency;
  245 +#else
235 246 /** Cpu usage at last sample
236 247 */
237 248 timeval LastCPU;
238 249 /** Time last sample was read
239 250 */
240 251 timespec LastSampled;
  252 +#endif
241 253 /** The constructor initializes all the counts to zero
242 254 */
243 255 serverstats()
@@ -308,10 +320,6 @@ class CoreExport InspIRCd
308 320 */
309 321 char ReadBuffer[65535];
310 322
311   -#ifdef WIN32
312   - IPC* WindowsIPC;
313   -#endif
314   -
315 323 public:
316 324
317 325 /** Global cull list, will be processed on next iteration
2  include/modules.h
@@ -1696,7 +1696,7 @@ struct AllModuleList {
1696 1696 * and functions needed to make a module loadable by the OS.
1697 1697 * It defines the class factory and external init_module function.
1698 1698 */
1699   -#ifdef WINDOWS
  1699 +#ifdef _WIN32
1700 1700
1701 1701 #define MODULE_INIT(y) \
1702 1702 extern "C" DllExport Module * MODULE_INIT_SYM() \
2  include/socket.h
@@ -25,7 +25,7 @@
25 25 #ifndef INSPIRCD_SOCKET_H
26 26 #define INSPIRCD_SOCKET_H
27 27
28   -#ifndef WIN32
  28 +#ifndef _WIN32
29 29
30 30 #include <arpa/inet.h>
31 31 #include <sys/time.h>
4 include/threadengine.h
@@ -27,10 +27,6 @@
27 27 #include "inspircd_config.h"
28 28 #include "base.h"
29 29
30   -#ifdef WINDOWS
31   -#include "threadengines/threadengine_win32.h"
32   -#endif
33   -
34 30 class ThreadData;
35 31
36 32 /** Derive from this class to implement your own threaded sections of
5 include/threadengines/threadengine_win32.h
@@ -108,12 +108,15 @@ class ThreadQueueData
108 108 public:
109 109 ThreadQueueData()
110 110 {
111   - InitializeCriticalSection(&mutex);
112 111 event = CreateEvent(NULL, false, false, NULL);
  112 + if (event == NULL)
  113 + throw CoreException("CreateEvent() failed in ThreadQueueData::ThreadQueueData()!");
  114 + InitializeCriticalSection(&mutex);
113 115 }
114 116
115 117 ~ThreadQueueData()
116 118 {
  119 + CloseHandle(event);
117 120 DeleteCriticalSection(&mutex);
118 121 }
119 122
15 include/typedefs.h
@@ -56,17 +56,12 @@ struct ResourceRecord;
56 56 #include "hashcomp.h"
57 57 #include "base.h"
58 58
59   -#if defined(WINDOWS) && !defined(HASHMAP_DEPRECATED)
60   - typedef nspace::hash_map<std::string, User*, nspace::hash_compare<std::string, std::less<std::string> > > user_hash;
61   - typedef nspace::hash_map<std::string, Channel*, nspace::hash_compare<std::string, std::less<std::string> > > chan_hash;
  59 +#ifdef HASHMAP_DEPRECATED
  60 + typedef nspace::hash_map<std::string, User*, nspace::insensitive, irc::StrHashComp> user_hash;
  61 + typedef nspace::hash_map<std::string, Channel*, nspace::insensitive, irc::StrHashComp> chan_hash;
62 62 #else
63   - #ifdef HASHMAP_DEPRECATED
64   - typedef nspace::hash_map<std::string, User*, nspace::insensitive, irc::StrHashComp> user_hash;
65   - typedef nspace::hash_map<std::string, Channel*, nspace::insensitive, irc::StrHashComp> chan_hash;
66   - #else
67   - typedef nspace::hash_map<std::string, User*, nspace::hash<std::string>, irc::StrHashComp> user_hash;
68   - typedef nspace::hash_map<std::string, Channel*, nspace::hash<std::string>, irc::StrHashComp> chan_hash;
69   - #endif
  63 + typedef nspace::hash_map<std::string, User*, nspace::hash<std::string>, irc::StrHashComp> user_hash;
  64 + typedef nspace::hash_map<std::string, Channel*, nspace::hash<std::string>, irc::StrHashComp> chan_hash;
70 65 #endif
71 66
72 67 /** A list of failed port bindings, used for informational purposes on startup */
2  include/users.h
@@ -60,7 +60,7 @@ enum UserModes {
60 60 */
61 61 enum RegistrationState {
62 62
63   -#ifndef WIN32 // Burlex: This is already defined in win32, luckily it is still 0.
  63 +#ifndef _WIN32 // Burlex: This is already defined in win32, luckily it is still 0.
64 64 REG_NONE = 0, /* Has sent nothing */
65 65 #endif
66 66
34 src/commands/cmd_stats.cpp
@@ -23,8 +23,9 @@
23 23 #include "xline.h"
24 24 #include "commands/cmd_whowas.h"
25 25
26   -#ifdef WINDOWS
27   -# pragma comment(lib, "psapi.lib") // For GetProcessMemoryInfo()
  26 +#ifdef _WIN32
  27 +#include <psapi.h>
  28 +#pragma comment(lib, "psapi.lib") // For GetProcessMemoryInfo()
28 29 #endif
29 30
30 31 /** Handle /STATS. These command handlers can be reloaded by the core,
@@ -240,7 +241,7 @@ void CommandStats::DoStats(char statschar, User* user, string_list &results)
240 241 results.push_back(sn+" 249 "+user->nick+" :Bandwidth out: "+ConvToStr(kbitpersec_out_s)+" kilobits/sec");
241 242 results.push_back(sn+" 249 "+user->nick+" :Bandwidth in: "+ConvToStr(kbitpersec_in_s)+" kilobits/sec");
242 243
243   -#ifndef WIN32
  244 +#ifndef _WIN32
244 245 /* Moved this down here so all the not-windows stuff (look w00tie, I didn't say win32!) is in one ifndef.
245 246 * Also cuts out some identical code in both branches of the ifndef. -- Om
246 247 */
@@ -278,7 +279,32 @@ void CommandStats::DoStats(char statschar, User* user, string_list &results)
278 279 results.push_back(sn+" 249 "+user->nick+" :Total allocation: "+ConvToStr((MemCounters.WorkingSetSize + MemCounters.PagefileUsage) / 1024)+"K");
279 280 results.push_back(sn+" 249 "+user->nick+" :Pagefile usage: "+ConvToStr(MemCounters.PagefileUsage / 1024)+"K");
280 281 results.push_back(sn+" 249 "+user->nick+" :Page faults: "+ConvToStr(MemCounters.PageFaultCount));
281   - results.push_back(sn+" 249 "+user->nick+" :CPU Usage: " + ConvToStr(getcpu()) + "%");
  282 + }
  283 +
  284 + FILETIME CreationTime;
  285 + FILETIME ExitTime;
  286 + FILETIME KernelTime;
  287 + FILETIME UserTime;
  288 + LARGE_INTEGER ThisSample;
  289 + if(GetProcessTimes(GetCurrentProcess(), &CreationTime, &ExitTime, &KernelTime, &UserTime) &&
  290 + QueryPerformanceCounter(&ThisSample))
  291 + {
  292 + KernelTime.dwHighDateTime += UserTime.dwHighDateTime;
  293 + KernelTime.dwLowDateTime += UserTime.dwLowDateTime;
  294 + double n_eaten = (double)( ( (uint64_t)(KernelTime.dwHighDateTime - ServerInstance->stats->LastCPU.dwHighDateTime) << 32 ) + (uint64_t)(KernelTime.dwLowDateTime - ServerInstance->stats->LastCPU.dwLowDateTime) )/100000;
  295 + double n_elapsed = (double)(ThisSample.QuadPart - ServerInstance->stats->LastSampled.QuadPart) / ServerInstance->stats->QPFrequency.QuadPart;
  296 + double per = (n_eaten/n_elapsed);
  297 +
  298 + char percent[30];
  299 +
  300 + snprintf(percent, 30, "%03.5f%%", per);
  301 + results.push_back(sn+" 249 "+user->nick+" :CPU Use (now): "+percent);
  302 +
  303 + n_elapsed = ServerInstance->Time() - ServerInstance->startup_time;
  304 + n_eaten = (double)(( (uint64_t)(KernelTime.dwHighDateTime) << 32 ) + (uint64_t)(KernelTime.dwLowDateTime))/100000;
  305 + per = (n_eaten / n_elapsed);
  306 + snprintf(percent, 30, "%03.5f%%", per);
  307 + results.push_back(sn+" 249 "+user->nick+" :CPU Use (total): "+percent);
282 308 }
283 309 #endif
284 310 }
40 src/configreader.cpp
@@ -28,6 +28,10 @@
28 28 #include "exitcodes.h"
29 29 #include "commands/cmd_whowas.h"
30 30 #include "configparser.h"
  31 +#ifdef _WIN32
  32 +#include <Iphlpapi.h>
  33 +#pragma comment(lib, "Iphlpapi.lib")
  34 +#endif
31 35
32 36 ServerConfig::ServerConfig()
33 37 {
@@ -140,15 +144,41 @@ bool ServerConfig::ApplyDisabledCommands(const std::string& data)
140 144 return true;
141 145 }
142 146
143   -#ifdef WINDOWS
144   -// Note: the windows validator is in win32wrapper.cpp
145   -void FindDNS(std::string& server);
146   -#else
147 147 static void FindDNS(std::string& server)
148 148 {
149 149 if (!server.empty())
150 150 return;
  151 +#ifdef _WIN32
  152 + // attempt to look up their nameserver from the system
  153 + ServerInstance->Logs->Log("CONFIG",DEFAULT,"WARNING: <dns:server> not defined, attempting to find a working server in the system settings...");
  154 +
  155 + PFIXED_INFO pFixedInfo;
  156 + DWORD dwBufferSize = sizeof(FIXED_INFO);
  157 + pFixedInfo = (PFIXED_INFO) HeapAlloc(GetProcessHeap(), 0, sizeof(FIXED_INFO));
  158 +
  159 + if(pFixedInfo)
  160 + {
  161 + if (GetNetworkParams(pFixedInfo, &dwBufferSize) == ERROR_BUFFER_OVERFLOW) {
  162 + HeapFree(GetProcessHeap(), 0, pFixedInfo);
  163 + pFixedInfo = (PFIXED_INFO) HeapAlloc(GetProcessHeap(), 0, dwBufferSize);
  164 + }
  165 +
  166 + if(pFixedInfo) {
  167 + if (GetNetworkParams(pFixedInfo, &dwBufferSize) == NO_ERROR)
  168 + server = pFixedInfo->DnsServerList.IpAddress.String;
  169 +
  170 + HeapFree(GetProcessHeap(), 0, pFixedInfo);
  171 + }
  172 +
  173 + if(!server.empty())
  174 + {
  175 + ServerInstance->Logs->Log("CONFIG",DEFAULT,"<dns:server> set to '%s' as first active resolver in the system settings.", server.c_str());
  176 + return;
  177 + }
  178 + }
151 179
  180 + ServerInstance->Logs->Log("CONFIG",DEFAULT,"No viable nameserver found! Defaulting to nameserver '127.0.0.1'!");
  181 +#else
152 182 // attempt to look up their nameserver from /etc/resolv.conf
153 183 ServerInstance->Logs->Log("CONFIG",DEFAULT,"WARNING: <dns:server> not defined, attempting to find working server in /etc/resolv.conf...");
154 184
@@ -168,9 +198,9 @@ static void FindDNS(std::string& server)
168 198 }
169 199
170 200 ServerInstance->Logs->Log("CONFIG",DEFAULT,"/etc/resolv.conf contains no viable nameserver entries! Defaulting to nameserver '127.0.0.1'!");
  201 +#endif
171 202 server = "127.0.0.1";
172 203 }
173   -#endif
174 204
175 205 static void ReadXLine(ServerConfig* conf, const std::string& tag, const std::string& key, XLineFactory* make)
176 206 {
2  src/dns.cpp
@@ -34,7 +34,7 @@ Please do not assume that firedns works like this,
34 34 looks like this, walks like this or tastes like this.
35 35 */
36 36
37   -#ifndef WIN32
  37 +#ifndef _WIN32
38 38 #include <sys/types.h>
39 39 #include <sys/socket.h>
40 40 #include <errno.h>
24 src/dynamic.cpp
@@ -23,8 +23,12 @@
23 23
24 24 #include "inspircd.h"
25 25 #include "dynamic.h"
26   -#ifndef WIN32
  26 +#ifndef _WIN32
27 27 #include <dlfcn.h>
  28 +#else
  29 +#define dlopen(path, state) (void*)LoadLibraryA(path)
  30 +#define dlsym(handle, export) (void*)GetProcAddress((HMODULE)handle, export)
  31 +#define dlclose(handle) FreeLibrary((HMODULE)handle)
28 32 #endif
29 33
30 34 DLLManager::DLLManager(const char *fname)
@@ -39,7 +43,11 @@ DLLManager::DLLManager(const char *fname)
39 43 h = dlopen(fname, RTLD_NOW|RTLD_LOCAL);
40 44 if (!h)
41 45 {
  46 +#ifdef _WIN32
  47 + RetrieveLastError();
  48 +#else
42 49 err = dlerror();
  50 +#endif
43 51 }
44 52 }
45 53
@@ -64,7 +72,11 @@ Module* DLLManager::CallInit()
64 72 initfn.vptr = dlsym(h, MODULE_INIT_STR);
65 73 if (!initfn.vptr)
66 74 {
  75 +#ifdef _WIN32
  76 + RetrieveLastError();
  77 +#else
67 78 err = dlerror();
  79 +#endif
68 80 return NULL;
69 81 }
70 82
@@ -81,3 +93,13 @@ std::string DLLManager::GetVersion()
81 93 return srcver;
82 94 return "Unversioned module";
83 95 }
  96 +
  97 +#ifdef _WIN32
  98 +void DLLManager::RetrieveLastError()
  99 +{
  100 + CHAR errmsg[100];
  101 + FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, 0, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), errmsg, 100, 0);
  102 + SetLastError(ERROR_SUCCESS);
  103 + err = errmsg;
  104 +}
  105 +#endif
17 src/hashcomp.cpp
@@ -127,15 +127,12 @@ void nspace::strlower(char *n)
127 127 }
128 128 }
129 129
130   -#if defined(WINDOWS) && !defined(HASHMAP_DEPRECATED)
131   - size_t nspace::hash_compare<std::string, std::less<std::string> >::operator()(const std::string &s) const
  130 +#ifdef HASHMAP_DEPRECATED
  131 + size_t CoreExport nspace::insensitive::operator()(const std::string &s) const
132 132 #else
133   - #ifdef HASHMAP_DEPRECATED
134   - size_t CoreExport nspace::insensitive::operator()(const std::string &s) const
135   - #else
136   - size_t nspace::hash<std::string>::operator()(const std::string &s) const
137   - #endif
  133 + size_t nspace::hash<std::string>::operator()(const std::string &s) const
138 134 #endif
  135 +
139 136 {
140 137 /* XXX: NO DATA COPIES! :)
141 138 * The hash function here is practically
@@ -150,11 +147,7 @@ void nspace::strlower(char *n)
150 147 }
151 148
152 149
153   -#if defined(WINDOWS) && !defined(HASHMAP_DEPRECATED)
154   - size_t nspace::hash_compare<irc::string, std::less<irc::string> >::operator()(const irc::string &s) const
155   -#else
156   - size_t CoreExport irc::hash::operator()(const irc::string &s) const
157   -#endif
  150 +size_t CoreExport irc::hash::operator()(const irc::string &s) const
158 151 {
159 152 register size_t t = 0;
160 153 for (irc::string::const_iterator x = s.begin(); x != s.end(); ++x) /* ++x not x++, as its faster */
17 src/helperfuncs.cpp
@@ -24,6 +24,11 @@
24 24
25 25 /* $Core */
26 26
  27 +#ifdef _WIN32
  28 +#define _CRT_RAND_S
  29 +#include <stdlib.h>
  30 +#endif
  31 +
27 32 #include "inspircd.h"
28 33 #include "xline.h"
29 34 #include "exitcodes.h"
@@ -311,12 +316,14 @@ bool InspIRCd::OpenLog(char**, int)
311 316
312 317 void InspIRCd::CheckRoot()
313 318 {
  319 +#ifndef _WIN32
314 320 if (geteuid() == 0)
315 321 {
316 322 printf("WARNING!!! You are running an irc server as ROOT!!! DO NOT DO THIS!!!\n\n");
317 323 this->Logs->Log("STARTUP",DEFAULT,"Cant start as root");
318 324 Exit(EXIT_STATUS_ROOT);
319 325 }
  326 +#endif
320 327 }
321 328
322 329 void InspIRCd::SendWhoisLine(User* user, User* dest, int numeric, const std::string &text)
@@ -451,7 +458,17 @@ unsigned long InspIRCd::GenRandomInt(unsigned long max)
451 458 void GenRandomHandler::Call(char *output, size_t max)
452 459 {
453 460 for(unsigned int i=0; i < max; i++)
  461 +#ifdef _WIN32
  462 + {
  463 + unsigned int uTemp;
  464 + if(rand_s(&uTemp) != 0)
  465 + output[i] = rand();
  466 + else
  467 + output[i] = uTemp;
  468 + }
  469 +#else
454 470 output[i] = random();
  471 +#endif
455 472 }
456 473
457 474 ModResult OnCheckExemptionHandler::Call(User* user, Channel* chan, const std::string& restriction)
107 src/inspircd.cpp
@@ -31,7 +31,7 @@
31 31 #include "inspircd_version.h"
32 32 #include <signal.h>
33 33
34   -#ifndef WIN32
  34 +#ifndef _WIN32
35 35 #include <dirent.h>
36 36 #include <unistd.h>
37 37 #include <sys/resource.h>
@@ -163,9 +163,9 @@ void InspIRCd::Restart(const std::string &reason)
163 163
164 164 char** argv = Config->cmdline.argv;
165 165
166   -#ifdef WINDOWS
  166 +#ifdef _WIN32
167 167 char module[MAX_PATH];
168   - if (GetModuleFileName(NULL, module, MAX_PATH))
  168 + if (GetModuleFileNameA(NULL, module, MAX_PATH))
169 169 me = module;
170 170 #else
171 171 me = argv[0];
@@ -223,7 +223,7 @@ void InspIRCd::RehashUsersAndChans()
223 223
224 224 void InspIRCd::SetSignals()
225 225 {
226   -#ifndef WIN32
  226 +#ifndef _WIN32
227 227 signal(SIGALRM, SIG_IGN);
228 228 signal(SIGHUP, InspIRCd::SetSignal);
229 229 signal(SIGPIPE, SIG_IGN);
@@ -241,7 +241,7 @@ void InspIRCd::QuickExit(int status)
241 241
242 242 bool InspIRCd::DaemonSeed()
243 243 {
244   -#ifdef WINDOWS
  244 +#ifdef _WIN32
245 245 printf_c("InspIRCd Process ID: \033[1;32m%lu\033[0m\n", GetCurrentProcessId());
246 246 return true;
247 247 #else
@@ -285,6 +285,7 @@ bool InspIRCd::DaemonSeed()
285 285
286 286 void InspIRCd::WritePID(const std::string &filename)
287 287 {
  288 +#ifndef _WIN32
288 289 std::string fname(filename);
289 290 if (fname.empty())
290 291 fname = DATA_PATH "/inspircd.pid";
@@ -300,6 +301,7 @@ void InspIRCd::WritePID(const std::string &filename)
300 301 this->Logs->Log("STARTUP",DEFAULT,"Failed to write PID-file '%s', exiting.",fname.c_str());
301 302 Exit(EXIT_STATUS_PID);
302 303 }
  304 +#endif
303 305 }
304 306
305 307 InspIRCd::InspIRCd(int argc, char** argv) :
@@ -321,14 +323,6 @@ InspIRCd::InspIRCd(int argc, char** argv) :
321 323 FloodQuitUser(&HandleFloodQuitUser),
322 324 OnCheckExemption(&HandleOnCheckExemption)
323 325 {
324   -#ifdef WIN32
325   - // Strict, frequent checking of memory on debug builds
326   - _CrtSetDbgFlag ( _CRTDBG_CHECK_ALWAYS_DF | _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
327   -
328   - // Avoid erroneous frees on early exit
329   - WindowsIPC = 0;
330   -#endif
331   -
332 326 ServerInstance = this;
333 327
334 328 Extensions.Register(&NICKForced);
@@ -393,7 +387,11 @@ InspIRCd::InspIRCd(int argc, char** argv) :
393 387 this->Config->cmdline.argv = argv;
394 388 this->Config->cmdline.argc = argc;
395 389
  390 +#ifdef _WIN32
  391 + srand(TIME.tv_nsec ^ TIME.tv_sec);
  392 +#else
396 393 srandom(TIME.tv_nsec ^ TIME.tv_sec);
  394 +#endif
397 395
398 396 struct option longopts[] =
399 397 {
@@ -444,27 +442,17 @@ InspIRCd::InspIRCd(int argc, char** argv) :
444 442 Exit(EXIT_STATUS_NOERROR);
445 443 }
446 444
447   -#ifdef WIN32
448   -
449   - // Handle forking
450   - if(!do_nofork)
451   - {
452   - DWORD ExitCode = WindowsForkStart();
453   - if(ExitCode)
454   - exit(ExitCode);
455   - }
456   -
  445 +#ifdef _WIN32
457 446 // Set up winsock
458 447 WSADATA wsadata;
459   - WSAStartup(MAKEWORD(2,0), &wsadata);
460   - ChangeWindowsSpecificPointers();
  448 + WSAStartup(MAKEWORD(2,2), &wsadata);
461 449 #endif
462 450
463 451 /* Set the finished argument values */
464   - Config->cmdline.nofork = do_nofork;
465   - Config->cmdline.forcedebug = do_debug;
466   - Config->cmdline.writelog = !do_nolog;
467   - Config->cmdline.TestSuite = do_testsuite;
  452 + Config->cmdline.nofork = (do_nofork != 0);
  453 + Config->cmdline.forcedebug = (do_debug != 0);
  454 + Config->cmdline.writelog = (!do_nolog != 0);
  455 + Config->cmdline.TestSuite = (do_testsuite != 0);
468 456
469 457 if (do_debug)
470 458 {
@@ -480,7 +468,7 @@ InspIRCd::InspIRCd(int argc, char** argv) :
480 468
481 469 if (!ServerConfig::FileExists(ConfigFileName.c_str()))
482 470 {
483   -#ifdef WIN32
  471 +#ifdef _WIN32
484 472 /* Windows can (and defaults to) hide file extensions, so let's play a bit nice for windows users. */
485 473 std::string txtconf = this->ConfigFileName;
486 474 txtconf.append(".txt");
@@ -507,6 +495,7 @@ InspIRCd::InspIRCd(int argc, char** argv) :
507 495
508 496 this->Modes = new ModeParser;
509 497
  498 +#ifndef _WIN32
510 499 if (!do_root)
511 500 this->CheckRoot();
512 501 else
@@ -521,6 +510,7 @@ InspIRCd::InspIRCd(int argc, char** argv) :
521 510 printf("\nInspIRCd starting in 20 seconds, ctrl+c to abort...\n");
522 511 sleep(20);
523 512 }
  513 +#endif
524 514
525 515 this->SetSignals();
526 516
@@ -598,7 +588,7 @@ InspIRCd::InspIRCd(int argc, char** argv) :
598 588 printf("\nInspIRCd is now running as '%s'[%s] with %d max open sockets\n",
599 589 Config->ServerName.c_str(),Config->GetSID().c_str(), SE->GetMaxFds());
600 590
601   -#ifndef WINDOWS
  591 +#ifndef _WIN32
602 592 if (!Config->cmdline.nofork)
603 593 {
604 594 if (kill(getppid(), SIGTERM) == -1)
@@ -640,19 +630,21 @@ InspIRCd::InspIRCd(int argc, char** argv) :
640 630 Logs->Log("STARTUP", DEFAULT,"Keeping pseudo-tty open as we are running in the foreground.");
641 631 }
642 632 #else
643   - WindowsIPC = new IPC;
644   - if(!Config->cmdline.nofork)
  633 + /* Set win32 service as running, if we are running as a service */
  634 + SetServiceRunning();
  635 +
  636 + // Handle forking
  637 + if(!do_nofork)
645 638 {
646   - WindowsForkKillOwner();
647 639 FreeConsole();
648 640 }
649   - /* Set win32 service as running, if we are running as a service */
650   - SetServiceRunning();
  641 +
  642 + QueryPerformanceFrequency(&stats->QPFrequency);
651 643 #endif
652 644
653 645 Logs->Log("STARTUP", DEFAULT, "Startup complete as '%s'[%s], %d max open sockets", Config->ServerName.c_str(),Config->GetSID().c_str(), SE->GetMaxFds());
654 646
655   -#ifndef WIN32
  647 +#ifndef _WIN32
656 648 std::string SetUser = Config->ConfValue("security")->getString("runasuser");
657 649 std::string SetGroup = Config->ConfValue("security")->getString("runasgroup");
658 650 if (!SetGroup.empty())
@@ -711,20 +703,28 @@ InspIRCd::InspIRCd(int argc, char** argv) :
711 703 this->QuickExit(0);
712 704 }
713 705 }
714   -#endif
715 706
716 707 this->WritePID(Config->PID);
  708 +#endif
717 709 }
718 710
719 711 void InspIRCd::UpdateTime()
720 712 {
721   -#ifdef HAS_CLOCK_GETTIME
722   - clock_gettime(CLOCK_REALTIME, &TIME);
  713 +#ifdef _WIN32
  714 + SYSTEMTIME st;
  715 + GetSystemTime(&st);
  716 +
  717 + TIME.tv_sec = time(NULL);
  718 + TIME.tv_nsec = st.wMilliseconds;
723 719 #else
724   - struct timeval tv;
725   - gettimeofday(&tv, NULL);
726   - TIME.tv_sec = tv.tv_sec;
727   - TIME.tv_nsec = tv.tv_usec * 1000;
  720 + #ifdef HAS_CLOCK_GETTIME
  721 + clock_gettime(CLOCK_REALTIME, &TIME);
  722 + #else
  723 + struct timeval tv;
  724 + gettimeofday(&tv, NULL);
  725 + TIME.tv_sec = tv.tv_sec;
  726 + TIME.tv_nsec = tv.tv_usec * 1000;
  727 + #endif
728 728 #endif
729 729 }
730 730
@@ -743,12 +743,8 @@ int InspIRCd::Run()
743 743
744 744 while (true)
745 745 {
746   -#ifndef WIN32
  746 +#ifndef _WIN32
747 747 static rusage ru;
748   -#else
749   - static time_t uptime;
750   - static struct tm * stime;
751   - static char window_title[100];
752 748 #endif
753 749
754 750 /* Check if there is a config thread which has finished executing but has not yet been freed */
@@ -774,12 +770,21 @@ int InspIRCd::Run()
774 770 if (TIME.tv_sec != OLDTIME)
775 771 {
776 772 OLDTIME = TIME.tv_sec;
777   -#ifndef WIN32
  773 +#ifndef _WIN32
778 774 getrusage(RUSAGE_SELF, &ru);
779 775 stats->LastSampled = TIME;
780 776 stats->LastCPU = ru.ru_utime;
781 777 #else
782   - WindowsIPC->Check();
  778 + if(QueryPerformanceCounter(&stats->LastSampled))
  779 + {
  780 + FILETIME CreationTime;
  781 + FILETIME ExitTime;
  782 + FILETIME KernelTime;
  783 + FILETIME UserTime;
  784 + GetProcessTimes(GetCurrentProcess(), &CreationTime, &ExitTime, &KernelTime, &UserTime);
  785 + stats->LastCPU.dwHighDateTime = KernelTime.dwHighDateTime + UserTime.dwHighDateTime;
  786 + stats->LastCPU.dwLowDateTime = KernelTime.dwLowDateTime + UserTime.dwLowDateTime;
  787 + }
783 788 #endif
784 789
785 790 /* Allow a buffer of two seconds drift on this so that ntpdate etc dont harass admins */
2  src/modmanager_dynamic.cpp
@@ -25,7 +25,7 @@
25 25 #include "dns.h"
26 26 #include "exitcodes.h"
27 27
28   -#ifndef WIN32
  28 +#ifndef _WIN32
29 29 #include <dirent.h>
30 30 #endif
31 31
4 src/modules.cpp
@@ -32,7 +32,7 @@
32 32 #include "dns.h"
33 33 #include "exitcodes.h"
34 34
35   -#ifndef WIN32
  35 +#ifndef _WIN32
36 36 #include <dirent.h>
37 37 #endif
38 38
@@ -558,7 +558,7 @@ dynamic_reference_base::operator bool()
558 558 if (i != ServerInstance->Modules->DataProviders.end())
559 559 value = static_cast<DataProvider*>(i->second);
560 560 }
561   - return value;
  561 + return (value != NULL);
562 562 }
563 563
564 564 void InspIRCd::SendMode(const std::vector<std::string>& parameters, User *user)
2  src/modules/extra/m_geoip.cpp
@@ -23,7 +23,7 @@
23 23
24 24 #include <GeoIP.h>
25 25
26   -#ifdef WINDOWS
  26 +#ifdef _WIN32
27 27 # pragma comment(lib, "GeoIP.lib")
28 28 #endif
29 29
2  src/modules/extra/m_ldapauth.cpp
@@ -30,7 +30,7 @@
30 30
31 31 #include <ldap.h>
32 32
33   -#ifdef WINDOWS
  33 +#ifdef _WIN32
34 34 # pragma comment(lib, "ldap.lib")
35 35 # pragma comment(lib, "lber.lib")
36 36 #endif
2  src/modules/extra/m_ldapoper.cpp
@@ -27,7 +27,7 @@
27 27
28 28 #include <ldap.h>
29 29
30   -#ifdef WINDOWS
  30 +#ifdef _WIN32
31 31 # pragma comment(lib, "ldap.lib")
32 32 # pragma comment(lib, "lber.lib")
33 33 #endif
2  src/modules/extra/m_mysql.cpp
@@ -27,7 +27,7 @@
27 27 #include <mysql.h>
28 28 #include "sql.h"
29 29
30   -#ifdef WINDOWS
  30 +#ifdef _WIN32
31 31 # pragma comment(lib, "mysqlclient.lib")
32 32 # pragma comment(lib, "advapi32.lib")
33 33 # pragma comment(linker, "/NODEFAULTLIB:LIBCMT")
2  src/modules/extra/m_regex_pcre.cpp
@@ -27,7 +27,7 @@
27 27 /* $CompileFlags: exec("pcre-config --cflags") */
28 28 /* $LinkerFlags: exec("pcre-config --libs") rpath("pcre-config --libs") -lpcre */
29 29
30   -#ifdef WINDOWS
  30 +#ifdef _WIN32
31 31 # pragma comment(lib, "libpcre.lib")
32 32 #endif
33 33
2  src/modules/extra/m_sqlite3.cpp
@@ -24,7 +24,7 @@
24 24 #include <sqlite3.h>
25 25 #include "sql.h"
26 26
27   -#ifdef WINDOWS
  27 +#ifdef _WIN32
28 28 # pragma comment(lib, "sqlite3.lib")
29 29 #endif
30 30
2  src/modules/extra/m_ssl_gnutls.cpp
@@ -28,7 +28,7 @@
28 28 #include "ssl.h"
29 29 #include "m_cap.h"
30 30
31   -#ifdef WINDOWS
  31 +#ifdef _WIN32
32 32 # pragma comment(lib, "libgnutls.lib")
33 33 # pragma comment(lib, "libgcrypt.lib")
34 34 # pragma comment(lib, "libgpg-error.lib")
2  src/modules/extra/m_ssl_openssl.cpp
@@ -27,7 +27,7 @@
27 27 #include <openssl/err.h>
28 28 #include "ssl.h"
29 29
30   -#ifdef WINDOWS
  30 +#ifdef _WIN32
31 31 # pragma comment(lib, "libcrypto.lib")
32 32 # pragma comment(lib, "libssl.lib")
33 33 # pragma comment(lib, "user32.lib")
2  src/modules/m_spanningtree/main.cpp
@@ -306,7 +306,7 @@ void ModuleSpanningTree::ConnectServer(Link* x, Autoconnect* y)
306 306 {
307 307 try
308 308 {
309   - bool cached;
  309 + bool cached = false;
310 310 ServernameResolver* snr = new ServernameResolver(Utils, x->IPAddr, x, cached, start_type, y);
311 311 ServerInstance->AddResolver(snr, cached);
312 312 }
4 src/modules/m_spanningtree/resolvers.cpp
@@ -71,7 +71,7 @@ void ServernameResolver::OnError(ResolverError e, const std::string &errormessag
71 71 /* Ooops! */
72 72 if (query == DNS_QUERY_AAAA)
73 73 {
74   - bool cached;
  74 + bool cached = false;
75 75 ServernameResolver* snr = new ServernameResolver(Utils, host, MyLink, cached, DNS_QUERY_A, myautoconnect);
76 76 ServerInstance->AddResolver(snr, cached);
77 77 return;
@@ -102,7 +102,7 @@ void SecurityIPResolver::OnError(ResolverError e, const std::string &errormessag
102 102 {
103 103 if (query == DNS_QUERY_AAAA)
104 104 {
105   - bool cached;
  105 + bool cached = false;
106 106 SecurityIPResolver* res = new SecurityIPResolver(mine, Utils, host, MyLink, cached, DNS_QUERY_A);
107 107 ServerInstance->AddResolver(res, cached);
108 108 return;
2  src/modules/m_spanningtree/utils.cpp
@@ -314,7 +314,7 @@ void SpanningTreeUtilities::RefreshIPCache()
314 314 {
315 315 try
316 316 {
317   - bool cached;
  317 + bool cached = false;
318 318 SecurityIPResolver* sr = new SecurityIPResolver(Creator, this, L->IPAddr, L, cached, DNS_QUERY_AAAA);
319 319 ServerInstance->AddResolver(sr, cached);
320 320 }
10 src/modules/m_spanningtree/utils.h
@@ -36,14 +36,10 @@ class SpanningTreeUtilities;
36 36 /* This hash_map holds the hash equivalent of the server
37 37 * tree, used for rapid linear lookups.
38 38 */
39   -#if defined(WINDOWS) && !defined(HASHMAP_DEPRECATED)
40   - typedef nspace::hash_map<std::string, TreeServer*, nspace::hash_compare<std::string, std::less<std::string> > > server_hash;
  39 +#ifdef HASHMAP_DEPRECATED
  40 + typedef nspace::hash_map<std::string, TreeServer*, nspace::insensitive, irc::StrHashComp> server_hash;
41 41 #else
42   - #ifdef HASHCOMP_DEPRECATED
43   - typedef nspace::hash_map<std::string, TreeServer*, nspace::insensitive, irc::StrHashComp> server_hash;
44   - #else
45   - typedef nspace::hash_map<std::string, TreeServer*, nspace::hash<std::string>, irc::StrHashComp> server_hash;
46   - #endif
  42 + typedef nspace::hash_map<std::string, TreeServer*, nspace::hash<std::string>, irc::StrHashComp> server_hash;
47 43 #endif
48 44
49 45 typedef std::map<TreeServer*,TreeServer*> TreeServerList;
7 src/modules/m_watch.cpp
@@ -96,11 +96,8 @@
96 96 * Before you start screaming, this definition is only used here, so moving it to a header is pointless.
97 97 * Yes, it's horrid. Blame cl for being different. -- w00t
98 98 */
99   -#if defined(WINDOWS) && !defined(HASHMAP_DEPRECATED)
100   - typedef nspace::hash_map<irc::string, std::deque<User*>, nspace::hash_compare<irc::string, std::less<irc::string> > > watchentries;
101   -#else
102   - typedef nspace::hash_map<irc::string, std::deque<User*>, irc::hash> watchentries;
103   -#endif
  99 +
  100 +typedef nspace::hash_map<irc::string, std::deque<User*>, irc::hash> watchentries;
104 101 typedef std::map<irc::string, std::string> watchlist;
105 102
106 103 /* Who's watching each nickname.
2  src/modules/ssl.h
@@ -121,7 +121,7 @@ class ssl_cert : public refcountbase
121 121 std::string GetMetaLine()
122 122 {
123 123 std::stringstream value;
124   - bool hasError = error.length();
  124 + bool hasError = !error.empty();
125 125 value << (IsInvalid() ? "v" : "V") << (IsTrusted() ? "T" : "t") << (IsRevoked() ? "R" : "r")
126 126 << (IsUnknownSigner() ? "s" : "S") << (hasError ? "E" : "e") << " ";
127 127 if (hasError)
8 src/server.cpp
@@ -27,11 +27,15 @@
27 27
28 28 void InspIRCd::SignalHandler(int signal)
29 29 {
  30 +#ifdef _WIN32
  31 + if (signal == SIGTERM)
  32 +#else
30 33 if (signal == SIGHUP)
31 34 {
32 35 Rehash("Caught SIGHUP");
33 36 }
34 37 else if (signal == SIGTERM)
  38 +#endif
35 39 {
36 40 Exit(signal);
37 41 }
@@ -39,9 +43,7 @@ void InspIRCd::SignalHandler(int signal)
39 43
40 44 void InspIRCd::Exit(int status)
41 45 {
42   -#ifdef WINDOWS
43   - if (WindowsIPC)
44   - delete WindowsIPC;
  46 +#ifdef _WIN32
45 47 SetServiceStopped(status);
46 48 #endif
47 49 if (this)
12 src/socketengine.cpp
@@ -98,7 +98,7 @@ bool SocketEngine::HasFd(int fd)
98 98 {
99 99 if ((fd < 0) || (fd > GetMaxFds()))
100 100 return false;
101   - return ref[fd];
  101 + return (ref[fd] != NULL);
102 102 }
103 103
104 104 EventHandler* SocketEngine::GetRef(int fd)
@@ -125,7 +125,7 @@ int SocketEngine::Accept(EventHandler* fd, sockaddr *addr, socklen_t *addrlen)
125 125
126 126 int SocketEngine::Close(EventHandler* fd)
127 127 {
128   -#ifdef WINDOWS
  128 +#ifdef _WIN32
129 129 return closesocket(fd->GetFd());
130 130 #else
131 131 return close(fd->GetFd());
@@ -134,7 +134,7 @@ int SocketEngine::Close(EventHandler* fd)
134 134
135 135 int SocketEngine::Close(int fd)
136 136 {
137   -#ifdef WINDOWS
  137 +#ifdef _WIN32
138 138 return closesocket(fd);
139 139 #else
140 140 return close(fd);
@@ -143,7 +143,7 @@ int SocketEngine::Close(int fd)
143 143
144 144 int SocketEngine::Blocking(int fd)
145 145 {
146   -#ifdef WINDOWS
  146 +#ifdef _WIN32
147 147 unsigned long opt = 0;
148 148 return ioctlsocket(fd, FIONBIO, &opt);
149 149 #else
@@ -154,7 +154,7 @@ int SocketEngine::Blocking(int fd)
154 154
155 155 int SocketEngine::NonBlocking(int fd)
156 156 {
157   -#ifdef WINDOWS
  157 +#ifdef _WIN32
158 158 unsigned long opt = 1;
159 159 return ioctlsocket(fd, FIONBIO, &opt);
160 160 #else
@@ -209,7 +209,7 @@ int SocketEngine::SendTo(EventHandler* fd, const void *buf, size_t len, int flag
209 209 int SocketEngine::Connect(EventHandler* fd, const sockaddr *serv_addr, socklen_t addrlen)
210 210 {
211 211 int ret = connect(fd->GetFd(), serv_addr, addrlen);
212   -#ifdef WINDOWS
  212 +#ifdef _WIN32
213 213 if ((ret == SOCKET_ERROR) && (WSAGetLastError() == WSAEWOULDBLOCK))
214 214 errno = EINPROGRESS;
215 215 #endif
2  src/socketengines/socketengine_poll.cpp
@@ -33,7 +33,7 @@
33 33 #include "inspircd.h"
34 34 #include "socketengine.h"
35 35
36   -#ifndef WINDOWS
  36 +#ifndef _WIN32
37 37 #ifndef __USE_XOPEN
38 38 #define __USE_XOPEN /* fuck every fucking OS ever made. needed by poll.h to work.*/
39 39 #endif
4 src/socketengines/socketengine_select.cpp
@@ -23,9 +23,9 @@
23 23 #include "inspircd.h"
24 24 #include "socketengine.h"
25 25
26   -#ifndef WINDOWS
  26 +#ifndef _WIN32
27 27 #include <sys/select.h>
28   -#endif // WINDOWS
  28 +#endif // _WIN32
29 29
30 30 /** A specialisation of the SocketEngine class, designed to use traditional select().
31 31 */
11 src/threadengines/threadengine_win32.cpp
@@ -37,7 +37,16 @@ void ThreadEngine::Start(Thread* thread)
37 37 {
38 38 thread->state = NULL;
39 39 delete data;
40   - throw CoreException(std::string("Unable to create new thread: ") + dlerror());
  40 + std::string err = "Unable to create new thread: ";
  41 +#ifdef _WIN32
  42 + CHAR errdetail[100];
  43 + FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, 0, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), errdetail, 100, 0);
  44 + SetLastError(ERROR_SUCCESS);
  45 + err += errdetail;