diff --git a/checkin_notes b/checkin_notes index 89bf85dcb6..6cad78b2ce 100755 --- a/checkin_notes +++ b/checkin_notes @@ -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 + diff --git a/client/hostinfo_unix.C b/client/hostinfo_unix.C index 25ac1734f9..d78b62db15 100644 --- a/client/hostinfo_unix.C +++ b/client/hostinfo_unix.C @@ -20,7 +20,7 @@ #include #include #include -#include +#include #if HAVE_SYS_SYSTEMINFO_H #include #endif @@ -32,10 +32,15 @@ #if HAVE_SYS_SWAP_H #include #endif +#ifdef _WIN32 +#include +#else +#include #include #include #include #include +#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; iswt_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 diff --git a/client/hostinfo_win.C b/client/hostinfo_win.C new file mode 100644 index 0000000000..eb04bf7270 --- /dev/null +++ b/client/hostinfo_win.C @@ -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 +#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 diff --git a/client/http.C b/client/http.C index 6d495dc152..9a3d8c828d 100644 --- a/client/http.C +++ b/client/http.C @@ -17,9 +17,16 @@ // Contributor(s): // +#include "windows_cpp.h" + #include #include + +#ifdef _WIN32 +#include "winsock.h" +#else #include +#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); } diff --git a/client/main.C b/client/main.C index eeb5ac3b89..81609035c9 100644 --- a/client/main.C +++ b/client/main.C @@ -19,12 +19,15 @@ // command-line version of the BOINC core client +#ifndef _WIN32 #include +#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; } diff --git a/client/net_xfer.C b/client/net_xfer.C index 6b1082a10b..f860bbbca1 100644 --- a/client/net_xfer.C +++ b/client/net_xfer.C @@ -17,18 +17,27 @@ // Contributor(s): // +#include "windows_cpp.h" + #include + +#ifdef _WIN32 +#include "winsock.h" +#else #include -#include #include #include -//#include #include #include #include +#include +#endif + +#include +//#include #include #include -#include +#include #include #include @@ -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::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); } diff --git a/client/prefs.C b/client/prefs.C index f91600c032..96325b9c95 100644 --- a/client/prefs.C +++ b/client/prefs.C @@ -17,6 +17,8 @@ // Contributor(s): // +#include "windows_cpp.h" + #include #include #include diff --git a/client/speed_stats.C b/client/speed_stats.C index c31552dd8f..7d4abb62fb 100644 --- a/client/speed_stats.C +++ b/client/speed_stats.C @@ -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 diff --git a/client/test_file_xfer.C b/client/test_file_xfer.C index d1b9992f12..15318b171b 100644 --- a/client/test_file_xfer.C +++ b/client/test_file_xfer.C @@ -71,7 +71,7 @@ int main() { fx2 = 0; } if (!fx1 && !fx2) break; - sleep(1); + boinc_sleep(1); } printf("all done\n"); } diff --git a/client/test_http.C b/client/test_http.C index bc4f8ae77e..54e6b8fe36 100644 --- a/client/test_http.C +++ b/client/test_http.C @@ -51,7 +51,7 @@ int main() { op2 = 0; } if (!op1 && !op2) break; - sleep(1); + boinc_sleep(1); } printf("all done\n"); } diff --git a/client/test_net_xfer.C b/client/test_net_xfer.C index e1090c8f35..edabfc7b18 100644 --- a/client/test_net_xfer.C +++ b/client/test_net_xfer.C @@ -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); diff --git a/client/util.C b/client/util.C index 8333c2b5ff..fe2a103f04 100644 --- a/client/util.C +++ b/client/util.C @@ -17,7 +17,21 @@ // Contributor(s): // +#ifndef _WIN32 #include +#include +#else +#include +#include + +/* 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 diff --git a/client/util.h b/client/util.h index 525c6ff4bb..cab119426f 100644 --- a/client/util.h +++ b/client/util.h @@ -18,3 +18,4 @@ // extern double dtime(); +extern void boinc_sleep( int seconds ); diff --git a/gfx_todo b/gfx_todo index cb967121a0..5426e9edb1 100644 --- a/gfx_todo +++ b/gfx_todo @@ -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 diff --git a/lib/md5.c b/lib/md5.c index 707488479d..2c71fc94a2 100644 --- a/lib/md5.c +++ b/lib/md5.c @@ -39,6 +39,7 @@ */ #include "md5.h" +#include #ifdef TEST /* diff --git a/lib/parse.C b/lib/parse.C index b5264eb36a..0cbc8e6c1d 100644 --- a/lib/parse.C +++ b/lib/parse.C @@ -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 #include