|
From: <ls...@us...> - 2008-06-15 12:50:48
|
Revision: 4241
http://jnode.svn.sourceforge.net/jnode/?rev=4241&view=rev
Author: lsantha
Date: 2008-06-15 05:50:44 -0700 (Sun, 15 Jun 2008)
Log Message:
-----------
Turned off dangerous logging.
Modified Paths:
--------------
trunk/net/src/net/org/jnode/net/arp/ARPNetworkLayer.java
trunk/net/src/net/org/jnode/net/ipv4/tcp/TCPControlBlock.java
trunk/net/src/net/org/jnode/net/ipv4/tcp/TCPOutChannel.java
trunk/net/src/net/org/jnode/net/ipv4/tcp/TCPOutSegment.java
trunk/net/src/net/org/jnode/net/ipv4/tcp/TCPProtocol.java
trunk/net/src/net/org/jnode/net/ipv4/tcp/TCPSocketImpl.java
Modified: trunk/net/src/net/org/jnode/net/arp/ARPNetworkLayer.java
===================================================================
--- trunk/net/src/net/org/jnode/net/arp/ARPNetworkLayer.java 2008-06-15 09:44:26 UTC (rev 4240)
+++ trunk/net/src/net/org/jnode/net/arp/ARPNetworkLayer.java 2008-06-15 12:50:44 UTC (rev 4241)
@@ -24,7 +24,6 @@
import java.net.SocketException;
import java.util.ArrayList;
import java.util.Collection;
-
import org.apache.log4j.Logger;
import org.jnode.driver.ApiNotFoundException;
import org.jnode.driver.Device;
@@ -49,12 +48,19 @@
*/
@SharedStatics
public class ARPNetworkLayer implements NetworkLayer, ARPConstants {
+ private static final boolean DEBUG = false;
- /** My logger */
+ /**
+ * My logger
+ */
private static final Logger log = Logger.getLogger(ARPNetworkLayer.class);
- /** My statistics */
+ /**
+ * My statistics
+ */
private final ARPStatistics stat = new ARPStatistics();
- /** ARP cache */
+ /**
+ * ARP cache
+ */
private static final ARPCache cache = new ARPCache();
/**
@@ -87,7 +93,7 @@
/**
* Process a packet that has been received and matches getType()
- *
+ *
* @param skbuf
* @param deviceAPI
* @throws SocketException
@@ -126,7 +132,7 @@
/**
* Process and ARP request.
- *
+ *
* @param skbuf
* @param hdr
* @param deviceAPI
@@ -154,7 +160,7 @@
/**
* Process and ARP reply
- *
+ *
* @param skbuf
* @param hdr
* @param deviceAPI
@@ -167,7 +173,7 @@
/**
* Process and RARP request
- *
+ *
* @param skbuf
* @param hdr
* @param deviceAPI
@@ -181,7 +187,7 @@
/**
* Process and RARP reply
- *
+ *
* @param skbuf
* @param hdr
* @param deviceAPI
@@ -230,7 +236,7 @@
/**
* Gets a registered transportlayer by its protocol ID.
- *
+ *
* @param protocolID
*/
public TransportLayer getTransportLayer(int protocolID) throws NoSuchProtocolException {
@@ -239,7 +245,7 @@
/**
* Gets the hardware address for a given protocol address.
- *
+ *
* @param address
* @param myAddress
* @param device
@@ -248,13 +254,15 @@
* @throws NetworkException
*/
public HardwareAddress getHardwareAddress(ProtocolAddress address, ProtocolAddress myAddress,
- Device device, long timeout) throws TimeoutException, NetworkException {
+ Device device, long timeout) throws TimeoutException, NetworkException {
final long start = System.currentTimeMillis();
long lastReq = 0;
- if (log.isDebugEnabled()) {
- log.debug("getHardwareAddress(" + address + ", " + myAddress + ", " + device.getId() +
+ if (DEBUG) {
+ if (log.isDebugEnabled()) {
+ log.debug("getHardwareAddress(" + address + ", " + myAddress + ", " + device.getId() +
", " + timeout + ")");
+ }
}
if (address.equals(myAddress)) {
@@ -285,7 +293,7 @@
/**
* Gets the protocol addresses for a given name, or null if not found.
- *
+ *
* @param hostname
* @return
*/
@@ -295,7 +303,7 @@
/**
* Create and transmit an ARP request
- *
+ *
* @param address
* @param myAddress
* @param device
@@ -310,8 +318,7 @@
final int hwtype = srcHwAddr.getType();
final int ptype = address.getType();
- final ARPHeader hdr =
- new ARPHeader(srcHwAddr, myAddress, trgHwAddr, address, op, hwtype, ptype);
+ final ARPHeader hdr = new ARPHeader(srcHwAddr, myAddress, trgHwAddr, address, op, hwtype, ptype);
final SocketBuffer skbuf = new SocketBuffer();
skbuf.setProtocolID(EthernetConstants.ETH_P_ARP);
hdr.prefixTo(skbuf);
@@ -321,7 +328,7 @@
/**
* Gets the NetDeviceAPI for a given device
- *
+ *
* @param device
*/
private NetDeviceAPI getAPI(Device device) {
Modified: trunk/net/src/net/org/jnode/net/ipv4/tcp/TCPControlBlock.java
===================================================================
--- trunk/net/src/net/org/jnode/net/ipv4/tcp/TCPControlBlock.java 2008-06-15 09:44:26 UTC (rev 4240)
+++ trunk/net/src/net/org/jnode/net/ipv4/tcp/TCPControlBlock.java 2008-06-15 12:50:44 UTC (rev 4241)
@@ -18,14 +18,13 @@
* along with this library; If not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-
+
package org.jnode.net.ipv4.tcp;
import java.net.ConnectException;
import java.net.SocketException;
import java.util.LinkedList;
-
import org.apache.log4j.Logger;
import org.jnode.net.SocketBuffer;
import org.jnode.net.ipv4.IPv4Address;
@@ -39,7 +38,7 @@
* @author Ewout Prangsma (ep...@us...)
*/
public class TCPControlBlock extends IPv4ControlBlock implements TCPConstants {
-
+ private static final boolean DEBUG = false;
/**
* My logger
*/
@@ -57,7 +56,7 @@
/** Last incoming sequence number */
// private int lastInSeqNr;
-
+
/**
* Window size of the outgoing connection
*/
@@ -95,14 +94,14 @@
/**
* Create a new instance
- *
+ *
* @param list
* @param parent
* @param tcp
- * @param isn The initial outgoing sequence number
+ * @param isn The initial outgoing sequence number
*/
public TCPControlBlock(TCPControlBlockList list, TCPControlBlock parent, TCPProtocol tcp,
- int isn) {
+ int isn) {
super(list, IPv4Constants.IPPROTO_TCP, TCP_DEFAULT_TTL);
this.parent = parent;
this.outChannel = new TCPOutChannel(tcp, this, isn);
@@ -120,13 +119,15 @@
/**
* Handle a received segment for this connection
- *
+ *
* @param hdr
* @param skbuf
*/
public synchronized void receive(TCPHeader hdr, SocketBuffer skbuf) throws SocketException {
- if (log.isDebugEnabled()) {
- log.debug("receive: me=[" + this + "], hdr=[" + hdr + "]");
+ if (DEBUG) {
+ if (log.isDebugEnabled()) {
+ log.debug("receive: me=[" + this + "], hdr=[" + hdr + "]");
+ }
}
final IPv4Header ipHdr = (IPv4Header) skbuf.getNetworkLayerHeader();
@@ -171,19 +172,21 @@
receiveTimeWait(ipHdr, hdr, skbuf);
break;
default:
- log.debug("Unhandled state in receive (" + getStateName() + ")");
+ if (DEBUG) {
+ log.debug("Unhandled state in receive (" + getStateName() + ")");
+ }
break;
}
}
/**
* Process a reset segment
- *
+ *
* @param ipHdr
* @param hdr
* @param skbuf
*/
- private final void receiveProcessReset(IPv4Header ipHdr, TCPHeader hdr, SocketBuffer skbuf)
+ private void receiveProcessReset(IPv4Header ipHdr, TCPHeader hdr, SocketBuffer skbuf)
throws SocketException {
final boolean ack = hdr.isFlagAcknowledgeSet();
final boolean syn = hdr.isFlagSynchronizeSet();
@@ -227,13 +230,15 @@
/**
* Current state is LISTEN. If a SYN segment is received, send a SYN&ACK,
* and set the state to SYN_RECV
- *
+ *
* @param hdr
* @param skbuf
*/
- private final void receiveListen(IPv4Header ipHdr, TCPHeader hdr, SocketBuffer skbuf)
+ private void receiveListen(IPv4Header ipHdr, TCPHeader hdr, SocketBuffer skbuf)
throws SocketException {
- log.debug("receiveListen");
+ if (DEBUG) {
+ log.debug("receiveListen");
+ }
final boolean ack = hdr.isFlagAcknowledgeSet();
final boolean syn = hdr.isFlagSynchronizeSet();
@@ -251,7 +256,7 @@
} else {
// Process the SYN request
final TCPControlBlock copy =
- (TCPControlBlock) copyAndConnect(dst, ipHdr.getSource(), hdr.getSrcPort());
+ (TCPControlBlock) copyAndConnect(dst, ipHdr.getSource(), hdr.getSrcPort());
copy.listenSynReceivedOnCopy(hdr, skbuf);
}
} else {
@@ -264,13 +269,15 @@
* Current state is 0, SYN segment received. This method is called on a copy
* of the listening control block. Send a SYN&ACK, and set the state to
* SYN_RECV
- *
+ *
* @param hdr
* @param skbuf
*/
- private final void listenSynReceivedOnCopy(TCPHeader hdr, SocketBuffer skbuf)
+ private void listenSynReceivedOnCopy(TCPHeader hdr, SocketBuffer skbuf)
throws SocketException {
- log.debug("listenSynReceivedOnCopy");
+ if (DEBUG) {
+ log.debug("listenSynReceivedOnCopy");
+ }
// Save the foreign seq nr
inChannel.initISN(hdr);
@@ -285,7 +292,7 @@
/**
* Current state is SYN_RECV.
*/
- private final void receiveSynRecv(IPv4Header ipHdr, TCPHeader hdr, SocketBuffer skbuf)
+ private void receiveSynRecv(IPv4Header ipHdr, TCPHeader hdr, SocketBuffer skbuf)
throws SocketException {
final boolean ack = hdr.isFlagAcknowledgeSet();
@@ -301,7 +308,7 @@
/**
* Current state is SYN_SEND.
*/
- private final void receiveSynSend(IPv4Header ipHdr, TCPHeader hdr, SocketBuffer skbuf)
+ private void receiveSynSend(IPv4Header ipHdr, TCPHeader hdr, SocketBuffer skbuf)
throws SocketException {
final boolean syn = hdr.isFlagSynchronizeSet();
@@ -319,11 +326,11 @@
/**
* Current state is ESTABLISHED, FIN segment received. Send a ACK, and set
* the state to CLOSE_WAIT
- *
+ *
* @param hdr
* @param skbuf
*/
- private final void receiveEstablished(IPv4Header ipHdr, TCPHeader hdr, SocketBuffer skbuf)
+ private void receiveEstablished(IPv4Header ipHdr, TCPHeader hdr, SocketBuffer skbuf)
throws SocketException {
final boolean fin = hdr.isFlagFinishedSet();
// Process the data
@@ -336,11 +343,11 @@
/**
* State is FIN_WAIT_1, any segment received
- *
+ *
* @param hdr
* @param skbuf
*/
- private final void receiveFinWait1(IPv4Header ipHdr, TCPHeader hdr, SocketBuffer skbuf)
+ private void receiveFinWait1(IPv4Header ipHdr, TCPHeader hdr, SocketBuffer skbuf)
throws SocketException {
final boolean fin = hdr.isFlagFinishedSet();
final boolean ack = hdr.isFlagAcknowledgeSet();
@@ -361,11 +368,11 @@
/**
* State is FIN_WAIT_2, any segment received
- *
+ *
* @param hdr
* @param skbuf
*/
- private final void receiveFinWait2(IPv4Header ipHdr, TCPHeader hdr, SocketBuffer skbuf)
+ private void receiveFinWait2(IPv4Header ipHdr, TCPHeader hdr, SocketBuffer skbuf)
throws SocketException {
final boolean fin = hdr.isFlagFinishedSet();
// Process the data
@@ -401,11 +408,11 @@
/**
* State is LAST_ACK, any segment received
- *
+ *
* @param hdr
* @param skbuf
*/
- private final void receiveLastAck(IPv4Header ipHdr, TCPHeader hdr, SocketBuffer skbuf)
+ private void receiveLastAck(IPv4Header ipHdr, TCPHeader hdr, SocketBuffer skbuf)
throws SocketException {
final boolean ack = hdr.isFlagAcknowledgeSet();
if (ack) {
@@ -418,11 +425,11 @@
/**
* State is CLOSING, any segment received
- *
+ *
* @param hdr
* @param skbuf
*/
- private final void receiveClosing(IPv4Header ipHdr, TCPHeader hdr, SocketBuffer skbuf)
+ private void receiveClosing(IPv4Header ipHdr, TCPHeader hdr, SocketBuffer skbuf)
throws SocketException {
final boolean ack = hdr.isFlagAcknowledgeSet();
if (ack) {
@@ -435,11 +442,11 @@
/**
* State is TIME_WAIT, discard any segments
- *
+ *
* @param hdr
* @param skbuf
*/
- private final void receiveTimeWait(IPv4Header ipHdr, TCPHeader hdr, SocketBuffer skbuf)
+ private void receiveTimeWait(IPv4Header ipHdr, TCPHeader hdr, SocketBuffer skbuf)
throws SocketException {
setState(TCPS_CLOSED);
drop(ipHdr, hdr, "discard all in TIME_WAIT state");
@@ -468,15 +475,18 @@
* Notify a segment drop to the debug log
*/
private void drop(IPv4Header ipHdr, TCPHeader hdr, String reason) {
- log.debug("Dropping segment due to: " + reason);
+ if (DEBUG) {
+ log.debug("Dropping segment due to: " + reason);
+ }
}
/**
* Send a ACK segment
*/
protected final void sendACK(int extraFlags, int ackNr) throws SocketException {
- log.debug("sendACK(0x" + NumberUtils.hex(extraFlags, 4) + ", " + (ackNr & 0xFFFFFFFFL) +
- ")");
+ if (DEBUG) {
+ log.debug("sendACK(0x" + NumberUtils.hex(extraFlags, 4) + ", " + (ackNr & 0xFFFFFFFFL) + ")");
+ }
// Create the FIN TCP reply
final TCPHeader replyHdr = createOutgoingTCPHeader(extraFlags | TCPF_ACK, ackNr);
@@ -492,12 +502,14 @@
/**
* Send a FIN segment
*/
- private final void sendFIN() throws SocketException {
- log.debug("sendFIN");
+ private void sendFIN() throws SocketException {
+ if (DEBUG) {
+ log.debug("sendFIN");
+ }
// Create the FIN TCP reply
final TCPHeader replyHdr =
- createOutgoingTCPHeader(TCPF_FIN | TCPF_ACK, inChannel.getRcvNext());
+ createOutgoingTCPHeader(TCPF_FIN | TCPF_ACK, inChannel.getRcvNext());
// Create the IP reply header
final IPv4Header replyIp = createOutgoingIPv4Header();
@@ -509,8 +521,10 @@
/**
* Send a RST segment
*/
- private final void sendRST() throws SocketException {
- log.debug("sendRST");
+ private void sendRST() throws SocketException {
+ if (DEBUG) {
+ log.debug("sendRST");
+ }
// Create the RST TCP reply
final TCPHeader replyHdr = createOutgoingTCPHeader(TCPF_RST, 0);
@@ -526,8 +540,10 @@
/**
* Send a SYN segment
*/
- private final void sendSYN() throws SocketException {
- log.debug("sendSYN");
+ private void sendSYN() throws SocketException {
+ if (DEBUG) {
+ log.debug("sendSYN");
+ }
// Create the SYN TCP
final TCPHeader hdr = createOutgoingTCPHeader(TCPF_SYN, 0);
@@ -542,7 +558,7 @@
/**
* Notify this listening parent that one of my children have established a
* connection.
- *
+ *
* @param child
*/
private synchronized void notifyChildEstablished(TCPControlBlock child) throws SocketException {
@@ -577,7 +593,7 @@
/**
* Is the current state equal to the given state?
- *
+ *
* @param state
* @return
*/
@@ -587,7 +603,7 @@
/**
* Update the state and notify any waiting threads
- *
+ *
* @param state
*/
private synchronized void setState(int state) throws SocketException {
@@ -625,13 +641,13 @@
/**
* Create a TCP header for outgoing trafic
- *
+ *
* @param options
* @return The created TCP header
*/
protected TCPHeader createOutgoingTCPHeader(int options, int ackNr) {
final TCPHeader hdr =
- new TCPHeader(getLocalPort(), getForeignPort(), 0, 0, ackNr, outWindowSize, 0);
+ new TCPHeader(getLocalPort(), getForeignPort(), 0, 0, ackNr, outWindowSize, 0);
hdr.setFlags(options);
return hdr;
}
@@ -642,7 +658,7 @@
/**
* Wait for incoming requests
- *
+ *
* @throws SocketException
*/
public synchronized void appListen() throws SocketException {
@@ -655,7 +671,7 @@
/**
* Active connect to a foreign address. This method blocks until the
* connection has been established.
- *
+ *
* @throws SocketException
*/
public synchronized void appConnect(IPv4Address fAddr, int fPort) throws SocketException {
@@ -675,7 +691,9 @@
if (isRefused()) {
throw new ConnectException("Connection refused");
}
- log.debug("Connected to " + fAddr + ":" + fPort);
+ if (DEBUG) {
+ log.debug("Connected to " + fAddr + ":" + fPort);
+ }
return;
} catch (TimeoutException ex) {
// Ignore and just try again
@@ -687,7 +705,7 @@
/**
* Wait for an established connection.
- *
+ *
* @return The accepted connection
*/
public synchronized TCPControlBlock appAccept() {
@@ -710,14 +728,16 @@
* Active close the connection by the application.
*/
public/* synchronized */void appClose() throws SocketException {
- if (log.isDebugEnabled()) {
- log.debug("active close state=" + getStateName());
+ if (DEBUG) {
+ if (log.isDebugEnabled()) {
+ log.debug("active close state=" + getStateName());
+ }
}
try {
switch (curState) {
case TCPS_SYN_RECV:
- case TCPS_ESTABLISHED:
+ case TCPS_ESTABLISHED:
sendFIN();
setState(TCPS_FIN_WAIT_1);
@@ -727,7 +747,7 @@
// waitUntilState(TCPS_CLOSED, 0);
break;
case TCPS_SYN_SENT:
- case TCPS_LISTEN:
+ case TCPS_LISTEN:
setState(TCPS_CLOSED);
break;
case TCPS_CLOSE_WAIT:
@@ -735,7 +755,7 @@
setState(TCPS_LAST_ACK);
waitUntilState(TCPS_CLOSED, 0);
break;
- case TCPS_CLOSED:
+ case TCPS_CLOSED:
// Ignore
break;
default:
@@ -753,14 +773,16 @@
* Send data to the foreign side. This method can split-up the data in
* chunks and blocks until there is space in the send buffer to hold the
* data.
- *
+ *
* @param data
* @param offset
* @param length
* @throws SocketException
*/
public void appSendData(byte[] data, int offset, int length) throws SocketException {
- log.debug("appSendData(data, " + offset + ", " + length + ")");
+ if (DEBUG) {
+ log.debug("appSendData(data, " + offset + ", " + length + ")");
+ }
if (!isState(TCPS_ESTABLISHED) && !isState(TCPS_CLOSE_WAIT)) {
throw new SocketException("Illegal state to send data: " + getStateName());
}
@@ -795,7 +817,7 @@
/**
* Read data from the input buffer up to len bytes long. Block until there
* is data available.
- *
+ *
* @param dst
* @param off
* @param len
@@ -828,7 +850,7 @@
/**
* Has this connection been reset
- *
+ *
* @return Returns the reset.
*/
public final boolean isReset() {
Modified: trunk/net/src/net/org/jnode/net/ipv4/tcp/TCPOutChannel.java
===================================================================
--- trunk/net/src/net/org/jnode/net/ipv4/tcp/TCPOutChannel.java 2008-06-15 09:44:26 UTC (rev 4240)
+++ trunk/net/src/net/org/jnode/net/ipv4/tcp/TCPOutChannel.java 2008-06-15 12:50:44 UTC (rev 4241)
@@ -18,13 +18,12 @@
* along with this library; If not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-
+
package org.jnode.net.ipv4.tcp;
import java.net.SocketException;
import java.util.Iterator;
import java.util.LinkedList;
-
import org.apache.log4j.Logger;
import org.jnode.net.ipv4.IPv4Header;
@@ -32,6 +31,7 @@
* @author Ewout Prangsma (ep...@us...)
*/
public class TCPOutChannel {
+ private static final boolean DEBUG = false;
/**
* My logger
@@ -181,8 +181,10 @@
* @param length Must be smaller or equal to mss.
*/
public synchronized void send(IPv4Header ipHdr, TCPHeader hdr, byte[] data, int offset,
- int length) throws SocketException {
- log.debug("outChannel.send(ipHdr,hdr,data," + offset + ", " + length + ")");
+ int length) throws SocketException {
+ if (DEBUG) {
+ log.debug("outChannel.send(ipHdr,hdr,data," + offset + ", " + length + ")");
+ }
// Check for maximum datalength
if (length > mss) {
throw new IllegalArgumentException("dataLength must be <= mss");
@@ -213,7 +215,7 @@
* @param hdr
* @param dataOffset
*/
- private final void sendHelper(IPv4Header ipHdr, TCPHeader hdr, int dataOffset)
+ private void sendHelper(IPv4Header ipHdr, TCPHeader hdr, int dataOffset)
throws SocketException {
// Adjust the sequence numbers
hdr.setSequenceNr(snd_next);
@@ -226,10 +228,12 @@
snd_max = snd_next;
// Create & send the segment
final TCPOutSegment seg =
- new TCPOutSegment(ipHdr, hdr, dataBuffer, dataOffset, timeoutTicks);
+ new TCPOutSegment(ipHdr, hdr, dataBuffer, dataOffset, timeoutTicks);
seg.send(tcp);
if (!seg.isAckOnly() && !hdr.isFlagSynchronizeSet()) {
- log.debug("Adding segment " + seg.getSeqNr() + " to unacklist");
+ if (DEBUG) {
+ log.debug("Adding segment " + seg.getSeqNr() + " to unacklist");
+ }
unackedSegments.add(seg);
}
}
Modified: trunk/net/src/net/org/jnode/net/ipv4/tcp/TCPOutSegment.java
===================================================================
--- trunk/net/src/net/org/jnode/net/ipv4/tcp/TCPOutSegment.java 2008-06-15 09:44:26 UTC (rev 4240)
+++ trunk/net/src/net/org/jnode/net/ipv4/tcp/TCPOutSegment.java 2008-06-15 12:50:44 UTC (rev 4241)
@@ -18,12 +18,11 @@
* along with this library; If not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-
+
package org.jnode.net.ipv4.tcp;
import java.net.SocketException;
-
import org.apache.log4j.Logger;
import org.jnode.net.SocketBuffer;
import org.jnode.net.ipv4.IPv4Header;
@@ -32,17 +31,24 @@
* @author Ewout Prangsma (ep...@us...)
*/
public class TCPOutSegment extends TCPSegment {
+ private static final boolean DEBUG = false;
- /** My logger */
+ /**
+ * My logger
+ */
private static final Logger log = Logger.getLogger(TCPOutSegment.class);
-
+
private final TCPDataBuffer buffer;
private int dataOffset;
-
- /** Timeout counter, if 0, re-transmit */
+
+ /**
+ * Timeout counter, if 0, re-transmit
+ */
private int timeout;
-
- /** Number of timeout ticks (usually grows) */
+
+ /**
+ * Number of timeout ticks (usually grows)
+ */
private int timeoutTicks;
/**
@@ -51,7 +57,7 @@
* @param dataOffset
*/
public TCPOutSegment(IPv4Header ipHdr, TCPHeader hdr, TCPDataBuffer buffer, int dataOffset,
- int timeout) {
+ int timeout) {
super(ipHdr, hdr);
this.buffer = buffer;
this.dataOffset = dataOffset;
@@ -65,7 +71,9 @@
public void timeout(TCPProtocol tcp) throws SocketException {
timeout--;
if (timeout == 0) {
- log.debug("Resend segment " + getSeqNr());
+ if (DEBUG) {
+ log.debug("Resend segment " + getSeqNr());
+ }
send(tcp);
timeoutTicks = timeoutTicks * 2;
timeout = timeoutTicks;
@@ -74,7 +82,7 @@
/**
* Send this segment
- *
+ *
* @param tcp
*/
public void send(TCPProtocol tcp) throws SocketException {
@@ -102,6 +110,7 @@
/**
* Does this segment only contain an ACK?
+ *
* @return True if this segment contains only an acknowledgment, false otherwise
*/
public boolean isAckOnly() {
Modified: trunk/net/src/net/org/jnode/net/ipv4/tcp/TCPProtocol.java
===================================================================
--- trunk/net/src/net/org/jnode/net/ipv4/tcp/TCPProtocol.java 2008-06-15 09:44:26 UTC (rev 4240)
+++ trunk/net/src/net/org/jnode/net/ipv4/tcp/TCPProtocol.java 2008-06-15 12:50:44 UTC (rev 4241)
@@ -18,7 +18,7 @@
* along with this library; If not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-
+
package org.jnode.net.ipv4.tcp;
import java.io.IOException;
@@ -31,7 +31,6 @@
import java.security.AccessController;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
-
import org.apache.log4j.Logger;
import org.jnode.driver.net.NetworkException;
import org.jnode.net.SocketBuffer;
@@ -46,31 +45,44 @@
* @author epr
*/
public class TCPProtocol implements IPv4Protocol, IPv4Constants, TCPConstants {
+ private static final boolean DEBUG = false;
- /** The IP service I'm a part of */
+ /**
+ * The IP service I'm a part of
+ */
private final IPv4Service ipService;
/** The ICMP service */
// private final ICMPUtils icmp;
-
- /** My statistics */
+
+ /**
+ * My statistics
+ */
private final TCPStatistics stat = new TCPStatistics();
- /** The SocketImpl factory for TCP */
+ /**
+ * The SocketImpl factory for TCP
+ */
private final TCPSocketImplFactory socketImplFactory;
- /** My control blocks */
+ /**
+ * My control blocks
+ */
private final TCPControlBlockList controlBlocks;
- /** The timer */
+ /**
+ * The timer
+ */
private final TCPTimer timer;
- /** My logger */
+ /**
+ * My logger
+ */
private static final Logger log = Logger.getLogger(TCPProtocol.class);
/**
* Initialize a new instance
- *
+ *
* @param ipService
*/
public TCPProtocol(IPv4Service ipService) throws NetworkException {
@@ -156,19 +168,23 @@
skbuf.trim(hdr.getDataLength());
if (!hdr.isChecksumOk()) {
- if (log.isDebugEnabled()) {
- log.debug("Receive: badsum: " + hdr);
+ if (DEBUG) {
+ if (log.isDebugEnabled()) {
+ log.debug("Receive: badsum: " + hdr);
+ }
}
stat.badsum.inc();
} else {
- if (log.isDebugEnabled()) {
- log.debug("Receive: " + hdr);
+ if (DEBUG) {
+ if (log.isDebugEnabled()) {
+ log.debug("Receive: " + hdr);
+ }
}
// Find the corresponding control block
final TCPControlBlock cb =
- (TCPControlBlock) controlBlocks.lookup(ipHdr.getSource(), hdr.getSrcPort(),
- ipHdr.getDestination(), hdr.getDstPort(), true);
+ (TCPControlBlock) controlBlocks.lookup(ipHdr.getSource(), hdr.getSrcPort(),
+ ipHdr.getDestination(), hdr.getDstPort(), true);
if (cb == null) {
final boolean ack = hdr.isFlagAcknowledgeSet();
final boolean rst = hdr.isFlagResetSet();
@@ -178,8 +194,7 @@
// Port unreachable
if (ack && rst) {
// the source is also unreachable
- log
- .debug("Dropping segment due to: connection refused as the source is also unreachable");
+ log.debug("Dropping segment due to: connection refused as the source is also unreachable");
} else {
processPortUnreachable(ipHdr, hdr);
}
@@ -200,13 +215,13 @@
/**
* Process a segment whose destination port is unreachable
- *
+ *
* @param hdr
*/
private void processPortUnreachable(IPv4Header ipHdr, TCPHeader hdr) throws SocketException {
final TCPHeader replyHdr =
- new TCPHeader(hdr.getDstPort(), hdr.getSrcPort(), 0, 0, hdr.getSequenceNr() + 1, 0,
- 0);
+ new TCPHeader(hdr.getDstPort(), hdr.getSrcPort(), 0, 0, hdr.getSequenceNr() + 1, 0,
+ 0);
replyHdr.setFlags(TCPF_ACK | TCPF_RST);
final IPv4Header replyIpHdr = new IPv4Header(ipHdr);
replyIpHdr.swapAddresses();
@@ -215,7 +230,7 @@
/**
* Create a binding for a local address
- *
+ *
* @param lAddr
* @param lPort
*/
@@ -225,13 +240,15 @@
/**
* Send an TCP packet
- *
+ *
* @param skbuf
*/
protected void send(IPv4Header ipHdr, TCPHeader tcpHdr, SocketBuffer skbuf)
throws SocketException {
- if (log.isDebugEnabled()) {
- log.debug("send(ipHdr, " + tcpHdr + ")");
+ if (DEBUG) {
+ if (log.isDebugEnabled()) {
+ log.debug("send(ipHdr, " + tcpHdr + ")");
+ }
}
skbuf.setTransportLayerHeader(tcpHdr);
tcpHdr.prefixTo(skbuf);
Modified: trunk/net/src/net/org/jnode/net/ipv4/tcp/TCPSocketImpl.java
===================================================================
--- trunk/net/src/net/org/jnode/net/ipv4/tcp/TCPSocketImpl.java 2008-06-15 09:44:26 UTC (rev 4240)
+++ trunk/net/src/net/org/jnode/net/ipv4/tcp/TCPSocketImpl.java 2008-06-15 12:50:44 UTC (rev 4241)
@@ -18,7 +18,7 @@
* along with this library; If not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-
+
package org.jnode.net.ipv4.tcp;
import java.io.IOException;
@@ -30,7 +30,6 @@
import java.net.SocketException;
import java.net.SocketImpl;
import java.net.SocketOptions;
-
import org.apache.log4j.Logger;
import org.jnode.net.ipv4.IPv4Address;
@@ -38,6 +37,7 @@
* @author epr
*/
public class TCPSocketImpl extends SocketImpl {
+ private static final boolean DEBUG = false;
/**
* The protocol I'm using
@@ -66,7 +66,7 @@
/**
* Initialize a new instance
- *
+ *
* @param protocol
*/
public TCPSocketImpl(TCPProtocol protocol) {
@@ -75,23 +75,31 @@
/**
* Accepts a connection on this socket.
- *
+ *
* @param s The implementation object for the accepted connection.
* @see java.net.SocketImpl#accept(java.net.SocketImpl)
*/
protected void accept(SocketImpl s) throws IOException {
- log.debug("accept " + s);
+ if (DEBUG) {
+ log.debug("accept " + s);
+ }
if (controlBlock == null) {
throw new IOException("Not listening");
}
final TCPSocketImpl impl = (TCPSocketImpl) s;
- log.debug("accept: blocking");
+ if (DEBUG) {
+ log.debug("accept: blocking");
+ }
impl.controlBlock = controlBlock.appAccept();
- log.debug("accept: got one");
+ if (DEBUG) {
+ log.debug("accept: got one");
+ }
}
protected int getLocalPort() {
- log.debug("getLocalPort: controlBlock.getLocalPort()");
+ if (DEBUG) {
+ log.debug("getLocalPort: controlBlock.getLocalPort()");
+ }
return controlBlock.getLocalPort();
}
@@ -195,7 +203,7 @@
return 0;
default:
throw new SocketException("Option " + option_id +
- " is not recognised or not implemented");
+ " is not recognised or not implemented");
}
}
@@ -217,7 +225,7 @@
* how many pending connections will queue up waiting to be serviced before
* being accept'ed. If the queue of pending requests exceeds this number,
* additional connections will be refused.
- *
+ *
* @param backlog The length of the pending connection queue
* @throws IOException If an error occurs
* @see java.net.SocketImpl#listen(int)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|