Esempio n. 1
0
        public static void WriteBytes(SafeMailslotHandle h, byte[] bytes)
        {
            var success = WriteFile(h, bytes, bytes.Length, out var written, IntPtr.Zero);

            if (!success || bytes.Length != written)
            {
                throw Throw("Failed to write message");
            }
        }
Esempio n. 2
0
        public static byte[] ReadBytes(SafeMailslotHandle h, int count)
        {
            var ret = new byte[count];
            var res = ReadFile(h, ret, count, out var read, IntPtr.Zero);

            if (!res)
            {
                throw Throw("Failed to read bytes");
            }
            return(ret);
        }
Esempio n. 3
0
        public static int?GetInfo(SafeMailslotHandle h)
        {
            var result = GetMailslotInfo(h, IntPtr.Zero, out var ret, out var count, IntPtr.Zero);

            if (!result)
            {
                throw Throw("Failed to get info about mail slot");
            }
            if (ret == MailslotNoMessage)
            {
                return(null);
            }
            return(ret);
        }
Esempio n. 4
0
        private bool disposedValue = false; // To detect redundant calls

        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    // TODO: dispose managed state (managed objects).
                }
                if (_handle != null)
                {
                    _handle.Close();
                    _handle = null;
                }
                disposedValue = true;
            }
        }
Esempio n. 5
0
        private MailSlot(string name, bool server)
        {
            try
            {
                if (server)
                {
                    _handle = RawMailSlot.CreateMailSlot(name);
                }
                else
                {
                    _handle = RawMailSlot.CreateFile(name);
                }
            }
            catch (Exception ex)
            {
                throw new Exception($"Unable to create new mailslot with path {name}", ex);
            }

            if (_handle.IsInvalid)
            {
                throw new Exception($"Unable to create new mailslot with path {name}", new Win32Exception());
            }
        }
Esempio n. 6
0
 private static extern bool WriteFile(SafeMailslotHandle handle,
                                      byte[] bytes, int numBytesToWrite, out int numBytesWritten,
                                      IntPtr overlapped);
Esempio n. 7
0
 private static extern bool ReadFile(SafeMailslotHandle handle,
                                     byte[] bytes, int numBytesToRead, out int numBytesRead,
                                     IntPtr overlapped);
Esempio n. 8
0
 private static extern bool GetMailslotInfo(SafeMailslotHandle hMailslot,
                                            IntPtr lpMaxMessageSize,
                                            out int lpNextSize, out int lpMessageCount,
                                            IntPtr lpReadTimeout);