void WriteHeader() { EnsureDataMessage(); _buf.WriteBytesSimple(NpgsqlRawCopyStream.BinarySignature); _buf.WriteInt32(0); // Flags field. OID inclusion not supported at the moment. _buf.WriteInt32(0); // Header extension area length }
public override void Write(byte[] buffer, int offset, int count) { CheckDisposed(); if (!CanWrite) { throw new InvalidOperationException("Stream not open for writing"); } if (count == 0) { return; } EnsureDataMessage(); if (count <= _buf.WriteSpaceLeft) { _buf.WriteBytesSimple(buffer, offset, count); return; } // Buffer is too big. Write whatever will fit and flush. var written = _buf.WriteSpaceLeft; _buf.WriteBytesSimple(buffer, offset, _buf.WriteSpaceLeft); Flush(); offset += written; count -= written; // If the remainder fits in a single buffer, no problem. if (count <= _buf.WriteSpaceLeft) { EnsureDataMessage(); _buf.WriteBytesSimple(buffer, offset, count); return; } // Otherwise, write the CopyData header via our buffer and the remaining data directly to the socket _buf.WriteByte((byte)BackendMessageCode.CopyData); _buf.WriteInt32(count); _buf.Flush(); _buf.Underlying.Write(buffer, offset, count); }
public override void Write(byte[] buffer, int offset, int count) { CheckDisposed(); if (!CanWrite) { throw new InvalidOperationException("Stream not open for writing"); } if (count == 0) { return; } EnsureDataMessage(); if (count <= _buf.WriteSpaceLeft) { _buf.WriteBytes(buffer, offset, count); return; } try { // Value is too big. Flush whatever is in the buffer, then write a new CopyData // directly with the buffer. Flush(); _buf.WriteByte((byte)BackendMessageCode.CopyData); _buf.WriteInt32(count + 4); _buf.Flush(); _buf.Underlying.Write(buffer, offset, count); EnsureDataMessage(); } catch { _connector.Break(); Cleanup(); throw; } }