Hi,

Please find attached a work-in-progress patch for Monkey git building on
FreeBSD.

I have hit an issue in mk_plugin_http_request_end (mk_plugin.c) that
looks like it is being worked on ...

/opt/work/chris/freebsd/monkey/monkey.git/src/mk_plugin.c:654:10:
warning: cast to 'void *' from smaller integer type 'int'
[-Wint-to-void-pointer-cast]
    cs = mk_http_session_get(socket);
         ^
The build then fails linking with ...

Linking C executable monkey
/usr/bin/ld: cannot find -ldl
cc: error: linker command failed with exit code 1 (use -v to see invocation)

I will take a look at this now.

Chris
diff --git a/configure b/configure
index 31e1b95..574cc3b 100755
--- a/configure
+++ b/configure
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 #
 #  Monkey HTTP Server
 #  ==================
diff --git a/include/monkey/mk_event_kqueue.h b/include/monkey/mk_event_kqueue.h
index d5c398b..840c543 100644
--- a/include/monkey/mk_event_kqueue.h
+++ b/include/monkey/mk_event_kqueue.h
@@ -59,7 +59,6 @@ static inline int filter_mask(int16_t f)
 #define mk_event_foreach(event, evl)                                    \
     int __i;                                                            \
     struct mk_event_ctx *ctx = evl->data;                               \
-    struct mk_event_fd_state *st = NULL;                                \
                                                                         \
     if (evl->n_events > 0) {                                            \
         event = ctx->events[0].udata;                                   \
diff --git a/plugins/liana/liana.c b/plugins/liana/liana.c
index 7b08ab1..1185415 100644
--- a/plugins/liana/liana.c
+++ b/plugins/liana/liana.c
@@ -169,6 +169,20 @@ int mk_liana_send_file(int socket_fd, int file_fd, off_t 
*file_offset,
         return len;
     }
     return ret;
+#elif defined (__FreeBSD__)
+    off_t offset = *file_offset;
+    off_t len = (off_t) file_count;
+
+    ret = sendfile(file_fd, socket_fd, offset, len, NULL, 0, 0);
+    if (ret == -1 && errno != EAGAIN) {
+        PLUGIN_TRACE("[FD %i] error from sendfile(): %s",
+                     socket_fd, strerror(errno));
+    }
+    else if (len > 0) {
+        *file_offset += len;
+        return len;
+    }
+    return ret;
 #else
 #error Sendfile not supported on platform
 #endif
diff --git a/src/mk_event_kqueue.c b/src/mk_event_kqueue.c
index 73fb8b8..e95a04d 100644
--- a/src/mk_event_kqueue.c
+++ b/src/mk_event_kqueue.c
@@ -166,7 +166,13 @@ static inline int _mk_event_timeout_create(struct 
mk_event_ctx *ctx,
     event->type = MK_EVENT_NOTIFICATION;
     event->mask = MK_EVENT_EMPTY;
 
-    EV_SET(&ke, fd, EVFILT_TIMER, EV_ADD, NOTE_SECONDS, expire, event);
+#if defined(NOTE_SECONDS)
+    #define _EV_FFLAGS NOTE_SECONDS
+#else
+    #define _EV_FFLAGS 0
+#endif
+
+    EV_SET(&ke, fd, EVFILT_TIMER, EV_ADD, _EV_FFLAGS, expire, event);
     ret = kevent(ctx->kfd, &ke, 1, NULL, 0, NULL);
     if (ret < 0) {
         close(fd);
diff --git a/src/mk_plugin.c b/src/mk_plugin.c
index f3a9518..45fb20d 100644
--- a/src/mk_plugin.c
+++ b/src/mk_plugin.c
@@ -615,6 +615,7 @@ int mk_plugin_event_add(int socket, int mode,
     struct mk_sched_worker *sched;
     struct plugin_event *event;
     struct mk_list *list;
+    (void) mode;
     (void) behavior;
 
     sched = mk_sched_get_thread_conf();
diff --git a/src/mk_socket.c b/src/mk_socket.c
index 84d6fb0..0834ecd 100644
--- a/src/mk_socket.c
+++ b/src/mk_socket.c
@@ -32,6 +32,7 @@
 
 #include <time.h>
 #include <netinet/tcp.h>
+#include <sys/socket.h>
 
 static void mk_socket_safe_event_write(int socket)
 {
@@ -51,10 +52,10 @@ int mk_socket_set_cork_flag(int fd, int state)
 {
     MK_TRACE("Socket, set Cork Flag FD %i to %s", fd, (state ? "ON" : "OFF"));
 
-#if defined (__linux__)
+#if defined (TCP_CORK)
     return setsockopt(fd, SOL_TCP, TCP_CORK, &state, sizeof(state));
-#elif defined (__APPLE__)
-    return setsockopt(fd, SOL_TCP, TCP_NOPUSH, &state, sizeof(state));
+#elif defined (TCP_NOPUSH)
+    return setsockopt(fd, SOL_SOCKET, TCP_NOPUSH, &state, sizeof(state));
 #endif
 }
 
@@ -96,7 +97,15 @@ int mk_socket_set_tcp_nodelay(int sockfd)
 {
     int on = 1;
 
+#if defined (SOL_TCP)
     return setsockopt(sockfd, SOL_TCP, TCP_NODELAY, &on, sizeof(on));
+#eif defined (SOL_SOCKET)
+    return setsockopt(sockfd, SOL_SOCKET, TCP_NODELAY, &on, sizeof(on));
+#else
+    (void) sockfd;
+    (void) on;
+    return 0;
+#endif
 }
 
 int mk_socket_set_tcp_defer_accept(int sockfd)
_______________________________________________
Monkey mailing list
[email protected]
http://lists.monkey-project.com/listinfo/monkey

Reply via email to