shithub: mc

Download patch

ref: 78ef9193ce11d95dd93d49f875ac27f79858ace0
parent: d457a0d8f9f7bc6e136200fc814354d15aadbd42
author: Ori Bernstein <ori@eigenstate.org>
date: Sun May 1 07:22:17 EDT 2016

Add poll on OSX

--- a/lib/sys/sys+freebsd-x64.myr
+++ b/lib/sys/sys+freebsd-x64.myr
@@ -38,23 +38,6 @@
 		revents	: uint16
 	;;
 
-	const Pollin		: uint16 = 0x0001	/* any readable data available */
-	const Pollpri		: uint16 = 0x0002	/* OOB/Urgent readable data */
-	const Pollout		: uint16 = 0x0004	/* file descriptor is writeable */
-	const Pollrdnorm	: uint16 = 0x0040	/* non-OOB/URG data available */
-	const Pollwrnorm	: uint16 = Pollout	/* no write type differentiation */
-	const Pollrdband	: uint16 = 0x0080	/* OOB/Urgent readable data */
-	const Pollwrband	: uint16 = 0x0100	/* OOB/Urgent data can be written */
-	/* General FreeBSD extension (currently only supported for sockets): */
-	const Pollinigneof	: uint16 = 0x2000	/* like POLLIN, except ignore EOF */
-	/*
-	* These events are set if they occur regardless of whether they were
-	* requested.
-	*/
-	const Pollerr		: uint16 = 0x0008		/* some poll error occurred */
-	const Pollhup		: uint16 = 0x0010		/* file descriptor was "hung up" */
-	const Pollnval		: uint16 = 0x0020		/* requested events "invalid" */
-
 	type waitstatus = union
 		`Waitfail int32
 		`Waitexit int32
@@ -261,6 +244,7 @@
 	const Sobintime		: sockopt = 0x2000	/* timestamp received dgram traffic */
 	const Sonooffload	: sockopt = 0x4000	/* socket cannot be offloaded */
 	const Sonoddp		: sockopt = 0x8000	/* disable direct data placement */
+	
 
 	/* network protocols */
 	const Ipproto_ip	: sockproto = 0
@@ -268,6 +252,24 @@
 	const Ipproto_tcp	: sockproto = 6
 	const Ipproto_udp	: sockproto = 17
 	const Ipproto_raw	: sockproto = 255
+
+	/* poll options */
+	const Pollin		: uint16 = 0x0001	/* any readable data available */
+	const Pollpri		: uint16 = 0x0002	/* OOB/Urgent readable data */
+	const Pollout		: uint16 = 0x0004	/* file descriptor is writeable */
+	const Pollrdnorm	: uint16 = 0x0040	/* non-OOB/URG data available */
+	const Pollwrnorm	: uint16 = Pollout	/* no write type differentiation */
+	const Pollrdband	: uint16 = 0x0080	/* OOB/Urgent readable data */
+	const Pollwrband	: uint16 = 0x0100	/* OOB/Urgent data can be written */
+	/* General FreeBSD extension (currently only supported for sockets): */
+	const Pollinigneof	: uint16 = 0x2000	/* like POLLIN, except ignore EOF */
+	/*
+	* These events are set if they occur regardless of whether they were
+	* requested.
+	*/
+	const Pollerr		: uint16 = 0x0008		/* some poll error occurred */
+	const Pollhup		: uint16 = 0x0010		/* file descriptor was "hung up" */
+	const Pollnval		: uint16 = 0x0020		/* requested events "invalid" */
 
 	const Seekset	: whence = 0
 	const Seekcur	: whence = 1
--- a/lib/sys/sys+osx-x64.myr
+++ b/lib/sys/sys+osx-x64.myr
@@ -44,6 +44,12 @@
 		`Waitfail int32
 	;;
 
+	type pollfd = struct
+		fd	: fd
+		events	: uint16
+		revents	: uint16
+	;;
+
 	type statbuf = struct
 		dev	: int32
 		mode	: filemode
@@ -288,6 +294,35 @@
 	const Ipproto_tcp	: sockproto = 6
 	const Ipproto_udp	: sockproto = 17
 	const Ipproto_raw	: sockproto = 255
+
+	/*
+	* Requestable events.  If poll(2) finds any of these set, they are
+	* copied to revents on return.
+	*/
+	const Pollin		: uint16 = 0x0001	/* any readable data available */
+	const Pollpri		: uint16 = 0x0002	/* OOB/Urgent readable data */
+	const Pollout		: uint16 = 0x0004	/* file descriptor is writeable */
+	const Pollrdnorm	: uint16 = 0x0040	/* non-OOB/URG data available */
+	const Pollwrnorm	: uint16 = Pollout	/* no write type differentiation */
+	const Pollrdband	: uint16 = 0x0080	/* OOB/Urgent readable data */
+	const Pollwrband	: uint16 = 0x0100	/* OOB/Urgent data can be written */
+
+	/*
+	* FreeBSD extensions: polling on a regular file might return one
+	* of these events (currently only supported on local filesystems).
+	*/
+	const Pollextend	: uint16 = 0x0200	/* file may have been extended */
+	const Pollattrib	: uint16 = 0x0400	/* file attributes may have changed */
+	const Pollnlink		: uint16 = 0x0800	/* (un)link/rename may have happened */
+	const Pollwrite		: uint16 = 0x1000	/* file's contents may have changed */
+
+	/*
+	* These events are set if they occur regardless of whether they were
+	* requested.
+	*/
+	const Pollerr		: uint16 = 0x0008	/* some poll error occurred */
+	const Pollhup		: uint16 = 0x0010	/* file descriptor was "hung up" */
+	const Pollnval		: uint16 = 0x0020	/* requested events "invalid" */
 
 	/* return value for a failed mapping */
 	const Mapbad	: byte# = -1 castto(byte#)