equal
deleted
inserted
replaced
41 import sun.net.ConnectionResetException; |
41 import sun.net.ConnectionResetException; |
42 import sun.net.NetHooks; |
42 import sun.net.NetHooks; |
43 import sun.net.PlatformSocketImpl; |
43 import sun.net.PlatformSocketImpl; |
44 import sun.net.ResourceManager; |
44 import sun.net.ResourceManager; |
45 import sun.net.ext.ExtendedSocketOptions; |
45 import sun.net.ext.ExtendedSocketOptions; |
|
46 import sun.net.util.IPAddressUtil; |
46 import sun.net.util.SocketExceptions; |
47 import sun.net.util.SocketExceptions; |
47 |
48 |
48 /** |
49 /** |
49 * Default Socket Implementation. This implementation does |
50 * Default Socket Implementation. This implementation does |
50 * not implement any security checks. |
51 * not implement any security checks. |
155 throws UnknownHostException, IOException |
156 throws UnknownHostException, IOException |
156 { |
157 { |
157 boolean connected = false; |
158 boolean connected = false; |
158 try { |
159 try { |
159 InetAddress address = InetAddress.getByName(host); |
160 InetAddress address = InetAddress.getByName(host); |
|
161 // recording this.address as supplied by caller before calling connect |
|
162 this.address = address; |
160 this.port = port; |
163 this.port = port; |
161 this.address = address; |
164 if (address.isLinkLocalAddress()) { |
|
165 address = IPAddressUtil.toScopedAddress(address); |
|
166 } |
162 |
167 |
163 connectToAddress(address, port, timeout); |
168 connectToAddress(address, port, timeout); |
164 connected = true; |
169 connected = true; |
165 } finally { |
170 } finally { |
166 if (!connected) { |
171 if (!connected) { |
180 * the specified port. |
185 * the specified port. |
181 * @param address the address |
186 * @param address the address |
182 * @param port the specified port |
187 * @param port the specified port |
183 */ |
188 */ |
184 protected void connect(InetAddress address, int port) throws IOException { |
189 protected void connect(InetAddress address, int port) throws IOException { |
|
190 // recording this.address as supplied by caller before calling connect |
|
191 this.address = address; |
185 this.port = port; |
192 this.port = port; |
186 this.address = address; |
193 if (address.isLinkLocalAddress()) { |
|
194 address = IPAddressUtil.toScopedAddress(address); |
|
195 } |
187 |
196 |
188 try { |
197 try { |
189 connectToAddress(address, port, timeout); |
198 connectToAddress(address, port, timeout); |
190 isConnected = true; |
199 isConnected = true; |
191 return; |
200 return; |
213 if (address == null || !(address instanceof InetSocketAddress)) |
222 if (address == null || !(address instanceof InetSocketAddress)) |
214 throw new IllegalArgumentException("unsupported address type"); |
223 throw new IllegalArgumentException("unsupported address type"); |
215 InetSocketAddress addr = (InetSocketAddress) address; |
224 InetSocketAddress addr = (InetSocketAddress) address; |
216 if (addr.isUnresolved()) |
225 if (addr.isUnresolved()) |
217 throw new UnknownHostException(addr.getHostName()); |
226 throw new UnknownHostException(addr.getHostName()); |
|
227 // recording this.address as supplied by caller before calling connect |
|
228 InetAddress ia = addr.getAddress(); |
|
229 this.address = ia; |
218 this.port = addr.getPort(); |
230 this.port = addr.getPort(); |
219 this.address = addr.getAddress(); |
231 if (ia.isLinkLocalAddress()) { |
220 |
232 ia = IPAddressUtil.toScopedAddress(ia); |
221 connectToAddress(this.address, port, timeout); |
233 } |
|
234 connectToAddress(ia, port, timeout); |
222 connected = true; |
235 connected = true; |
223 } finally { |
236 } finally { |
224 if (!connected) { |
237 if (!connected) { |
225 try { |
238 try { |
226 close(); |
239 close(); |
543 { |
556 { |
544 synchronized (fdLock) { |
557 synchronized (fdLock) { |
545 if (!closePending && !isBound) { |
558 if (!closePending && !isBound) { |
546 NetHooks.beforeTcpBind(fd, address, lport); |
559 NetHooks.beforeTcpBind(fd, address, lport); |
547 } |
560 } |
|
561 } |
|
562 if (address.isLinkLocalAddress()) { |
|
563 address = IPAddressUtil.toScopedAddress(address); |
548 } |
564 } |
549 socketBind(address, lport); |
565 socketBind(address, lport); |
550 isBound = true; |
566 isBound = true; |
551 } |
567 } |
552 |
568 |