/// <summary> /// Creates a <see cref="RetryOptions"/> for <see cref="RetryType.Retry"/>. /// </summary> /// <param name="exceptionHandling">Optional, how exceptions should be handled. /// Defaults to <see cref="ExceptionHandling.Ignore"/>.</param> /// <param name="bufferOverflow">Optional, how a buffer overflow should be handled. /// Defaults to <see cref="BufferOverflow.IgnoreNewEntries"/>.</param> /// <param name="bufferSizeBytes">Optional, the size of the buffer to be used in bytes. /// Defaults to <see cref="DefaultBufferSize"/>.</param> /// <param name="retryInterval">Optional, the time between retries. Default to <see cref="DefaultRetryInterval"/>.</param> /// <param name="retryAttempts">Optional, the number of retry attempts. Defaults to <see cref="DefaultRetryAttempts"/>.</param> public static RetryOptions Retry( ExceptionHandling exceptionHandling = ExceptionHandling.Ignore, BufferOverflow bufferOverflow = BufferOverflow.IgnoreNewEntries, int?bufferSizeBytes = null, TimeSpan?retryInterval = null, int?retryAttempts = null) => new RetryOptions(RetryType.Retry, exceptionHandling, bufferOverflow, bufferSizeBytes ?? DefaultBufferSize, retryAttempts ?? DefaultRetryAttempts, retryInterval ?? DefaultRetryInterval);
///<summary> /// Fügt ein Byte hinten an den Buffer an (an die Stelle, auf die der Datenpointer vorher zeigte) /// </summary> /// <param name="pByte">Anzuhängendes Byte</param> /// <returns> /// <list type="bullet"> /// <item>0 bei Erfolg (<see cref="EDOLLHandler">EDOLL-Code</see>)</item> /// <item>-201 wenn Buffer voll (Byte wurde nicht geschrieben) (<see cref="EDOLLHandler">EDOLL-Code</see>)</item> /// </list> /// </returns> /// <example> /// Beispieloperationen mit dem Buffer /// <para><img src="tbl_img/receiveBufferExample.jpg" /></para> /// <code> /// public static void receiveBufferExample() /// { /// receiveBuffer testBuffer = new receiveBuffer(); /// /// testBuffer.AddByte((byte)'a'); /// testBuffer.AddByte((byte)'b'); /// testBuffer.AddByte((byte)'c'); /// /// stdOut.Debug("Dataptr now: " + testBuffer.DataPtr.ToString()); // printet 3 /// stdOut.Debug("Buffer content: " + testBuffer.ToString());// Zeigt Hexwerte im Buffer an /// /// testBuffer.FreeBytes(0,1); // markiert 'a' und 'b' zum Löschen /// /// stdOut.Info("a und b marked for erasing"); /// stdOut.Debug("Dataptr now: " + testBuffer.DataPtr.ToString()); // liefert 3, wurde ja erst markiert /// /// testBuffer.Flush(); /// /// stdOut.Info("buffer flushed..."); /// stdOut.Debug("Dataptr now: " + testBuffer.DataPtr.ToString()); // liefert 1, 'c' wurde ganz nach vorne gerutscht /// stdOut.Debug("Buffer content: " + testBuffer.ToString());// Zeigt Hexwerte im Buffer an /// /// testBuffer.Clear(); // Buffer wieder ausleeren /// /// stdOut.Info("buffer cleared"); /// stdOut.Debug("Dataptr now: " + testBuffer.DataPtr.ToString()); // liefert 0 /// } /// </code> /// </example>> // TODO: EXCEPTION dokumentieren public int AddByte(byte pByte) { int tmpError; accessControl.WaitOne(); tmpError = addByteInternal(pByte); if (tmpError == 0) { accessControl.Release(); if (ByteAdded != null) { ByteAdded(this, EventArgs.Empty); // Call Events (if there are any) } return(0); // EDOLL no Error } else { EDOLLHandler.Error(tmpError); // Buffer overflow... BufferOverflow ex = new BufferOverflow(EDOLLHandler.GetLastError() + "Datapointer: " + this.dptr.ToString()); accessControl.Release(); throw ex; } }
public int AddBytes(byte[] rBytes) { int tmpError; accessControl.WaitOne(); for (int i = 0; i < rBytes.Length; i++) // Der reihe nach hinzufügen { tmpError = addByteInternal(rBytes[i]); if (tmpError != 0) // sollte beispielsweise der Buffer überlaufen, Exception raus { EDOLLHandler.Error(tmpError); // Buffer overflow... BufferOverflow ex = new BufferOverflow(EDOLLHandler.GetLastError() + "Datapointer: " + this.dptr.ToString()); accessControl.Release(); throw ex; } } // wenn ich bis hierher gekommen bin, gabs keinen Fehler... availableSema = accessControl.Release(); if (ByteAdded != null) { ByteAdded(this, EventArgs.Empty); // Fire Events (if there are any) } return(0); }
public void CreateBufferOverflow() { BufferOverflow x = new BufferOverflow(); x.after = 1; for (int i = 0; i <= 16; ++i) { unsafe { x.items[i] = 99; } } }
internal RetryOptions(RetryType retryType, ExceptionHandling exceptionHandling, BufferOverflow bufferOverflow, int?bufferSizeBytes = null, int?retryAttempts = null, TimeSpan?retryInterval = null) { RetryType = GaxPreconditions.CheckEnumValue(retryType, nameof(retryType)); ExceptionHandling = GaxPreconditions.CheckEnumValue(exceptionHandling, nameof(exceptionHandling)); BufferOverflow = GaxPreconditions.CheckEnumValue(bufferOverflow, nameof(bufferOverflow)); BufferSizeBytes = GaxPreconditions.CheckArgumentRange( bufferSizeBytes ?? 0, nameof(bufferSizeBytes), 0, int.MaxValue); RetryAttempts = GaxPreconditions.CheckArgumentRange( retryAttempts ?? 0, nameof(retryAttempts), 0, int.MaxValue); RetryInterval = retryInterval ?? TimeSpan.Zero; GaxPreconditions.CheckArgument(RetryInterval >= TimeSpan.Zero, nameof(retryInterval), $"{nameof(retryInterval)} must be greater than 0"); }