mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-10-27 11:57:38 +00:00
Add file descriptor limit
This commit is contained in:
@@ -123,6 +123,7 @@ public class ComputerCraft
|
|||||||
|
|
||||||
public static int computerSpaceLimit = 1000 * 1000;
|
public static int computerSpaceLimit = 1000 * 1000;
|
||||||
public static int floppySpaceLimit = 125 * 1000;
|
public static int floppySpaceLimit = 125 * 1000;
|
||||||
|
public static int maximumFilesOpen = 128;
|
||||||
|
|
||||||
// Blocks and Items
|
// Blocks and Items
|
||||||
public static class Blocks
|
public static class Blocks
|
||||||
|
|||||||
@@ -290,8 +290,8 @@ public class FileSystem
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<String, MountWrapper> m_mounts = new HashMap<String, MountWrapper>();
|
private final Map<String, MountWrapper> m_mounts = new HashMap<String, MountWrapper>();
|
||||||
private Set<IMountedFile> m_openFiles = new HashSet<IMountedFile>();
|
private final Set<IMountedFile> m_openFiles = new HashSet<IMountedFile>();
|
||||||
|
|
||||||
public FileSystem( String rootLabel, IMount rootMount ) throws FileSystemException
|
public FileSystem( String rootLabel, IMount rootMount ) throws FileSystemException
|
||||||
{
|
{
|
||||||
@@ -649,6 +649,33 @@ public class FileSystem
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private synchronized IMountedFile openFile( IMountedFile file ) throws FileSystemException
|
||||||
|
{
|
||||||
|
synchronized( m_openFiles )
|
||||||
|
{
|
||||||
|
if( m_openFiles.size() >= 4 )
|
||||||
|
{
|
||||||
|
throw new FileSystemException("Too many files already open");
|
||||||
|
}
|
||||||
|
|
||||||
|
m_openFiles.add( file );
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private synchronized void closeFile( IMountedFile file, Closeable handle ) throws IOException
|
||||||
|
{
|
||||||
|
synchronized( m_openFiles )
|
||||||
|
{
|
||||||
|
m_openFiles.remove( file );
|
||||||
|
|
||||||
|
if( handle != null )
|
||||||
|
{
|
||||||
|
handle.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public synchronized IMountedFileNormal openForRead( String path ) throws FileSystemException
|
public synchronized IMountedFileNormal openForRead( String path ) throws FileSystemException
|
||||||
{
|
{
|
||||||
@@ -684,11 +711,7 @@ public class FileSystem
|
|||||||
@Override
|
@Override
|
||||||
public void close() throws IOException
|
public void close() throws IOException
|
||||||
{
|
{
|
||||||
synchronized( m_openFiles )
|
closeFile( this, reader );
|
||||||
{
|
|
||||||
m_openFiles.remove( this );
|
|
||||||
reader.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -697,11 +720,7 @@ public class FileSystem
|
|||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
synchronized( m_openFiles )
|
return (IMountedFileNormal) openFile( file );
|
||||||
{
|
|
||||||
m_openFiles.add( file );
|
|
||||||
}
|
|
||||||
return file;
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -744,11 +763,7 @@ public class FileSystem
|
|||||||
@Override
|
@Override
|
||||||
public void close() throws IOException
|
public void close() throws IOException
|
||||||
{
|
{
|
||||||
synchronized( m_openFiles )
|
closeFile( this, writer );
|
||||||
{
|
|
||||||
m_openFiles.remove( this );
|
|
||||||
writer.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -757,11 +772,7 @@ public class FileSystem
|
|||||||
writer.flush();
|
writer.flush();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
synchronized( m_openFiles )
|
return (IMountedFileNormal) openFile( file );
|
||||||
{
|
|
||||||
m_openFiles.add( file );
|
|
||||||
}
|
|
||||||
return file;
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -790,11 +801,7 @@ public class FileSystem
|
|||||||
@Override
|
@Override
|
||||||
public void close() throws IOException
|
public void close() throws IOException
|
||||||
{
|
{
|
||||||
synchronized( m_openFiles )
|
closeFile( this, stream );
|
||||||
{
|
|
||||||
m_openFiles.remove( this );
|
|
||||||
stream.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -803,11 +810,7 @@ public class FileSystem
|
|||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
synchronized( m_openFiles )
|
return (IMountedFileBinary) openFile( file );
|
||||||
{
|
|
||||||
m_openFiles.add( file );
|
|
||||||
}
|
|
||||||
return file;
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -836,11 +839,7 @@ public class FileSystem
|
|||||||
@Override
|
@Override
|
||||||
public void close() throws IOException
|
public void close() throws IOException
|
||||||
{
|
{
|
||||||
synchronized( m_openFiles )
|
closeFile( this, stream );
|
||||||
{
|
|
||||||
m_openFiles.remove( this );
|
|
||||||
stream.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -849,11 +848,7 @@ public class FileSystem
|
|||||||
stream.flush();
|
stream.flush();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
synchronized( m_openFiles )
|
return (IMountedFileBinary) openFile( file );
|
||||||
{
|
|
||||||
m_openFiles.add( file );
|
|
||||||
}
|
|
||||||
return file;
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user