예제 #1
0
        public void Connect()
        {
            try
            {
                IPAddress = GetIPAddress(_dataSource);
                var endPoint = new IPEndPoint(IPAddress, _portNumber);

                var socket = new Socket(IPAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
                socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveBuffer, _packetSize);
                socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendBuffer, _packetSize);
                socket.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.NoDelay, 1);
                socket.TrySetKeepAlive(KeepAliveTime, KeepAliveInterval);
                socket.TryEnableLoopbackFastPath();

#if NETSTANDARD1_6
                socket.Connect(endPoint);
#else
                IAsyncResult result = socket.BeginConnect(endPoint, null, null);

                result.AsyncWaitHandle.WaitOne(_timeout * 1000, true);

                if (socket.Connected)
                {
                    socket.EndConnect(result);
                    _firebirdNetworkStream = new FirebirdNetworkStream(new NetworkStream(socket, true));
                    Xdr = new XdrReaderWriter(_firebirdNetworkStream, _charset);
                }
                else
                {
                    socket.Close();
                    throw IscException.ForTypeErrorCodeStrParam(IscCodes.isc_arg_gds, IscCodes.isc_network_error, _dataSource);
                }
#endif
            }
            catch (SocketException ex)
            {
                throw IscException.ForTypeErrorCodeStrParam(IscCodes.isc_arg_gds, IscCodes.isc_network_error, _dataSource, ex);
            }
        }
        public void Connect()
        {
            try
            {
                IPAddress = GetIPAddress(_dataSource);
                var endPoint = new IPEndPoint(IPAddress, _portNumber);

                var socket = new Socket(IPAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
                socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveBuffer, _packetSize);
                socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendBuffer, _packetSize);
                socket.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.NoDelay, 1);
                socket.TrySetKeepAlive(KeepAliveTime, KeepAliveInterval);
                socket.TryEnableLoopbackFastPath();
                socket.Connect(endPoint);

                _firebirdNetworkStream = new FirebirdNetworkStream(new NetworkStream(socket, true));
                Xdr = new XdrReaderWriter(_firebirdNetworkStream, _charset);
            }
            catch (SocketException ex)
            {
                throw IscException.ForTypeErrorCodeStrParam(IscCodes.isc_arg_gds, IscCodes.isc_network_error, _dataSource, ex);
            }
        }
예제 #3
0
        public void Connect()
        {
            try
            {
                IPAddress = GetIPAddress(DataSource);
                var endPoint = new IPEndPoint(IPAddress, PortNumber);

                var socket = new Socket(IPAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
                socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveBuffer, PacketSize);
                socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendBuffer, PacketSize);
                socket.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.NoDelay, 1);
                socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, 1);

                socket.Connect(endPoint);

                _networkStream = new NetworkStream(socket, true);
                _firebirdNetworkHandlingWrapper = new FirebirdNetworkHandlingWrapper(new DataProviderStreamWrapper(_networkStream));
                Xdr = new XdrReaderWriter(_firebirdNetworkHandlingWrapper, Charset);
            }
            catch (SocketException ex)
            {
                throw IscException.ForTypeErrorCodeStrParam(IscCodes.isc_arg_gds, IscCodes.isc_network_error, DataSource, ex);
            }
        }