diff -r --ignore-space --new-file JacORB.orig/src/org/jacorb/orb/iiop/ClientIIOPConnection.java JacORB/src/org/jacorb/orb/iiop/ClientIIOPConnection.java
125a126,143
> 			final IIOPLoopback loopback = getLocalLoopback() ;
> 			if (loopback != null)
> 			{
> 				final IIOPLoopbackInputStream lis = new IIOPLoopbackInputStream() ;
> 				final IIOPLoopbackOutputStream los = new IIOPLoopbackOutputStream() ;
> 				
> 				loopback.initLoopback(lis, los) ;
> 				
> 				in_stream = lis ;
> 				out_stream = los ;
> 				
>                 connected = true;
> 				
>                 //for testing purposes
>                 ++openTransports;
> 			}
> 			else
> 			{
192d209
< 
205a223,246
>     }
> 	
> 	private IIOPLoopback getLocalLoopback()
> 	{
> 		final IIOPProfile iiopProfile = (IIOPProfile)profile ;
>         final List addressList = new ArrayList() ;
>         addressList.add(iiopProfile.getAddress());
>         addressList.addAll(iiopProfile.getAlternateAddresses());
> 		
> 		final Iterator addressIterator = addressList.iterator() ;
> 		final IIOPLoopbackRegistry registry = IIOPLoopbackRegistry.getRegistry() ;
> 		
> 		while(addressIterator.hasNext())
> 		{
> 			final IIOPAddress address = (IIOPAddress)addressIterator.next() ;
> 			final IIOPLoopback loopback = registry.getLoopback(address) ;
> 			if (loopback != null)
> 			{
> 				return loopback ;
> 			}
> 		}
> 		
> 		return null ;
> 	}
344c385
<             if (connected && socket != null)
---
>             if (connected)
346c387,388
<                 socket.close ();
---
> 				if (socket != null)
> 					socket.close();
diff -r --ignore-space --new-file JacORB.orig/src/org/jacorb/orb/iiop/IIOPListener.java JacORB/src/org/jacorb/orb/iiop/IIOPListener.java
65a66
>     private LoopbackAcceptor loopbackAcceptor ;
148a150,151
> 		loopbackAcceptor = new LoopbackAcceptor() ;
> 
170a174,175
> 		
> 		loopbackAcceptor.start() ;
179a185,186
> 		loopbackAcceptor.terminate() ;
> 		
560a568,591
> 	private class LoopbackAcceptor implements IIOPLoopback
> 	{
> 		public void start()
> 		{
> 			IIOPLoopbackRegistry.getRegistry().register(getAddress(), this) ;
> 		}
> 		
> 		public void terminate()
> 		{
> 			IIOPLoopbackRegistry.getRegistry().unregister(getAddress()) ;
> 		}
> 		
> 		public void initLoopback(final IIOPLoopbackInputStream lis, final IIOPLoopbackOutputStream los)
> 		{
> 			final IIOPLoopbackConnection connection = new IIOPLoopbackConnection(lis, los) ;
> 			deliverConnection(connection) ;
> 		}
> 		
> 		private IIOPAddress getAddress()
> 		{
> 			final IIOPProfile profile = (IIOPProfile)IIOPListener.this.endpoint ;
> 			return profile.getAddress() ;
> 		}
> 	}
diff -r --ignore-space --new-file JacORB.orig/src/org/jacorb/orb/iiop/IIOPLoopbackConnection.java JacORB/src/org/jacorb/orb/iiop/IIOPLoopbackConnection.java
0a1,61
> 
> package org.jacorb.orb.iiop;
> 
> import java.io.IOException;
> 
> import org.omg.CORBA.INITIALIZE;
> import org.omg.ETF.Profile;
> 
> public class IIOPLoopbackConnection
>     extends org.jacorb.orb.etf.StreamConnectionBase
> {
> 	IIOPLoopbackConnection(final IIOPLoopbackInputStream lis, final IIOPLoopbackOutputStream los)
> 	{
> 		try
> 		{
> 			in_stream = new IIOPLoopbackInputStream(los) ;
> 			out_stream = new IIOPLoopbackOutputStream(lis) ;
> 			connected = true ;
> 		}
> 		catch (final IOException ioe)
> 		{
>             throw new INITIALIZE("Could not create loopback pipe connection");
> 		}
> 	}
> 	
> 	public void close()
> 	{
> 		try
> 		{
> 	        if(in_stream != null)
> 	        {
> 	            in_stream.close();
> 	        }
> 	
> 	        if(out_stream != null)
> 	        {
> 	            out_stream.close();
> 	        }
> 		}
>         catch (final IOException ioe)
>         {
>             throw to_COMM_FAILURE(ioe);
>         }
> 	}
> 	
> 	protected void setTimeout(final int timeout)
> 	{
> 		// Can't handle timeout
> 	}
> 	
> 	protected int getTimeout()
> 	{
> 		// Can't handle timeout
> 		return 0;
> 	}
> 	
> 	public void connect(final Profile server_profile, final long time_out)
> 	{
> 		// Can't handle reconnect
> 	}
> }
diff -r --ignore-space --new-file JacORB.orig/src/org/jacorb/orb/iiop/IIOPLoopbackInputStream.java JacORB/src/org/jacorb/orb/iiop/IIOPLoopbackInputStream.java
0a1,223
> package org.jacorb.orb.iiop;
> 
> import java.io.IOException;
> import java.io.InputStream;
> 
> class IIOPLoopbackInputStream extends InputStream
> {
> 	private static final int BUF_SIZE = 2048 ;
> 	
> 	private final byte[] buf = new byte[BUF_SIZE] ;
> 	
> 	private boolean connected ;
> 	private boolean closed ;
> 	private int writerIndex ;
> 	private int readerIndex ;
> 	
> 	IIOPLoopbackInputStream()
> 	{
> 	}
> 	
> 	IIOPLoopbackInputStream(final IIOPLoopbackOutputStream los)
> 		throws IOException
> 	{
> 		connect(los) ;
> 	}
> 	
> 	synchronized void connect(final IIOPLoopbackOutputStream los)
> 		throws IOException
> 	{
> 		if (connected)
> 		{
> 			throw new IOException("Alread connected") ;
> 		}
> 		connected = true ;
> 		los.connect(this) ;
> 	}
> 	
> 	public synchronized int read()
> 		throws IOException
> 	{
> 		checkConnect() ;
> 		return internalRead() ;
> 	}
> 
> 	public synchronized int read(final byte[] b, final int off, final int len)
> 		throws IOException
> 	{
> 		checkConnect() ;
> 		checkBuffer(b, off, len) ;
> 		
> 		int returnCount = 0 ;
> 		
> 		while(returnCount < len)
> 		{
> 			final int val = internalRead() ;
> 			if (val == -1)
> 			{
> 				break ;
> 			}
> 			b[off + returnCount] = (byte)val ;
> 			returnCount++ ;
> 		}
> 		
> 		return (returnCount > 0 ? returnCount : -1) ;
> 	}
> 
> 	public synchronized int available()
> 		throws IOException
> 	{
> 		checkConnect() ;
> 		
> 		if (writerIndex > readerIndex)
> 		{
> 			return (writerIndex - readerIndex) ;
> 		}
> 		else if (readerIndex > writerIndex)
> 		{
> 			return BUF_SIZE + writerIndex - readerIndex ;
> 		}
> 		else
> 		{
> 			checkClosed() ;
> 			return 0 ;
> 		}
> 	}
> 
> 	public synchronized void close()
> 		throws IOException
> 	{
> 		checkConnect() ;
> 		closed = true ;
> 		notifyAll() ;
> 	}
> 
> 	synchronized void writerClose()
> 		throws IOException
> 	{
> 		checkConnect() ;
> 		closed = true ;
> 		notifyAll() ;
> 	}
> 	
> 	synchronized void writeIntoBuffer(final int b)
> 		throws IOException
> 	{
> 		checkConnect() ;
> 		internalWrite((byte)b) ;
> 	}
> 	
> 	synchronized void writeIntoBuffer(final byte[] b, final int off, final int len)
> 		throws IOException
> 	{
> 		checkConnect() ;
> 		checkBuffer(b, off, len) ;
> 		
> 		for(int count= 0 ; count < len ; count++)
> 		{
> 			internalWrite(b[off + count]) ;
> 		}
> 	}
> 	
> 	private int internalRead()
> 	{
> 		while(bufferEmpty())
> 		{
> 			if (closed)
> 			{
> 				return -1 ;
> 			}
> 			try
> 			{
> 				wait() ;
> 			}
> 			catch (final InterruptedException ie) {} // Ignore
> 		}
> 		
> 		final boolean shouldNotify = bufferFull() ;
> 		
> 		final int val = buf[readerIndex] & 0xff ;
> 		readerIndex = nextIndex(readerIndex) ;
> 		
> 		if (shouldNotify)
> 		{
> 			notifyAll() ;
> 		}
> 		
> 		return val ;
> 	}
> 	
> 	private void internalWrite(final byte b)
> 		throws IOException
> 	{
> 		while(bufferFull())
> 		{
> 			checkClosed() ;
> 			try
> 			{
> 				wait() ;
> 			}
> 			catch (final InterruptedException ie) {} // Ignore
> 		}
> 		
> 		checkClosed() ;
> 		
> 		final boolean shouldNotify = bufferEmpty() ;
> 		
> 		buf[writerIndex] = b ;
> 		writerIndex = nextIndex(writerIndex) ;
> 		
> 		if (shouldNotify)
> 		{
> 			notifyAll() ;
> 		}
> 	}
> 	
> 	private void checkConnect()
> 		throws IOException
> 	{
> 		if (!connected)
> 		{
> 			throw new IOException("IIOPLoopbackInputStream not connected") ;
> 		}
> 	}
> 	
> 	private void checkClosed()
> 		throws IOException
> 	{
> 		if (closed)
> 		{
> 			throw new IOException("IIOPLoopbackInputStream closed") ;
> 		}
> 	}
> 	
> 	private void checkBuffer(final byte[] b, final int off, final int len)
> 	{
> 		if (b == null)
> 		{
> 			throw new NullPointerException("Null buffer") ;
> 		}
> 		
> 		final int bufLen = b.length ;
> 		if ((off < 0) || (off >= bufLen) || (len < 0) || (len > bufLen) || (off + len > bufLen))
> 		{
> 			throw new IndexOutOfBoundsException("Invalid offset/length") ;
> 		}
> 	}
> 	
> 	private boolean bufferEmpty()
> 	{
> 		return (readerIndex == writerIndex) ;
> 	}
> 	
> 	private boolean bufferFull()
> 	{
> 		return (readerIndex == nextIndex(writerIndex)) ;
> 	}
> 	
> 	private int nextIndex(final int index)
> 	{
> 		final int nextIndex = index+1 ;
> 		return (nextIndex == BUF_SIZE ? 0 : nextIndex) ;
> 	}
> }
diff -r --ignore-space --new-file JacORB.orig/src/org/jacorb/orb/iiop/IIOPLoopback.java JacORB/src/org/jacorb/orb/iiop/IIOPLoopback.java
0a1,6
> package org.jacorb.orb.iiop;
> 
> public interface IIOPLoopback
> {
> 	public void initLoopback(final IIOPLoopbackInputStream pis, final IIOPLoopbackOutputStream pos) ;
> }
diff -r --ignore-space --new-file JacORB.orig/src/org/jacorb/orb/iiop/IIOPLoopbackOutputStream.java JacORB/src/org/jacorb/orb/iiop/IIOPLoopbackOutputStream.java
0a1,55
> package org.jacorb.orb.iiop;
> 
> import java.io.IOException;
> import java.io.OutputStream;
> 
> class IIOPLoopbackOutputStream extends OutputStream
> {
> 	private IIOPLoopbackInputStream lis ;
> 	
> 	IIOPLoopbackOutputStream()
> 	{
> 	}
> 	
> 	IIOPLoopbackOutputStream(final IIOPLoopbackInputStream lis)
> 		throws IOException
> 	{
> 		lis.connect(this) ;
> 	}
> 	
> 	public synchronized void write(final byte[] b, final int off, final int len)
> 		throws IOException
> 	{
> 		checkConnect() ;
> 		lis.writeIntoBuffer(b, off, len) ;
> 	}
> 	
> 	public synchronized void write(final int b)
> 		throws IOException
> 	{
> 		checkConnect() ;
> 		lis.writeIntoBuffer(b) ;
> 	}
> 	
> 	public synchronized void close()
> 		throws IOException
> 	{
> 		checkConnect() ;
> 		lis.writerClose() ;
> 	}
> 	
> 	synchronized void connect(final IIOPLoopbackInputStream lis)
> 		throws IOException
> 	{
> 		this.lis = lis ;
> 	}
> 	
> 	private void checkConnect()
> 		throws IOException
> 	{
> 		if (lis == null)
> 		{
> 			throw new IOException("IIOPLoopbackOutputStream not connected") ;
> 		}
> 	}
> }
diff -r --ignore-space --new-file JacORB.orig/src/org/jacorb/orb/iiop/IIOPLoopbackRegistry.java JacORB/src/org/jacorb/orb/iiop/IIOPLoopbackRegistry.java
0a1,33
> package org.jacorb.orb.iiop;
> 
> import java.util.HashMap;
> import java.util.Map;
> 
> import org.jacorb.orb.IIOPAddress;
> 
> public class IIOPLoopbackRegistry
> {
> 	private static final IIOPLoopbackRegistry REGISTRY = new IIOPLoopbackRegistry() ;
> 	
> 	private final Map loopbackMap = new HashMap() ;
> 	
> 	public static IIOPLoopbackRegistry getRegistry()
> 	{
> 		return REGISTRY ;
> 	}
> 	
> 	public synchronized void register(final IIOPAddress address, final IIOPLoopback loopback)
> 	{
> 		loopbackMap.put(address, loopback) ;
> 	}
> 	
> 	public synchronized void unregister(final IIOPAddress address)
> 	{
> 		loopbackMap.remove(address) ;
> 	}
> 	
> 	public synchronized IIOPLoopback getLoopback(final IIOPAddress address)
> 	{
> 		return (IIOPLoopback)loopbackMap.get(address) ;
> 	}
> }
