Changeset 5632

Show
Ignore:
Timestamp:
08/03/12 19:38:50 (7 years ago)
Author:
cmatthew
Message:

Select now uses NULL to None support to act exactly as man page says. Select parsers are partially moved to the parsers file as well.

Location:
seattle/branches/nacl_repy/seattlelib
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • seattle/branches/nacl_repy/seattlelib/lind_parsers.repy

    r5579 r5632  
    122122                         files, ffree, fsid, namelen, frsize, spare) 
    123123    return result 
     124 
     125 
     126SEC_PER_MICROSEC = 0.000001 
     127MICROSEC_PER_SEC = 1000000 
     128 
     129def parse_timeval(timeval_str): 
     130    """given a struct timeval, make it into a float in seconds. 
     131 
     132    @return a float in seceonds, then each sec and usec member 
     133    """ 
     134     
     135    tv_sec, tv_usec = struct_unpack("<Q<Q",timeval_str) 
     136    return ((tv_sec + (SEC_PER_MICROSEC * tv_usec)), tv_sec, tv_usec) 
     137 
     138 
     139def pack_struct_timeval(tv_sec, tv_usec): 
     140    """given a struct timeval, make it into a float in seconds. 
     141 
     142    @return a float in seceonds, then each sec and usec member 
     143    """ 
     144    print tv_sec, tv_usec 
     145    new_struct= struct_pack("<Q<Q",tv_sec, tv_usec) 
     146    return new_struct 
     147 
     148     
  • seattle/branches/nacl_repy/seattlelib/net_select.repy

    r5522 r5632  
    122122 
    123123 
    124 SEC_PER_MICROSEC = 0.000001 
    125 MICROSEC_PER_SEC = 1000000 
    126  
    127  
    128 def parse_timeval(timeval_str): 
    129     """given a struct timeval, make it into a float in seconds. 
    130  
    131     @return a float in seceonds, then each sec and usec member 
    132     """ 
    133     tv_sec, tv_usec = struct_unpack("<Q<Q",timeval_str) 
    134     return ((tv_sec + (SEC_PER_MICROSEC * tv_usec)), tv_sec, tv_usec) 
    135  
    136  
    137 def build_struct_timeval(tv_sec, tv_usec): 
    138     """given a struct timeval, make it into a float in seconds. 
    139  
    140     @return a float in seceonds, then each sec and usec member 
    141     """ 
    142     print tv_sec, tv_usec 
    143     new_struct= struct_pack("<Q<Q",tv_sec, tv_usec) 
    144     return new_struct 
    145  
    146      
    147124def lind_net_select(args): 
    148125    """ 
     
    150127    Args should have a nfds, bitvectors for read write and except, and a time. 
    151128    """ 
    152  
     129    print "\n!!!!!!!!!!!!!!", args 
    153130    nonblocking = False 
    154131    notimer = False 
     
    156133    nfds = args[0] 
    157134 
    158     readfds = args[4] 
    159     writefds = args[5] 
    160     exceptfds = args[6] 
    161      
    162     time, sec, usec = parse_timeval(args[7]) 
     135    readfds = args[1] 
     136    writefds = args[2] 
     137    exceptfds = args[3] 
     138    timeval = args[4] 
    163139 
    164     if sec == 0 and usec == 0: 
    165         nonblocking = True 
    166         time = 0 
    167     elif usec == 4000000:  # sentinal value passed by glibc when time is NULL 
    168         notimer = True 
    169         time = 0 
    170          
    171  
    172     readfds = get_fds(bit_string_to_bitlist(readfds), nfds) 
    173     writefds = get_fds(bit_string_to_bitlist(writefds), nfds) 
    174     exceptfds = get_fds(bit_string_to_bitlist(exceptfds), nfds) 
     140    if timeval == None: 
     141        time = -1 
     142    else: 
     143        time, sec, usec = parse_timeval(args[4]) 
     144  
     145    readfds = [] if readfds == None else get_fds(bit_string_to_bitlist(readfds), nfds) 
     146    writefds = [] if writefds == None else get_fds(bit_string_to_bitlist(writefds), nfds) 
     147    exceptfds = [] if exceptfds == None else get_fds(bit_string_to_bitlist(exceptfds), nfds) 
    175148    try: 
    176         rc, nread, nwrite, nexcept, usedtime = select_syscall(nfds, readfds, writefds, exceptfds, time, nonblocking, notimer) 
     149        rc, nread, nwrite, nexcept, usedtime = select_syscall(nfds, readfds, writefds, exceptfds, time) 
    177150    except SyscallError, e: 
    178151        return ErrorResponseBuilder("net_select", e[1], e[2]) 
     
    180153    used_sec = long((usedtime)) 
    181154    used_usec = long((usedtime - used_sec) * MICROSEC_PER_SEC) 
    182     used_timeval = build_struct_timeval(used_sec, used_usec) 
     155    used_timeval = pack_struct_timeval(used_sec, used_usec) 
    183156    readfds = bit_bitlist_to_str(set_fds(readfds, nfds)) 
    184157    writefds = bit_bitlist_to_str(set_fds(writefds, nfds))