Ticket #522: socket6.patch

File socket6.patch, 1.8 KB (added by bacek, 13 years ago)
  • (a) /dev/null vs. (b) b/examples/io/http.pir

    commit 10950fedf9f63bf6c2f301290eeae48f869a17f8
    Author: Vasily Chekalkin <bacek@bacek.com>
    Date:   Mon Mar 30 20:33:12 2009 +1100
    
        Use modern socket API in examples/io/http.pir
    
    diff --git a/examples/io/http.pir b/examples/io/http.pir
    new file mode 100644
    index 0000000..e0035df
    a b  
     1# Copyright (C) 2001-2008, Parrot Foundation. 
     2# $Id: http.pir 36833 2009-02-17 20:09:26Z allison $ 
     3 
     4=head1 NAME 
     5 
     6examples/io/http.pir - HTTP client 
     7 
     8=head1 SYNOPSIS 
     9 
     10    % ./parrot examples/io/http.pir 
     11 
     12=head1 DESCRIPTION 
     13 
     14HTTP client, connects to WWW port and grabs a page (L<http://www.ibm.com>). 
     15 
     16You should be running the echo service on your box (port 7). Be sure to 
     17set C<PARROT_NET_DEVEL> to 1 in F<io/io_private.h> and rebuld Parrot or 
     18the network layer won't exist. 
     19 
     20=cut 
     21 
     22.sub example :main 
     23    .local pmc sock 
     24    .local pmc address 
     25    .local string buf 
     26    .local int ret 
     27    .local int len 
     28 
     29    # create the socket handle 
     30    print "Creating socket.\n" 
     31    sock = new 'Socket' 
     32    sock.'socket'(2, 1, 0) 
     33    unless sock goto ERR 
     34 
     35    # Pack a sockaddr_in structure with IP and port 
     36    address = sock.'sockaddr'("www.ibm.com", 80) 
     37    print "Connecting to http://www.ibm.com:80\n" 
     38    ret = sock.'connect'(address) 
     39    print "connect returned " 
     40    print ret 
     41    print "\n" 
     42 
     43    ret = sock.'send'("GET /us/en/ HTTP/1.0\r\nUser-agent: Parrot\r\n\r\n") 
     44MORE: 
     45    buf = sock.'recv'() 
     46    ret = length buf 
     47    if ret <= 0 goto END 
     48    print buf 
     49    goto MORE 
     50ERR: 
     51    print "Socket error\n" 
     52    end 
     53END: 
     54    close sock 
     55    end 
     56.end 
     57 
     58=head1 SEE ALSO 
     59 
     60F<io/io_private.h>. 
     61 
     62=cut 
     63 
     64# Local Variables: 
     65#   mode: pir 
     66#   fill-column: 100 
     67# End: 
     68# vim: expandtab shiftwidth=4 ft=pir: