public static bool AddFileDescriptor(this BPS bps, NetworkStream ns, BPSIO ioEvents, Func <NetworkStream, BPSIO, object, bool> ioHandler, object data = null) { var socketProp = typeof(NetworkStream).GetProperties(BindingFlags.GetProperty | BindingFlags.NonPublic).First(prop => prop.Name == "Socket"); var socket = socketProp.GetValue(ns) as Socket; return(bps.AddFileDescriptor(new SafeFileHandle(socket.Handle, false), ns, ioEvents, ioHandler, data)); // Not really the proper way to do this }
public static void SectionExists_Test() { File bpsFile = BPSIO.Read(path + rf); Console.WriteLine(bpsFile.Exists("section")); BPSIO.Write(bpsFile, path + wf); }
public static void RemoveSection_Test() { File bpsFile = BPSIO.Read(path + rf); Console.WriteLine(bpsFile.Remove("section")); BPSIO.Write(bpsFile, path + wf); }
public static void RemoveData_Test() { File bpsFile = BPSIO.Read(path + rf); bpsFile.Find("section").Remove("key"); BPSIO.Write(bpsFile, path + wf); }
public static void FindSection_Test() { File bpsFile = BPSIO.Read(path + rf); Console.WriteLine(bpsFile.Find("section").Name); foreach (var d in bpsFile.Find("section").FindAll()) { Console.WriteLine(d.Key + ":" + d.Value); } BPSIO.Write(bpsFile, path + wf); }
public static void ReadWrite_Test() { File bpsFile = BPSIO.Read(path + rf); foreach (var s in bpsFile.FindAll()) { Console.WriteLine(s.Name); foreach (var d in s.FindAll()) { Console.WriteLine(d.Key + ":" + d.Value); } Console.WriteLine("\n"); } BPSIO.Write(bpsFile, path + wf); }
internal bool AddFileDescriptor <T>(SafeHandle handle, T sender, BPSIO ioEvents, Func <T, BPSIO, object, bool> ioHandler, object callbackData) { if (disposed) { throw new ObjectDisposedException("BPS"); } if (handle == null) { throw new ArgumentNullException("handle"); } if (ioHandler == null) { throw new ArgumentNullException("ioHandler"); } // Could probably just pass sender directly into the ioHandler instead of routing it through the HandleFileDescriptor function var genericCallback = new Func <object, BPSIO, object, bool>((s, e, d) => ioHandler((T)s, e, d)); var toSerialize = callbackData == null ? new object[] { sender, genericCallback } : new object[] { sender, genericCallback, callbackData }; var data = Util.SerializeToPointer(toSerialize); if (data == IntPtr.Zero) { return(false); } var fd = handle.DangerousGetHandle(); var success = bps_add_fd(fd.ToInt32(), ioEvents, HandleFileDescriptor, data) == BPS_SUCCESS; if (success) { handleToStructPointer.Add(fd, data); allocatedPointers.Add(data); } else { Util.FreeSerializePointer(data); } return(success); }
public bool AddFileDescriptor(SafeHandle handle, BPSIO ioEvents, Func <SafeHandle, BPSIO, object, bool> ioHandler, object data = null) { return(AddFileDescriptor(handle, handle, ioEvents, ioHandler, data)); }
private static extern int bps_add_fd(int fd, BPSIO io_events, Func <int, int, IntPtr, int> io_handler, IntPtr data);
public static bool AddFileDescriptor(this BPS bps, Socket s, BPSIO ioEvents, Func <Socket, BPSIO, object, bool> ioHandler, object data = null) { return(bps.AddFileDescriptor(new SafeFileHandle(s.Handle, false), s, ioEvents, ioHandler, data)); // Not really the proper way to do this }
public static bool AddFileDescriptor(this BPS bps, FileStream fs, BPSIO ioEvents, Func <FileStream, BPSIO, object, bool> ioHandler, object data = null) { return(bps.AddFileDescriptor(fs.SafeFileHandle, fs, ioEvents, ioHandler, data)); }
public static bool AddFileDescriptor(this BPS bps, MemoryMappedViewStream mmv, BPSIO ioEvents, Func <MemoryMappedViewStream, BPSIO, object, bool> ioHandler, object data = null) { return(bps.AddFileDescriptor(mmv.SafeMemoryMappedViewHandle, mmv, ioEvents, ioHandler, data)); }
public static bool AddFileDescriptor(this BPS bps, PipeStream p, BPSIO ioEvents, Func <PipeStream, BPSIO, object, bool> ioHandler, object data = null) { return(bps.AddFileDescriptor(p.SafePipeHandle, p, ioEvents, ioHandler, data)); }