Changeset 21243 for lang

Show
Ignore:
Timestamp:
10/13/08 19:09:27 (6 years ago)
Author:
tokuhirom
Message:

fixed some problems

Location:
lang/cplusplus/llv8call/branches/unixsocket
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • lang/cplusplus/llv8call/branches/unixsocket/ext/socket/socket.cc

    r21241 r21243  
    119119 
    120120            String::Utf8Value path(args->Get(Int32::New(0))); 
     121            if ((unsigned int)path.length() >= sizeof(addr->sun_path)) { 
     122                ThrowException(String::New("path too long")); 
     123                return; 
     124            } 
    121125            addr->sun_family = AF_UNIX; 
    122             puts(*path); 
    123             strncpy(addr->sun_path, *path, 104); 
     126            memcpy(addr->sun_path, *path, path.length()); 
     127            addr->sun_path[path.length()] = '\0'; 
    124128            puts(addr->sun_path); 
    125             *len = sizeof(sockaddr_un); 
     129            *len = path.length() + (sizeof(*addr) - sizeof(addr->sun_path)); 
    126130        } 
    127131        break; 
     
    260264    ARG_array(addrsrc, 0); 
    261265    _gen_sockaddr(addrsrc, family, &addr, &len); 
     266    printf("connect: FAMILY: %d, %d, %s, %d\n", family, len, addr.un.sun_path, addr.un.sun_family); 
    262267    if (connect(sock, (sockaddr*)&addr, len) == 0) { 
    263268        return Undefined(); 
     
    276281        _flags = flags; 
    277282    } 
    278     char * buf = new char [len]; 
     283    char * buf = new char [len+1]; 
     284    assert(sock); 
     285    printf("FOOEEE %d, %d, %d\n", sock, len, _flags); 
    279286    ssize_t size = recv(sock, buf, len, _flags); 
    280287    if (size >= 0) { 
  • lang/cplusplus/llv8call/branches/unixsocket/t/100_socket/05_unix_socket.js

    r21241 r21243  
    55var Socket = org.coderepos.socket.Socket; 
    66var POSIX = org.coderepos.posix; 
    7 var Temp = org.coderepos.fs.Temp; 
    87 
    98var pid = POSIX.fork(); 
    10 var tmpfile = Temp.tempfile(); 
     9var sockfile = "t/100_socket/unix.sock"; 
     10if (File.access(sockfile, File.R_OK)) { 
     11    File.remove(sockfile); 
     12} 
    1113 
    1214if (Socket.AF_UNIX) { 
    1315    if (pid == 0) { 
    1416        // child(client) 
    15         POSIX.sleep(3); 
     17        POSIX.sleep(1); 
    1618        var sock = new Socket(Socket.AF_UNIX); 
    17         sock.connect([tmpfile]); 
     19        sock.connect([sockfile]); 
    1820        sock.send("ABCDEFGHIJ"); 
     21        p("SENT"); 
    1922        sock.close(); 
    2023        exit(0); 
     
    2629        p(Socket.AF_UNIX); 
    2730        p(sock); 
    28         sock.bind([tmpfile]); 
     31        sock.bind([sockfile]); 
     32        sock.listen(1); 
     33        POSIX.sleep(3); 
    2934        is(sock.recv(10), "ABCDEFGHIJ"); 
    3035        sock.close(); 
    31         File.remove(tmpfile); 
     36        File.remove(sockfile); 
    3237    } else { 
    3338        throw "Cannot fork";