Exemple #1
0
        public void test()
        {
            const string filePath = "a.txt";

            var osHandle = new OSHandle();
            var fs       = File.Open(filePath, FileMode.Create, FileAccess.ReadWrite, FileShare.None);

            osHandle.Handle = fs.Handle;

            osHandle.Dispose();

            try
            {
                fs.WriteByte(1);
                fs.Close();
                Assert.Fail();
            }
            catch (IOException)
            {
            }

            Assert.That(File.ReadAllBytes(filePath).Length, Is.EqualTo(0));
        }
Exemple #2
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;
        }
Exemple #3
0
 private static bool IOHandler(IntPtr channel, int condition, IntPtr data)
 {
     object[] args = (GCHandle.FromIntPtr(data).Target as object[]);
     WatchHandler handler = args[0] as WatchHandler;
     object source = args[1];
     try
     {
         OSHandle h = new OSHandle((IntPtr)g_io_channel_unix_get_fd(channel));
         handler(source, h, MapEventsL((IOCondition)condition));
     }
     catch(Exception e)
     {
             ExceptionManager.RaiseUnhandledException(e, true);
             return false;
     }
     return true;
 }