public override void WriteToStream(Stream outputStream) { PGUtil.WriteInt32(outputStream, CancelRequestMessageSize); PGUtil.WriteInt32(outputStream, CancelRequestCode); PGUtil.WriteInt32(outputStream, BackendKeydata.ProcessID); PGUtil.WriteInt32(outputStream, BackendKeydata.SecretKey); }
/// <summary> /// Sends CopyDone message to server. Handles responses, ie. may throw an exception. /// </summary> public override void SendCopyDone(NpgsqlConnector context) { Stream toServer = context.Stream; toServer.WriteByte((byte)FrontEndMessageCode.CopyDone); PGUtil.WriteInt32(toServer, 4); // message without data ProcessAndDiscardBackendResponses(context); }
/// <summary> /// Sends given packet to server as a CopyData message. /// Does not check for notifications! Use another thread for that. /// </summary> public override void SendCopyData(NpgsqlConnector context, byte[] buf, int off, int len) { Stream toServer = context.Stream; toServer.WriteByte((byte)FrontEndMessageCode.CopyData); PGUtil.WriteInt32(toServer, len + 4); toServer.Write(buf, off, len); }
/// <summary> /// Sends CopyFail message to server. Handles responses, ie. should always throw an exception: /// in CopyIn state the server responds to CopyFail with an error response; /// outside of a CopyIn state the server responds to CopyFail with an error response; /// without network connection or whatever, there's going to eventually be a failure, timeout or user intervention. /// </summary> public override void SendCopyFail(NpgsqlConnector context, String message) { Stream toServer = context.Stream; toServer.WriteByte((byte)FrontEndMessageCode.CopyFail); byte[] buf = BackendEncoding.UTF8Encoding.GetBytes((message ?? string.Empty) + '\x00'); PGUtil.WriteInt32(toServer, 4 + buf.Length); toServer.Write(buf, 0, buf.Length); ProcessAndDiscardBackendResponses(context); }
public override void WriteToStream(Stream outputStream) { if (_messageLength == 0) { _messageLength = 4 + // Message length (32 bits) _bPortalName.Length + 1 + // Portal name + null terminator _bPreparedStatementName.Length + 1 + // Statement name + null terminator 2 + // Parameter format code array length (16 bits) _parameterFormatCodes.Length * 2 + // Parameter format code array (16 bits per code) 2; // Parameter va;ue array length (16 bits) if (_parameterValues != null) { for (int i = 0; i < _parameterValues.Length; i++) { _messageLength += 4; // Parameter value length (32 bits) if (_parameterValues[i] != null) { _messageLength += _parameterValues[i].Length; // Parameter value } } } _messageLength += 2 + // Result format code array length (16 bits) _resultFormatCodes.Length * 2; // Result format code array (16 bits per code) } outputStream .WriteBytes((byte)FrontEndMessageCode.Bind) .WriteInt32(_messageLength) .WriteBytesNullTerminated(_bPortalName) .WriteBytesNullTerminated(_bPreparedStatementName) .WriteInt16((Int16)_parameterFormatCodes.Length); foreach (short code in _parameterFormatCodes) { PGUtil.WriteInt16(outputStream, code); } if (_parameterValues != null) { PGUtil.WriteInt16(outputStream, (Int16)_parameterValues.Length); for (int i = 0; i < _parameterValues.Length; i++) { Byte[] parameterValue = _parameterValues[i]; if (parameterValue == null) { PGUtil.WriteInt32(outputStream, -1); } else { outputStream .WriteInt32(parameterValue.Length) .WriteBytes(parameterValue); } } } else { PGUtil.WriteInt16(outputStream, 0); } PGUtil.WriteInt16(outputStream, (Int16)_resultFormatCodes.Length); foreach (short code in _resultFormatCodes) { PGUtil.WriteInt16(outputStream, code); } }