diff --git a/checkin_notes b/checkin_notes index bccc6a33d9..d7b9b0638b 100755 --- a/checkin_notes +++ b/checkin_notes @@ -9195,3 +9195,12 @@ David Jan 14 2004 client/win/ wingui_mainwindow.cpp,h + +David Jan 14 2004 + - windows console version works again (from Rom Walton) + + client/ + main.C + net_xfer.C + win_build/ + boinc_cli.vcproj diff --git a/client/main.C b/client/main.C index 08234d252f..38522882d6 100644 --- a/client/main.C +++ b/client/main.C @@ -22,6 +22,11 @@ // This file contains no GUI-related code, // and is not included in the source code for Mac or Win GUI clients +#ifdef WIN32 +#include +#include "stackwalker.h" +#endif + #ifdef HAVE_UNISTD_H #include #endif @@ -141,22 +146,50 @@ void quit_client(int a) { gstate.requested_exit = true; } -#ifndef _WIN32 void susp_client(int a) { gstate.active_tasks.suspend_all(); msg_printf(NULL, MSG_INFO, "Suspending activity - user request"); - signal(SIGTSTP, SIG_DFL); +#ifndef _WIN32 + signal(SIGTSTP, SIG_DFL); raise(SIGTSTP); +#endif } void resume_client(int a) { gstate.active_tasks.unsuspend_all(); msg_printf(NULL, MSG_INFO, "Resuming activity"); } + +#ifdef _WIN32 +BOOL WINAPI ConsoleControlHandler ( DWORD dwCtrlType ){ + BOOL bReturnStatus = FALSE; + switch( dwCtrlType ){ + case CTRL_C_EVENT: + if(gstate.activities_suspended) + resume_client(NULL); + else + susp_client(NULL); + bReturnStatus = TRUE; + break; + case CTRL_BREAK_EVENT: + case CTRL_CLOSE_EVENT: + case CTRL_LOGOFF_EVENT: + case CTRL_SHUTDOWN_EVENT: + quit_client(NULL); + bReturnStatus = TRUE; + break; + } + return bReturnStatus; +} #endif int main(int argc, char** argv) { - int retval; + +#ifdef WIN32 + InitAllocCheck(); +#endif + + int retval; double dt; setbuf(stdout, 0); @@ -165,13 +198,8 @@ int main(int argc, char** argv) { exit(1); } - read_log_flags(); - gstate.parse_cmdline(argc, argv); - gstate.parse_env_vars(); - retval = gstate.init(); - if (retval) exit(retval); - -#ifndef _WIN32 +// Unix/Linux console controls +#ifndef WIN32 // Handle quit signals gracefully signal(SIGHUP, quit_client); signal(SIGINT, quit_client); @@ -183,6 +211,25 @@ int main(int argc, char** argv) { signal(SIGCONT, resume_client); #endif +// Windows console controls +#ifdef WIN32 + if (!SetConsoleCtrlHandler((PHANDLER_ROUTINE)ConsoleControlHandler, TRUE)){ + fprintf(stderr, "Failed to register the console control handler\n"); + exit(1); + } else { + printf( + "\nTo pause/resume tasks hit CTRL-C, to exit hit CTRL-BREAK\n" + ); + } +#endif + + read_log_flags(); + gstate.parse_cmdline(argc, argv); + gstate.parse_env_vars(); + retval = gstate.init(); + if (retval) exit(retval); + + while (1) { if (!gstate.do_something()) { dt = dtime(); @@ -207,5 +254,10 @@ int main(int argc, char** argv) { } } gstate.cleanup_and_exit(); - return 0; + +#ifdef WIN32 + DeInitAllocCheck(); +#endif + + return 0; } diff --git a/client/net_xfer.C b/client/net_xfer.C index 7aa2764963..392b1bc6eb 100644 --- a/client/net_xfer.C +++ b/client/net_xfer.C @@ -18,7 +18,7 @@ // // Revision History: // $Log$ -// Revision 1.78 2004/01/10 06:40:44 davea +// Revision 1.79 2004/01/15 01:42:48 davea // *** empty log message *** // // Revision 1.77 2003/12/12 23:13:01 davea @@ -100,7 +100,7 @@ typedef size_t socklen_t; int get_socket_error(int fd) { socklen_t intsize = sizeof(int); int n; -#ifdef _WIN32 +#ifdef WIN32 getsockopt(fd, SOL_SOCKET, SO_ERROR, (char *)&n, &intsize); #elif __APPLE__ getsockopt(fd, SOL_SOCKET, SO_ERROR, &n, (int *)&intsize); @@ -113,7 +113,7 @@ int get_socket_error(int fd) { int NET_XFER::get_ip_addr(char *hostname, int &ip_addr) { hostent* hep; -#ifdef _WIN32 +#ifdef WIN32 int retval; retval = NetOpen(); if (retval) return retval; @@ -124,7 +124,7 @@ int NET_XFER::get_ip_addr(char *hostname, int &ip_addr) { int n; n = sprintf(msg, "Can't resolve hostname %s ", hostname); -#ifdef _WIN32 +#ifdef WIN32 switch (WSAGetLastError()) { case WSANOTINITIALISED: @@ -194,13 +194,13 @@ int NET_XFER::open_server() { fd = ::socket(AF_INET, SOCK_STREAM, 0); if (fd < 0) { -#ifdef _WIN32 +#ifdef WIN32 NetClose(); #endif return ERR_SOCKET; } -#ifdef _WIN32 +#ifdef WIN32 unsigned long one = 1; ioctlsocket(fd, FIONBIO, &one); #else @@ -219,14 +219,14 @@ int NET_XFER::open_server() { addr.sin_addr.s_addr = ((long)ipaddr); retval = connect(fd, (sockaddr*)&addr, sizeof(addr)); if (retval) { -#ifdef _WIN32 +#ifdef WIN32 errno = WSAGetLastError(); if (errno != WSAEINPROGRESS && errno != WSAEWOULDBLOCK) { closesocket(fd); NetClose(); return ERR_CONNECT; } -#ifndef WIN_CLI +#ifndef WIN32 && _CONSOLE if (WSAAsyncSelect( fd, g_myWnd->GetSafeHwnd(), g_myWnd->m_nNetActivityMsg, FD_READ|FD_WRITE )) { errno = WSAGetLastError(); if (errno != WSAEINPROGRESS && errno != WSAEWOULDBLOCK) { @@ -251,7 +251,7 @@ int NET_XFER::open_server() { } void NET_XFER::close_socket() { -#ifdef _WIN32 +#ifdef WIN32 NetClose(); if (socket) closesocket(socket); #else @@ -364,7 +364,7 @@ int NET_XFER_SET::net_sleep(double x) { // int NET_XFER_SET::do_select(double& bytes_transferred, double timeout) { int n, fd, retval, nsocks_queried; - unsigned int i; + unsigned int i; NET_XFER *nxp; struct timeval tv; @@ -517,7 +517,7 @@ int NET_XFER::do_xfer(int& nbytes_transferred) { ScopeMessages scope_messages(log_messages, ClientMessages::DEBUG_NET_XFER); if (want_download) { -#ifdef _WIN32 +#ifdef WIN32 n = recv(socket, buf, blocksize, 0); #else n = read(socket, buf, blocksize); @@ -558,7 +558,7 @@ int NET_XFER::do_xfer(int& nbytes_transferred) { } nleft = file_read_buf_len - file_read_buf_offset; while (nleft) { -#ifdef _WIN32 +#ifdef WIN32 n = send(socket, file_read_buf+file_read_buf_offset, nleft, 0); would_block = (WSAGetLastError() == WSAEWOULDBLOCK); #else diff --git a/win_build/boinc_cli.vcproj b/win_build/boinc_cli.vcproj index 069ebb80fe..889efbe958 100644 --- a/win_build/boinc_cli.vcproj +++ b/win_build/boinc_cli.vcproj @@ -22,7 +22,7 @@ Name="VCCLCompilerTool" Optimization="0" AdditionalIncludeDirectories="../lib/,../api/,../RSAEuro/source/,../client/win/,../client" - PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;WIN_CLI" + PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_CONSOLE" BasicRuntimeChecks="3" RuntimeLibrary="0" UsePrecompiledHeader="2" @@ -46,7 +46,7 @@ IgnoreDefaultLibraryNames="libc,nafxcwd,libcmtd,libcmt,libcd" GenerateDebugInformation="TRUE" ProgramDatabaseFile=".\Build\Debug/boinc_cli.pdb" - SubSystem="2" + SubSystem="1" TargetMachine="1"/> + + - - - - - - - - + +