diff options
author | Andreas Baumann <abaumann@yahoo.com> | 2014-11-14 10:07:12 +0100 |
---|---|---|
committer | Andreas Baumann <abaumann@yahoo.com> | 2014-11-14 10:07:12 +0100 |
commit | 97265e0f6a8165159a6e3cef5623db29632e3bc8 (patch) | |
tree | e9c51cb3d7e2b7728c946de13c4b6f9161ef4bf2 | |
parent | 7342b11a3c12f48b44597232723304150e868328 (diff) | |
download | biruda-97265e0f6a8165159a6e3cef5623db29632e3bc8.tar.gz biruda-97265e0f6a8165159a6e3cef5623db29632e3bc8.tar.bz2 |
fixed for FreeBSD
-rw-r--r-- | TODOS | 3 | ||||
-rw-r--r-- | src/GNUmakefile | 3 | ||||
-rw-r--r-- | src/biruda.conf | 7 | ||||
-rw-r--r-- | src/system.c | 29 |
4 files changed, 30 insertions, 12 deletions
@@ -13,4 +13,5 @@ http://xmodulo.com/alternatives-skype-linux.html -which embedded web server microhttpd (GNU) or swill - +- platform/compiler macros +http://nadeausoftware.com/articles/2012/01/c_c_tip_how_use_compiler_predefined_macros_detect_operating_system diff --git a/src/GNUmakefile b/src/GNUmakefile index f6db48e..5e531c8 100644 --- a/src/GNUmakefile +++ b/src/GNUmakefile @@ -3,7 +3,8 @@ all: biruda CFLAGS = -g -std=c99 -Wall -pedantic -D_XOPEN_SOURCE=600 -LDFLAGS = +CFLAGS += -I/usr/local/include +LDFLAGS = -L/usr/local/lib LIBS = -lconfuse -lpthread -lnanomsg -ljson-c -lmicrohttpd %.o : %.c diff --git a/src/biruda.conf b/src/biruda.conf index 51da929..df78a0f 100644 --- a/src/biruda.conf +++ b/src/biruda.conf @@ -27,10 +27,3 @@ worker worker2 # control = "inproc://control" control = "tcp://localhost:5555" } - -webserver -{ - threads = 4 - host = localhost - port = 8080 -} diff --git a/src/system.c b/src/system.c index 7ce5f83..5a62242 100644 --- a/src/system.c +++ b/src/system.c @@ -6,9 +6,15 @@ #define WIN32_LEAN_AND_MEAN #include <windows.h> #else +#ifdef __FreeBSD__ +#include <sys/param.h> +#include <sys/sysctl.h> +#include <sys/utsname.h> +#else /* __FreeBSD__ */ #include <unistd.h> #include <sys/utsname.h> -#endif +#endif /* __FreeBSD__ */ +#endif /* _WIN32 */ #include <stdio.h> #include <string.h> @@ -16,11 +22,27 @@ unsigned int system_available_cpus( void ) { + // operating specific cases #ifdef _WIN32 SYSTEM_INFO info; GetSystemInfo( &info ); return info.dwNumberOfProcessors; #else +#ifdef __FreeBSD__ + int req[2]; + req[0] = CTL_HW; + req[1] = HW_NCPU; + int nprocs; + size_t len = sizeof( nprocs ); + if( sysctl( req, 2, &nprocs, &len, NULL, 0 ) < 0 ) { + // assuming one CPU in case of error + // (safe fallback) + return 1; + } + return nprocs; +#else // __FreeBSD__ + + // generic POSIX case #ifdef _SC_NPROCESSORS_ONLN long nprocs = sysconf( _SC_NPROCESSORS_ONLN ); if( nprocs < -1 ) { @@ -31,8 +53,9 @@ unsigned int system_available_cpus( void ) return nprocs; #else #error No _SC_NPROCESSORS_ONLN, must port first! -#endif -#endif +#endif // _SC_NPROCESSORS_ONLN +#endif // __FreeBSD__ +#endif // _WIN32 } void system_os( char *name, size_t len ) |