Npgsql.WriteBuffer.Flush C# (CSharp) Method

Flush() private method

private Flush ( ) : void
return void
        internal void Flush()
        {
            if (_writePosition != 0)
            {
                try
                {
                    Underlying.Write(_buf, 0, _writePosition);
                }
                catch (Exception e)
                {
                    Connector.Break();
                    throw new NpgsqlException("Exception while writing to stream", e);
                }

                try
                {
                    Underlying.Flush();
                }
                catch (Exception e)
                {
                    Connector.Break();
                    throw new NpgsqlException("Exception while flushing stream", e);
                }

                TotalBytesFlushed += _writePosition;
                _writePosition = 0;
            }
        }

Usage Example

Esempio n. 1
0
        async Task AuthenticateMD5(string username, byte[] salt, bool async, CancellationToken cancellationToken)
        {
            var passwd = Settings.Password;

            if (passwd == null)
            {
                // No password was provided. Attempt to pull the password from the pgpass file.
                var matchingEntry = PgPassFile.LoadDefaultFile()?.GetFirstMatchingEntry(Settings.Host, Settings.Port, Settings.Database, Settings.Username);
                if (matchingEntry != null)
                {
                    Log.UsingPgpassFile();
                    passwd = matchingEntry.Password;
                }
            }

            if (passwd == null)
            {
                throw new NpgsqlException("No password has been provided but the backend requires one (in MD5)");
            }

            await PasswordMessage
            .CreateMD5(passwd, username, salt)
            .Write(WriteBuffer, async, cancellationToken);

            await WriteBuffer.Flush(async);

            await ReadExpecting <AuthenticationRequestMessage>(async);
        }
All Usage Examples Of Npgsql.WriteBuffer::Flush