Beispiel #1
0
        private void GetConnectNumber(uint timeOut)
        {
            EventWaitHandle eventWaitHandle;

            try
            {
                eventWaitHandle = EventWaitHandle.OpenExisting(this.memoryName + "_CONNECT_REQUEST");
            }
            catch (Exception)
            {
                string str = "Global\\" + this.memoryName;
                eventWaitHandle = EventWaitHandle.OpenExisting(str + "_CONNECT_REQUEST");
                this.memoryName = str;
            }
            EventWaitHandle eventWaitHandle2 = EventWaitHandle.OpenExisting(this.memoryName + "_CONNECT_ANSWER");

            using (SharedMemory sharedMemory = new SharedMemory(this.memoryName + "_CONNECT_DATA", (IntPtr)4))
            {
                if (!eventWaitHandle.Set())
                {
                    throw new MySqlException("Failed to open shared memory connection");
                }
                if (!eventWaitHandle2.WaitOne((int)(timeOut * 1000u), false))
                {
                    throw new MySqlException("Timeout during connection");
                }
                this.connectNumber = Marshal.ReadInt32(sharedMemory.View);
            }
        }
        public override void Close()
        {
            if (connectionClosed != null)
            {
                bool isClosed = connectionClosed.WaitOne(0);
                if (!isClosed)
                {
                    connectionClosed.Set();
                    connectionClosed.Close();
                }
                connectionClosed = null;
                EventWaitHandle[] handles = { serverRead, serverWrote, clientRead, clientWrote };

                for (int i = 0; i < handles.Length; i++)
                {
                    if (handles[i] != null)
                    {
                        handles[i].Close();
                    }
                }
                if (data != null)
                {
                    data.Dispose();
                    data = null;
                }
            }
        }
Beispiel #3
0
 public override void Close()
 {
     if (this.connectionClosed != null)
     {
         if (!this.connectionClosed.WaitOne(0))
         {
             this.connectionClosed.Set();
             this.connectionClosed.Close();
         }
         this.connectionClosed = null;
         EventWaitHandle[] array = new EventWaitHandle[]
         {
             this.serverRead,
             this.serverWrote,
             this.clientRead,
             this.clientWrote
         };
         for (int i = 0; i < array.Length; i++)
         {
             if (array[i] != null)
             {
                 array[i].Close();
             }
         }
         if (this.data != null)
         {
             this.data.Dispose();
             this.data = null;
         }
     }
 }
