Ticket #507: pc.patch

File pc.patch, 1.3 KB (added by bacek, 13 years ago)

postalcodes.pir patch to use sockets' methods.

  • compilers/json/postalcodes.pir

    diff --git a/compilers/json/postalcodes.pir b/compilers/json/postalcodes.pir
    index d047169..b4337dd 100755
    a b  
    2727 
    2828    postal = argv[1] 
    2929 
    30     .local pmc sock 
    31     .local string address, buf, json_result 
     30    .local pmc sock, address 
     31    .local string buf, json_result 
    3232    json_result = '' 
    3333    .local int ret 
    3434    .local int len 
    3535 
    3636    # create the socket handle 
    37     socket sock, 2, 1, 0 
     37    sock = new 'Socket' 
     38    sock.'socket'(2, 1, 0) 
    3839    unless sock goto ERR 
    3940 
    4041    # Pack a sockaddr_in structure with IP and port 
    41     sockaddr address, 80, 'ws.geonames.org' 
    42     connect ret, sock, address 
     42    address = sock.'sockaddr'('ws.geonames.org', 80) 
     43    sock.'connect'(address) 
    4344 
    4445    .local string url 
    4546    url = 'http://ws.geonames.org/postalCodeSearchJSON?maxRows=10&postalcode=' 
     
    4849    $S0 = 'GET ' 
    4950    $S0 .= url 
    5051    $S0 .= " HTTP/1.0\nUser-agent: Parrot\n\n" 
    51     send ret, sock, $S0 
    52     poll ret, sock, 1, 5, 0 
     52    sock.'send'($S0) 
     53    #poll ret, sock, 1, 5, 0 
    5354MORE: 
    54     recv ret, sock, buf 
    55     if ret < 0 goto END 
     55    buf = sock.'recv'() 
     56    ret = length buf 
     57    if ret <= 0 goto END 
    5658    json_result .= buf 
    5759    goto MORE 
    5860ERR: