Skip to content

Commit

Permalink
Fail if can't create socket.
Browse files Browse the repository at this point in the history
  • Loading branch information
nunorc committed May 30, 2010
1 parent 1727ca5 commit 5fc925c
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/core/IO/Socket/INET.pm
Expand Up @@ -2,7 +2,7 @@ class IO::Socket::INET is Cool does IO::Socket {

method open (Str $hostname, Int $port) {

Q:PIR {
my $s = Q:PIR {
.include "socket.pasm"
.local pmc sock
.local pmc address
Expand All @@ -22,16 +22,22 @@ class IO::Socket::INET is Cool does IO::Socket {
# Create the socket handle
sock = root_new ['parrot';'Socket']
$P1 = new 'Integer'
unless sock goto ERR
sock.'socket'(.PIO_PF_INET, .PIO_SOCK_STREAM, .PIO_PROTO_TCP)
# Pack a sockaddr_in structure with IP and port
address = sock.'sockaddr'(hostname, port)
sock.'connect'(address)
$P1 = sock.'connect'(address)
setattribute self, '$!PIO', sock
goto DONE
ERR:
.return (0)
}
$P1 = -1
DONE:
%r = $P1
};
unless $s==0 { fail "IO::Socket::INET Couldn't create socket."; }
return 1;
}

method socket(Int $domain, Int $type, Int $protocol) {
Expand Down

0 comments on commit 5fc925c

Please sign in to comment.