예제 #1
0
        public void Open(uint timeOut)
        {
            if (connectionClosed != null)
            {
                Debug.Assert(false, "Connection is already open");
            }

            MySqlSecurityPermission.CreatePermissionSet(false).Assert();

            GetConnectNumber(timeOut);
            SetupEvents();
        }
예제 #2
0
        private void AcquireCredentials()
        {
#if !CF
            MySqlSecurityPermission.CreatePermissionSet(false).Assert();
#endif
            continueProcessing = true;

            int ss = AcquireCredentialsHandle(null, "Negotiate", SECPKG_CRED_OUTBOUND,
                                              IntPtr.Zero, IntPtr.Zero, 0, IntPtr.Zero, ref outboundCredentials,
                                              ref lifetime);
            if (ss != SEC_E_OK)
            {
                throw new MySqlException("AcquireCredentialsHandle failed with errorcode" + ss);
            }
        }
예제 #3
0
        private Stream CreateSocketStream(IPAddress ip, bool unix)
        {
            EndPoint endPoint;

#if !CF
            if (!Platform.IsWindows() && unix)
            {
                endPoint = CreateUnixEndPoint(hostList);
            }
            else
#endif

            endPoint = new IPEndPoint(ip, (int)port);

#if !CF
            MySqlSecurityPermission.CreatePermissionSet(false).Assert();
#endif

            Socket socket = unix ?
                            new Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.IP) :
                            new Socket(ip.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
            if (keepalive > 0)
            {
                SetKeepAlive(socket, keepalive);
            }


            IAsyncResult ias = socket.BeginConnect(endPoint, null, null);
            if (!ias.AsyncWaitHandle.WaitOne((int)timeOut * 1000, false))
            {
                socket.Close();
                return(null);
            }
            try
            {
                socket.EndConnect(ias);
            }
            catch (Exception)
            {
                socket.Close();
                throw;
            }
            MyNetworkStream stream = new MyNetworkStream(socket, true);
            GC.SuppressFinalize(socket);
            GC.SuppressFinalize(stream);
            return(stream);
        }
예제 #4
0
        public void Open(string path, FileAccess mode, uint timeout)
        {
            IntPtr nativeHandle;

            for (; ;)
            {
                NativeMethods.SecurityAttributes security = new NativeMethods.SecurityAttributes();
                security.inheritHandle = true;
                security.Length        = Marshal.SizeOf(security);

                MySqlSecurityPermission.CreatePermissionSet(false).Assert();

                nativeHandle = NativeMethods.CreateFile(path, NativeMethods.GENERIC_READ | NativeMethods.GENERIC_WRITE,
                                                        0, security, NativeMethods.OPEN_EXISTING, NativeMethods.FILE_FLAG_OVERLAPPED, 0);

                if (nativeHandle != IntPtr.Zero)
                {
                    break;
                }

                if (Marshal.GetLastWin32Error() != ERROR_PIPE_BUSY)
                {
                    throw new Win32Exception(Marshal.GetLastWin32Error(),
                                             "Error opening pipe");
                }
                LowResolutionStopwatch sw = LowResolutionStopwatch.StartNew();
                bool success = NativeMethods.WaitNamedPipe(path, timeout);
                sw.Stop();
                if (!success)
                {
                    if (timeout < sw.ElapsedMilliseconds ||
                        Marshal.GetLastWin32Error() == ERROR_SEM_TIMEOUT)
                    {
                        throw new TimeoutException("Timeout waiting for named pipe");
                    }
                    else
                    {
                        throw new Win32Exception(Marshal.GetLastWin32Error(),
                                                 "Error waiting for pipe");
                    }
                }
                timeout -= (uint)sw.ElapsedMilliseconds;
            }
            handle     = new SafeFileHandle(nativeHandle, true);
            fileStream = new FileStream(handle, mode, 4096, true);
        }