Skip to content
Snippets Groups Projects
Commit 42188d21 authored by Masood Malekghassemi's avatar Masood Malekghassemi
Browse files

Merge pull request #3128 from nathanielmanistaatgoogle/add_port

Accept addresses rather than ports in add_port
parents 0ed0843a 6e6ddbec
Branches
Tags
No related merge requests found
...@@ -316,9 +316,8 @@ class _Kernel(object): ...@@ -316,9 +316,8 @@ class _Kernel(object):
call.status(status, call) call.status(status, call)
self._rpc_states.pop(call, None) self._rpc_states.pop(call, None)
def add_port(self, port, server_credentials): def add_port(self, address, server_credentials):
with self._lock: with self._lock:
address = '[::]:%d' % port
if self._server is None: if self._server is None:
self._completion_queue = _intermediary_low.CompletionQueue() self._completion_queue = _intermediary_low.CompletionQueue()
self._server = _intermediary_low.Server(self._completion_queue) self._server = _intermediary_low.Server(self._completion_queue)
...@@ -362,17 +361,20 @@ class ServiceLink(links.Link): ...@@ -362,17 +361,20 @@ class ServiceLink(links.Link):
""" """
@abc.abstractmethod @abc.abstractmethod
def add_port(self, port, server_credentials): def add_port(self, address, server_credentials):
"""Adds a port on which to service RPCs after this link has been started. """Adds a port on which to service RPCs after this link has been started.
Args: Args:
port: The port on which to service RPCs, or zero to request that a port address: The address on which to service RPCs with a port number of zero
be automatically selected and used. requesting that a port number be automatically selected and used.
server_credentials: An _intermediary_low.ServerCredentials object, or server_credentials: An _intermediary_low.ServerCredentials object, or
None for insecure service. None for insecure service.
Returns: Returns:
A port on which RPCs will be serviced after this link has been started. A integer port on which RPCs will be serviced after this link has been
started. This is typically the same number as the port number contained
in the passed address, but will likely be different if the port number
contained in the passed address was zero.
""" """
raise NotImplementedError() raise NotImplementedError()
...@@ -417,8 +419,8 @@ class _ServiceLink(ServiceLink): ...@@ -417,8 +419,8 @@ class _ServiceLink(ServiceLink):
def join_link(self, link): def join_link(self, link):
self._relay.set_behavior(link.accept_ticket) self._relay.set_behavior(link.accept_ticket)
def add_port(self, port, server_credentials): def add_port(self, address, server_credentials):
return self._kernel.add_port(port, server_credentials) return self._kernel.add_port(address, server_credentials)
def start(self): def start(self):
self._relay.start() self._relay.start()
......
...@@ -95,7 +95,7 @@ class _Implementation(test_interfaces.Implementation): ...@@ -95,7 +95,7 @@ class _Implementation(test_interfaces.Implementation):
service_grpc_link = service.service_link( service_grpc_link = service.service_link(
serialization_behaviors.request_deserializers, serialization_behaviors.request_deserializers,
serialization_behaviors.response_serializers) serialization_behaviors.response_serializers)
port = service_grpc_link.add_port(0, None) port = service_grpc_link.add_port('[::]:0', None)
channel = _intermediary_low.Channel('localhost:%d' % port, None) channel = _intermediary_low.Channel('localhost:%d' % port, None)
invocation_grpc_link = invocation.invocation_link( invocation_grpc_link = invocation.invocation_link(
channel, b'localhost', channel, b'localhost',
......
...@@ -85,7 +85,7 @@ class _Implementation(test_interfaces.Implementation): ...@@ -85,7 +85,7 @@ class _Implementation(test_interfaces.Implementation):
service_grpc_link = service.service_link( service_grpc_link = service.service_link(
serialization_behaviors.request_deserializers, serialization_behaviors.request_deserializers,
serialization_behaviors.response_serializers) serialization_behaviors.response_serializers)
port = service_grpc_link.add_port(0, None) port = service_grpc_link.add_port('[::]:0', None)
channel = _intermediary_low.Channel('localhost:%d' % port, None) channel = _intermediary_low.Channel('localhost:%d' % port, None)
invocation_grpc_link = invocation.invocation_link( invocation_grpc_link = invocation.invocation_link(
channel, b'localhost', channel, b'localhost',
......
...@@ -50,7 +50,7 @@ class TransmissionTest(test_cases.TransmissionTest, unittest.TestCase): ...@@ -50,7 +50,7 @@ class TransmissionTest(test_cases.TransmissionTest, unittest.TestCase):
service_link = service.service_link( service_link = service.service_link(
{self.group_and_method(): self.deserialize_request}, {self.group_and_method(): self.deserialize_request},
{self.group_and_method(): self.serialize_response}) {self.group_and_method(): self.serialize_response})
port = service_link.add_port(0, None) port = service_link.add_port('[::]:0', None)
service_link.start() service_link.start()
channel = _intermediary_low.Channel('localhost:%d' % port, None) channel = _intermediary_low.Channel('localhost:%d' % port, None)
invocation_link = invocation.invocation_link( invocation_link = invocation.invocation_link(
...@@ -116,7 +116,7 @@ class RoundTripTest(unittest.TestCase): ...@@ -116,7 +116,7 @@ class RoundTripTest(unittest.TestCase):
identity_transformation, identity_transformation) identity_transformation, identity_transformation)
service_mate = test_utilities.RecordingLink() service_mate = test_utilities.RecordingLink()
service_link.join_link(service_mate) service_link.join_link(service_mate)
port = service_link.add_port(0, None) port = service_link.add_port('[::]:0', None)
service_link.start() service_link.start()
channel = _intermediary_low.Channel('localhost:%d' % port, None) channel = _intermediary_low.Channel('localhost:%d' % port, None)
invocation_link = invocation.invocation_link( invocation_link = invocation.invocation_link(
...@@ -160,7 +160,7 @@ class RoundTripTest(unittest.TestCase): ...@@ -160,7 +160,7 @@ class RoundTripTest(unittest.TestCase):
{(test_group, test_method): scenario.serialize_response}) {(test_group, test_method): scenario.serialize_response})
service_mate = test_utilities.RecordingLink() service_mate = test_utilities.RecordingLink()
service_link.join_link(service_mate) service_link.join_link(service_mate)
port = service_link.add_port(0, None) port = service_link.add_port('[::]:0', None)
service_link.start() service_link.start()
channel = _intermediary_low.Channel('localhost:%d' % port, None) channel = _intermediary_low.Channel('localhost:%d' % port, None)
invocation_link = invocation.invocation_link( invocation_link = invocation.invocation_link(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment