libresman

changeset 26:6b9974a8bdae tip

started BSD/mac support for file watching
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 31 Mar 2014 19:51:00 +0300
parents 1be0a35aa216
children
files examples/imgthumbs/Makefile src/filewatch_bsd.c src/resman_impl.h
diffstat 3 files changed, 35 insertions(+), 1 deletions(-) [+]
line diff
     1.1 --- a/examples/imgthumbs/Makefile	Thu Feb 13 21:34:41 2014 +0200
     1.2 +++ b/examples/imgthumbs/Makefile	Mon Mar 31 19:51:00 2014 +0300
     1.3 @@ -5,7 +5,7 @@
     1.4  obj = $(src:.c=.o)
     1.5  bin = imgthumbs
     1.6  
     1.7 -CFLAGS = -pedantic -Wall -g -I../../src
     1.8 +CFLAGS = -pedantic -Wall -g -I../../src -Wno-deprecated-declarations
     1.9  LDFLAGS = $(libgl) -limago $(resman) -lpthread
    1.10  
    1.11  ifeq ($(shell uname -s), Darwin)
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/src/filewatch_bsd.c	Mon Mar 31 19:51:00 2014 +0300
     2.3 @@ -0,0 +1,25 @@
     2.4 +/* file modification monitoring with kqueue */
     2.5 +#if defined(__FreeBSD__) || defined(__APPLE__)
     2.6 +#include <stdio.h>
     2.7 +#include <fcntl.h>
     2.8 +#include <sys/event.h>
     2.9 +#include "filewatch.h"
    2.10 +#include "resman.h"
    2.11 +#include "resman_impl.h"
    2.12 +
    2.13 +int resman_init_file_monitor(struct resman *rman)
    2.14 +{
    2.15 +	if((rman->kq = kqueue()) == -1) {
    2.16 +		return -1;
    2.17 +	}
    2.18 +	/* set non-blocking flag, to allow polling by reading */
    2.19 +	fcntl(rman->kq, F_SETFL, fcntl(rman->kq, F_GETFL) | O_NONBLOCK);
    2.20 +
    2.21 +	/* createh the fd->resource map */
    2.22 +	rman->nresmap = rb_create(RB_KEY_INT);
    2.23 +	return 0;
    2.24 +}
    2.25 +
    2.26 +#else
    2.27 +int resman_filewatch_bsd_silence_empty_file_warning;
    2.28 +#endif	/* __FreeBSD__ or __APPLE__ */
     3.1 --- a/src/resman_impl.h	Thu Feb 13 21:34:41 2014 +0200
     3.2 +++ b/src/resman_impl.h	Mon Mar 31 19:51:00 2014 +0300
     3.3 @@ -10,6 +10,9 @@
     3.4  #include <fcntl.h>
     3.5  #include <sys/inotify.h>
     3.6  #endif
     3.7 +#if defined(__FreeBSD__) || defined(__APPLE__)
     3.8 +#include <sys/event.h>
     3.9 +#endif
    3.10  #ifdef WIN32
    3.11  #include <windows.h>
    3.12  #endif
    3.13 @@ -33,6 +36,9 @@
    3.14  #ifdef __linux__
    3.15  	int nfd;
    3.16  #endif
    3.17 +#if defined(__FreeBSD__) || defined(__APPLE__)
    3.18 +	struct kevent kev;
    3.19 +#endif
    3.20  };
    3.21  
    3.22  
    3.23 @@ -56,6 +62,9 @@
    3.24  	int inotify_fd;
    3.25  	struct rbtree *modset;
    3.26  #endif
    3.27 +#if defined(__FreeBSD__) || defined(__APPLE__)
    3.28 +	int kq;
    3.29 +#endif
    3.30  #ifdef WIN32
    3.31  	struct rbtree *watchdirs, *wdirbyev;
    3.32  	HANDLE *watch_handles;	/* dynamic array of all the watched directory handles */