}
public void run()
{
EventHandler handler = new EventHandler();
Buffer buffer = newBuffer(DEFAULT_TCP_MESSAGE);
SipParser parser = new SipParser(buffer, this, handler);
try
{
connectionOpened(this);
SipMessage message = null;
while (isStarted() && !isClosed())
{
int size = DEFAULT_TCP_MESSAGE;
boolean overflow = false;
do
{
overflow = false;
try
{
parser.parse();
size = DEFAULT_TCP_MESSAGE;
parser.setBuffer(newBuffer(size));
}
catch (BufferOverflowException e)
{
//System.out.println("Overflow");
overflow = true;
size = size * 2;
if (size > MAX_TCP_MESSAGE)
throw new IOException("Message too large");
Buffer extended = newBuffer(size);
parser.setBuffer(extended, true);
}
}
while (overflow);