Changeset 470 for trunk/thune/net.c

Show
Ignore:
Timestamp:
09/03/07 18:33:32 (15 months ago)
Author:
krobillard
Message:

Added 'wait. UDP port now has 'nowait option.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/thune/net.c

    r458 r470  
    173173/* 
    174174  ('udp port -- port!) 
    175   ('udp [port host host-port] -- port!) 
     175  ('udp [port host host-port 'nowait] -- port!) 
    176176 
    177177  The UPortDevice open method must return the following: 
     
    184184    struct sockaddr_in addr; 
    185185    int port = 0; 
     186    int blocking = 1; 
     187    UCell* initAddr = 0; 
    186188    UCell* spec = 0; 
    187189    UCell* res = ur_s_prev(tos); 
     
    204206        UCell* end; 
    205207        int hostPort; 
     208        UAtom atom_nb = 0; 
    206209        UBlock* blk = ur_block(spec); 
    207210 
     
    221224            else if( ur_is(it, UT_STRING) ) 
    222225            { 
    223                 spec = it; 
     226                initAddr = it; 
     227            } 
     228            else if( ur_is(it, UT_WORD) ) 
     229            { 
     230                if( ! atom_nb ) 
     231                    atom_nb = ur_intern( "nowait", 6 ); 
     232                if( ur_atom(it) == atom_nb ) 
     233                    blocking = 0; 
    224234            } 
    225235            ++it; 
    226236        } 
    227237 
    228         if( (! hostPort) || (! ur_is(spec, UT_STRING)) ) 
    229         { 
    230             ur_throwErr( UR_ERR_DATATYPE, "Invalid socket spec" ); 
    231             return -1; 
    232         } 
    233  
    234         if( ! _makeAddrName( &addr, ur_cstring(ut,spec), hostPort ) ) 
    235         { 
    236             ur_throwErr( UR_ERR_ACCESS, "gethostbyname failed" ); 
    237             return -1; 
     238        if( initAddr && hostPort ) 
     239        { 
     240            if( ! _makeAddrName( &addr, ur_cstring(ut,initAddr), hostPort ) ) 
     241            { 
     242                ur_throwErr( UR_ERR_ACCESS, "gethostbyname failed" ); 
     243                return -1; 
     244            } 
    238245        } 
    239246    } 
     
    242249        UCell* val; 
    243250        int socket; 
    244         int block = 1; 
    245251 
    246252        if( ! ur_userAllows( ut, "Open socket on port %d", port ) ) 
     
    250256        } 
    251257 
    252         socket = _openUdpSocket( ut, port, block ); 
     258        socket = _openUdpSocket( ut, port, blocking ); 
    253259        if( socket < 0 ) 
    254260            return -1; 
     
    264270 
    265271            binN = ur_makeBinary( sizeof(struct sockaddr), &bin ); 
    266             if( spec ) 
     272            if( initAddr ) 
    267273            { 
    268274                bin->used = sizeof(addr);