Browse files

changes to get yaws_sendfile working on FreeBSD, and some Makefile cl…

…eanup

git-svn-id: https://erlyaws.svn.sourceforge.net/svnroot/erlyaws/trunk/yaws@1308 9fbdc01b-0d2c-0410-bfb7-fb27d70d8b52
  • Loading branch information...
1 parent bcfb002 commit 50472eb444f17620a146989f086010a739186fdc @vinoski vinoski committed Dec 22, 2008
Showing with 22 additions and 12 deletions.
  1. +11 −11 c_src/Makefile
  2. +11 −1 c_src/yaws_sendfile_drv.c
View
22 c_src/Makefile
@@ -11,7 +11,7 @@ else
# don't make pam if configured out with --disable-pam
PRIV_FILES= ../priv/lib/setuid_drv.$(DLL) $(EPAM)
endif
-
+
ifeq ($(HAVE_SENDFILE),true)
PRIV_FILES += ../priv/lib/yaws_sendfile_drv.$(DLL)
endif
@@ -29,7 +29,7 @@ CFLAGS += -I/usr/include/pam/ $(EXTRAINCLUDE)
all: $(PRIV_FILES)
clean:
- -rm -f $(PRIV_FILES) setuid_drv.$(OBJ)
+ -rm -f $(PRIV_FILES) setuid_drv.$(OBJ) epam.$(OBJ) yaws_sendfile_drv.$(OBJ)
install: $(PRIV_FILES)
$(INSTALL) -d $(DESTDIR)$(PREFIX)/lib/yaws/priv/lib
@@ -43,19 +43,19 @@ endif
../priv/lib/setuid_drv.$(DLL): setuid_drv.$(OBJ)
- $(LD_SHARED) $(OUT) $@ setuid_drv.$(OBJ) $(DLL_LIBS)
+ $(LD_SHARED) $(OUT) $@ $< $(DLL_LIBS)
setuid_drv.$(OBJ): setuid_drv.c
- $(CC) -c $(FPIC) $(CFLAGS) -DDYNAMIC_DRIVER setuid_drv.c
+ $(CC) -c $(FPIC) $(CFLAGS) -DDYNAMIC_DRIVER $<
../priv/lib/yaws_sendfile_drv.$(DLL): yaws_sendfile_drv.$(OBJ)
- $(LD_SHARED) $(OUT) $@ yaws_sendfile_drv.$(OBJ) $(DLL_LIBS)
+ $(LD_SHARED) $(OUT) $@ $< $(DLL_LIBS)
yaws_sendfile_drv.$(OBJ): yaws_sendfile_drv.c
- $(CC) -c $(FPIC) $(CFLAGS) -DDYNAMIC_DRIVER yaws_sendfile_drv.c
+ $(CC) -c $(FPIC) $(CFLAGS) -DDYNAMIC_DRIVER $<
../priv/.foo:
- touch ../priv/.foo
+ touch $@
-epam.o: epam.c
- $(CC) -c $(CFLAGS) epam.c
-../priv/epam: epam.o
- $(CC) -o $@ epam.o -lpam
+epam.$(OBJ): epam.c
+ $(CC) -c $(CFLAGS) $<
+../priv/epam: epam.$(OBJ)
+ $(CC) -o $@ $< -lpam
View
12 c_src/yaws_sendfile_drv.c
@@ -10,7 +10,7 @@
#include <assert.h>
#if defined(__linux__)
#include <sys/sendfile.h>
-#elif defined(__APPLE__) && defined(__MACH__)
+#elif (defined(__APPLE__) && defined(__MACH__)) || defined(__FreeBSD__)
#include <sys/socket.h>
#include <sys/uio.h>
#else
@@ -106,6 +106,16 @@ static ssize_t yaws_sendfile_call(int out_fd, int in_fd, off_t* offset, size_t c
*offset += len;
}
return retval == 0 ? len : retval;
+#elif defined(__FreeBSD__)
+ off_t len = 0;
+ int retval;
+ do {
+ retval = sendfile(in_fd, out_fd, *offset, count, NULL, &len, 0);
+ } while (retval < 0 && errno == EINTR);
+ if (retval < 0 && errno == EAGAIN) {
+ *offset += len;
+ }
+ return retval == 0 ? len : retval;
#else
errno = ENOSYS;
return -1;

0 comments on commit 50472eb

Please sign in to comment.