Update of /cvsroot/freenet/freenet/src/freenet In directory sc8-pr-cvs1:/tmp/cvs-serv1889/src/freenet
Modified Files: ConnectionHandler.java Log Message: notify everybody on the sendingQueue in terminate() Index: ConnectionHandler.java =================================================================== RCS file: /cvsroot/freenet/freenet/src/freenet/ConnectionHandler.java,v retrieving revision 1.146 retrieving revision 1.147 diff -u -r1.146 -r1.147 --- ConnectionHandler.java 7 Sep 2003 19:28:36 -0000 1.146 +++ ConnectionHandler.java 8 Sep 2003 05:39:20 -0000 1.147 @@ -7,7 +7,7 @@ import freenet.session.*; import freenet.support.*; import freenet.support.io.*; -import freenet.thread.*; +//import freenet.thread.*; import freenet.transport.*; import java.util.*; import java.nio.*; @@ -55,7 +55,7 @@ private int maxPadding; private int messages = 0; - + public final boolean isFNP; // obsolete if we don't remove from OCM until the last minute // public static long openButNotOnOCM = 0; @@ -249,6 +249,7 @@ startTime = System.currentTimeMillis(); link.setTimeout(600000); // 10 minutes initRegisteredInOCM = false; + isFNP = link instanceof FnpLink ? true : false; //there may be more elegant way //profiling //WARNING:remove before release synchronized(profLock) { @@ -889,10 +890,24 @@ // Open new conn if necessary if(identity != null && ocm.findFreeConnection(identity) == null) - Main.node.scheduleConnectionOpener(identity); + Main.node.scheduleConnectionOpener(identity); //this is an overkill --zab + + //we should check the status if terminate() is called from elsewhere + if (!status) { + //tell everybody they failed + //this is where the PeerHandler will really help + Iterator i = sendingQueue.iterator(); + while (i.hasNext()) { + MessageSend current = (MessageSend) i.next(); + current.jobDone(0,false); + } + //FIXME: we also need to iterate through the current packet + //not sure exactly how to do that. + return; + } if (currentSOS != null) { //if not trailing, continue and get next message from queue - if (sendingQueue.size() > 0) { + if (sendingQueue.size() > 0 && isFNP) { Core.logger.log(this,"something got enqueued on a connection after a trailer."+ " discarding "+sendingQueue.size() +" messages for "+this, Logger.ERROR); @@ -2456,151 +2471,7 @@ return send; } - /** - * Sends a message using this connection. This will return after the message - * headers have been sent. - * - [EMAIL PROTECTED] m the message to send. If m is null, the - * method will lock until m _could_ have been sent, and then return. - [EMAIL PROTECTED] the OutputStream to write the trailing field - * to if there is one, otherwise null. - [EMAIL PROTECTED] SendFailedException Description of the Exception - */ -// public OutputStream sendMessage(Message m) -// throws SendFailedException { - -// // non terminal SFEs if we just stopped sending on this pipe - -// if (sendClosed.state()) -// throw new SendFailedException(link.getPeerAddress(), false); - -// boolean needToRemoveFromOCM = false; -// try { -// synchronized (sendLock) { -// if (sendClosed.state()) -// // check again when synced -// throw new SendFailedException(link.getPeerAddress(), false); - -// //int n = sending.incCount(); -// OutputStream send = null; -// try { -// ++sendingCount; -// //if (sending.count() > 1) { - -// waitForOneSender(); - -// // if we were just waiting for the connection to become free.. -// if (m == null) -// return null; - -// RawMessage raw = m.toRawMessage(p); -// //if (raw == null) { -// // return null; -// //} -// if (raw.close) { -// needToRemoveFromOCM = true; -// sendClosed.change(true); -// //} else if (raw.sustain) { -// // persist.change(true); -// // hm, we only want to persist if we *receive* -// // a sustain message, right? -// } - -// sendQueueSize += meanMessageSize + raw.trailingFieldLength; -// logDEBUG(sendingCount + " messages in sendqueue"); - -// // dont need now -// //raw.close = (sendClosed.state() && sendingCount <= 1); -// // defensive coding .. b/c i'm tired -// // of puzzling over this -// if (Core.logger.shouldLog(Logger.DEBUG)) -// logDEBUG("Sending RawMessage: " + raw, true); - -// // WATCHME -// if (Main.watchme != null) { -// logWatchme(m); -// } - -// // users are fond of this log entry -// if (Core.logger.shouldLog(Logger.MINOR)) -// Core.logger.log(this, -// raw.messageType + " @ " + -// Long.toHexString(m.id()) -// + " -> " + link.getPeerAddress(), -// Logger.MINOR); - -// OutputStream mout; -// try { -// logDEBUG("Still sending message"); -// mout = link.makeOutputStream(new CHOutputStream()); -// logDEBUG("Got CHOutputStream: "+mout); -// raw.writeMessage(mout); -// logDEBUG("Written rawMessage"); -// mout.flush(); -// logDEBUG("Flushed message"); -// messages++; -// } -// catch (IOException e) { -// Core.logger.log(this, "Got IOException trying to sendMessage: "+this, e, Logger.DEBUG); -// needToRemoveFromOCM = true; -// sendClosed.change(true); -// // terminal failure -// throw new SendFailedException(link.getPeerAddress(), true); -// } -// logDEBUG("Got stream, still here"); -// //sendQueueSize -= Math.min(meanMessageSize, sendQueueSize); -// // i am ever so slightly worried this syntax is bad with volatiles -// sendQueueSize = Math.max(sendQueueSize - meanMessageSize, 0); - -// if (raw.trailingFieldLength > 0) { -// // has trailing -// logDEBUG("Has trailing"); -// send = new SendOutputStream(mout, -// raw.trailingFieldLength); -// logDEBUG("Started SendOutputStream"); -// } else { -// logDEBUG("Does not have trailing"); -// // does not -// //Core.logger.log(this, "Message sent.", Logger.DEBUG); -// Core.randSource.acceptTimerEntropy(sendTimer); -// lastActiveTime = System.currentTimeMillis(); -// } -// logDEBUG("About to return send: "+send); -// return send; -// } -// finally { -// // only if there is a trailing field to write do we not -// // decrement sendingCount and notify() immediately -// logDEBUG("in finally{}"); -// if (send == null) { -// //sending.decCount(); // done -// --sendingCount; -// logDEBUG("send == null"); -// logDEBUG("Receiving "+receivingCount+ -// " messages, sending "+sendingCount+ -// " messages, receiveClosed="+ -// receiveClosed.state()+", sendClosed="+ -// sendClosed.state()+" ("+this+")"); -// if (receiveClosed.state() && receivingCount == 0 -// && sendClosed.state() && sendingCount == 0) { -// logDEBUG("terminating"); -// terminate(); -// } -// sendLock.notify(); -// logDEBUG("notified"); -// } -// } -// } -// } -// finally { -// if (needToRemoveFromOCM) { -// logDEBUG("Need to remove from OCM"); -// removeFromOCM(); -// logDEBUG("Removed from OCM"); -// } -// } -// } // IMPORTANT: Don't call this while holding sendLock @@ -2617,13 +2488,6 @@ } } -// private synchronized static void incOpenButNotOnOCM() { -// openButNotOnOCM++; -// } - -// private synchronized static void decOpenButNotOnOCM() { -// openButNotOnOCM--; -// } /** * Initiates a close dialog on this connection by sending a closeMessage() as @@ -2716,8 +2580,8 @@ CHOutputStreamLock.notifyAll(); } if(logDEBUG) logDEBUG("notified CHOS in terminate()"); - if(currentSender != null) - currentSender.jobDone(0, false); + //if(currentSender != null) + jobDone(0, false); //call jobDone for the entire CH --zab if(logDEBUG) logDEBUG("notified current sender in terminate()"); //terminatedInstances++; if (!sendClosed.state()) @@ -2856,6 +2720,7 @@ } public final boolean reallySending() { + if (!isFNP) return false; return trailingPresent; } @@ -2864,6 +2729,7 @@ * The higher the worse. */ public final int useValue() { + if (!isFNP) return 0; if(trailingPresent) return Integer.MAX_VALUE; return sendingQueueBytes; } @@ -2872,7 +2738,7 @@ [EMAIL PROTECTED] whether the connection is currently sending something */ public final boolean sending() { - if (link instanceof PlainLink) //fcp messages can be behind trailers. + if (!isFNP) //fcp messages can be behind trailers. return false; //return sending.count() > 0; // Don't synchronize here! _______________________________________________ cvs mailing list [EMAIL PROTECTED] http://dodo.freenetproject.org/cgi-bin/mailman/listinfo/cvs