shithub: mc

Download patch

ref: ddffd453738e97de59d5320c14bb08714cc8ef22
parent: e0364588c26acb824be02dff420847eb20272c41
author: Ori Bernstein <ori@eigenstate.org>
date: Tue Apr 26 07:03:07 EDT 2016

Add sockopt crud to OSX.

--- a/lib/sys/sys+osx-x64.myr
+++ b/lib/sys/sys+osx-x64.myr
@@ -8,6 +8,7 @@
 	type mprot	= int64	/* memory protection */
 	type mopt	= int64	/* memory mapping options */
 	type socktype	= int64	/* socket type */
+	type sockopt	= int64	/* socket option */
 	type sockproto	= int64	/* socket protocol */
 	type sockfam	= uint8	/* socket family */
 	type filemode	= uint16	/* file permission bits */
@@ -260,7 +261,27 @@
 	const Sockraw		: socktype = 3
 	const Sockrdm		: socktype = 4
 	const Sockseqpacket	: socktype = 5
+	const Solsock	: socktype =	0xffff
 
+	/* socket options */
+	const Sodebug	: sockopt = 0x0001		/* turn on debugging info recording */
+	const Soacceptconn	: sockopt = 0x0002	/* socket has had listen() */
+	const Soreuseaddr	: sockopt = 0x0004	/* allow local address reuse */
+	const Sokeepalive	: sockopt = 0x0008	/* keep connections alive */
+	const Sodontroute	: sockopt = 0x0010	/* just use interface addresses */
+	const Sobroadcast	: sockopt = 0x0020	/* permit sending of broadcast msgs */
+	const Souseloopback	: sockopt = 0x0040	/* bypass hardware when possible */
+	const Solingerticks	: sockopt = 0x0080	/* linger on close if data present (in ticks) */
+	const Solingersecs	: sockopt = 0x1080	/* linger on close if data present (in seconds) */
+	const Sooobinline	: sockopt = 0x0100	/* leave received OOB data in line */
+	const Soreuseport	: sockopt = 0x0200	/* allow local address & port reuse */
+	const Sotimestamp	: sockopt = 0x0400	/* timestamp received dgram traffic */
+	const Somonotimestamp	: sockopt = 0x0800	/* Monotonically increasing timestamp on rcvd dgram */
+	const Soacceptfilter	: sockopt = 0x1000	/* there is an accept filter */
+	const Sodonttrunc	: sockopt = 0x2000	/* APPLE: Retain unread data */
+	const Sowantmore	: sockopt = 0x4000	/* APPLE: Give hint when more data ready */
+	const Sowantoobflag	: sockopt = 0x8000	/* APPLE: Want OOB in MSG_FLAG on receive */
+
 	/* network protocols */
 	const Ipproto_ip	: sockproto = 0
 	const Ipproto_icmp	: sockproto = 1
@@ -673,8 +694,9 @@
 	const accept	: (sock : fd, addr : sockaddr#, len : size# -> fd)
 	const listen	: (sock : fd, backlog : int	-> int)
 	const bind	: (sock : fd, addr : sockaddr#, len : size -> int)
+	const setsockopt	: (sock : fd, lev : socktype, opt : sockopt, val : void#, len : size -> int)
+	const getsockopt	: (sock : fd, lev : socktype, opt : sockopt, val : void#, len : size# -> int)
 
-
 	/* memory mapping */
 	const munmap	: (addr:byte#, len:size -> int64)
 	const mmap	: (addr:byte#, len:size, prot:mprot, flags:mopt, fd:fd, off:off -> byte#)
@@ -832,6 +854,8 @@
 const accept	= {sock, addr, len;	-> syscall(Sysaccept, a(sock), a(addr), a(len)) castto(fd)}
 const listen	= {sock, backlog;	-> syscall(Syslisten, a(sock), a(backlog)) castto(int)}
 const bind	= {sock, addr, len;	-> syscall(Sysbind, a(sock), a(addr), a(len)) castto(int)}
+const setsockopt	= {sock, lev, opt, val, len;	-> syscall(Syssetsockopt, a(sock), a(lev), a(opt), a(val), a(len)) castto(int)}
+const getsockopt	= {sock, lev, opt, val, len;	-> syscall(Syssetsockopt, a(sock), a(lev), a(opt), a(val), a(len)) castto(int)}
 
 /* memory management */
 const munmap	= {addr, len;		-> syscall(Sysmunmap, a(addr), a(len))}