Skip to content

Conversation

@ponast
Copy link

@ponast ponast commented Mar 28, 2021

Nice ring buffer implementation! I like it and plan to use it with socket-IO in a stack. I had an issue with writing and reading sockets as they require continuous memory segments. So I implemented a sockets interface extension to the ring buffer that allows for efficient access to sockets from Ringbuffer without intermediate copying steps. The extension requires some additional methods within the class to get the length of continuous data in the data_buff member. The actual socket read and write functions are implemented outside class Ringbuffer. All added methods to Ringbuffer can be made protected (except print which is just a quick fix for testing) if the two external functions are made friends as they likely shouldn't be directly accessed from elsewhere. I haven't done that.

I'm not too good at atomics programming and there might be better methods to implement the socket interface which I'm not aware of. Anyway, this is a first shot and if you don't think this sockets API is too specialized and of good enough quality then I think it would be nice to have it integrated with Ringbuffer.

The test file shows how the interface is used. I have added dummy socket-IO functions with Posix interface for testing in a rudimentary test sequence.

/*!
* \brief For debug purposes. Outputs data_buff array in full
*/
void print()
Copy link

@drewr95 drewr95 Aug 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. This will produce a compiler error for files that include this header that do not include <iostream> before including this header
  2. Since this library is OS independent, embedded applications could use this, and <string> is notoriously large and not typically used, which is included by <iostream>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants