Re: [Vala] How to wrap select(2)'s fd_set?



Ok, here's what I have so far:

----------------
    [CCode (cname = "fd_set", cheader_filename = "sys/select.h", free_function 
= "")]
    [Compact]
    public class FdSet
    {
        [CCode (cname = "FD_CLR", instance_pos=1.1)]
        public void clear (int fd);
        [CCode (cname = "FD_ISSET", instance_pos=1.1)]
        public bool isSet (int fd);
        [CCode (cname = "FD_SET", instance_pos=1.1)]
        public void set (int fd);
        [CCode (cname = "FD_ZERO")]
        public void zero ();
    }

    [CCode (cname = "struct timeval", cheader_filename = "time.h", 
free_function = "")]
    [Compact]
    public struct TimeVal
    {
        public long tv_sec;
        public long tv_usec;
    }

    [CCode (cheader_filename = "sys/select.h")]
    public int select (int nfds, FdSet readfds, FdSet writefds, FdSet 
exceptfds, TimeVal timeval);
----------------

I'm trying to use this like that:
----------------
        var readfds = new Posix.FdSet();
        var writefds = new Posix.FdSet();
        var exceptfds = new Posix.FdSet();
        Posix.TimeVal t = { 0, 0 };
        int maxfd = 10;
        int result = Posix.select( maxfd, readfds, writefds, exceptfds, t );
----------------

The code compiles, but emits two warnings:

src/multiplexer.vala:162.13-162.75: warning: result variable type incompatible 
with return type
        int result = Posix.select( maxfd, readfds, writefds, exceptfds, t );
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
src/multiplexer.vala:162.13-162.75: warning: local variable `result' declared 
but never used
        int result = Posix.select( maxfd, readfds, writefds, exceptfds, t );
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

The generated code looks good so far, but I did not have a chance to test it 
yet.

-- 
:M:



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]