-
Notifications
You must be signed in to change notification settings - Fork 877
Add port descriptor destroy API #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
Merged
Merged
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
Some comments aren't visible on the classic Files Changed page.
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
97 changes: 97 additions & 0 deletions
97
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,97 @@ | ||
| .. 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> | ||
|
|
||
| .. type:: TSPortDescriptor | ||
| .. function:: TSPortDescriptor TSPortDescriptorParse(const char *descriptor) | ||
| .. function:: TSReturnCode TSPortDescriptorAccept(TSPortDescriptor descriptor, TSCont contp) | ||
| .. function:: void TSPortDescriptorDestroy(TSPortDescriptor descriptor) | ||
|
|
||
| Description | ||
| =========== | ||
|
|
||
| :func:`TSPortDescriptorParse` parses the same descriptor syntax used by | ||
| :ts:cv:`proxy.config.http.server_ports` and returns an allocated, opaque | ||
| :type:`TSPortDescriptor` handle. Each successful call must be paired with | ||
| exactly one call to :func:`TSPortDescriptorDestroy`. | ||
|
|
||
| :func:`TSPortDescriptorAccept` copies the information it needs from | ||
| :arg:`descriptor` and does not retain a pointer to it. The descriptor can | ||
| therefore be destroyed immediately after :func:`TSPortDescriptorAccept` | ||
| returns, regardless of whether the listener remains active. | ||
|
|
||
| A descriptor containing only an ``fd=`` option is not supported because this | ||
| API requires an explicit listen endpoint. The ``quic`` option is also not | ||
| supported by this API and must not be used; it does not create a QUIC listener. | ||
|
|
||
| For example, this function destroys the descriptor after opening the listener: | ||
|
|
||
| .. code-block:: cpp | ||
|
|
||
| TSReturnCode | ||
| listen_on_descriptor(TSCont contp, const char *spec) | ||
| { | ||
| TSPortDescriptor descriptor = TSPortDescriptorParse(spec); | ||
| if (descriptor == nullptr) { | ||
| return TS_ERROR; | ||
| } | ||
|
|
||
| TSReturnCode result = TSPortDescriptorAccept(descriptor, contp); | ||
| TSPortDescriptorDestroy(descriptor); | ||
| return result; | ||
| } | ||
|
|
||
| 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 a new descriptor handle when | ||
| :arg:`descriptor` was parsed successfully. It returns ``nullptr`` for a null | ||
| argument, invalid descriptor, or descriptor that cannot be used by | ||
| :func:`TSPortDescriptorAccept`. | ||
|
|
||
| :func:`TSPortDescriptorAccept` returns :enumerator:`TS_SUCCESS` when the | ||
| listener was opened. It returns :enumerator:`TS_ERROR` for a null argument, a | ||
| descriptor with an unusable listen endpoint, or an error opening the listener. | ||
|
|
||
| :func:`TSPortDescriptorDestroy` releases :arg:`descriptor`. Passing | ||
| ``nullptr`` has no effect. Destroying a descriptor does not stop a listener | ||
| previously opened from it. | ||
|
|
||
| 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
62 changes: 62 additions & 0 deletions
62
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,62 @@ | ||
| ''' | ||
| 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') | ||
| ts.Disk.diags_log.Content += Testers.ContainsExpression( | ||
| r'port_descriptor.*accepted connection', 'Verify the plugin handled the accepted connection.') | ||
| ts.Disk.diags_log.Content += Testers.ExcludesExpression( | ||
| r'port_descriptor.*unexpected accept event', 'Verify the plugin received the expected accept event.') | ||
| 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.