Beispiel #4
0
        private void SetupEvents()
        {
            string str = this.memoryName + "_" + this.connectNumber;

            this.data             = new SharedMemory(str + "_DATA", (IntPtr)16004);
            this.serverWrote      = EventWaitHandle.OpenExisting(str + "_SERVER_WROTE");
            this.serverRead       = EventWaitHandle.OpenExisting(str + "_SERVER_READ");
            this.clientWrote      = EventWaitHandle.OpenExisting(str + "_CLIENT_WROTE");
            this.clientRead       = EventWaitHandle.OpenExisting(str + "_CLIENT_READ");
            this.connectionClosed = EventWaitHandle.OpenExisting(str + "_CONNECTION_CLOSED");
            this.serverRead.Set();
        }
        private void SetupEvents()
        {
            string prefix = memoryName + "_" + connectNumber;

            data             = new SharedMemory(prefix + "_DATA", (IntPtr)BUFFERLENGTH);
            serverWrote      = EventWaitHandle.OpenExisting(prefix + "_SERVER_WROTE");
            serverRead       = EventWaitHandle.OpenExisting(prefix + "_SERVER_READ");
            clientWrote      = EventWaitHandle.OpenExisting(prefix + "_CLIENT_WROTE");
            clientRead       = EventWaitHandle.OpenExisting(prefix + "_CLIENT_READ");
            connectionClosed = EventWaitHandle.OpenExisting(prefix + "_CONNECTION_CLOSED");

            // tell the server we are ready
            serverRead.Set();
        }
        private void GetConnectNumber(uint timeOut)
        {
            EventWaitHandle connectRequest;

            try
            {
                connectRequest =
                    EventWaitHandle.OpenExisting(memoryName + "_CONNECT_REQUEST");
            }
            catch (Exception)
            {
                // If server runs as service, its shared memory is global
                // And if connector runs in user session, it needs to prefix
                // shared memory name with "Global\"
                string prefixedMemoryName = @"Global\" + memoryName;
                connectRequest =
                    EventWaitHandle.OpenExisting(prefixedMemoryName + "_CONNECT_REQUEST");
                memoryName = prefixedMemoryName;
            }
            EventWaitHandle connectAnswer =
                EventWaitHandle.OpenExisting(memoryName + "_CONNECT_ANSWER");

            using (SharedMemory connectData =
                       new SharedMemory(memoryName + "_CONNECT_DATA", (IntPtr)4))
            {
                // now start the connection
                if (!connectRequest.Set())
                {
                    throw new MySqlException("Failed to open shared memory connection");
                }
                if (!connectAnswer.WaitOne((int)(timeOut * 1000), false))
                {
                    throw new MySqlException("Timeout during connection");
                }
                connectNumber = Marshal.ReadInt32(connectData.View);
            }
        }
        private void SetupEvents()
        {
            string prefix = memoryName + "_" + connectNumber;
              data = new SharedMemory(prefix + "_DATA", (IntPtr)BUFFERLENGTH);
              serverWrote = EventWaitHandle.OpenExisting(prefix + "_SERVER_WROTE");
              serverRead = EventWaitHandle.OpenExisting(prefix + "_SERVER_READ");
              clientWrote = EventWaitHandle.OpenExisting(prefix + "_CLIENT_WROTE");
              clientRead = EventWaitHandle.OpenExisting(prefix + "_CLIENT_READ");
              connectionClosed = EventWaitHandle.OpenExisting(prefix + "_CONNECTION_CLOSED");

              // tell the server we are ready
              serverRead.Set();
        }
        private void GetConnectNumber(uint timeOut)
        {
            EventWaitHandle connectRequest;
              try
              {
            connectRequest =
            EventWaitHandle.OpenExisting(memoryName + "_CONNECT_REQUEST");

              }
              catch (Exception)
              {
            // If server runs as service, its shared memory is global
            // And if connector runs in user session, it needs to prefix
            // shared memory name with "Global\"
            string prefixedMemoryName = @"Global\" + memoryName;
            connectRequest =
            EventWaitHandle.OpenExisting(prefixedMemoryName + "_CONNECT_REQUEST");
            memoryName = prefixedMemoryName;
              }
              EventWaitHandle connectAnswer =
             EventWaitHandle.OpenExisting(memoryName + "_CONNECT_ANSWER");
              using (SharedMemory connectData =
              new SharedMemory(memoryName + "_CONNECT_DATA", (IntPtr)4))
              {
            // now start the connection
            if (!connectRequest.Set())
              throw new MySqlException("Failed to open shared memory connection");
            if (!connectAnswer.WaitOne((int)(timeOut * 1000), false))
              throw new MySqlException("Timeout during connection");
            connectNumber = Marshal.ReadInt32(connectData.View);
              }
        }
        public override void Close()
        {
            if (connectionClosed != null)
              {
            bool isClosed = connectionClosed.WaitOne(0);
            if (!isClosed)
            {
              connectionClosed.Set();
              connectionClosed.Close();
            }
            connectionClosed = null;
            EventWaitHandle[] handles = { serverRead, serverWrote, clientRead, clientWrote };

            for (int i = 0; i < handles.Length; i++)
            {
              if (handles[i] != null)
            handles[i].Close();
            }
            if (data != null)
            {
              data.Dispose();
              data = null;
            }
              }
        }