1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.jboss.netty.channel.socket.nio;
17
18 import static org.jboss.netty.channel.Channels.*;
19
20 import java.io.IOException;
21 import java.nio.channels.SocketChannel;
22
23 import org.jboss.netty.channel.ChannelException;
24 import org.jboss.netty.channel.ChannelFactory;
25 import org.jboss.netty.channel.ChannelFuture;
26 import org.jboss.netty.channel.ChannelPipeline;
27 import org.jboss.netty.channel.ChannelSink;
28 import org.jboss.netty.logging.InternalLogger;
29 import org.jboss.netty.logging.InternalLoggerFactory;
30
31
32
33
34
35
36
37
38
39 final class NioClientSocketChannel extends NioSocketChannel {
40
41 private static final InternalLogger logger =
42 InternalLoggerFactory.getInstance(NioClientSocketChannel.class);
43
44 private static SocketChannel newSocket() {
45 SocketChannel socket;
46 try {
47 socket = SocketChannel.open();
48 } catch (IOException e) {
49 throw new ChannelException("Failed to open a socket.", e);
50 }
51
52 boolean success = false;
53 try {
54 socket.configureBlocking(false);
55 success = true;
56 } catch (IOException e) {
57 throw new ChannelException("Failed to enter non-blocking mode.", e);
58 } finally {
59 if (!success) {
60 try {
61 socket.close();
62 } catch (IOException e) {
63 logger.warn(
64 "Failed to close a partially initialized socket.",
65 e);
66 }
67 }
68 }
69
70 return socket;
71 }
72
73 volatile ChannelFuture connectFuture;
74 volatile boolean boundManually;
75
76
77 long connectDeadlineNanos;
78
79 NioClientSocketChannel(
80 ChannelFactory factory, ChannelPipeline pipeline,
81 ChannelSink sink, NioWorker worker) {
82
83 super(null, factory, pipeline, sink, newSocket(), worker);
84 fireChannelOpen(this);
85 }
86 }