sendfile / sendfile.setup

(define madvise-test #<<CODE
#include "sys/mman.h"
int main (){
  char *buff;
  madvise(buff,0,MADV_WILLNEED);
  return 0;
}            
CODE
)

(define posix-fadvise-test #<<CODE
#define _XOPEN_SOURCE 600
#include <fcntl.h>
int main(){
  int fake_fd = 0;
  posix_fadvise(fake_fd,0,0,POSIX_FADV_SEQUENTIAL);    
  return posix_fadvise(fake_fd,0,0,POSIX_FADV_NOREUSE);
}
CODE
)

(define sendfile-bsd-test #<<CODE
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/uio.h>
int main(){
  int src,dst;         
  off_t offset,res;
  return sendfile(src,dst,offset,0,NULL,&res,0);      
}           
CODE
)

(define sendfile-macos-test #<<CODE
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/uio.h>
int main(){
  int src,dst;         
  off_t offset,res;
  return sendfile(src,dst,offset,&res,0,0);      
}           
CODE
)

(define sendfile-sun-test #<<CODE
#include <sys/sendfile.h>
int main(){
  int dst;         
  sendfilevec_t fvec;
  size_t written;        
  return sendfile(dst,&fvec,1,&written);
}
CODE
)

(define sendfile-linux-test #<<CODE
#include <sys/sendfile.h>
int main(){
  int in,out;
  off_t offset;     
  return sendfile(in,out,&offset,0);
}
CODE
)

(define mmap-test #<<CODE
#include <sys/mman.h>
int main(){
   int src;         
   return mmap(0, 100, PROT_READ | PROT_WRITE, MAP_SHARED,src, 0);
}           
CODE
)  



(define madvise? (try-compile madvise-test compile-only: #t))
(define posix-fadvise? (try-compile posix-fadvise-test compile-only: #t))
(define mmap? (try-compile mmap-test compile-only: #t))
(define sendfile?
          (cond-expand
          (linux   
           (try-compile sendfile-linux-test compile-only: #t))
          ((or netbsd openbsd freebsd) 
           (try-compile sendfile-bsd-test compile-only: #t))
          (macosx
           (try-compile sendfile-macos-test compile-only: #t))
          (sun
           (try-compile sendfile-sun-test compile-only: #t))
          (else #f)))


(let ((features '()))
  (when madvise?
    (set! features (cons '-D (cons 'madvise features))))
  (when posix-fadvise?
    (set! features (cons '-D (cons 'posix-fadvise features))))
  (when mmap?
    (set! features (cons '-D (cons 'mmap features))))
  (when sendfile?
    (set! features (cons '-D (cons 'sendfile features))))
  (compile -s -O2 -d0 ,@features sendfile.scm -j sendfile)
  (compile -s -O2 -d0 sendfile.import.scm)
  (compile -c -O2 -d0 ,@features sendfile.scm  -unit sendfile -o sendfile-static.o)
  (install-extension 
    'sendfile
    '("sendfile.so" "sendfile.import.so" "sendfile-static.o")
    '((version "1.7.4")
     (static "sendfile-static.o")
     (documentation "sendfile.html"))))

;; cleanup temp-files
;; remove this in production
(system "rm *.o")
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.