Skip to content

Commit

Permalink
Everything now builds on windows CDRIVER-9
Browse files Browse the repository at this point in the history
  • Loading branch information
RedBeard0531 committed Feb 4, 2010
1 parent 58e403e commit 0827f40
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 9 deletions.
3 changes: 3 additions & 0 deletions .gitignore
@@ -1,11 +1,14 @@

*~
*.o
*.obj
*.a
*.lib
.scon*

test_*
benchmark
benchmark.exe

tags

Expand Down
24 changes: 18 additions & 6 deletions SConstruct
Expand Up @@ -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/"] )
Expand All @@ -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
Expand All @@ -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" )

Expand All @@ -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
Expand Down
8 changes: 6 additions & 2 deletions src/mongo.c
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
17 changes: 16 additions & 1 deletion test/benchmark.c
Expand Up @@ -4,7 +4,10 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#ifndef _WIN32
#include <sys/time.h>
#endif

#define ASSERT(x) \
do{ \
Expand Down Expand Up @@ -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));
Expand All @@ -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;
Expand Down

0 comments on commit 0827f40

Please sign in to comment.