This is the mail archive of the
java-discuss@sources.redhat.com
mailing list for the Java project.
Re: More bugs with inner classes (was: Freenet compilation errors.)
- To: Alexandre Petit-Bianco <apbianco at cygnus dot com>
- Subject: Re: More bugs with inner classes (was: Freenet compilation errors.)
- From: "Mark J. Roberts" <mjr at statesmean dot com>
- Date: Wed, 17 Jan 2001 23:36:25 -0600 (CST)
- cc: java-discuss at sources dot redhat dot com
On Wed, 17 Jan 2001, Alexandre Petit-Bianco wrote:
> Mark J. Roberts writes:
>
> > However, when I try to compile it into classes with the -C option, a
> > new error emerges:
>
> I'll need a test case or a pointer to the source of the package you're
> building, whichever is convenient for you.
The source is included. My bad.
> > where -h tells it to make header files too? Also, when dealing with
> > packages, it is more difficult to deduce the class from the
> > filename. A feature like this would be very useful.
>
> Yeah, I think so too. I don't know how hard it is to hack the driver.
>
> ./A
--
Mark Roberts
mjr@statesmean.com
package Freenet.transport;
import Freenet.*;
import Freenet.ConnectException; // we seem to have to import this
// explicitly - why?
import Freenet.support.io.ThrottledOutputStream;
import Freenet.support.Logger;
import java.io.*;
import java.net.*;
public class tcpConnection extends Connection {
protected Socket sock=null;
private class ConnectThread extends Thread {
public boolean done;
private boolean abandoned = false;
public Exception exception = null;
private tcpAddress tcpaddr;
public ConnectThread(tcpAddress addr) {
super();
setName("tcpConnectThread");
tcpaddr=addr;
}
public void run() {
try {
sock=new Socket(tcpaddr.host, tcpaddr.port);
} catch(IOException e) {
sock = null;
exception = e;
}
done=true;
if (sock != null && abandoned) {
try {
sock.close();
} catch (IOException e) {}
}
}
public void timedOut() {
abandoned = true;
}
}
public String toString() {
return getPeerAddress().toString();
}
public tcpConnection(tcpAddress addr) throws UnknownHostException,
IOException, ConnectException
{
ConnectThread st = new ConnectThread(addr);
st.start();
for (long r=0; r<Core.connectTimeout && !st.done; r+=100) {
try {
Thread.sleep(100);
} catch(InterruptedException e) {
//interrupted is a good thing here
break;
}
}
if(sock==null) {
st.timedOut();
if (st.exception == null) {
throw new ConnectTimedOutException();
}
else {
// hm, would it be ok to throw st.exception directly?
throw new ConnectException(st.exception.toString());
}
}
in=sock.getInputStream();
if (sock.getLocalAddress().equals(sock.getInetAddress())) {
Core.logger.log(this,
"not throttling local connection", Logger.DEBUG);
out = sock.getOutputStream();
} else {
out = ThrottledOutputStream.throttledStream(sock.getOutputStream());
}
}
public tcpConnection(Socket sock) throws IOException {
this.sock = sock;
// sock.setSoLinger(true, 0);
in=sock.getInputStream();
if (sock.getLocalAddress().equals(sock.getInetAddress())) {
Core.logger.log(this,
"not throttling local connection", Logger.DEBUG);
out = sock.getOutputStream();
} else {
out = ThrottledOutputStream.throttledStream(sock.getOutputStream());
}
}
public void close()
{
try {
in.close();
} catch(Exception e) {}
in=null;
try {
out.close();
} catch(Exception e) {}
out=null;
try {
sock.close();
} catch(IOException e) {
// It may have been closed remotely in which case
// sock.close will throw an exception. We really don't
// care though.
}
}
public void setSoTimeout(int timeout) throws IOException {
if (sock != null)
sock.setSoTimeout(timeout);
else
throw new IOException();
}
public int getSoTimeout() throws IOException {
return sock.getSoTimeout();
}
public Address getMyAddress(ListeningAddress lstaddr)
{
return (sock == null)? null :
new Address("tcp",
new tcpAddress(sock.getLocalAddress(),
((tcpListeningAddress)lstaddr.address).port));
}
public Address getMyAddress()
{
return (sock == null)? null :
new Address("tcp",
new tcpAddress(sock.getLocalAddress(),
sock.getLocalPort()));
}
public Address getPeerAddress(ListeningAddress lstaddr)
{
return (sock == null)? null :
new Address("tcp",
new tcpAddress(sock.getInetAddress(),
((tcpListeningAddress)lstaddr.address).port));
}
public Address getPeerAddress()
{
return (sock == null)? null :
new Address("tcp",
new tcpAddress(sock.getInetAddress(),
sock.getPort()));
}
}