- Changes and additions made to begin porting to Windows.

- This code will compile on Windows, but is not quite fully functional.

svn path=/trunk/boinc/; revision=91
This commit is contained in:
Eric Heien 2002-06-06 18:50:12 +00:00
parent 6233799071
commit 90664f37a8
16 changed files with 263 additions and 28 deletions

View File

@ -328,3 +328,27 @@ Eric Heien June 03, 2002
parse.C (removed, uses lib version now)
parse.h (removed, uses lib version now)
Makefile.in
Eric Heien June 06, 2002
- Changes and additions made to begin porting to Windows.
- This code will compile on Windows, but is not quite fully functional.
client/
hostinfo_unix.C
hostinfo_win.C (added)
http.C
main.C
net_xfer.C
prefs.C
speed_stats.C
test_file_xfer.C
test_http.C
test_net_xfer.C
util.C
util.h
windows_cpp.h (added)
win_main.C (added)
lib/
md5.c
parse.C

View File

@ -20,7 +20,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/utsname.h>
#include <time.h>
#if HAVE_SYS_SYSTEMINFO_H
#include <sys/systeminfo.h>
#endif
@ -32,10 +32,15 @@
#if HAVE_SYS_SWAP_H
#include <sys/swap.h>
#endif
#ifdef _WIN32
#include <windows.h>
#else
#include <sys/utsname.h>
#include <unistd.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#endif
#include "client_types.h"
@ -161,23 +166,19 @@ void get_osinfo(HOST_INFO& host) {
#endif
#ifdef solaris
int get_host_info(HOST_INFO& host) {
#ifndef mac
struct statvfs foo;
#endif
memset(&host, 0, sizeof(host));
get_local_domain_name(host.domain_name);
get_local_ip_addr_str(host.ip_addr);
#ifndef mac
statvfs(".", &foo);
host.d_total = (double)foo.f_bsize * (double)foo.f_blocks;
host.d_free = (double)foo.f_bsize * (double)foo.f_bavail;
#endif
#ifdef solaris
int i, n;
sysinfo(SI_SYSNAME, host.os_name, sizeof(host.os_name));
sysinfo(SI_RELEASE, host.os_version, sizeof(host.os_version));
@ -197,14 +198,29 @@ int get_host_info(HOST_INFO& host) {
for (i=0; i<n; i++) {
host.m_swap += 512.*(double)s->swt_ent[i].ste_length;
}
return 0;
}
#endif
#ifdef mac
int get_host_info(HOST_INFO &host) {
return 0;
}
#endif
#ifdef linux
int get_host_info(HOST_INFO& host) {
memset(&host, 0, sizeof(host));
get_local_domain_name(host.domain_name);
get_local_ip_addr_str(host.ip_addr);
parse_cpuinfo(host);
parse_meminfo(host);
get_osinfo(host);
get_timezone(host.timezone);
#endif
return 0;
}
#endif

109
client/hostinfo_win.C Normal file
View File

@ -0,0 +1,109 @@
// The contents of this file are subject to the Mozilla Public License
// Version 1.0 (the "License"); you may not use this file except in
// compliance with the License. You may obtain a copy of the License at
// http://www.mozilla.org/MPL/
//
// Software distributed under the License is distributed on an "AS IS"
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
// License for the specific language governing rights and limitations
// under the License.
//
// The Original Code is the Berkeley Open Infrastructure for Network Computing.
//
// The Initial Developer of the Original Code is the SETI@home project.
// Portions created by the SETI@home project are Copyright (C) 2002
// University of California at Berkeley. All Rights Reserved.
//
// Contributor(s):
//
#ifdef _WIN32
#include <windows.h>
#include "client_types.h"
extern int get_local_domain_name(char* p);
extern int get_local_ip_addr_str(char* p);
int get_host_info(HOST_INFO& host) {
OSVERSIONINFO OSVersionInfo;
memset( &OSVersionInfo, NULL, sizeof( OSVersionInfo ) );
OSVersionInfo.dwOSVersionInfoSize = sizeof( OSVersionInfo );
::GetVersionEx( &OSVersionInfo );
switch ( OSVersionInfo.dwPlatformId ) {
case VER_PLATFORM_WIN32s:
strcpy( host.os_name, "Windows 3.1/Win32s" ); // does ANYBODY use this anymore?
break;
case VER_PLATFORM_WIN32_WINDOWS:
if ( OSVersionInfo.dwMajorVersion > 4 || ( OSVersionInfo.dwMajorVersion == 4
&& OSVersionInfo.dwMinorVersion > 10 ) )
{
strcpy( host.os_name, "Windows 98" );
} else {
strcpy( host.os_name, "Windows 95" );
}
break;
case VER_PLATFORM_WIN32_NT:
strcpy( host.os_name, "Windows NT" );
break;
default:
sprintf( host.os_name, "Unknown Win32 (%ld)", OSVersionInfo.dwPlatformId );
break;
}
char Version[ 25 ];
Version[ 0 ] = NULL;
sprintf( Version, ": %lu.%lu", OSVersionInfo.dwMajorVersion,
OSVersionInfo.dwMinorVersion );
strcat( host.os_name, Version );
SYSTEM_INFO SystemInfo;
memset( &SystemInfo, NULL, sizeof( SystemInfo ) );
::GetSystemInfo( &SystemInfo );
switch ( SystemInfo.wProcessorArchitecture ) {
case PROCESSOR_ARCHITECTURE_INTEL:
switch ( SystemInfo.dwProcessorType ) {
case PROCESSOR_INTEL_386:
strcpy( host.p_model, "Intel 80386" );
break;
case PROCESSOR_INTEL_486:
strcpy( host.p_model, "Intel 80486" );
break;
case PROCESSOR_INTEL_PENTIUM:
strcpy( host.p_model, "Intel Pentium" );
break;
default:
strcpy( host.p_model, "Intel x86" );
break;
}
break;
case PROCESSOR_ARCHITECTURE_MIPS:
strcpy( host.p_model, "MIPS" );
break;
case PROCESSOR_ARCHITECTURE_ALPHA:
strcpy( host.p_model, "Alpha" );
break;
case PROCESSOR_ARCHITECTURE_PPC:
strcpy( host.p_model, "Power PC" );
break;
case PROCESSOR_ARCHITECTURE_UNKNOWN:
default:
strcpy( host.p_model, "Unknown" );
break;
}
memset(&host, 0, sizeof(host));
get_local_domain_name(host.domain_name);
get_local_ip_addr_str(host.ip_addr);
return 0;
}
#endif

View File

@ -17,9 +17,16 @@
// Contributor(s):
//
#include "windows_cpp.h"
#include <string.h>
#include <sys/stat.h>
#ifdef _WIN32
#include "winsock.h"
#else
#include <unistd.h>
#endif
#include "error_numbers.h"
#include "filesys.h"
@ -92,7 +99,11 @@ int read_http_reply_header(int socket, HTTP_REPLY_HEADER& header) {
header.content_length = 0;
header.status = 404; // default to failure
for (i=0; i<1024; i++) {
#ifdef _WIN32
recv(socket, buf+i, 1, 0);
#else
read(socket, buf+i, 1);
#endif
if (strstr(buf, "\r\n\r\n") || strstr(buf, "\n\n")) {
if (log_flags.http_debug) printf("reply header:\n%s", buf);
p = strchr(buf, ' ');
@ -203,7 +214,11 @@ bool HTTP_OP_SET::poll() {
);
break;
}
#ifdef _WIN32
n = send(htp->socket, hdr, strlen(hdr), 0);
#else
n = write(htp->socket, hdr, strlen(hdr));
#endif
if (log_flags.http_debug) {
printf("wrote HTTP header: %d bytes\n", n);
}

View File

@ -19,12 +19,15 @@
// command-line version of the BOINC core client
#ifndef _WIN32
#include <unistd.h>
#endif
#include "accounts.h"
#include "file_names.h"
#include "log_flags.h"
#include "client_state.h"
#include "util.h"
void show_message(char* message, char* priority) {
if (!strcmp(priority, "high")) {
@ -58,10 +61,12 @@ int main(int argc, char** argv) {
if (!cs.do_something()) {
if (log_flags.time_debug) printf("SLEEP 1 SECOND\n");
fflush(stdout);
sleep(1);
boinc_sleep(1);
}
if (cs.time_to_exit()) {
exit(0);
}
}
return 0;
}

View File

@ -17,18 +17,27 @@
// Contributor(s):
//
#include "windows_cpp.h"
#include <stdio.h>
#ifdef _WIN32
#include "winsock.h"
#else
#include <sys/time.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/select.h>
//#include <sys/ioctl.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <netdb.h>
#include <unistd.h>
#endif
#include <sys/types.h>
//#include <sys/ioctl.h>
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
#include <fcntl.h>
#include <string.h>
@ -50,8 +59,6 @@ int NET_XFER::open_server() {
sockaddr_in addr;
hostent* hep;
int fd=0, ipaddr, retval=0;
int flags;
//long one = 1;
hep = gethostbyname(hostname);
if (!hep) {
@ -63,20 +70,33 @@ int NET_XFER::open_server() {
fd = ::socket(AF_INET, SOCK_STREAM, 0);
if (fd < 0) return -1;
#ifdef _WIN32
unsigned long one = 1;
ioctlsocket(fd, FIONBIO, &one);
#else
int flags;
//ioctl(fd, FIONBIO, &one);
flags = fcntl(fd, F_GETFL, 0);
if (flags < 0) return -1;
else if( fcntl(fd, F_SETFL, flags|O_NONBLOCK) < 0 ) return -1;
#endif
addr.sin_family = AF_INET;
addr.sin_port = htons(port);
addr.sin_addr.s_addr = ((long)ipaddr);
retval = connect(fd, (sockaddr*)&addr, sizeof(addr));
if (retval) {
#ifdef _WIN32
if (errno != WSAEINPROGRESS) {
closesocket(fd);
return -1;
}
#else
if (errno != EINPROGRESS) {
close(fd);
return -1;
}
#endif
} else {
is_connected = true;
}
@ -108,7 +128,11 @@ int NET_XFER_SET::insert(NET_XFER* nxp) {
int NET_XFER_SET::remove(NET_XFER* nxp) {
vector<NET_XFER*>::iterator iter;
#ifdef _WIN32
if (nxp->socket) closesocket(nxp->socket);
#else
if (nxp->socket) close(nxp->socket);
#endif
iter = net_xfers.begin();
while (iter != net_xfers.end()) {
@ -190,7 +214,11 @@ int NET_XFER_SET::do_select(int max_bytes, int& bytes_transferred) {
fd = nxp->socket;
if (FD_ISSET(fd, &read_fds) || FD_ISSET(fd, &write_fds)) {
if (!nxp->is_connected) {
getsockopt(fd, SOL_SOCKET, SO_ERROR, &n, &intsize);
#ifdef _WIN32
getsockopt(fd, SOL_SOCKET, SO_ERROR, (char *)&n, (int *)&intsize);
#else
getsockopt(fd, SOL_SOCKET, SO_ERROR, &n, (int *)&intsize);
#endif
if (n) {
if (log_flags.net_xfer_debug) {
printf("socket %d connect failed\n", fd);
@ -241,7 +269,11 @@ int NET_XFER::do_xfer(int& nbytes_transferred) {
if (!buf) return ERR_MALLOC;
if (want_download) {
n = read(socket, buf, blocksize);
#ifdef _WIN32
n = recv(socket, buf, blocksize, 0);
#else
n = read(socket, buf, blocksize);
#endif
if (log_flags.net_xfer_debug) {
printf("read %d bytes from socket %d\n", n, socket);
}
@ -276,7 +308,11 @@ int NET_XFER::do_xfer(int& nbytes_transferred) {
nleft = m;
offset = 0;
while (nleft) {
n = write(socket, buf+offset, nleft);
#ifdef _WIN32
n = send(socket, buf+offset, nleft, 0);
#else
n = write(socket, buf+offset, nleft);
#endif
if (log_flags.net_xfer_debug) {
printf("wrote %d bytes to socket %d\n", n, socket);
}

View File

@ -17,6 +17,8 @@
// Contributor(s):
//
#include "windows_cpp.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

View File

@ -229,10 +229,6 @@ double run_mem_bandwidth_test( double num_secs ) {
}
void run_test_suite( double num_secs_per_test ) {
int bw_test_time;
double bw_secs;
int bw_iters;
printf(
"Running tests. This will take about %.1lf seconds.\n\n",
num_secs_per_test*3

View File

@ -71,7 +71,7 @@ int main() {
fx2 = 0;
}
if (!fx1 && !fx2) break;
sleep(1);
boinc_sleep(1);
}
printf("all done\n");
}

View File

@ -51,7 +51,7 @@ int main() {
op2 = 0;
}
if (!op1 && !op2) break;
sleep(1);
boinc_sleep(1);
}
printf("all done\n");
}

View File

@ -75,7 +75,7 @@ int main() {
if (nxp->io_done) break;
}
if (nxp->io_done) break;
sleep(1);
boinc_sleep(1);
}
nxs.remove(nxp);
if (nxp->file) fclose(nxp->file);

View File

@ -17,7 +17,21 @@
// Contributor(s):
//
#ifndef _WIN32
#include <sys/time.h>
#include <unistd.h>
#else
#include <time.h>
#include <windows.h>
/* Replacement gettimeofday
Sets the microseconds to clock() * 1000 which is microseconds in Windows */
void gettimeofday(timeval *t, void *tz) {
t->tv_sec = time(NULL);
t->tv_usec = 1000 * (long)(clock());
}
#endif
#include "util.h"
@ -28,3 +42,16 @@ double dtime() {
gettimeofday(&tv, 0);
return tv.tv_sec + (tv.tv_usec/1.e6);
}
#ifdef _WIN32
void boinc_sleep( int seconds ) {
::Sleep( 1000*seconds );
}
#else
void boinc_sleep( int seconds ) {
sleep( seconds );
}
#endif

View File

@ -18,3 +18,4 @@
//
extern double dtime();
extern void boinc_sleep( int seconds );

View File

@ -7,5 +7,4 @@
- produce bitmap in separate process, use shared mem
- Allow for hardware acceleration direct to screen.
-Test
- Allow for hardware acceleration direct to screen

View File

@ -39,6 +39,7 @@
*/
#include "md5.h"
#include <string.h>
#ifdef TEST
/*

View File

@ -24,6 +24,10 @@
// by the BOINC scheduling server or client.
// Could replace this with a more general parser.
#ifdef _WIN32
#include "windows.h"
#endif
#include <string.h>
#include <stdlib.h>