added Linux support

Tue, 01 Jan 2013 13:32:04 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Tue, 01 Jan 2013 13:32:04 +0100
changeset 41
bb7a1f5a8b48
parent 40
56cda23f48d4
child 42
cb9c63c1edee

added Linux support

configure file | annotate | diff | comparison | revisions
make/gcc.mk file | annotate | diff | comparison | revisions
make/install.mk file | annotate | diff | comparison | revisions
make/linux.mk file | annotate | diff | comparison | revisions
make/solaris.mk file | annotate | diff | comparison | revisions
make/suncc.mk file | annotate | diff | comparison | revisions
src/server/Makefile file | annotate | diff | comparison | revisions
src/server/admin/Makefile file | annotate | diff | comparison | revisions
src/server/config/Makefile file | annotate | diff | comparison | revisions
src/server/daemon/Makefile file | annotate | diff | comparison | revisions
src/server/daemon/config.c file | annotate | diff | comparison | revisions
src/server/daemon/event.h file | annotate | diff | comparison | revisions
src/server/daemon/event_linux.c file | annotate | diff | comparison | revisions
src/server/daemon/event_linux.h file | annotate | diff | comparison | revisions
src/server/daemon/httplistener.c file | annotate | diff | comparison | revisions
src/server/daemon/ldap_auth.h file | annotate | diff | comparison | revisions
src/server/daemon/log.c file | annotate | diff | comparison | revisions
src/server/daemon/objs.mk file | annotate | diff | comparison | revisions
src/server/daemon/sessionhandler.c file | annotate | diff | comparison | revisions
src/server/daemon/sessionhandler.h file | annotate | diff | comparison | revisions
src/server/daemon/webserver.c file | annotate | diff | comparison | revisions
src/server/safs/Makefile file | annotate | diff | comparison | revisions
src/server/ucx/Makefile file | annotate | diff | comparison | revisions
src/server/ucx/atomic.c file | annotate | diff | comparison | revisions
src/server/ucx/atomic.h file | annotate | diff | comparison | revisions
src/server/ucx/objs.mk file | annotate | diff | comparison | revisions
src/server/util/Makefile file | annotate | diff | comparison | revisions
src/server/util/atomic.h file | annotate | diff | comparison | revisions
src/server/util/io.c file | annotate | diff | comparison | revisions
src/server/util/system.c file | annotate | diff | comparison | revisions
src/server/util/systhr.c file | annotate | diff | comparison | revisions
src/server/webdav/Makefile file | annotate | diff | comparison | revisions
--- a/configure	Mon Dec 31 00:07:52 2012 +0100
+++ b/configure	Tue Jan 01 13:32:04 2013 +0100
@@ -46,21 +46,29 @@
 INSTALL_DIR = $INSTALL_DIR
 HOST = $HOST
 
-# make variables
 __EOF__
 
 # platform
+
 if [ $OS = SunOS ]; then
-echo "SUNOS = true" >> config.mk
+CCONF=suncc.mk
+PLATFORM=solaris.mk
 fi
 
 if [ $OS = Linux ]; then
-echo "LINUX = true" >> config.mk
+CCONF=gcc.mk
+PLATFORM=linux.mk
 fi
 
 if [ $OS = Darwin ]; then
-echo "OSX = true" >> config.mk
+CCONF=gcc.mk
+
 fi
 
+echo "
+include \$(BUILD_ROOT)/make/$CCONF
+include \$(BUILD_ROOT)/make/$PLATFORM
+" >> config.mk
+
 
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/make/gcc.mk	Tue Jan 01 13:32:04 2013 +0100
@@ -0,0 +1,34 @@
+#
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+#
+# Copyright 2012 Olaf Wintermann. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+#
+#   1. Redistributions of source code must retain the above copyright
+#      notice, this list of conditions and the following disclaimer.
+#
+#   2. Redistributions in binary form must reproduce the above copyright
+#      notice, this list of conditions and the following disclaimer in the
+#      documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+
+CFLAGS = -std=gnu99 
+
+CC  = gcc
+CXX = g++
+LD = gcc
+
--- a/make/install.mk	Mon Dec 31 00:07:52 2012 +0100
+++ b/make/install.mk	Tue Jan 01 13:32:04 2013 +0100
@@ -26,6 +26,8 @@
 # POSSIBILITY OF SUCH DAMAGE.
 #
 
