ref: d77ea4e5a34e9a7a54ed1302dcd0d0c9ef13fda9
parent: 80ae8b93281474a85ca5f3790e34ffeaff4ac866
author: Ori Bernstein <[email protected]>
date: Wed Oct 23 21:14:14 EDT 2013
Start adding preliminary code for sockets. Syscalls still not working, but the structs are there.
--- a/libstd/sys-osx.myr
+++ b/libstd/sys-osx.myr
@@ -1,12 +1,18 @@
use "types.use"
pkg std =
- type scno = int64
- type fdopt = int64
- type mprot = int64
- type mopt = int64
- type fd = int64
+ type scno = int64
+ type fdopt = int64
+ type fd = int64
+
+ type mprot = int64
+ type mopt = int64
+
+ type socktype = int64
+ type sockproto = int64
+ type sockfam = uint8
+
type timespec = struct
sec : uint64
nsec : uint32
@@ -57,6 +63,20 @@
machine : byte[256]
;;
+ type sockaddr = struct
+ len : byte
+ fam : sockfam
+ data : byte[128] /* what is the *actual* length? */
+ ;;
+
+ type sockaddr_in = struct
+ len : byte
+ fam : sockfam
+ port : uint16
+ addr : uint32
+ zero : byte[8]
+ ;;
+
/* open options */
const Ordonly : fdopt = 0x0
const Owronly : fdopt = 0x1
@@ -84,7 +104,19 @@
const M32bit : mopt = 0x40
*/
+ /* socket families. INCOMPLETE. */
+ const Afunspec : sockfam = 0
+ const Afunix : sockfam = 1
+ const Afinet : sockfam = 2
+ /* socket types. */
+ const Sockstream : socktype = 1
+ const Sockdgram : socktype = 2
+ const Sockraw : socktype = 3
+ const Sockrdm : socktype = 4
+ const Sockseqpacket : socktype = 5
+
+
/* return value for a failed mapping */
const Mapbad : byte# = -1 castto(byte#)
@@ -455,6 +487,13 @@
const lseek : (fd:fd, off:uint64, whence:int64 -> int64)
const fstat : (fd:fd, sb:statbuf# -> int64)
+ /* networking */
+ const socket : (dom : sockfam, stype : socktype, proto : sockproto -> fd)
+ const connect : (sock : fd, addr : sockaddr#, len : size -> int)
+ 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)
+
/* memory mapping */
const munmap : (addr:byte#, len:size -> int64)
const mmap : (addr:byte#, len:size, prot:mprot, flags:mopt, fd:fd, off:off -> byte#)
@@ -485,6 +524,10 @@
const write = {fd, buf; -> syscall(Syswrite, fd, buf castto(char#), buf.len castto(size)) castto(size)}
const lseek = {fd, off, whence; -> syscall(Syslseek, fd, off, whence)}
const fstat = {fd, sb; -> syscall(Sysfstat, fd, sb)}
+
+/* networking */
+const socket = {dom, stype, proto; -> syscall(Syssocket, dom castto(int64), stype, proto) castto(fd) }
+const connect = {sock, addr, len; -> syscall(Sysconnect, sock, addr, len) castto(fd)}
/* memory management */
const munmap = {addr, len; -> syscall(Sysmunmap, addr, len)}