diff --git a/ringbuffer/RingBuffer.go b/ringbuffer/RingBuffer.go index 2372131c..bb7d8ec3 100644 --- a/ringbuffer/RingBuffer.go +++ b/ringbuffer/RingBuffer.go @@ -81,7 +81,7 @@ a call to Get without an accompanying call to DoneWriting. func (rb *ringBuffer) Get() ([]byte, error) { rb.mutex.Lock() defer rb.mutex.Unlock() - if rb.noOfElements == rb.size { + if !rb.IsWritable() { return nil, errors.New("Buffer full!") } if rb.currentlyWriting { @@ -129,7 +129,7 @@ second call to Read before a call to DoneReading. func (rb *ringBuffer) Read() ([]byte, error) { rb.mutex.Lock() defer rb.mutex.Unlock() - if !rb.CanRead() { + if !rb.IsReadable() { return nil, errors.New("Buffer is empty, nothging to read!") } if rb.currentlyReading { @@ -160,12 +160,23 @@ func (rb *ringBuffer) DoneReading() error { } /* -CanRead returns true if it is possible to read from the buffer, i.e. if +IsReadable returns true if it is possible to read from the buffer, i.e. if it is not empty. */ -func (rb *ringBuffer) CanRead() bool { +func (rb *ringBuffer) IsReadable() bool { if rb.first == -1 || rb.noOfElements == 0 { return false } return true } + +/* +IsWritable returns true if it is possible to write to the buffer, i.e. if +it is not full. +*/ +func (rb *ringBuffer) IsWritable() bool { + if rb.noOfElements == rb.size { + return false + } + return true +}