Esempio n. 1
0
        public static IntPtr CreateWatch(int fd, WatchEventKind events, 
            WatchHandler handler, object source_id)
        {
            IntPtr channel = g_io_channel_unix_new(fd);
            IntPtr source = g_io_create_watch(channel, (int)MapEventsN(events));
            g_io_channel_unref(channel);

            object[] args = new object[2];
            args[0] = handler;
            args[1] = source_id;

            IntPtr data = (IntPtr)GCHandle.Alloc(args);
            DestroyNotify notify = DestroyHelper.NotifyHandler;
            g_source_set_callback(source, IOHandler, data, notify);

            return source;
        }
Esempio n. 2
0
        public override object AddWatch(OSHandle handle, WatchEventKind events, 
            WatchHandler handler)
        {
            object[] closure = new object[2];

            closure[0] = new EPollSourceID((uint)(int)(IntPtr)handle);
            closure[1] = handler;

            poll.AddWatch(handle, events);
            poll_handlers[(IntPtr)handle] = closure;

            Console.WriteLine("{0} = {1}", (IntPtr)handle, closure.GetHashCode());

            return closure[0];
        }
Esempio n. 3
0
        public override void UpdateWatch(object source, WatchEventKind events)
        {
            if(! (source is EPollSourceID))
                throw new ArgumentException("source");

            uint id = ((EPollSourceID)source).ID;
            poll.UpdateEvents(new OSHandle((IntPtr)(int)id, HandleKind.FD), events);
        }
Esempio n. 4
0
 //TODO
 public virtual void UpdateWatch(object source, WatchEventKind events)
 {
 }
Esempio n. 5
0
        public virtual object AddWatch(OSHandle handle, WatchEventKind events, WatchHandler handler)
        {
            if(handle.HandleKind != HandleKind.FD)
                throw new ArgumentException(String.Format("Handle of type \"{0}\" not supported by {1}", handle.HandleKind, GetType()));

            SourceID id_object = null;
            IntPtr source = GIOChannel.CreateWatch((int)((IntPtr)handle),
                events, handler, id_object);

            uint id = g_source_attach(source, Context);
            g_source_unref(source);

            id_object = new SourceID(id);

            return (object)id_object;
        }
Esempio n. 6
0
 internal static int MapEventsN(WatchEventKind events)
 {
     int val = 0;
     if((events & WatchEventKind.In) != 0)
         val |= EPOLLIN;
     else if((events & WatchEventKind.Out) != 0)
         val |= EPOLLOUT;
     else if((events & WatchEventKind.Err) != 0)
         val |= EPOLLERR;
     else if((events & WatchEventKind.Hup) != 0)
         val |= EPOLLHUP;
     return val;
 }
Esempio n. 7
0
 private static IOCondition MapEventsN(WatchEventKind events)
 {
     IOCondition val = (IOCondition)0;
     if((events & WatchEventKind.In) != 0)
         val |= IOCondition.In;
     else if((events & WatchEventKind.Out) != 0)
         val |= IOCondition.Out;
     else if((events & WatchEventKind.Err) != 0)
         val |= IOCondition.Err;
     else if((events & WatchEventKind.Hup) != 0)
         val |= IOCondition.Hup;
     return val;
 }
Esempio n. 8
0
        public void UpdateEvents(OSHandle handle, WatchEventKind events)
        {
            EPollEvent evt;

            if(handle.HandleKind != HandleKind.FD)
                throw new ArgumentException(String.Format("Handle of type \"{0}\" not supported by {1}", handle.HandleKind, GetType()));

            evt.FD = (int)handle.Handle;
            evt.EventKind = MapEventsN(events);

            int r = epoll_ctl(m_fd, EPOLL_CTL_MOD, evt.FD, ref evt);
            UnixMarshal.ThrowExceptionForLastErrorIf(r);
        }
Esempio n. 9
0
        public void AddWatch(OSHandle handle, WatchEventKind events)
        {
            EPollEvent evt;

            if(handle.HandleKind != HandleKind.FD)
                throw new ArgumentException(String.Format("Handle of type \"{0}\" not supported by {1}", handle.HandleKind, GetType()));

            evt.FD = (int)handle.Handle;
            evt.EventKind = MapEventsN(events);

            Console.WriteLine("AddWatch({0})", evt.FD);

            int r = epoll_ctl(m_fd, EPOLL_CTL_ADD, evt.FD, ref evt);
            UnixMarshal.ThrowExceptionForLastErrorIf(r);

            m_buffer.Count += 1;
        }
Esempio n. 10
0
 public static object AddWatch(OSHandle handle, WatchEventKind events, 
     WatchHandler handler)
 {
     return Native.Factory.GetLoop().AddWatch(handle, events, handler);
 }
Esempio n. 11
0
        private void OnPingReceived(object source, OSHandle handle, 
                                    WatchEventKind events)
        {
            lock(olock)
            {
                if(m_disposed)
                    throw new ObjectDisposedException("this");

                Dispatch();
            }
        }
Esempio n. 12
0
 public WatchEvent(OSHandle handle, WatchEventKind events)
 {
     Handle = handle;
     Events = events;
 }