diff --git a/.gitignore b/.gitignore index 66335e7383..27ef80ae48 100644 --- a/.gitignore +++ b/.gitignore @@ -1,11 +1,14 @@ *~ *.o +*.obj *.a +*.lib .scon* test_* benchmark +benchmark.exe tags diff --git a/SConstruct b/SConstruct index 74fd17e6b8..48eee0a4f8 100644 --- a/SConstruct +++ b/SConstruct @@ -27,7 +27,7 @@ import sys env = Environment( ENV=os.environ ) -if "darwin" == os.sys.platform or "linux2" == os.sys.platform: +if os.sys.platform in ["darwin", "linux2"]: env.Append( CPPFLAGS=" -pedantic -Wall -ggdb " ) env.Append( CPPPATH=["/opt/local/include/"] ) env.Append( LIBPATH=["/opt/local/lib/"] ) @@ -41,6 +41,8 @@ if "darwin" == os.sys.platform or "linux2" == os.sys.platform: if GetOption('optimize'): env.Append( CPPFLAGS=" -O3 " ) # -O3 benchmarks *significantly* faster than -O2 when disabling networking +elif 'win32' == os.sys.platform: + env.Append( LIBS='ws2_32' ) #we shouldn't need these options in c99 mode @@ -62,6 +64,12 @@ if not GetOption('use_c99'): env = conf.Finish() +have_libjson = False +conf = Configure(env) +if conf.CheckLib('json'): + have_libjson = True +env = conf.Finish() + if sys.byteorder == 'big': env.Append( CPPDEFINES="MONGO_BIG_ENDIAN" ) @@ -75,21 +83,25 @@ b = env.Library( "bson" , coreFiles + [ "src/bson.c", "src/numbers.c"] ) env.Default( env.Alias( "lib" , [ m[0] , b[0] ] ) ) benchmarkEnv = env.Clone() -benchmarkEnv.Append( CPPDEFINES=[('DTEST_SERVER', '"%s"'%GetOption('test_server'))] ) +benchmarkEnv.Append( CPPDEFINES=[('TEST_SERVER', r'\"%s\"'%GetOption('test_server'))] ) benchmarkEnv.Append( LIBS=[m, b] ) benchmarkEnv.Prepend( LIBPATH=["."] ) benchmarkEnv.Program( "benchmark" , [ "test/benchmark.c"] ) testEnv = benchmarkEnv.Clone() -testEnv.Append( LIBS=["json"] ) - testCoreFiles = [ ] -for name in Split('sizes resize endian_swap all_types json simple update errors count_delete auth pair'): +tests = Split('sizes resize endian_swap all_types simple update errors count_delete auth pair') + +if have_libjson: + tests.append('json') + testEnv.Append( LIBS=["json"] ) + +for name in tests: filename = "test/%s.c" % name exe = "test_" + name test = testEnv.Program( exe , testCoreFiles + [filename] ) - test_alias = testEnv.Alias('test', [test], test[0].abspath + ' 2> /dev/null') + test_alias = testEnv.Alias('test', [test], test[0].abspath + ' 2> ' + os.path.devnull) AlwaysBuild(test_alias) # special case for cpptest diff --git a/src/mongo.c b/src/mongo.c index 2049393795..91bd2fde4b 100644 --- a/src/mongo.c +++ b/src/mongo.c @@ -20,7 +20,7 @@ static const int one = 1; static void looping_write(mongo_connection * conn, const void* buf, int len){ const char* cbuf = buf; while (len){ - int sent = write(conn->sock, cbuf, len); + int sent = send(conn->sock, cbuf, len, 0); if (sent == -1) MONGO_THROW(MONGO_EXCEPT_NETWORK); cbuf += sent; len -= sent; @@ -30,7 +30,7 @@ static void looping_write(mongo_connection * conn, const void* buf, int len){ static void looping_read(mongo_connection * conn, void* buf, int len){ char* cbuf = buf; while (len){ - int sent = read(conn->sock, cbuf, len); + int sent = recv(conn->sock, cbuf, len, 0); if (sent == 0 || sent == -1) MONGO_THROW(MONGO_EXCEPT_NETWORK); cbuf += sent; len -= sent; @@ -389,7 +389,11 @@ bson_bool_t mongo_disconnect( mongo_connection * conn ){ if ( ! conn->connected ) return 1; +#ifdef _WIN32 + closesocket( conn->sock ); +#else close( conn->sock ); +#endif conn->sock = 0; conn->connected = 0; diff --git a/test/benchmark.c b/test/benchmark.c index 97b207cd1f..266ddbf763 100644 --- a/test/benchmark.c +++ b/test/benchmark.c @@ -4,7 +4,10 @@ #include #include #include + +#ifndef _WIN32 #include +#endif #define ASSERT(x) \ do{ \ @@ -321,10 +324,21 @@ static void find_range_large_test() {find_range(DB ".index.large");} typedef void(*nullary)(); static void time_it(nullary func, const char* name, bson_bool_t gle){ - struct timeval start, end; double timer; double ops; +#ifdef _WIN32 + int64_t start, end; + + start = GetTickCount64(); + func(); + if (gle) ASSERT(!mongo_cmd_get_last_error(conn, DB, NULL)); + end = GetTickCount64(); + + timer = end - start; +#else + struct timeval start, end; + gettimeofday(&start, NULL); func(); if (gle) ASSERT(!mongo_cmd_get_last_error(conn, DB, NULL)); @@ -333,6 +347,7 @@ static void time_it(nullary func, const char* name, bson_bool_t gle){ timer = end.tv_sec - start.tv_sec; timer *= 1000000; timer += end.tv_usec - start.tv_usec; +#endif ops = PER_TRIAL / timer; ops *= 1000000;