+BUILD_ROOT = ..
+
 include ../config.mk
 
 install:
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/make/linux.mk	Tue Jan 01 13:32:04 2013 +0100
@@ -0,0 +1,38 @@
+#
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+#
+# Copyright 2012 Olaf Wintermann. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+#
+#   1. Redistributions of source code must retain the above copyright
+#      notice, this list of conditions and the following disclaimer.
+#
+#   2. Redistributions in binary form must reproduce the above copyright
+#      notice, this list of conditions and the following disclaimer in the
+#      documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+
+
+# compiler and linker flags
+
+
+
+
+# platform dependend source files
+PLATFORM_DAEMONOBJ = event_linux.o
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/make/solaris.mk	Tue Jan 01 13:32:04 2013 +0100
@@ -0,0 +1,38 @@
+#
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+#
+# Copyright 2012 Olaf Wintermann. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+#
+#   1. Redistributions of source code must retain the above copyright
+#      notice, this list of conditions and the following disclaimer.
+#
+#   2. Redistributions in binary form must reproduce the above copyright
+#      notice, this list of conditions and the following disclaimer in the
+#      documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+
+
+# compiler and linker flags
+
+
+
+
+# platform dependend source files
+PLATFORM_DAEMONOBJ = event_solaris.o
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/make/suncc.mk	Tue Jan 01 13:32:04 2013 +0100
@@ -0,0 +1,31 @@
+#
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+#
+# Copyright 2012 Olaf Wintermann. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+#
+#   1. Redistributions of source code must retain the above copyright
+#      notice, this list of conditions and the following disclaimer.
+#
+#   2. Redistributions in binary form must reproduce the above copyright
+#      notice, this list of conditions and the following disclaimer in the
+#      documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+
+CFLAGS = -xc99
+
+
--- a/src/server/Makefile	Mon Dec 31 00:07:52 2012 +0100
+++ b/src/server/Makefile	Tue Jan 01 13:32:04 2013 +0100
@@ -26,16 +26,14 @@
 # POSSIBILITY OF SUCH DAMAGE.
 #
 
-BUILD_ROOT = ../../
-include $(BUILD_ROOT)config.mk
-
-CFLAGS  = -xc99
+BUILD_ROOT = ../..
+include $(BUILD_ROOT)/config.mk
 
-LDFLAGS = -pg -lpthread -ldl -lposix4  -lsocket -lnsl -lgen -lm -lsendfile -lxerces-c -lldap
+LDFLAGS = -pg -lpthread -ldl -lnsl -lm -lxerces-c -lldap
 
-OBJ_DIR = $(BUILD_ROOT)build/
+OBJ_DIR = $(BUILD_ROOT)/build/
 
-MAIN_TARGET = $(BUILD_ROOT)work/bin/webservd
+MAIN_TARGET = $(BUILD_ROOT)/work/bin/webservd
 
 all: preparation $(MAIN_TARGET)
 
@@ -59,7 +57,7 @@
 
 OBJ_DIRS = daemon safs ucx util webdav config admin
 MK_OBJ_DIRS = $(OBJ_DIRS:%=$(OBJ_DIR)server/%)
-MK_OBJ_DIRS += $(BUILD_ROOT)work/bin
+MK_OBJ_DIRS += $(BUILD_ROOT)/work/bin
 
 include ucx/Makefile
 
@@ -69,11 +67,11 @@
 	mkdir -p $@
 
 $(MAIN_TARGET): $(MAINOBJS)
-	CC -o $(MAIN_TARGET) $(LDFLAGS) $(MAINOBJS)
+	$(CXX) -o $(MAIN_TARGET) $(LDFLAGS) $(MAINOBJS)
 
 
 ../../build/server/ucx/%.o: %.c
-	cc -o $@ -c $(CFLAGS) $<
+	$(CC) -o $@ -c $(CFLAGS) $<
 
 
 	
