view modules/socket.tp @ 139:9bce890a7ff2

Old work on a socket module
author Mike Pavone <pavone@retrodev.com>
date Fri, 09 Aug 2013 01:32:35 -0700
parents
children 7db37f040a6f
line wrap: on
line source

#{
	llMessage: AF_INET withVars: {
		intret <- obj_int32 ptr
	} andCode: {
		intret <- make_object: (addr_of: obj_int32_meta) NULL 0
		intret num!: AF_INET
		intret
	}
	llMessage: AF_UNIX withVars: {
		intret <- obj_int32 ptr
	} andCode: {
		intret <- make_object: (addr_of: obj_int32_meta) NULL 0
		intret num!: AF_UNIX
		intret
	}
	llMessage: STREAM withVars: {
		intret <- obj_int32 ptr
	} andCode: {
		intret <- make_object: (addr_of: obj_int32_meta) NULL 0
		intret num!: SOCK_STREAM
		intret
	}
	llMessage: DGRAM withVars: {
		intret <- obj_int32 ptr
	} andCode: {
		intret <- make_object: (addr_of: obj_int32_meta) NULL 0
		intret num!: SOCK_DGRAM
		intret
	}
	llMessage: socket withVars: {
		fd <- obj_int32 ptr
		domain <- obj_int32 ptr
		type <- obj_int32 ptr
		protocol <- obj_int32 ptr
	} andCode: :domain type protocol {
		fd <- make_object: (addr_of: obj_int32_meta) NULL 0
		fd num!: (socket: (domain num) (type num) (protocol num))
		fd
	}
	
	llMessage: getaddrinfo withVars: {
		
	} andCode: {
	}
	
	new <- :domain type protocol {
		sfd <- socket: domain type protocol
		#{
			fd <- {sfd}
			llMessage: close withVars: {
				sfd <- obj_int32 ptr
			} andCode: {
				sfd <- mcall: fd 1 self
				close: (sfd num)
				self
			}
		}
	}
	
	connectTo:onPort <- :host :port {
		
	}
	listenOn: <- :port {
	}
	listenAt:onPort <- :host :port {
	}
}