-
Notifications
You must be signed in to change notification settings - Fork 871
Make port descriptors caller-owned #13518
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
Draft
bneradt
wants to merge
1
commit into
apache:master
Choose a base branch
from
bneradt:fix-port-descriptor-api
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
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
96 changes: 96 additions & 0 deletions
96
doc/developer-guide/api/functions/TSPortDescriptorParse.en.rst
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 |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| .. Licensed to the Apache Software Foundation (ASF) under one or more | ||
| contributor license agreements. See the NOTICE file distributed | ||
| with this work for additional information regarding copyright | ||
| ownership. The ASF licenses this file to you under the Apache | ||
| License, Version 2.0 (the "License"); you may not use this file | ||
| except in compliance with the License. You may obtain a copy of | ||
| the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or | ||
| implied. See the License for the specific language governing | ||
| permissions and limitations under the License. | ||
|
|
||
| .. include:: ../../../common.defs | ||
|
|
||
| .. default-domain:: cpp | ||
|
|
||
| TSPortDescriptorParse | ||
| ********************* | ||
|
|
||
| Parse and listen on a proxy port descriptor. | ||
|
|
||
| Synopsis | ||
| ======== | ||
|
|
||
| .. code-block:: cpp | ||
|
|
||
| #include <ts/ts.h> | ||
|
|
||
| .. class:: TSPortDescriptor | ||
| .. function:: TSReturnCode TSPortDescriptorParse(const char *descriptor, TSPortDescriptor *result) | ||
| .. function:: TSReturnCode TSPortDescriptorAccept(const TSPortDescriptor *descriptor, TSCont contp) | ||
|
|
||
| Description | ||
| =========== | ||
|
|
||
| :func:`TSPortDescriptorParse` parses the same descriptor syntax used by | ||
| :ts:cv:`proxy.config.http.server_ports`. The parsed representation is written | ||
| to caller-owned :type:`TSPortDescriptor` storage. A descriptor must be | ||
| successfully parsed before it is passed to :func:`TSPortDescriptorAccept`. | ||
|
|
||
| The API does not allocate or free the :type:`TSPortDescriptor` object. No | ||
| separate destruction function is required. Its memory is released according | ||
| to its normal C++ storage duration: an automatic object is released when it | ||
| leaves scope, and a dynamically allocated object is released when the plugin | ||
| deletes it. Calling :func:`TSPortDescriptorParse` again reuses the same | ||
| descriptor storage. | ||
|
|
||
| :func:`TSPortDescriptorAccept` copies the information it needs from | ||
| :arg:`descriptor` and does not retain a pointer to it. The descriptor can | ||
| therefore leave scope immediately after :func:`TSPortDescriptorAccept` | ||
| returns, regardless of whether the listener remains active. | ||
|
|
||
| For example, the descriptor in this function is released when the function | ||
| returns while the listener continues to accept connections: | ||
|
|
||
| .. code-block:: cpp | ||
|
|
||
| TSReturnCode | ||
| listen_on_descriptor(TSCont contp, const char *spec) | ||
| { | ||
| TSPortDescriptor descriptor; | ||
|
|
||
| if (TSPortDescriptorParse(spec, &descriptor) != TS_SUCCESS) { | ||
| return TS_ERROR; | ||
| } | ||
|
|
||
| return TSPortDescriptorAccept(&descriptor, contp); | ||
| } | ||
|
|
||
| When a connection is accepted, :arg:`contp` receives | ||
| :enumerator:`TS_EVENT_NET_ACCEPT`. The event data is a :type:`TSVConn` for the | ||
| accepted connection. | ||
|
|
||
| Return Values | ||
| ============= | ||
|
|
||
| :func:`TSPortDescriptorParse` returns :enumerator:`TS_SUCCESS` when | ||
| :arg:`descriptor` was parsed successfully. It returns :enumerator:`TS_ERROR` | ||
| for a null argument or invalid descriptor. After a failed parse, | ||
| :arg:`result` remains invalid until it is parsed successfully. | ||
|
|
||
| :func:`TSPortDescriptorAccept` returns :enumerator:`TS_SUCCESS` when the | ||
| listener was opened. It returns :enumerator:`TS_ERROR` for a null argument, a | ||
| descriptor that was not successfully parsed, an unusable listen endpoint, or | ||
| an error opening the listener. | ||
|
|
||
| See Also | ||
| ======== | ||
|
|
||
| :manpage:`TSAPI(3ts)`, | ||
| :manpage:`TSNetAccept(3ts)`, | ||
| :manpage:`records.yaml(5)` |
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
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
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
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
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
58 changes: 58 additions & 0 deletions
58
tests/gold_tests/pluginTest/port_descriptor/port_descriptor.test.py
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 |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| ''' | ||
| Verify that a plugin can listen on a port described by TSPortDescriptor. | ||
| ''' | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| import os | ||
|
|
||
| Test.Summary = 'Test the TSPortDescriptor API.' | ||
| Test.SkipUnless(Condition.HasProgram('nc', 'nc is required to connect to the plugin port')) | ||
|
|
||
|
|
||
| class TestPortDescriptor: | ||
| '''Verify that a plugin can accept connections on a parsed port.''' | ||
|
|
||
| def __init__(self) -> None: | ||
| '''Configure the Traffic Server and client processes.''' | ||
| Test.GetTcpPort('descriptor_port') | ||
| tr = Test.AddTestRun('Connect to the plugin port') | ||
| self._ts = self._configure_traffic_server(tr) | ||
| self._configure_client(tr) | ||
|
|
||
| def _configure_traffic_server(self, tr: 'TestRun') -> 'Process': | ||
| '''Configure Traffic Server with the port descriptor test plugin. | ||
|
|
||
| :return: The Traffic Server process. | ||
| ''' | ||
| ts = tr.MakeATSProcess('ts', enable_cache=False) | ||
| plugin_path = os.path.join(Test.Variables.AtsTestPluginsDir, 'port_descriptor.so') | ||
| Test.PrepareTestPlugin(plugin_path, ts, f'{ts.Variables.descriptor_port}:ipv4') | ||
| return ts | ||
|
|
||
| def _configure_client(self, tr: 'TestRun') -> 'Process': | ||
| '''Configure the client that connects to the plugin port. | ||
|
|
||
| :return: The client process. | ||
| ''' | ||
| client = tr.Processes.Default | ||
| client.Command = f'nc -z 127.0.0.1 {self._ts.Variables.descriptor_port}' | ||
| client.ReturnCode = 0 | ||
| client.StartBefore(self._ts) | ||
| return client | ||
|
|
||
|
|
||
| TestPortDescriptor() |
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
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.