--- a/src/server/admin/Makefile	Mon Dec 31 00:07:52 2012 +0100
+++ b/src/server/admin/Makefile	Tue Jan 01 13:32:04 2013 +0100
@@ -29,8 +29,8 @@
 ADMIN_CFLAGS = -I/usr/include/mps -g
 
 $(ADMIN_OBJPRE)%.o: admin/%.c
-	cc -o $@ -c $(ADMIN_CFLAGS) $(CFLAGS) $<
+	$(CC) -o $@ -c $(ADMIN_CFLAGS) $(CFLAGS) $<
 
 $(ADMIN_OBJPRE)%.o: admin/%.cpp
-	CC -o $@ -c $(ADMIN_CFLAGS) $(CFLAGS) $<
+	$(CXX) -o $@ -c $(ADMIN_CFLAGS) $(CFLAGS) $<
 	
--- a/src/server/config/Makefile	Mon Dec 31 00:07:52 2012 +0100
+++ b/src/server/config/Makefile	Tue Jan 01 13:32:04 2013 +0100
@@ -27,8 +27,8 @@
 #
 
 $(CONF_OBJPRE)%.o: config/%.c
-	cc -o $@ -c -g $(CFLAGS) $<
+	$(CC) -o $@ -c -g $(CFLAGS) $<
 
 $(CONF_OBJPRE)%.o: config/%.cpp
-	CC -o $@ -c -g $(CFLAGS) $<
+	$(CXX) -o $@ -c -g $(CFLAGS) $<
 	
--- a/src/server/daemon/Makefile	Mon Dec 31 00:07:52 2012 +0100
+++ b/src/server/daemon/Makefile	Tue Jan 01 13:32:04 2013 +0100
@@ -29,8 +29,8 @@
 DMN_CFLAGS = -I/usr/include/mps -g
 
 $(DMN_OBJPRE)%.o: daemon/%.c
-	cc -o $@ -c $(DMN_CFLAGS) $(CFLAGS) $<
+	$(CC) -o $@ -c $(DMN_CFLAGS) $(CFLAGS) $<
 
 $(DMN_OBJPRE)%.o: daemon/%.cpp
-	CC -o $@ -c $(DMN_CFLAGS) $(CFLAGS) $<
+	$(CXX) -o $@ -c $(DMN_CFLAGS) $(CFLAGS) $<
 	
--- a/src/server/daemon/config.c	Mon Dec 31 00:07:52 2012 +0100
+++ b/src/server/daemon/config.c	Tue Jan 01 13:32:04 2013 +0100
@@ -38,7 +38,6 @@
 #include <sys/mman.h>
 
 #include "../ucx/string.h"
-#include "../ucx/atomic.h"
 
 #include "httplistener.h"
 #include "config.h"
@@ -52,6 +51,7 @@
 #include "vserver.h"
 #include "../util/pblock.h"
 #include "../util/util.h"
+#include "../util/atomic.h"
 
 pool_handle_t *cfg_pool;
 
