OLD | NEW |
(Empty) | |
| 1 #region Copyright notice and license |
| 2 |
| 3 // Copyright 2015-2016, Google Inc. |
| 4 // All rights reserved. |
| 5 // |
| 6 // Redistribution and use in source and binary forms, with or without |
| 7 // modification, are permitted provided that the following conditions are |
| 8 // met: |
| 9 // |
| 10 // * Redistributions of source code must retain the above copyright |
| 11 // notice, this list of conditions and the following disclaimer. |
| 12 // * Redistributions in binary form must reproduce the above |
| 13 // copyright notice, this list of conditions and the following disclaimer |
| 14 // in the documentation and/or other materials provided with the |
| 15 // distribution. |
| 16 // * Neither the name of Google Inc. nor the names of its |
| 17 // contributors may be used to endorse or promote products derived from |
| 18 // this software without specific prior written permission. |
| 19 // |
| 20 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 21 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 22 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 23 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 24 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 25 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 26 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 27 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 28 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 29 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 30 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 |
| 32 #endregion |
| 33 |
| 34 using System; |
| 35 |
| 36 using Grpc.Core.Utils; |
| 37 |
| 38 namespace Grpc.Core |
| 39 { |
| 40 /// <summary> |
| 41 /// A port exposed by a server. |
| 42 /// </summary> |
| 43 public class ServerPort |
| 44 { |
| 45 /// <summary> |
| 46 /// Pass this value as port to have the server choose an unused listenin
g port for you. |
| 47 /// Ports added to a server will contain the bound port in their <see cr
ef="BoundPort"/> property. |
| 48 /// </summary> |
| 49 public const int PickUnused = 0; |
| 50 |
| 51 readonly string host; |
| 52 readonly int port; |
| 53 readonly ServerCredentials credentials; |
| 54 readonly int boundPort; |
| 55 |
| 56 /// <summary> |
| 57 /// Creates a new port on which server should listen. |
| 58 /// </summary> |
| 59 /// <returns>The port on which server will be listening.</returns> |
| 60 /// <param name="host">the host</param> |
| 61 /// <param name="port">the port. If zero, an unused port is chosen autom
atically.</param> |
| 62 /// <param name="credentials">credentials to use to secure this port.</p
aram> |
| 63 public ServerPort(string host, int port, ServerCredentials credentials) |
| 64 { |
| 65 this.host = GrpcPreconditions.CheckNotNull(host, "host"); |
| 66 this.port = port; |
| 67 this.credentials = GrpcPreconditions.CheckNotNull(credentials, "cred
entials"); |
| 68 } |
| 69 |
| 70 /// <summary> |
| 71 /// Creates a port from an existing <c>ServerPort</c> instance and bound
Port value. |
| 72 /// </summary> |
| 73 internal ServerPort(ServerPort serverPort, int boundPort) |
| 74 { |
| 75 this.host = serverPort.host; |
| 76 this.port = serverPort.port; |
| 77 this.credentials = serverPort.credentials; |
| 78 this.boundPort = boundPort; |
| 79 } |
| 80 |
| 81 /// <value>The host.</value> |
| 82 public string Host |
| 83 { |
| 84 get |
| 85 { |
| 86 return host; |
| 87 } |
| 88 } |
| 89 |
| 90 /// <value>The port.</value> |
| 91 public int Port |
| 92 { |
| 93 get |
| 94 { |
| 95 return port; |
| 96 } |
| 97 } |
| 98 |
| 99 /// <value>The server credentials.</value> |
| 100 public ServerCredentials Credentials |
| 101 { |
| 102 get |
| 103 { |
| 104 return credentials; |
| 105 } |
| 106 } |
| 107 |
| 108 /// <value> |
| 109 /// The port actually bound by the server. This is useful if you let ser
ver |
| 110 /// pick port automatically. <see cref="PickUnused"/> |
| 111 /// </value> |
| 112 public int BoundPort |
| 113 { |
| 114 get |
| 115 { |
| 116 return boundPort; |
| 117 } |
| 118 } |
| 119 } |
| 120 } |
OLD | NEW |