Robert Lowry avatar Robert Lowry committed b9b82c1

changed FIONREAD to nonblocking reading and got channel close detection working on BSD.

Comments (0)

Files changed (2)

 nii - ncurses ii interface
 --------------------------
-nii is an ncurses interface to the ii[1] irc client that uses inotify (in
-Linux) or kqueue (in BSD) to monitor a filetree created by ii and displays the
-out files and writes to the in files for each channel and server directory
-created by ii.
+nii is an ncurses interface to the ii[1] irc client that uses inotify (in Linux)
+or kqueue (in BSD) to monitor a filetree created by ii and displays the 'out'
+files and writes to the 'in' files for each channel and server directory created
+by ii.
 
 Installation
 ------------
-Edit config.mk to match your local machine's configuration. nii is installed
-to /usr/local by default.
+Edit config.mk to match your local machine's configuration. nii is installed to
+/usr/local by default.
 
 Then enter the following commands to build and install:
 
 Simply invoke the 'nii' command with the required arguments.
 
 NOTE: For nii to function smoothly you must apply the ii-1.4-autojoin.diff
-      patch. You may, rather, want to apply the ii-1.4-joinuser.diff patch,
-      but you cannot apply both, since the joinuser patch includes the
-      autojoin pathc. See the ii patches page[2] for an explaination of the
-      patches.
+      patch. You may, rather, want to apply the ii-1.4-joinuser.diff patch, but
+      you cannot apply both, since the joinuser patch includes the autojoin
+      patch. See the ii patches page[2] for an explaination of the patches.
 
 [1](http://tools.suckless.org/ii)
 [2](http://tools.suckless.org/ii/patches)
 # define CHECK_WATCHES	check_watches_kqueue
 #endif
 
-#define WATCH_TIMEOUT 10000
+#define WATCH_TIMEOUT 25000
 #define MAX_OPENFD 4
 #define MAX_IN 512
 
 {
 	char buf[4096];
 	Line *l;
-	int num;
 
-	do {
-		if (ioctl(w->infd,FIONREAD,&num) == -1)
-			err(1,"ioctl() FIONREAD failed on %s/out",w->path);
-		if (num) {
-			read_line(w->infd,buf,sizeof(buf));
-			l = add_line(w->lastline,buf);
-			w->lastline = l;
-		}
-	} while(num > 0);
+	while(read_line(w->infd,buf,sizeof(buf)) != -1) {
+		l = add_line(w->lastline,buf);
+		w->lastline = l;
+	}
 	if (w == curwatch)
 		updatescreen = 1;
 }
 	if (w->infd == -1) {
 		snprintf(file,sizeof(file),"%s/out",path);
 		if(stat(file,&sb) == 0) {
-			if((fd = open(file,O_RDONLY)) < 0)
+			if((fd = open(file,O_RDONLY|O_NONBLOCK)) < 0)
 				warn("error opening %s for reading",file);
 			else 
 				w->infd = fd;
 		if(kevent(wq, &kadd, 1, NULL, 0, NULL) == -1)
 			err(1,"kevent() failed on %s/out", fpath);
 	}
+	if(w->outfd > -1) { 
+		EV_SET(&kadd, w->outfd, EVFILT_WRITE, EV_ADD, 0, 0, w);
+		if(kevent(wq, &kadd, 1, NULL, 0, NULL) == -1)
+			err(1,"kevent() failed on %s/in", fpath);
+	}
 
 	return 0;
 }
 		if(event.ident == w->wd) {
 			ftw(w->path, add_dir_kqueue, MAX_OPENFD);
 		} else if (event.ident == w->infd) {
+			if(!w->active)
+				ftw(w->path, add_dir_kqueue, MAX_OPENFD);
 			read_watch_input(w);
+		} else if (event.ident == w->outfd && event.flags & EV_EOF) {
+			rm_watch(w);
 		}
 	}
 }
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.