-
Notifications
You must be signed in to change notification settings - Fork 3
Return EOF once after the buffer is consumed #112
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -182,8 +182,9 @@ static ssize_t nat20device_write(struct file* filp, | |
| * nat20device_read - Read file operation | ||
| * | ||
| * Returns the current response buffer to userspace. Once the entire | ||
| * response has been read, the buffer is freed and subsequent reads | ||
| * return -EAGAIN until a new request is dispatched via write. | ||
| * response has been read, the first subsequent read returns 0 (EOF) | ||
| * and frees the response buffer. Subsequent reads return -EAGAIN until | ||
| * a new request is dispatched via write. | ||
| */ | ||
| static ssize_t nat20device_read(struct file* filp, char __user* buf, size_t count, loff_t* f_pos) { | ||
| struct nat20device_file_private* file_priv = filp->private_data; | ||
|
|
@@ -197,12 +198,17 @@ static ssize_t nat20device_read(struct file* filp, char __user* buf, size_t coun | |
|
|
||
| /* Check if we have a response buffer */ | ||
| if (!file_priv->response.data) { | ||
| /* No response available, return -EAGAIN to indicate try again later. */ | ||
| ret = -EAGAIN; | ||
| goto out; | ||
| } | ||
|
|
||
| /* Calculate bytes remaining from current offset */ | ||
| if (file_priv->response.size <= *f_pos) { | ||
| /* Entire response has been consumed, free buffer and return EOF. */ | ||
| kfree(file_priv->response.data); | ||
| file_priv->response.data = NULL; | ||
| file_priv->response.size = 0; | ||
| ret = 0; | ||
| goto out; | ||
| } | ||
|
|
@@ -220,16 +226,7 @@ static ssize_t nat20device_read(struct file* filp, char __user* buf, size_t coun | |
| /* Update offset */ | ||
| *f_pos += bytes_to_read; | ||
|
|
||
| /* Response fully consumed — free it so subsequent reads | ||
| * return -EAGAIN until the next write/dispatch cycle. */ | ||
| if (*f_pos >= file_priv->response.size) { | ||
| kfree(file_priv->response.data); | ||
| file_priv->response.data = NULL; | ||
| file_priv->response.size = 0; | ||
| } | ||
|
|
||
| ret = bytes_to_read; | ||
|
Comment on lines
226
to
229
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So would a user space process, that doesn't or partially reads the response. Closing the file descriptor will also free the buffer. |
||
|
|
||
| out: | ||
| mutex_unlock(&file_priv->lock); | ||
| return ret; | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.