-fixed race condition in notification about new data available for reading

- default MTU set to 1450
This commit is contained in:
paweldomas 2012-08-16 12:00:32 +00:00
parent 02a9f7e7af
commit 757aef02d4
2 changed files with 52 additions and 15 deletions

View File

@ -793,7 +793,7 @@ public class PseudoTCPBase
long now = Now(); long now = Now();
byte[] buffer = new byte[MAX_PACKET]; byte[] buffer = new byte[HEADER_SIZE + (int)len];
long_to_bytes(m_conv, buffer, 0); long_to_bytes(m_conv, buffer, 0);
long_to_bytes(seq, buffer, 4); long_to_bytes(seq, buffer, 4);
long_to_bytes(m_rcv_nxt, buffer, 8); long_to_bytes(m_rcv_nxt, buffer, 8);
@ -844,6 +844,39 @@ public class PseudoTCPBase
return WriteResult.WR_SUCCESS; return WriteResult.WR_SUCCESS;
} }
/**
* Method can be used in some debugging utilities
*/
public static String parseSeg(byte[] buffer, int size)
{
if (size < 12)
{
return null;
}
Segment seg = new Segment();
seg.conv = bytes_to_long(buffer, 0);
seg.seq = bytes_to_long(buffer, 4);
seg.ack = bytes_to_long(buffer, 8);
seg.flags = buffer[13];
seg.wnd = bytes_to_short(buffer, 14);
seg.tsval = bytes_to_long(buffer, 16);
seg.tsecr = bytes_to_long(buffer, 20);
seg.data = copy_buffer(buffer, HEADER_SIZE, size - HEADER_SIZE);
seg.len = size - HEADER_SIZE;
String data="data: ";
for(byte b : seg.data)
{
data += b;
}
return "segment " + "<CONV=" + seg.conv + "><FLG=" + seg.flags
+ "><SEQ=" + seg.seq + ":" + (seg.seq + seg.len) + "><ACK=" + seg.ack
+ "><WND=" + seg.wnd + "><TS=" + seg.tsval
+ "><TSR=" + seg.tsecr + "><LEN=" + seg.len + "> "+data;
}
/** /**
* Creates new segment from the data in <tt>buffer</tt> which is processed * Creates new segment from the data in <tt>buffer</tt> which is processed
* by the protocol. * by the protocol.
@ -952,9 +985,11 @@ public class PseudoTCPBase
//if ((seg.flags & FLAG_RST) == 0) { //if ((seg.flags & FLAG_RST) == 0) {
// packet(tcb, seg.ack, 0, FLAG_RST, 0, 0); // packet(tcb, seg.ack, 0, FLAG_RST, 0, 0);
//} //}
closedown(new IOException( //closedown(new IOException(
debugName + " wrong conversation number, this: " + m_conv // debugName + " wrong conversation number, this: " + m_conv
+ " remote: " + seg.conv)); // + " remote: " + seg.conv));
logger.info(debugName + " wrong conversation number, this: " + m_conv
+ " remote: " + seg.conv);
return false; return false;
} }

View File

@ -20,7 +20,7 @@ public class PseudoTcpSocketImpl
* The logger. * The logger.
*/ */
private static final java.util.logging.Logger logger = private static final java.util.logging.Logger logger =
java.util.logging.Logger.getLogger(PseudoTCPBase.class.getName()); java.util.logging.Logger.getLogger(PseudoTcpSocketImpl.class.getName());
/** /**
* Pseudotcp logic instance * Pseudotcp logic instance
*/ */
@ -84,6 +84,8 @@ public class PseudoTcpSocketImpl
public PseudoTcpSocketImpl(long conv_id, DatagramSocket sock) public PseudoTcpSocketImpl(long conv_id, DatagramSocket sock)
{ {
pseudoTcp = new PseudoTCPBase(this, conv_id); pseudoTcp = new PseudoTCPBase(this, conv_id);
//Default MTU
setMTU(1450);
this.socket = sock; this.socket = sock;
} }
@ -411,7 +413,7 @@ public class PseudoTcpSocketImpl
{ {
logger.log( logger.log(
Level.FINER, Level.FINER,
"TCP READABLE data available for reading: "); "TCP READABLE data available for reading: "+tcp.GetAvailable());
read_notify.notifyAll(); read_notify.notifyAll();
} }
} }
@ -768,6 +770,10 @@ public class PseudoTcpSocketImpl
while (true) while (true)
{ {
logger.log(Level.FINER, "Read Recv"); logger.log(Level.FINER, "Read Recv");
try
{
synchronized (read_notify)
{
read = pseudoTcp.Recv(buffer, offset, length); read = pseudoTcp.Recv(buffer, offset, length);
if (logger.isLoggable(Level.FINER)) if (logger.isLoggable(Level.FINER))
{ {
@ -777,10 +783,6 @@ public class PseudoTcpSocketImpl
{ {
return read; return read;
} }
try
{
synchronized (read_notify)
{
logger.log(Level.FINER, "Read wait for data available"); logger.log(Level.FINER, "Read wait for data available");
read_notify.wait(); read_notify.wait();
if (logger.isLoggable(Level.FINER)) if (logger.isLoggable(Level.FINER))