Skip to content
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

Исправление #1471 #1475

Merged
merged 2 commits into from
Dec 13, 2024
Merged

Conversation

akpaevj
Copy link
Contributor

@akpaevj akpaevj commented Dec 6, 2024

Если при вызове метода был установлен лимит и размер входящих данных был больше лимита, то на вход Read соединения подается буфер нулевого размера

Summary by CodeRabbit

  • Bug Fixes
    • Improved the precision of data reading operations by implementing a limit check in the reading loop of the TCP client.

…и использовании и достижении заданного лимита
Copy link

coderabbitai bot commented Dec 6, 2024

Walkthrough

The changes involve modifications to the ReadAllData method in the TCPClient class. A new conditional block has been added to check if the limit variable is less than or equal to zero after it has been decremented by the number of bytes read. This adjustment alters the control flow to ensure that reading operations cease when the specified limit is reached, improving the precision of data handling within the method.

Changes

File Path Change Summary
src/OneScript.StandardLibrary/Net/TCPClient.cs Modified ReadAllData method to include a conditional check for the limit variable.

Poem

In the meadow where bytes do play,
A rabbit reads data, come what may.
With limits set, it hops with glee,
Stopping just right, as it should be!
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 049247d and b9b20d1.

📒 Files selected for processing (1)
  • src/OneScript.StandardLibrary/Net/TCPClient.cs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/OneScript.StandardLibrary/Net/TCPClient.cs

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Experiment)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (1)
src/OneScript.StandardLibrary/Net/TCPClient.cs (1)

85-85: Fix indentation: Replace tab with spaces

The indentation on this line uses a tab character while the rest of the file uses spaces.

-					limit -= numberOfBytesRead;
+                    limit -= numberOfBytesRead;
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 0aea6cd and 049247d.

📒 Files selected for processing (1)
  • src/OneScript.StandardLibrary/Net/TCPClient.cs (1 hunks)
🔇 Additional comments (1)
src/OneScript.StandardLibrary/Net/TCPClient.cs (1)

84-88: LGTM! The fix correctly implements the byte limit.

The changes properly ensure that reading stops after the specified number of bytes have been read, fixing the previous behavior where the limit only affected the portion size but didn't stop the reading process.

Let's verify the fix handles all edge cases correctly:

✅ Verification successful

After analyzing the search results, I can now generate the final response:

The fix is correctly scoped and other read implementations are not affected

The investigation of similar read patterns in the codebase shows that:

  • The ReadAllData implementation in TCPClient is unique in its purpose of reading network data with a byte limit
  • Other read implementations (DataReader, TextReadImpl, CustomLineFeedStreamReader) handle text-based reading with different semantics and don't share the same byte-limit logic
  • The fix is properly contained to the specific use case in TCPClient
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any similar patterns in the codebase that might need the same fix

# Look for other methods that might have similar read-with-limit patterns
ast-grep --pattern 'Read($_, $_, $_)'

# Look for test files that verify this behavior
fd -e cs -e cpp -e c --type f -X rg -l "ReadAllData|read.*limit|limit.*read"

Length of output: 428


Script:

#!/bin/bash
# Let's examine the content of these files to see if they have similar read-with-limit patterns
# that might need the same fix

# Check DataReader.cs for similar patterns
rg -A 5 -B 5 "Read.*limit|limit.*read" ./src/OneScript.StandardLibrary/Binary/DataReader.cs

# Check TextReadImpl.cs for similar patterns
rg -A 5 -B 5 "Read.*limit|limit.*read" ./src/OneScript.StandardLibrary/Text/TextReadImpl.cs

# Check CustomLineFeedStreamReader.cs for similar patterns
rg -A 5 -B 5 "Read.*limit|limit.*read" ./src/OneScript.StandardLibrary/CustomLineFeedStreamReader.cs

# Look for tests specifically related to TCPClient's ReadAllData
rg -A 5 -B 5 "ReadAllData" ./src/OneScript.StandardLibrary/Net/TCPClient.cs

Length of output: 4461

@@ -81,7 +81,11 @@ private MemoryStream ReadAllData(NetworkStream source, int limit)
int numberOfBytesRead = source.Read(readBuffer, 0, portion);
ms.Write(readBuffer, 0, numberOfBytesRead);
if (useLimit)
limit -= numberOfBytesRead;
{
limit -= numberOfBytesRead;
Copy link
Owner

Choose a reason for hiding this comment

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

Что-то с отступами, лучше везде использовать пробелы, чтобы на разных машинах (где разный размер табуляции) показывалось одинаково

Copy link
Contributor Author

@akpaevj akpaevj Dec 10, 2024

Choose a reason for hiding this comment

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

Что-то с отступами, лучше везде использовать пробелы, чтобы на разных машинах (где разный размер табуляции) показывалось одинаково

Уже не первый раз замечаю подобное на коде от меня. Видимо что-то в vs поломалась, гляну

@EvilBeaver EvilBeaver merged commit cb998f2 into EvilBeaver:develop Dec 13, 2024
2 checks passed
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