summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2007-06-02 22:21:55 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2007-06-02 22:21:55 +0000
commit6cf3fc6b36e2046c36b729530117572ba44aafd7 (patch)
tree5dba5db873d470d2fb1dd60d1a037dd3806c6a5d
parent433837b847cd462b8fcf76da4b11772add35bf8e (diff)
Change the behaviour of insp in windows to keep its window open, with some status text in the title bar. It also clears the screen now on startup, see the wrapper for what a nasty amount of code it is to do such a simple thing to a windows console :(
Also, add somewhat of a hack to cut down on allocation time taken to map windows fd to a posix style fd in iocp engine. git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@7217 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r--include/socketengine_iocp.h16
-rw-r--r--src/inspircd.cpp36
-rw-r--r--src/socketengine_iocp.cpp2
-rw-r--r--win/inspircd_win32wrapper.cpp33
-rw-r--r--win/inspircd_win32wrapper.h3
5 files changed, 62 insertions, 28 deletions
diff --git a/include/socketengine_iocp.h b/include/socketengine_iocp.h
index 81563bc62..615c44fd7 100644
--- a/include/socketengine_iocp.h
+++ b/include/socketengine_iocp.h
@@ -58,12 +58,18 @@ class IOCPEngine : public SocketEngine
* in a future release.
* @return -1 if there are no free slots, and an integer if it finds one.
*/
- __inline int GenerateFd()
+ __inline int GenerateFd(int RealFd)
{
- register int i = 0;
- for(; i < MAX_DESCRIPTORS; ++i)
- if(ref[i] == 0)
- return i;
+ int index_hash = RealFd % MAX_DESCRIPTORS;
+ if(ref[index_hash] == 0)
+ return index_hash;
+ else
+ {
+ register int i = 0;
+ for(; i < MAX_DESCRIPTORS; ++i)
+ if(ref[i] == 0)
+ return i;
+ }
return -1;
}
diff --git a/src/inspircd.cpp b/src/inspircd.cpp
index 7066385ef..9e1d753b3 100644
--- a/src/inspircd.cpp
+++ b/src/inspircd.cpp
@@ -386,12 +386,12 @@ InspIRCd::InspIRCd(int argc, char** argv)
struct option longopts[] =
{
- { "nofork", no_argument, &do_nofork, 1 },
- { "logfile", required_argument, NULL, 'f' },
- { "config", required_argument, NULL, 'c' },
- { "debug", no_argument, &do_debug, 1 },
- { "nolog", no_argument, &do_nolog, 1 },
- { "runasroot", no_argument, &do_root, 1 },
+ { "nofork", no_argument, &do_nofork, 1 },
+ { "logfile", required_argument, NULL, 'f' },
+ { "config", required_argument, NULL, 'c' },
+ { "debug", no_argument, &do_debug, 1 },
+ { "nolog", no_argument, &do_nolog, 1 },
+ { "runasroot", no_argument, &do_root, 1 },
{ "version", no_argument, &do_version, 1 },
{ 0, 0, 0, 0 }
};
@@ -557,14 +557,8 @@ InspIRCd::InspIRCd(int argc, char** argv)
this->WritePID(Config->PID);
#ifdef WINDOWS
- InitIPC();
-
+ InitIPC();
g_starting = false;
-
- // remove the console if in no-fork
- if(!Config->nofork)
- FreeConsole();
-
#endif
}
@@ -985,14 +979,11 @@ void InspIRCd::DoOneIteration(bool process_module_sockets)
#else
CheckIPC(this);
- if(Config->nofork)
- {
- uptime = Time() - startup_time;
- stime = gmtime(&uptime);
- snprintf(window_title, 100, "InspIRCd - %u clients, %u accepted connections - Up %u days, %.2u:%.2u:%.2u",
- LocalUserCount(), stats->statsAccept, stime->tm_yday, stime->tm_hour, stime->tm_min, stime->tm_sec);
- SetConsoleTitle(window_title);
- }
+ uptime = Time() - startup_time;
+ stime = gmtime(&uptime);
+ snprintf(window_title, 100, "InspIRCd - %u clients, %u accepted connections - Up %u days, %.2u:%.2u:%.2u",
+ LocalUserCount(), stats->statsAccept, stime->tm_yday, stime->tm_hour, stime->tm_min, stime->tm_sec);
+ SetConsoleTitle(window_title);
#endif
}
@@ -1036,6 +1027,9 @@ int InspIRCd::Run()
int main(int argc, char** argv)
{
+#ifdef WINDOWS
+ ClearConsole();
+#endif
SI = new InspIRCd(argc, argv);
SI->Run();
delete SI;
diff --git a/src/socketengine_iocp.cpp b/src/socketengine_iocp.cpp
index 96e824899..58ce36177 100644
--- a/src/socketengine_iocp.cpp
+++ b/src/socketengine_iocp.cpp
@@ -32,7 +32,7 @@ IOCPEngine::~IOCPEngine()
bool IOCPEngine::AddFd(EventHandler* eh)
{
- int fake_fd = GenerateFd();
+ int fake_fd = GenerateFd(eh->GetFd());
int is_accept = 0;
int opt_len = sizeof(int);
if(fake_fd < 0)
diff --git a/win/inspircd_win32wrapper.cpp b/win/inspircd_win32wrapper.cpp
index 017ed4808..2be5a8bcd 100644
--- a/win/inspircd_win32wrapper.cpp
+++ b/win/inspircd_win32wrapper.cpp
@@ -9,7 +9,6 @@ using namespace std;
#define INADDR_NONE 0xffffffff
#endif
-
HANDLE hIPCPipe;
int inet_aton(const char *cp, struct in_addr *addr)
@@ -438,3 +437,35 @@ std::string FindNameServerWin()
return returnval;
}
+
+void ClearConsole()
+{
+ COORD coordScreen = { 0, 0 }; /* here's where we'll home the cursor */
+ HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
+ BOOL bSuccess;
+ DWORD cCharsWritten;
+ CONSOLE_SCREEN_BUFFER_INFO csbi; /* to get buffer info */
+ DWORD dwConSize; /* number of character cells in the current buffer */
+
+ /* get the number of character cells in the current buffer */
+
+ if (GetConsoleScreenBufferInfo( hConsole, &csbi ))
+ {
+ dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
+ /* fill the entire screen with blanks */
+ if (FillConsoleOutputCharacter( hConsole, (TCHAR) ' ', dwConSize, coordScreen, &cCharsWritten ))
+ {
+ /* get the current text attribute */
+ if (GetConsoleScreenBufferInfo( hConsole, &csbi ))
+ {
+ /* now set the buffer's attributes accordingly */
+ if (FillConsoleOutputAttribute( hConsole, csbi.wAttributes, dwConSize, coordScreen, &cCharsWritten ))
+ {
+ /* put the cursor at (0, 0) */
+ SetConsoleCursorPosition( hConsole, coordScreen );
+ }
+ }
+ }
+ }
+ return;
+} \ No newline at end of file
diff --git a/win/inspircd_win32wrapper.h b/win/inspircd_win32wrapper.h
index c8075b902..c4be4f9e5 100644
--- a/win/inspircd_win32wrapper.h
+++ b/win/inspircd_win32wrapper.h
@@ -180,5 +180,8 @@ void CloseIPC();
/* Look up the nameserver in use from the registry on windows */
std::string FindNameServerWin();
+/* Clear a windows console */
+void ClearConsole();
+
#endif