Skip to content

bpo-34932: Add socket.TCP_KEEPALIVE for macOS #25079

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 6 commits into from
Jul 14, 2021

Conversation

ShaneHarvey
Copy link
Contributor

@ShaneHarvey ShaneHarvey commented Mar 29, 2021

This change adds socket.TCP_KEEPALIVE for macOS.

https://bugs.python.org/issue34932

Copy link
Member

@corona10 corona10 left a comment

Choose a reason for hiding this comment

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

Please update Doc/library/socket.rst first and I don't prefer to add TCP_KEEPALIVE as alias.

PyModule_AddIntMacro(m, TCP_KEEPIDLE);
#elif defined(__APPLE__) && defined(TCP_KEEPALIVE)
/* TCP_KEEPALIVE is equivalent to TCP_KEEPIDLE on OSX. */
PyModule_AddIntConstant(m, "TCP_KEEPIDLE", TCP_KEEPALIVE);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
PyModule_AddIntConstant(m, "TCP_KEEPIDLE", TCP_KEEPALIVE);
PyModule_AddIntMacro(m, TCP_KEEPALIVE);;

PyModule_AddIntMacro(m, TCP_KEEPIDLE);
#elif defined(__APPLE__) && defined(TCP_KEEPALIVE)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
#elif defined(__APPLE__) && defined(TCP_KEEPALIVE)
#if defined(TCP_KEEPALIVE)

@bedevere-bot
Copy link

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@ShaneHarvey
Copy link
Contributor Author

I don't prefer to add TCP_KEEPALIVE as alias.

Noted. I've removed the alias and added TCP_KEEPALIVE directly.

@ShaneHarvey ShaneHarvey requested a review from corona10 March 30, 2021 17:06
@ShaneHarvey ShaneHarvey changed the title bpo-34932: Add socket.TCP_KEEPIDLE support to macOS bpo-34932: Add socket.TCP_KEEPALIVE for macOS Mar 30, 2021
@ShaneHarvey
Copy link
Contributor Author

ShaneHarvey commented Mar 30, 2021

@corona10 Is there a reason you suggested to remove the defined(__APPLE__) condition? Without it the TCP_KEEPALIVE constant is added on windows which breaks this test:

FAIL: test_new_tcp_flags (test.test_socket.TestMSWindowsTCPFlags)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "D:\a\cpython\cpython\lib\test\test_socket.py", line 6439, in test_new_tcp_flags
    self.assertEqual([], unknown,
AssertionError: Lists differ: [] != ['TCP_KEEPALIVE']

I have no idea what TCP_KEEPALIVE does on Windows. Should I:

  1. keep socketmodule.c as is and update the test to expect TCP_KEEPALIVE on Windows, or:
  2. change socketmodule.c to never add socket.TCP_KEEPALIVE on Windows

@ShaneHarvey
Copy link
Contributor Author

After reading https://bugs.python.org/issue32394 to figure out why TestMSWindowsTCPFlags exists, I discovered that TCP_KEEPALIVE is undocumented on Windows:

Since we don't know what version of windows introduced this flag we cannot add it on Windows.

I've updated the code to only add TCP_KEEPALIVE on macOS (when it exists).

@ShaneHarvey
Copy link
Contributor Author

I have made the requested changes; please review again.

@bedevere-bot
Copy link

Thanks for making the requested changes!

@corona10: please review the changes made to this pull request.

@ShaneHarvey
Copy link
Contributor Author

ping @corona10

@ShaneHarvey
Copy link
Contributor Author

Rebased on to main.

@ShaneHarvey
Copy link
Contributor Author

@corona10 @pablogsal I'm not sure what's holding up the review on this PR but I'm hoping it can be merged and backported to 3.10 similar to #25992.

@pablogsal pablogsal added the needs backport to 3.10 only security fixes label Jul 14, 2021
@pablogsal pablogsal merged commit d59d737 into python:main Jul 14, 2021
@miss-islington
Copy link
Contributor

Thanks @ShaneHarvey for the PR, and @pablogsal for merging it 🌮🎉.. I'm working now to backport this PR to: 3.10.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jul 14, 2021
(cherry picked from commit d59d737)

Co-authored-by: Shane Harvey <shnhrv@gmail.com>
@bedevere-bot
Copy link

GH-27153 is a backport of this pull request to the 3.10 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.10 only security fixes label Jul 14, 2021
@ShaneHarvey
Copy link
Contributor Author

Thanks all!

@pablogsal
Copy link
Member

Thanks for your contribution!

miss-islington added a commit that referenced this pull request Jul 14, 2021
(cherry picked from commit d59d737)

Co-authored-by: Shane Harvey <shnhrv@gmail.com>
@ShaneHarvey ShaneHarvey deleted the issue34932 branch July 15, 2021 03:16
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.

6 participants