1 // 2 // Copyright (c) ZeroC, Inc. All rights reserved. 3 // 4 5 namespace IceInternal 6 { 7 8 using System.Collections.Generic; 9 using System.Diagnostics; 10 using System; 11 12 public interface EndpointI_connectors 13 { connectors(List<Connector> connectors)14 void connectors(List<Connector> connectors); exception(Ice.LocalException ex)15 void exception(Ice.LocalException ex); 16 } 17 18 public abstract class EndpointI : Ice.Endpoint, IComparable<EndpointI> 19 { ToString()20 public override string ToString() 21 { 22 return ice_toString_(); 23 } 24 ice_toString_()25 public virtual string ice_toString_() 26 { 27 // 28 // WARNING: Certain features, such as proxy validation in Glacier2, 29 // depend on the format of proxy strings. Changes to toString() and 30 // methods called to generate parts of the reference string could break 31 // these features. Please review for all features that depend on the 32 // format of proxyToString() before changing this and related code. 33 // 34 return protocol() + options(); 35 } 36 getInfo()37 public abstract Ice.EndpointInfo getInfo(); 38 Equals(object obj)39 public override bool Equals(object obj) 40 { 41 if(!(obj is EndpointI)) 42 { 43 return false; 44 } 45 return CompareTo((EndpointI)obj) == 0; 46 } 47 GetHashCode()48 public override int GetHashCode() // Avoids a compiler warning. 49 { 50 Debug.Assert(false); 51 return 0; 52 } 53 54 // 55 // Marshal the endpoint. 56 // streamWrite(Ice.OutputStream s)57 virtual public void streamWrite(Ice.OutputStream s) 58 { 59 s.startEncapsulation(); 60 streamWriteImpl(s); 61 s.endEncapsulation(); 62 } streamWriteImpl(Ice.OutputStream s)63 public abstract void streamWriteImpl(Ice.OutputStream s); 64 65 // 66 // Return the endpoint type. 67 // type()68 public abstract short type(); 69 70 // 71 // Return the protocol name. 72 // protocol()73 public abstract string protocol(); 74 75 // 76 // Return the timeout for the endpoint in milliseconds. 0 means 77 // non-blocking, -1 means no timeout. 78 // timeout()79 public abstract int timeout(); 80 81 // 82 // Return a new endpoint with a different timeout value, provided 83 // that timeouts are supported by the endpoint. Otherwise the same 84 // endpoint is returned. 85 // timeout(int t)86 public abstract EndpointI timeout(int t); 87 88 // 89 // Return the connection ID. 90 // connectionId()91 public abstract string connectionId(); 92 93 // 94 // Return a new endpoint with a different connection id. 95 // connectionId(string connectionId)96 public abstract EndpointI connectionId(string connectionId); 97 98 // 99 // Return true if the endpoints support bzip2 compress, or false 100 // otherwise. 101 // compress()102 public abstract bool compress(); 103 104 // 105 // Return a new endpoint with a different compression value, 106 // provided that compression is supported by the 107 // endpoint. Otherwise the same endpoint is returned. 108 // compress(bool co)109 public abstract EndpointI compress(bool co); 110 111 // 112 // Return true if the endpoint is datagram-based. 113 // datagram()114 public abstract bool datagram(); 115 116 // 117 // Return true if the endpoint is secure. 118 // secure()119 public abstract bool secure(); 120 121 // 122 // Return a server side transceiver for this endpoint, or null if a 123 // transceiver can only be created by an acceptor. 124 // transceiver()125 public abstract Transceiver transceiver(); 126 127 // 128 // Return a connector for this endpoint, or empty list if no connector 129 // is available. 130 // connectors_async(Ice.EndpointSelectionType selType, EndpointI_connectors callback)131 public abstract void connectors_async(Ice.EndpointSelectionType selType, EndpointI_connectors callback); 132 133 // 134 // Return an acceptor for this endpoint, or null if no acceptors 135 // is available. 136 // acceptor(string adapterName)137 public abstract Acceptor acceptor(string adapterName); 138 139 // 140 // Expand endpoint out in to separate endpoints for each local 141 // host if listening on INADDR_ANY on server side or if no host 142 // was specified on client side. 143 // expandIfWildcard()144 public abstract List<EndpointI> expandIfWildcard(); 145 146 // 147 // Expand endpoint out into separate endpoints for each IP 148 // address returned by the DNS resolver. Also returns the 149 // endpoint which can be used to connect to the returned 150 // endpoints or null if no specific endpoint can be used to 151 // connect to these endpoints (e.g.: with the IP endpoint, 152 // it returns this endpoint if it uses a fixed port, null 153 // otherwise). 154 // expandHost(out EndpointI publishedEndpoint)155 public abstract List<EndpointI> expandHost(out EndpointI publishedEndpoint); 156 157 // 158 // Check whether the endpoint is equivalent to another one. 159 // equivalent(EndpointI endpoint)160 public abstract bool equivalent(EndpointI endpoint); 161 CompareTo(EndpointI obj)162 public abstract int CompareTo(EndpointI obj); 163 options()164 public abstract string options(); 165 initWithOptions(List<string> args)166 public virtual void initWithOptions(List<string> args) 167 { 168 List<string> unknown = new List<string>(); 169 170 string str = "`" + protocol() + " "; 171 foreach(string p in args) 172 { 173 if(IceUtilInternal.StringUtil.findFirstOf(p, " \t\n\r") != -1) 174 { 175 str += " \"" + p + "\""; 176 } 177 else 178 { 179 str += " " + p; 180 } 181 } 182 str += "'"; 183 184 for(int n = 0; n < args.Count; ++n) 185 { 186 string option = args[n]; 187 if(option.Length < 2 || option[0] != '-') 188 { 189 unknown.Add(option); 190 continue; 191 } 192 193 string argument = null; 194 if(n + 1 < args.Count && args[n + 1][0] != '-') 195 { 196 argument = args[++n]; 197 } 198 199 if(!checkOption(option, argument, str)) 200 { 201 unknown.Add(option); 202 if(argument != null) 203 { 204 unknown.Add(argument); 205 } 206 } 207 } 208 209 args.Clear(); 210 args.AddRange(unknown); 211 } 212 checkOption(string option, string argument, string endpoint)213 protected virtual bool checkOption(string option, string argument, string endpoint) 214 { 215 // Must be overridden to check for options. 216 return false; 217 } 218 } 219 220 } 221