Created
March 26, 2009 04:35
-
-
Save mberends/85885 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 sock, "$socket" # socket object | |
find_lex $P0, "$domain" # 2=PF_INET (read 'man socket') | |
find_lex $P1, "$type" # 1=SOCK_STREAM ?=SOCK_DGRAM | |
find_lex $P2, "$protocol" # is 6=tcp ?=udp | |
domain = $P0 | |
type = $P1 | |
protocol = $P2 | |
get_hll_global $P3, ["Bool"], "True" # success | |
socket sock, domain, type, protocol | |
if sock goto Sock1 | |
get_hll_global $P3, ["Bool"], "False" # failure | |
Sock1: %r = $P3 | |
} # returns Bool::True for success or Bool::False for failure | |
} | |
sub sockaddr( Int $port, Str $host ) { | |
# $host examples 'localhost', '127.0.0.1' or 'www.microsoft.com' | |
return Q:PIR{ # from q:PIR in sockaddr_in() in Daemon.pm | |
.local pmc address | |
.local string host | |
.local int port | |
find_lex $P0, "$port" | |
find_lex $P1, "$host" | |
port = $P0 | |
host = $P1 | |
address = sockaddr host, port | |
%r = address | |
}; # returns a packed binary string containing an Internet address:port | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment