*** empty log message ***

svn path=/trunk/boinc/; revision=5734
This commit is contained in:
David Anderson 2005-03-29 23:56:50 +00:00
parent 3ce5a7e89f
commit da9f04ebe0
11 changed files with 179 additions and 260 deletions

View File

@ -26298,3 +26298,20 @@ Rom 29 Mar 2005
MainFrame.cpp
clientgui/msw/
taskbarex.h
David 29 Mar 2005
- moved NetOpen(), NetClose(), NetCheck() from win_net.cpp (removed)
to lib/network.C
client/
client_state.C
hostinfo_network.h
time_stats.C
win/
win_net.cpp,h (removed)
wingui_mainwindow.cpp
lib/
network.C,h
win_build/
boinc_cli.vcproj
boinc_gui.vcproj

View File

@ -52,6 +52,7 @@
#include "file_names.h"
#include "hostinfo.h"
#include "hostinfo_network.h"
#include "network.h"
#include "http.h"
#include "log_flags.h"
#include "client_msgs.h"

View File

@ -17,9 +17,5 @@
// or write to the Free Software Foundation, Inc.,
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#define CONNECTED_STATE_NOT_CONNECTED 0
#define CONNECTED_STATE_CONNECTED 1
#define CONNECTED_STATE_UNKNOWN 2
extern int get_connected_state();
extern int get_local_network_info(char* dom, int ,char* ip, int iplen);

View File

@ -31,7 +31,7 @@
#include "util.h"
#include "error_numbers.h"
#include "client_msgs.h"
#include "hostinfo_network.h"
#include "network.h"
#include "time_stats.h"

View File

@ -1,168 +0,0 @@
// Berkeley Open Infrastructure for Network Computing
// http://boinc.berkeley.edu
// Copyright (C) 2005 University of California
//
// This is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation;
// either version 2.1 of the License, or (at your option) any later version.
//
// This software is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU Lesser General Public License for more details.
//
// To view the GNU Lesser General Public License visit
// http://www.gnu.org/copyleft/lesser.html
// or write to the Free Software Foundation, Inc.,
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#include "boinc_win.h"
#include "win_net.h"
#include "client_state.h"
#include "hostinfo_network.h"
#define DIAL_WAIT 60 // seconds after dial to wait (in case of cancel)
#define CONFIRM_WAIT 60 // seconds after user says not to connect to ask again
#define CLOSE_WAIT 5 // seconds after last call to close that the connection should be terminated
int net_ref_count = -1; // -1 closed, 0 open but not used, >0 number of users
double net_last_req_time = 0; // last time user was requested to connect in seconds
double net_last_dial_time = 0; // last time modem was dialed
double net_close_time = 0; // 0 don't close, >0 time when network connection should be terminated in seconds
bool dialed = false;
int WinsockInitialize()
{
WSADATA wsdata;
return WSAStartup( MAKEWORD( 1, 1 ), &wsdata);
}
int WinsockCleanup()
{
return WSACleanup();
}
typedef BOOL (WINAPI *GetStateProc)( OUT LPDWORD lpdwFlags, IN DWORD dwReserved);
int get_connected_state( ) {
int online = 0;
static bool first=true;
static HMODULE libmodule;
static GetStateProc GetState;
DWORD connectionFlags;
if (first) {
libmodule = LoadLibrary("wininet.dll");
if (libmodule) {
GetState = (GetStateProc) GetProcAddress(libmodule, "InternetGetConnectedState");
}
first = false;
}
if (libmodule && GetState) {
online = (*GetState)(&connectionFlags, 0);
if (online) {
return CONNECTED_STATE_CONNECTED;
} else {
return CONNECTED_STATE_NOT_CONNECTED;
}
}
return CONNECTED_STATE_UNKNOWN;
}
int NetOpen( void )
{
int rc;
typedef BOOL (WINAPI *GetStateProc)( OUT LPDWORD lpdwFlags, IN DWORD dwReserved);
typedef BOOL (WINAPI *AutoDialProc)( IN DWORD dwFlags, IN DWORD dwReserved);
if(net_ref_count >= 0) {
net_ref_count ++;
return 0;
}
GetStateProc GetState = NULL;
AutoDialProc AutoDial = NULL;
DWORD connectionFlags;
HMODULE libmodule = NULL;
libmodule = LoadLibrary("wininet.dll");
if (libmodule) {
GetState = (GetStateProc)GetProcAddress(libmodule, "InternetGetConnectedState");
AutoDial = (AutoDialProc)GetProcAddress(libmodule, "InternetAutodial");
if (GetState && AutoDial) {
rc = (*GetState)(&connectionFlags, 0);
// Don't Autodial if already connected to Internet by Modem or LAN
if (!rc) {
if((double)time(NULL) < net_last_dial_time + CONFIRM_WAIT) {
return -1;
}
#if !defined(_WIN32) && !defined(_CONSOLE)
if(gstate.global_prefs.confirm_before_connecting) {
net_last_req_time = (double)time(NULL);
if(!RequestNetConnect()) {
return -1;
}
}
#endif
net_last_dial_time = (double)time(NULL);
rc = (*AutoDial)(INTERNET_AUTODIAL_FORCE_UNATTENDED, 0);
if (rc) {
dialed = true;
} else {
// InternetAutodial() returns error 86 for some users
// and 668 for some other users, but a subsequent call
// to gethostbyname() or connect() autodials successfully.
// So (with one exception) we ignore failure returns
// from InternetAutodial() to work around this problem.
// Error 86 is "The specified Network Password is not correct."
// Error 668 is RAS Error "The connection dropped."
rc = GetLastError();
// Don't continue if busy signal, no answer or user cancelled
if (rc == ERROR_USER_DISCONNECTION) {
return -1;
}
}
}
}
}
net_ref_count = 1;
return 0;
}
void NetClose( void )
{
if(net_ref_count > 0) net_ref_count --;
if(net_ref_count == 0) {
net_close_time = (double)time(NULL) + CLOSE_WAIT;
}
}
void NetCheck( void ) {
if(net_ref_count == 0 && net_close_time > 0 && net_close_time < (double)time(NULL)) {
typedef BOOL (WINAPI *HangupProc)(IN DWORD dwReserved);
HangupProc HangUp = NULL;
HMODULE libmodule = NULL;
// Hang up the modem if we dialed it
if (dialed && gstate.global_prefs.hangup_if_dialed) {
libmodule = LoadLibrary("wininet.dll");
if (libmodule) {
HangUp = (HangupProc)GetProcAddress(libmodule, "InternetAutodialHangup");
if (HangUp) int rc = (* HangUp)(0);
}
}
dialed = false;
net_ref_count = -1;
net_close_time = 0;
}
}
const char *BOINC_RCSID_4971b5333e = "$Id$";

View File

@ -1,29 +0,0 @@
// Berkeley Open Infrastructure for Network Computing
// http://boinc.berkeley.edu
// Copyright (C) 2005 University of California
//
// This is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation;
// either version 2.1 of the License, or (at your option) any later version.
//
// This software is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU Lesser General Public License for more details.
//
// To view the GNU Lesser General Public License visit
// http://www.gnu.org/copyleft/lesser.html
// or write to the Free Software Foundation, Inc.,
#ifndef __WIN_NET_H
#define __WIN_NET_H
extern int WinsockInitialize();
extern int WinsockCleanup();
extern int NetOpen( void );
extern void NetClose( void );
extern void NetCheck( void );
#endif

View File

@ -22,7 +22,7 @@
#include "client_msgs.h"
#include "diagnostics.h"
#include "hostinfo.h"
#include "win_net.h"
#include "network.h"
#include "wingui_mainwindow.h"
@ -2175,7 +2175,9 @@ void CMainWindow::OnTimer(UINT uEventID) {
// update state and gui
while(gstate.do_something(dtime()));
NetCheck(); // check if network connection can be terminated
// check if network connection can be terminated
NetCheck(gstate.global_prefs.hangup_if_dialed);
UpdateGUI(&gstate);

View File

@ -46,3 +46,144 @@ int get_socket_error(int fd) {
#endif
return n;
}
#ifdef _WIN32
#define DIAL_WAIT 60 // seconds after dial to wait (in case of cancel)
#define CONFIRM_WAIT 60 // seconds after user says not to connect to ask again
#define CLOSE_WAIT 5 // seconds after last call to close that the connection should be terminated
int net_ref_count = -1; // -1 closed, 0 open but not used, >0 number of users
double net_last_req_time = 0; // last time user was requested to connect in seconds
double net_last_dial_time = 0; // last time modem was dialed
double net_close_time = 0; // 0 don't close, >0 time when network connection should be terminated in seconds
bool dialed = false;
int WinsockInitialize() {
WSADATA wsdata;
return WSAStartup( MAKEWORD( 1, 1 ), &wsdata);
}
int WinsockCleanup() {
return WSACleanup();
}
typedef BOOL (WINAPI *GetStateProc)( OUT LPDWORD lpdwFlags, IN DWORD dwReserved);
int get_connected_state( ) {
int online = 0;
static bool first=true;
static HMODULE libmodule;
static GetStateProc GetState;
DWORD connectionFlags;
if (first) {
libmodule = LoadLibrary("wininet.dll");
if (libmodule) {
GetState = (GetStateProc) GetProcAddress(libmodule, "InternetGetConnectedState");
}
first = false;
}
if (libmodule && GetState) {
online = (*GetState)(&connectionFlags, 0);
if (online) {
return CONNECTED_STATE_CONNECTED;
} else {
return CONNECTED_STATE_NOT_CONNECTED;
}
}
return CONNECTED_STATE_UNKNOWN;
}
int NetOpen() {
int rc;
typedef BOOL (WINAPI *GetStateProc)( OUT LPDWORD lpdwFlags, IN DWORD dwReserved);
typedef BOOL (WINAPI *AutoDialProc)( IN DWORD dwFlags, IN DWORD dwReserved);
if (net_ref_count >= 0) {
net_ref_count ++;
return 0;
}
GetStateProc GetState = NULL;
AutoDialProc AutoDial = NULL;
DWORD connectionFlags;
HMODULE libmodule = NULL;
libmodule = LoadLibrary("wininet.dll");
if (libmodule) {
GetState = (GetStateProc)GetProcAddress(libmodule, "InternetGetConnectedState");
AutoDial = (AutoDialProc)GetProcAddress(libmodule, "InternetAutodial");
if (GetState && AutoDial) {
rc = (*GetState)(&connectionFlags, 0);
// Don't Autodial if already connected to Internet by Modem or LAN
if (!rc) {
if((double)time(NULL) < net_last_dial_time + CONFIRM_WAIT) {
return -1;
}
#if !defined(_WIN32) && !defined(_CONSOLE)
if(gstate.global_prefs.confirm_before_connecting) {
net_last_req_time = (double)time(NULL);
if(!RequestNetConnect()) {
return -1;
}
}
#endif
net_last_dial_time = (double)time(NULL);
rc = (*AutoDial)(INTERNET_AUTODIAL_FORCE_UNATTENDED, 0);
if (rc) {
dialed = true;
} else {
// InternetAutodial() returns error 86 for some users
// and 668 for some other users, but a subsequent call
// to gethostbyname() or connect() autodials successfully.
// So (with one exception) we ignore failure returns
// from InternetAutodial() to work around this problem.
// Error 86 is "The specified Network Password is not correct."
// Error 668 is RAS Error "The connection dropped."
rc = GetLastError();
// Don't continue if busy signal, no answer or user cancelled
if (rc == ERROR_USER_DISCONNECTION) {
return -1;
}
}
}
}
}
net_ref_count = 1;
return 0;
}
void NetClose() {
if (net_ref_count > 0) net_ref_count --;
if (net_ref_count == 0) {
net_close_time = (double)time(NULL) + CLOSE_WAIT;
}
}
void NetCheck(bool hangup_if_dialed) {
if (net_ref_count == 0 && net_close_time > 0 && net_close_time < (double)time(NULL)) {
typedef BOOL (WINAPI *HangupProc)(IN DWORD dwReserved);
HangupProc HangUp = NULL;
HMODULE libmodule = NULL;
// Hang up the modem if we dialed it
if (dialed && hangup_if_dialed) {
libmodule = LoadLibrary("wininet.dll");
if (libmodule) {
HangUp = (HangupProc)GetProcAddress(libmodule, "InternetAutodialHangup");
if (HangUp) int rc = (* HangUp)(0);
}
}
dialed = false;
net_ref_count = -1;
net_close_time = 0;
}
}
#endif

View File

@ -29,3 +29,14 @@ typedef int32_t socklen_t;
typedef size_t socklen_t;
#endif
#define CONNECTED_STATE_NOT_CONNECTED 0
#define CONNECTED_STATE_CONNECTED 1
#define CONNECTED_STATE_UNKNOWN 2
extern int get_connected_state();
#ifdef _WIN32
extern int NetOpen();
extern void NetClose();
extern void NetCheck(bool hangup_if_dialed);
#endif

View File

@ -992,29 +992,6 @@
<File
RelativePath="..\client\whetstone.C">
</File>
<File
RelativePath="..\Client\win\Win_net.cpp">
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
BasicRuntimeChecks="3"
BrowseInformation="1"
CompileAs="2"/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
CompileAs="2"/>
</FileConfiguration>
</File>
<File
RelativePath="..\client\win\win_service.cpp">
</File>
@ -1148,9 +1125,6 @@
<File
RelativePath="..\client\version.h">
</File>
<File
RelativePath="..\Client\win\Win_net.h">
</File>
<File
RelativePath="..\client\win\win_service.h">
</File>

View File

@ -1014,29 +1014,6 @@
<File
RelativePath="..\client\whetstone.C">
</File>
<File
RelativePath="..\Client\win\Win_net.cpp">
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
CompileAs="2"/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
BasicRuntimeChecks="3"
BrowseInformation="1"
CompileAs="2"/>
</FileConfiguration>
</File>
<File
RelativePath="..\client\win\win_util.cpp">
<FileConfiguration
@ -1320,9 +1297,6 @@
<File
RelativePath="..\lib\util.h">
</File>
<File
RelativePath="..\Client\win\Win_net.h">
</File>
<File
RelativePath="..\client\win\win_util.h">
</File>
@ -1349,10 +1323,10 @@
Name="Resource Files"
Filter="ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">
<File
RelativePath="..\client\win\res\boinc.bmp">
RelativePath="..\client\win\boinc.bmp">
</File>
<File
RelativePath="..\client\win\boinc.bmp">
RelativePath="..\client\win\res\boinc.bmp">
</File>
<File
RelativePath="..\client\win\boinc_gui.rc">
@ -1372,10 +1346,10 @@
</FileConfiguration>
</File>
<File
RelativePath="..\client\win\boincsm.bmp">
RelativePath="..\client\win\res\boincsm.bmp">
</File>
<File
RelativePath="..\client\win\res\boincsm.bmp">
RelativePath="..\client\win\boincsm.bmp">
</File>
<File
RelativePath="..\res\CoreClient.ico">