Imported GNU Classpath 0.19 + gcj-import-20051115.

* sources.am: Regenerated.
       * Makefile.in: Likewise.
       * scripts/makemake.tcl: Use glob -nocomplain.

From-SVN: r107049
This commit is contained in:
Mark Wielaard
2005-11-15 23:20:01 +00:00
parent 02e549bfaa
commit 8f523f3a10
1241 changed files with 97711 additions and 25284 deletions
@@ -40,8 +40,9 @@ package gnu.CORBA;
import java.net.Socket;
import java.net.SocketException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
/**
* This class caches the opened sockets that are reused during the
@@ -56,9 +57,10 @@ public class SocketRepository
* The socket map.
*/
private static HashMap sockets = new HashMap();
/**
* Put a socket.
* Put a socket. This method also discards all not reusable sockets from
* the map.
*
* @param key as socket key.
*
@@ -66,7 +68,41 @@ public class SocketRepository
*/
public static void put_socket(Object key, Socket s)
{
sockets.put(key, s);
synchronized (sockets)
{
sockets.put(key, s);
gc();
}
}
/**
* Removes all non reusable sockets. As it is private,
* we know we call from the synchronized code already.
*/
private static void gc()
{
Iterator iter = sockets.entrySet().iterator();
Map.Entry e;
Socket sx;
while (iter.hasNext())
{
e = (Map.Entry) iter.next();
sx = (Socket) e.getValue();
if (not_reusable(sx))
iter.remove();
}
}
/**
* Return true if the socket is no longer reusable.
*/
static boolean not_reusable(Socket s)
{
return (s.isClosed() || !s.isBound() || !s.isConnected() ||
s.isInputShutdown() || s.isOutputShutdown());
}
/**
@@ -75,31 +111,41 @@ public class SocketRepository
* @param key a socket key.
*
* @return an opened socket for reuse, null if no such available or it is
* closed.
* closed, its input or output has been shutown or otherwise the socket is not
* reuseable.
*/
public static Socket get_socket(Object key)
{
Socket s = (Socket) sockets.get(key);
if (s == null)
if (true)
return null;
else if (s.isClosed())
synchronized (sockets)
{
sockets.remove(key);
return null;
}
else
{
sockets.remove(key);
try
Socket s = (Socket) sockets.get(key);
if (s == null)
return null;
// Ensure that the socket is fully reusable.
else if (not_reusable(s))
{
// Set one minute time out that will be changed later.
s.setSoTimeout(60*1000);
sockets.remove(key);
return null;
}
catch (SocketException e)
else
{
s = null;
try
{
// Set one minute time out that will be changed later.
s.setSoTimeout(60 * 1000);
}
catch (SocketException e)
{
s = null;
}
sockets.remove(key);
return s;
}
return s;
}
}
}