@@ -224,11 +224,11 @@
 }
 
 void cfg_ref(ServerConfiguration *cfg) {
-    ucx_atomic_inc_32(&cfg->ref);
+    ws_atomic_inc32(&cfg->ref);
 }
 
 void cfg_unref(ServerConfiguration *cfg) {
-    uint32_t ref = ucx_atomic_dec_32_nv(&cfg->ref);
+    uint32_t ref = ws_atomic_dec32(&cfg->ref);
     if(ref == 0) {
         // TODO: free configuration
     }
@@ -252,8 +252,8 @@
     
     sstr_t base = sstr("config/");
     sstr_t file;
-    file.length = base.length + mf.length + 1;
-    file.ptr = alloca(file.length);
+    file.length = base.length + mf.length;
+    file.ptr = alloca(file.length + 1);
     file.ptr[file.length] = 0;
     file = sstrncat(2, file, base, mf);
     
--- a/src/server/daemon/event.h	Mon Dec 31 00:07:52 2012 +0100
+++ b/src/server/daemon/event.h	Tue Jan 01 13:32:04 2013 +0100
@@ -39,7 +39,7 @@
 typedef struct event_handler event_handler_t;
 typedef struct event         event_t;
 
-typedef void(*event_func)(event_handler_t*, event_t*);
+typedef int(*event_func)(event_handler_t*, event_t*);
 
 struct event {
     pblock       *pb;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/server/daemon/event_linux.c	Tue Jan 01 13:32:04 2013 +0100
@@ -0,0 +1,159 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2011 Olaf Wintermann. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *   1. Redistributions of source code must retain the above copyright
+ *      notice, this list of conditions and the following disclaimer.
+ *
+ *   2. Redistributions in binary form must reproduce the above copyright
+ *      notice, this list of conditions and the following disclaimer in the
+ *      documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <sys/epoll.h>
+
+#include "../util/systhr.h"
+#include "../util/atomic.h"
+
+
+#include "event.h"
+#include "event_linux.h"
+
+
+event_handler_t* evhandler_create(int numthreads) {
+    event_handler_t *ev = malloc(sizeof(event_handler_t));
+    if(ev == NULL) {
+        return NULL;
+    }
+    
+    ev->ep = calloc(numthreads, sizeof(int));
+    if(ev->ep == NULL) {
+        free(ev);
+        return NULL;
+    }
+    ev->nep = numthreads;
+    ev->lep = 0;
+    
+    /* create ports event threads */
+    for(int i=0;i<numthreads;i++) {
+        /* create port */
+        ev->ep[i] = epoll_create(64);
+        if(ev->ep[i] == 0) {
+            free(ev->ep);
+            free(ev);
+            return NULL;
+        }
+        
+        /*
+         * start a new handler thread
+         * the thread needs the event port and a pointer to the event handler
+         */
+        ev_thr_conf_t *conf = malloc(sizeof(ev_thr_conf_t));
+        if(conf == NULL) {
+            free(ev->ep);
+            free(ev);
+            return NULL;
+        }
+        conf->handler = ev;
+        conf->ep = ev->ep[i];
+        
+        ev_thr_conf_t *thrconf = malloc(sizeof(ev_thr_conf_t));
+        thrconf->handler = ev;
+        thrconf->ep= ev->ep[i];
+        systhread_start(0, 0, (thrstartfunc)ev_handle_events, thrconf);
+        /* TODO: error handling */
+    }
+    
+    return ev;
+}
+
+
+void ev_handle_events(ev_thr_conf_t *conf) {
+    event_handler_t *ev = conf->handler;
+    int ep = conf->ep;
+    
+    free(conf);
+    
+    //port_event_t events[16];
+    struct epoll_event events[16];
+    struct timespec timeout;
+    timeout.tv_nsec = 0;
+    timeout.tv_sec = 600;
+    
+    for(;;) {
+        /* wait for events */
+        int ret = epoll_wait(ep, events, 16, 0);
+        if(ret == -1) {
+            /* TODO: check for error */
+            perror("epoll_wait");
+            continue;
+        }
+        
+        for(int i=0;i<ret;i++) {
+            event_t *event = events[i].data.ptr;
+            if(event->fn) {
+                if(!event->fn(ev, event)) {
+                    // event fn returned 0 -> remove event from epoll
+                    if(epoll_ctl(ep, EPOLL_CTL_DEL, event->object, NULL) != 0){
+                        perror("epoll_ctl");
+                    }
+                }
+            }
+        }
+    }
+}
+
+/* returns a event handler port */
+int ev_get_port(event_handler_t *h) {
+    int nps = h->nep;
+    if(nps == 1) {
+        return h->ep[0];
+    }
+    
+    int cp = h->lep % nps;
+    ws_atomic_inc32(&h->lep);
+    
+    return h->ep[cp];
+}
+
+int ev_pollin(event_handler_t *h, int fd, event_t *event) {
+    event->object = (intptr_t)fd;
+    struct epoll_event epev;
+    epev.events = EPOLLIN | EPOLLET; /* input event, edge triggered */
+    epev.data.ptr = event;
+    return epoll_ctl(ev_get_port(h), EPOLL_CTL_ADD, fd, &epev);
+}
+
+int ev_pollout(event_handler_t *h, int fd, event_t *event) {
+    event->object = (intptr_t)fd;
+    struct epoll_event epev;
+    epev.events = EPOLLOUT | EPOLLET; /* input event, edge triggered */
+    epev.data.ptr = event;
+    return epoll_ctl(ev_get_port(h), EPOLL_CTL_ADD, fd, &epev);
+}
+
+int evt_send(event_handler_t *h, event_t *event) {
+    event->object = 0;
+    // TODO: implement using threadpool
+    fprintf(stderr, "Warning: evt_send not implemented\n");
+    return 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/server/daemon/event_linux.h	Tue Jan 01 13:32:04 2013 +0100
@@ -0,0 +1,60 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2011 Olaf Wintermann. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *   1. Redistributions of source code must retain the above copyright
+ *      notice, this list of conditions and the following disclaimer.
+ *
+ *   2. Redistributions in binary form must reproduce the above copyright
+ *      notice, this list of conditions and the following disclaimer in the
+ *      documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef EVENT_LINUX_H
+#define	EVENT_LINUX_H
+
+#include "event.h"
+#include <inttypes.h>
+
+#ifdef	__cplusplus
+extern "C" {
+#endif
+
+struct event_handler {
+    int       *ep; // epoll fds
+    uint32_t  nep; // number of epoll fds
+    uint32_t  lep; // last fd
+    // TODO: message queue/thread pool
+};
+
+typedef struct ev_thr_conf {
+    event_handler_t *handler;
+    int             ep;
+} ev_thr_conf_t;
+
+void ev_handle_events(ev_thr_conf_t *conf);
+
+int ev_get_port(event_handler_t *h);
+
+#ifdef	__cplusplus
+}
+#endif
+
+#endif	/* EVENT_LINUX_H */
+
--- a/src/server/daemon/httplistener.c	Mon Dec 31 00:07:52 2012 +0100
+++ b/src/server/daemon/httplistener.c	Tue Jan 01 13:32:04 2013 +0100
@@ -47,7 +47,7 @@
 #include <pthread.h>
 
 #include "../ucx/map.h"
-#include "../ucx/atomic.h"
+#include "../util/atomic.h"
 #include "httplistener.h"
 
 #include "session.h"
@@ -209,11 +209,11 @@
 }
 
 void http_listener_ref(HttpListener *listener) {
-    ucx_atomic_inc_32(&listener->ref);
+    ws_atomic_inc32(&listener->ref);
 }
 
 void http_listener_unref(HttpListener *listener) {
-    uint32_t ref = ucx_atomic_dec_32_nv(&listener->ref);
+    uint32_t ref = ws_atomic_dec32(&listener->ref);
     if(ref == 0) {
         free(listener->acceptors);
         // TODO: unref cfg
--- a/src/server/daemon/ldap_auth.h	Mon Dec 31 00:07:52 2012 +0100
+++ b/src/server/daemon/ldap_auth.h	Tue Jan 01 13:32:04 2013 +0100
@@ -29,7 +29,7 @@
 #ifndef LDAP_AUTH_H
 #define	LDAP_AUTH_H
 
-#include "authdb.h"
+#include "authdb.h
 #include <ldap.h>
 
 #ifdef	__cplusplus
--- a/src/server/daemon/log.c	Mon Dec 31 00:07:52 2012 +0100
+++ b/src/server/daemon/log.c	Tue Jan 01 13:32:04 2013 +0100
@@ -26,6 +26,10 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
+#ifdef __gnu_linux__
+#define _GNU_SOURCE
+#endif
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
--- a/src/server/daemon/objs.mk	Mon Dec 31 00:07:52 2012 +0100
+++ b/src/server/daemon/objs.mk	Tue Jan 01 13:32:04 2013 +0100
@@ -50,9 +50,9 @@
 DAEMONOBJ += authdb.o
 DAEMONOBJ += ldap_auth.o
 
-#ifeq ($(OS), SunOS)
-DAEMONOBJ += event_solaris.o
-#endif
+# add additional platform dependend objects
+# defined in generated config.mk
+DAEMONOBJ += $(PLATFORM_DAEMONOBJ)
 
 DAEMONOBJS = $(DAEMONOBJ:%=$(DMN_OBJPRE)%)
 DAEMONSOURCE = $(DAEMONOBJ:%.o=daemon/%.c)
--- a/src/server/daemon/sessionhandler.c	Mon Dec 31 00:07:52 2012 +0100
+++ b/src/server/daemon/sessionhandler.c	Tue Jan 01 13:32:04 2013 +0100
@@ -168,7 +168,7 @@
     }
 }
 
-void evt_request_input(event_handler_t *handler, event_t *event) {
+int evt_request_input(event_handler_t *handler, event_t *event) {
     EventHttpIO *io = event->cookie;
     HttpParser  *parser  = io->parser;
     HTTPRequest *request = io->request;
@@ -183,7 +183,7 @@
     if(r == -1) {
         // TODO: error handling
         fprintf(stderr, "%s\n", "Error: Cannot read from socket");
-        return;
+        return 0;
     }
     
     buf->cursize += r;
@@ -191,12 +191,13 @@
     if(state == 2) {
         // TODO: error handling
         fprintf(stderr, "%s\n", "Error: Cannot parse http request");
-        return;
+        return 0;
     } else if(state == 1) {
-        // we need more data -> begin poll, which repeats this function
-        ev_pollin(handler, request->connection->fd, event);
-        // TODO: check ev_pollin return value for errors
-        return;
+        /*
+         * we need more data -> return 1 to tell the event handler to
+         * continue polling
+         */
+        return 1;
     }
     
     // we are done with reading
@@ -213,4 +214,6 @@
     
     // process request
     r = handle_request(request, NULL);
+    
+    return 0; // TODO: return before handle_request
 }
--- a/src/server/daemon/sessionhandler.h	Mon Dec 31 00:07:52 2012 +0100
+++ b/src/server/daemon/sessionhandler.h	Tue Jan 01 13:32:04 2013 +0100
@@ -92,7 +92,7 @@
 
 void evt_enq_conn(SessionHandler *handler, Connection *conn);
 
-void evt_request_input(event_handler_t *h, event_t *event);
+int evt_request_input(event_handler_t *h, event_t *event);
 
 
 #ifdef	__cplusplus
--- a/src/server/daemon/webserver.c	Mon Dec 31 00:07:52 2012 +0100
+++ b/src/server/daemon/webserver.c	Tue Jan 01 13:32:04 2013 +0100
@@ -26,6 +26,11 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
+
+#ifdef __gnu_linux__
+#define _GNU_SOURCE
+#endif
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <dlfcn.h> 
--- a/src/server/safs/Makefile	Mon Dec 31 00:07:52 2012 +0100
+++ b/src/server/safs/Makefile	Tue Jan 01 13:32:04 2013 +0100
@@ -29,8 +29,8 @@
 SAFS_CFLAGS = -I/usr/include/mps -g
 
 $(SAFS_OBJPRE)%.o: safs/%.c
-	cc -o $@ -c $(SAFS_CFLAGS) $(CFLAGS) $<
+	$(CC) -o $@ -c $(SAFS_CFLAGS) $(CFLAGS) $<
 
 $(SAFS_OBJPRE)%.o: /safs/%.cpp
-	CC -o $@ -c $(SAFS_CFLAGS) $(CFLAGS) $<
+	$(CXX) -o $@ -c $(SAFS_CFLAGS) $(CFLAGS) $<
 	
--- a/src/server/ucx/Makefile	Mon Dec 31 00:07:52 2012 +0100
+++ b/src/server/ucx/Makefile	Tue Jan 01 13:32:04 2013 +0100
@@ -27,5 +27,5 @@
 #
 
 $(UCX_OBJPRE)%.o: ucx/%.c
-	cc -o $@ -c -g $(CFLAGS) $<
+	$(CC) -o $@ -c -g $(CFLAGS) $<
 	
--- a/src/server/ucx/atomic.c	Mon Dec 31 00:07:52 2012 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,55 +0,0 @@
-/*
- * 
- */
-
-#include <atomic.h>
-
-#include "atomic.h"
-
-void ucx_atomic_inc_8(volatile uint8_t *t) {
-    atomic_inc_8(t);
-}
-
-void ucx_atomic_inc_16(volatile uint16_t *t) {
-    atomic_inc_16(t);
-}
-
-void ucx_atomic_inc_32(volatile uint32_t *t) {
-    atomic_inc_32(t);
-}
-
-void ucx_atomic_inc_64(volatile uint64_t *t) {
-    atomic_inc_64(t);
-}
-
-void ucx_atomic_dec_8(volatile uint8_t *t) {
-    atomic_dec_8(t);
-}
-
-void ucx_atomic_dec_16(volatile uint16_t *t) {
-    atomic_dec_16(t);
-}
-
-void ucx_atomic_dec_32(volatile uint32_t *t) {
-    atomic_dec_32(t);
-}
-
-void ucx_atomic_dec_64(volatile uint64_t *t) {
-    atomic_dec_64(t);
-}
-
-uint8_t ucx_atomic_dec_8_nv(volatile uint8_t *t) {
-    return atomic_dec_8_nv(t);
-}
-
-uint16_t ucx_atomic_dec_16_nv(volatile uint16_t *t) {
-    return atomic_dec_16_nv(t);
-}
-
-uint32_t ucx_atomic_dec_32_nv(volatile uint32_t *t) {
-    return atomic_dec_32_nv(t);
-}
-
-uint64_t ucx_atomic_dec_64_nv(volatile uint64_t *t) {
-    return atomic_dec_64_nv(t);
-}
--- a/src/server/ucx/atomic.h	Mon Dec 31 00:07:52 2012 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,47 +0,0 @@
-/* 
- * File:   atomic.h
- * Author: olaf
- *
- * Created on 29. Mai 2012, 09:38
- */
-
-#ifndef ATOMIC_H
-#define	ATOMIC_H
-
-#include <inttypes.h>
-
-#ifdef	__cplusplus
-extern "C" {
-#endif
-
-void ucx_atomic_inc_8(volatile uint8_t *t);
-
-void ucx_atomic_inc_16(volatile uint16_t *t);
-
-void ucx_atomic_inc_32(volatile uint32_t *t);
-
-void ucx_atomic_inc_64(volatile uint64_t *t);
-
-void ucx_atomic_dec_8(volatile uint8_t *t);
-
-void ucx_atomic_dec_16(volatile uint16_t *t);
-
-void ucx_atomic_dec_32(volatile uint32_t *t);
-
-void ucx_atomic_dec_64(volatile uint64_t *t);
-
-uint8_t ucx_atomic_dec_8_nv(volatile uint8_t *t);
-
-uint16_t ucx_atomic_dec_16_nv(volatile uint16_t *t);
-
-uint32_t ucx_atomic_dec_32_nv(volatile uint32_t *t);
-
-uint64_t ucx_atomic_dec_64_nv(volatile uint64_t *t);
-
-
-#ifdef	__cplusplus
-}
-#endif
-
-#endif	/* ATOMIC_H */
-
--- a/src/server/ucx/objs.mk	Mon Dec 31 00:07:52 2012 +0100
+++ b/src/server/ucx/objs.mk	Tue Jan 01 13:32:04 2013 +0100
@@ -35,7 +35,6 @@
 UCXOBJ += map.o
 UCXOBJ += mempool.o
 UCXOBJ += string.o
-UCXOBJ += atomic.o
 UCXOBJ += allocator.o
 
 UCXOBJS = $(UCXOBJ:%=$(UCX_OBJPRE)%)
--- a/src/server/util/Makefile	Mon Dec 31 00:07:52 2012 +0100
+++ b/src/server/util/Makefile	Tue Jan 01 13:32:04 2013 +0100
@@ -29,8 +29,8 @@
 UTIL_CFLAGS = -I/usr/include/mps -g
 
 $(UTIL_OBJPRE)%.o: util/%.c
-	cc -o $@ -c $(UTIL_CFLAGS) $(CFLAGS) $<
+	$(CC) -o $@ -c $(UTIL_CFLAGS) $(CFLAGS) $<
 
 $(UTIL_OBJPRE)%.o: util/%.cpp
-	CC -o $@ -c $(UTIL_CFLAGS) $(CFLAGS) $<
+	$(CXX) -o $@ -c $(UTIL_CFLAGS) $(CFLAGS) $<
 	
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/server/util/atomic.h	Tue Jan 01 13:32:04 2013 +0100
@@ -0,0 +1,59 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2011 Olaf Wintermann. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *   1. Redistributions of source code must retain the above copyright
+ *      notice, this list of conditions and the following disclaimer.
+ *
+ *   2. Redistributions in binary form must reproduce the above copyright
+ *      notice, this list of conditions and the following disclaimer in the
+ *      documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef ATOMIC_H
+#define	ATOMIC_H
+
+#ifdef	__cplusplus
+extern "C" {
+#endif
+
+#ifdef __gnu_linux__
+
+#define ws_atomic_inc32(intptr) __sync_fetch_and_add(intptr, 1)
+#define ws_atomic_dec32(intptr) __sync_fetch_and_sub(intptr, 1)
+#define ws_atomic_add32(intptr, val) __sync_fetch_and_add(intptr, val)
+#define ws_atomic_sub32(intptr, val) __sync_fetch_and_sub(intptr, val)
+
+#else
+// use atomic.h
+#include <atomic.h>
+
+#define ws_atomic_inc32(intptr) ucx_atomic_dec_32_nv(intptr)
+#define ws_atomic_dec32(intptr) ucx_atomic_dec_32_nv(intptr)
+// TODO
+
+#endif
+
+
+#ifdef	__cplusplus
+}
+#endif
+
+#endif	/* ATOMIC_H */
+
--- a/src/server/util/io.c	Mon Dec 31 00:07:52 2012 +0100
+++ b/src/server/util/io.c	Tue Jan 01 13:32:04 2013 +0100
@@ -26,6 +26,10 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
+#ifdef __gnu_linux__
+#define _GNU_SOURCE
+#endif
+
 #include <unistd.h>
 #include <stdlib.h>
 #include <sys/uio.h>
--- a/src/server/util/system.c	Mon Dec 31 00:07:52 2012 +0100
+++ b/src/server/util/system.c	Tue Jan 01 13:32:04 2013 +0100
@@ -38,8 +38,8 @@
  */
 
 #if (defined(__GNUC__) && (__GNUC__ > 2))
-#include <new>
-using namespace std;
+//include <new>
+//using namespace std;
 #else
 //include <new.h>
 #endif
--- a/src/server/util/systhr.c	Mon Dec 31 00:07:52 2012 +0100
+++ b/src/server/util/systhr.c	Tue Jan 01 13:32:04 2013 +0100
@@ -43,7 +43,7 @@
 
 //include "prinit.h"
 //include "prthread.h"
-#include "private/pprthred.h"
+//include "private/pprthred.h"
 
 #include "systems.h"
 
@@ -107,7 +107,7 @@
 
 void systhread_sleep(int msec) {
     if(msec > 0) {
-        poll(NULL, NULL, msec);
+        poll(NULL, 0, msec);
     } else {
         sched_yield();
     }
--- a/src/server/webdav/Makefile	Mon Dec 31 00:07:52 2012 +0100
+++ b/src/server/webdav/Makefile	Tue Jan 01 13:32:04 2013 +0100
@@ -26,11 +26,11 @@
 # POSSIBILITY OF SUCH DAMAGE.
 #
 
-DAV_CFLAGS = -I/usr/include/mps -g
+DAV_CFLAGS = 
 
 $(DAV_OBJPRE)%.o: webdav/%.c
-	cc -o $@ -c $(DAV_CFLAGS) $(CFLAGS) $<
+	$(CC) -o $@ -c $(DAV_CFLAGS) $(CFLAGS) $<
 
 $(DAV_OBJPRE)%.o: webdav/%.cpp
-	CC -o $@ -c $(DAV_CFLAGS) $(CFLAGS) $<
+	$(CXX) -o $@ -c $(DAV_CFLAGS) $(CFLAGS) $<
 	

mercurial