-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
read()
write()
functions return types.
#333
Comments
This is good feedback, but I should point out that The argument order can certainly be changed. This would be a good time to do that. Can you suggest a specific alternative? |
I see the point. But the problem is that the current The part I am stuck is in There can be a solution such as not encrypting the header byte, and only encrypting the payload. However, this will make the implementation much more complicated. Another point to mention is that the logic itself should be also fixed in This is also why I propose to read the entire buffer at once, and then process the buffer, not the socket itself. Suggestion
This will return the actually read bytes from the socket. For example,
The It isn't that hard to change the logic to return the actually read bytes. The only part changed is the last 7 lines, that returns the actual bytes read. Of course there will be some additional work.
ConclusionAs the comment has become too long, the main point of this comment is that the current |
I see your point about encryption, but I don't think we have the right solution yet. I think there are a couple of problems with your approach. First, as written above, the only time Second, always reading the full buffer will likely introduce deadlock in programs with feedback loops. Consider that a federate may not be able to produce an output until it has received an input. In the above code, it will not get a chance to process the input until it has filled the buffer. But it can't fill the buffer because subsequent messages won't arrive until an output is sent. I think that right approach if you don't know how many bytes to read is to read as many as you can (no while loop and no repeating with Also, even without feedback, this strategy could introduce large delays. Consider a simple program where fed1 sends messages to fed2 (no feedback). The first message is a short one sent at startup. The second message is sent a week later. The destination, fed2, will likely not process the first message until a week later because it will wait to fill its input buffer. If I'm right about this, then the |
Thanks for your feedback. I kind of decided to make a different approach with the network driver. Thank you! |
The return types of the
read()
andwrite()
functions seem quite odd.read()
write()
Prob1. Return values.
So, it currently returns 0 for success, -1 for failure.
This seems not to be a general practice for read() and write() functions.
According to the man page of read(),
To summarize,
Prob2. Parameter orders
The order of the parameters are quite different. It can be quite confusing.
Seems to need some refactoring.
Why it should be changed?
On PR #330, I am working on a network driver to enable other network protocols to work. Especially targeting to make TCP based encryption protocols such as TLS/SSL work.
Below is the read function of OpenSSL's TLS library. Details are here.
Return values
It follows the basic
read()
function style.For the scalability of the code the socket read and writes seem to need some refactoring.
The text was updated successfully, but these errors were encountered: