* messages until we are done or the other end has closed.
*/
public void run() {
Pipeline hispipe = null;
// Create a pipeline to connect to our message parser.
hispipe = new Pipeline(myClientInputStream, sipStack.readTimeout,
((SIPTransactionStack) sipStack).getTimer());
// Create a pipelined message parser to read and parse
// messages that we write out to him.
myParser = new PipelinedMsgParser(sipStack, this, hispipe,
this.sipStack.getMaxMessageSize());
// Start running the parser thread.
myParser.processInput();
// bug fix by Emmanuel Proulx
int bufferSize = 4096;
this.tcpMessageProcessor.useCount++;
this.isRunning = true;
try {
while (true) {
try {
byte[] msg = new byte[bufferSize];
int nbytes = myClientInputStream.read(msg, 0, bufferSize);
// no more bytes to read...
if (nbytes == -1) {
hispipe.write("\r\n\r\n".getBytes("UTF-8"));
try {
if (sipStack.maxConnections != -1) {
synchronized (tcpMessageProcessor) {
tcpMessageProcessor.nConnections--;
tcpMessageProcessor.notify();
}
}
hispipe.close();
if (mySock != null) { // self routing makes sock =
// ull
// https://jain-sip.dev.java.net/issues/show_bug.cgi?id=297
if (sipStack.isLoggingEnabled(LogWriter.TRACE_DEBUG))
sipStack.getStackLogger().logDebug(
"Closing socket");
mySock.close();
}
} catch (IOException ioex) {
}
return;
}
hispipe.write(msg, 0, nbytes);
} catch (IOException ex) {
// Terminate the message.
try {
hispipe.write("\r\n\r\n".getBytes("UTF-8"));
} catch (Exception e) {
// InternalErrorHandler.handleException(e);
}
try {
if (sipStack.isLoggingEnabled(LogWriter.TRACE_DEBUG))
sipStack.getStackLogger().logDebug(
"IOException closing sock " + ex);
try {
if (sipStack.maxConnections != -1) {
synchronized (tcpMessageProcessor) {
tcpMessageProcessor.nConnections--;
// System.out.println("Notifying!");
tcpMessageProcessor.notify();
}
}
if (mySock != null) { // self routing makes sock =
// null
// https://jain-sip.dev.java.net/issues/show_bug.cgi?id=297
if (sipStack.isLoggingEnabled(LogWriter.TRACE_DEBUG))
sipStack.getStackLogger().logDebug(
"Closing socket");
mySock.close();
}
hispipe.close();
} catch (IOException ioex) {
}
} catch (Exception ex1) {
// Do nothing.
}