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

Added timeout to send for tcp_client and tcp_client-windows #3355

Open
wants to merge 3 commits into
base: v1.x
Choose a base branch
from

Conversation

LowLevelLore
Copy link

This is against the issue: "Add timeout parameter to tcp_client::connect() #2682"
I have set socket options of SO_RCVTIMEO and SO_SNDTIMEO in the connect method of tcp_client (both normal and windows) to set the timeout that was passed in the constructor. Now the struct tcp_sink_config has extra timeout_sec parameter. Now when the tcp_client::connect() times out, it also throws an error.

Please guide me this is my first PR.

@gabime
Copy link
Owner

gabime commented Mar 8, 2025

Please remove the logs and undo example changes. Also please remove the cout << “here”

@LowLevelLore
Copy link
Author

I made the changes. And the appveyor builds are successful


// try to connect or throw on failure
void connect(const std::string &host, int port) {
// Added timeout_ms parameter (in milliseconds)
Copy link
Owner

Choose a reason for hiding this comment

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

Please fix the comment. is it for connect only? for read and write? in seconds?

Copy link
Author

Choose a reason for hiding this comment

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

Fixed the comments.

// Mapped Diagnostic Context (MDC) is a map that stores key-value pairs (string values) in thread
// local storage. Each thread maintains its own MDC, which loggers use to append diagnostic
// information to log outputs. Note: it is not supported in asynchronous mode due to its reliance on
// thread-local storage.
Copy link
Owner

Choose a reason for hiding this comment

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

undo all the changes in example

Copy link
Author

Choose a reason for hiding this comment

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

Done, should I take the latest example from the repo.

::setsockopt(socket_, SOL_SOCKET, SO_RCVTIMEO, reinterpret_cast<char *>(&timeout),
sizeof(timeout));
::setsockopt(socket_, SOL_SOCKET, SO_SNDTIMEO, reinterpret_cast<char *>(&timeout),
sizeof(timeout));
Copy link
Owner

Choose a reason for hiding this comment

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

i dont think it affects connect timeout. only recv and send

Copy link
Author

Choose a reason for hiding this comment

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

Yes it only send and recv timeout, I can do it for connect but it would be non blocking I guess. Can I proceed with that ?

Copy link
Owner

@gabime gabime Mar 13, 2025

Choose a reason for hiding this comment

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

I am confused. Isn't the connect timeout is the whole point of this pr?

Copy link
Author

@LowLevelLore LowLevelLore left a comment

Choose a reason for hiding this comment

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

I have made the other changes, about the timeout in connect syscall.


// try to connect or throw on failure
void connect(const std::string &host, int port) {
// Added timeout_ms parameter (in milliseconds)
Copy link
Author

Choose a reason for hiding this comment

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

Fixed the comments.

@LowLevelLore LowLevelLore requested a review from gabime March 13, 2025 03:46
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