80 |
public void finalizer() |
public void finalizer() |
81 |
{ |
{ |
82 |
if (connected) |
if (connected) |
83 |
{ |
{ |
84 |
try |
try |
85 |
{ |
{ |
86 |
close(); |
close (); |
87 |
} |
} |
88 |
catch (Exception e) |
catch (Exception e) |
89 |
{ |
{ |
90 |
} |
} |
91 |
} |
} |
92 |
} |
} |
93 |
|
|
94 |
protected void implCloseSelectableChannel() |
protected void implCloseSelectableChannel () throws IOException |
95 |
{ |
{ |
96 |
connected = false; |
connected = false; |
97 |
SocketClose(fd); |
SocketClose(fd); |
98 |
fd = SocketCreate(); |
fd = SocketCreate(); |
99 |
} |
} |
100 |
|
|
101 |
protected void implConfigureBlocking(boolean block) |
protected void implConfigureBlocking (boolean blocking) throws IOException |
102 |
{ |
{ |
103 |
if (blocking == block) |
if (this.blocking == blocking) |
104 |
return; |
return; |
105 |
} |
} |
106 |
|
|
107 |
public boolean connect(SocketAddress remote) |
public boolean connect (SocketAddress remote) throws IOException |
|
throws IOException |
|
108 |
{ |
{ |
109 |
if (connected) |
if (connected) |
110 |
{ |
{ |
111 |
throw new AlreadyConnectedException(); |
throw new AlreadyConnectedException (); |
112 |
} |
} |
113 |
|
|
114 |
// ok, lets connect ! |
// ok, lets connect ! |
115 |
|
|
129 |
return blocking; |
return blocking; |
130 |
} |
} |
131 |
|
|
132 |
public boolean finishConnect() |
public boolean finishConnect () |
133 |
{ |
{ |
134 |
return false; |
return false; |
135 |
} |
} |
136 |
|
|
137 |
public boolean isConnected() |
public boolean isConnected () |
138 |
{ |
{ |
139 |
return connected; |
return connected; |
140 |
} |
} |
141 |
|
|
142 |
public boolean isConnectionPending() |
public boolean isConnectionPending () |
143 |
{ |
{ |
144 |
if (blocking) |
if (blocking) |
145 |
return true; |
return true; |
147 |
return false; |
return false; |
148 |
} |
} |
149 |
|
|
150 |
public Socket socket() |
public Socket socket () |
151 |
{ |
{ |
152 |
if (sock_object != null) |
if (sock_object != null) |
153 |
{ |
{ |
157 |
return sock_object; |
return sock_object; |
158 |
} |
} |
159 |
|
|
160 |
public int read(ByteBuffer dst) |
public int read (ByteBuffer dst) throws IOException |
161 |
{ |
{ |
162 |
int bytes = 0; |
int bytes = 0; |
163 |
int len = 1024; |
int len = 1024; |
167 |
dst.put(b, 0, bytes); |
dst.put(b, 0, bytes); |
168 |
|
|
169 |
if (bytes == 0) |
if (bytes == 0) |
170 |
{ |
{ |
171 |
// we've hit eof ? |
// we've hit eof ? |
172 |
return -1; |
return -1; |
173 |
} |
} |
174 |
|
|
175 |
return bytes; |
return bytes; |
176 |
} |
} |
177 |
|
|
178 |
public long read(ByteBuffer[] dsts, int offset, int length) |
public long read (ByteBuffer[] dsts, int offset, int length) |
179 |
|
throws IOException |
180 |
{ |
{ |
181 |
long bytes = 0; |
long bytes = 0; |
182 |
|
|
183 |
for (int i=offset; i<length; i++) |
for (int i = offset; i < length; i++) |
184 |
{ |
{ |
185 |
bytes += read(dsts[i]); |
bytes += read (dsts [i]); |
186 |
} |
} |
187 |
|
|
188 |
return bytes; |
return bytes; |
189 |
} |
} |
190 |
|
|
191 |
public int write(ByteBuffer src) |
public int write (ByteBuffer src) |
192 |
|
throws IOException |
193 |
{ |
{ |
194 |
int bytes = 0; |
int bytes = 0; |
195 |
int len = src.position(); |
int len = src.position(); |
206 |
bytes = SocketWrite (fd, b, 0, len); |
bytes = SocketWrite (fd, b, 0, len); |
207 |
} |
} |
208 |
|
|
209 |
return bytes; |
return bytes; |
210 |
} |
} |
211 |
|
|
212 |
public long write (ByteBuffer[] srcs, int offset, int length) |
public long write (ByteBuffer[] srcs, int offset, int length) |
213 |
|
throws IOException |
214 |
{ |
{ |
215 |
long bytes = 0; |
long bytes = 0; |
216 |
|
|
217 |
for (int i=offset; i<length; i++) |
for (int i = offset; i < length; i++) |
218 |
{ |
{ |
219 |
bytes += write(srcs[i]); |
bytes += write (srcs [i]); |
220 |
} |
} |
221 |
|
|
222 |
return bytes; |
return bytes; |
223 |
} |
} |