qmsk/net/libc.pyx
author Tero Marttila <terom@fixme.fi>
Sat, 26 Sep 2009 21:50:42 +0300
changeset 52 722fc70a197a
parent 19 e6b670dbfe3b
permissions -rw-r--r--
change CallbackEvent to replace fd with ev, event2 doc/style tweaks
from qmsk.net.libc cimport *
from qmsk.net.py cimport raise_errno

cdef fcntl_set_flag (int fd, int flag, bint value) :
    """
        Set the given FCNTL file status flag(s) to the given boolean value.

        This will first get the current flags, then compute the new flags, and then update them if they have changed.
    """
    
    # get current flags
    cdef int old_flags = fcntl(fd, F_GETFL, 0)

    if old_flags < 0 :
        raise_errno('fcntl')

    # set bit
    cdef int new_flags = (old_flags & ~flag) | (flag if value else 0)
    
    if new_flags != old_flags :
        # set flags
        if fcntl(fd, F_SETFL, new_flags) :
            raise_errno('fcntl')


#cdef class Errno (py.OSError) :
#    def __init__ (self, func) :
#        self.func = func
#        self.err = errno
#        self.strerror = strerror(errno)
#
#    def __str__ (self) :
#        return "%s: %s" % (self.func, self.strerror)
#
#cdef class GAIError (py.OSError) :
#    def __init__ (self, func, err) :
#        self.func = func
#        self.err = err
#        self.strerror = gai_strerror(err)
#
#    def __str__ (self) :
#        return "%s: %s" % (self.func, self.strerror)
#