Skip to content

Instantly share code, notes, and snippets.

@mberends
Created March 25, 2009 19:01
Show Gist options
  • Save mberends/85641 to your computer and use it in GitHub Desktop.
Save mberends/85641 to your computer and use it in GitHub Desktop.
sub socket( IO $socket, Int $domain, Int $type, Int $protocol ) {
return q:PIR{ # from q:PIR in socket() in Daemon.pm
.local pmc sock
.local int domain
.local int type
.local int protocol
find_lex $P0, "$socket" # handle to be opened
find_lex $P1, "$domain" # 2=PF_INET (read 'man socket')
find_lex $P2, "$type" # 1=SOCK_STREAM ?=SOCK_DGRAM
find_lex $P3, "$protocol" # is 6=tcp ?=udp
"infix:="(sock, $P0)
"infix:="(domain, $P1)
"infix:="(type, $P2)
"infix:="(protocol, $P3)
get_hll_global $P4, ["Bool"], "True" # success
socket sock, domain, type, protocol
if sock goto Sock1
get_hll_global $P4, ["Bool"], "False" # failure
Sock1: %r = $P4
} # returns Bool::True for success or Bool::False for failure
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment