1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-06-25 22:53:22 +00:00

Add file descriptor limit

This commit is contained in:
Lignum 2017-05-02 00:05:42 +02:00
parent 1b562ae837
commit 2d0690e625
No known key found for this signature in database
GPG Key ID: E4DE8F54CA0912BA
2 changed files with 38 additions and 42 deletions

View File

@ -123,6 +123,7 @@ public class ComputerCraft
public static int computerSpaceLimit = 1000 * 1000;
public static int floppySpaceLimit = 125 * 1000;
public static int maximumFilesOpen = 128;
// Blocks and Items
public static class Blocks

View File

@ -290,8 +290,8 @@ private String toLocal( String path )
}
}
private Map<String, MountWrapper> m_mounts = new HashMap<String, MountWrapper>();
private Set<IMountedFile> m_openFiles = new HashSet<IMountedFile>();
private final Map<String, MountWrapper> m_mounts = new HashMap<String, MountWrapper>();
private final Set<IMountedFile> m_openFiles = new HashSet<IMountedFile>();
public FileSystem( String rootLabel, IMount rootMount ) throws FileSystemException
{
@ -649,6 +649,33 @@ private synchronized void copyRecursive( String sourcePath, MountWrapper sourceM
}
}
}
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
{
@ -684,11 +711,7 @@ public void write(String s, int off, int len, boolean newLine) throws IOExceptio
@Override
public void close() throws IOException
{
synchronized( m_openFiles )
{
m_openFiles.remove( this );
reader.close();
}
closeFile( this, reader );
}
@Override
@ -697,11 +720,7 @@ public void flush() throws IOException
throw new UnsupportedOperationException();
}
};
synchronized( m_openFiles )
{
m_openFiles.add( file );
}
return file;
return (IMountedFileNormal) openFile( file );
}
return null;
}
@ -744,11 +763,7 @@ public void write( String s, int off, int len, boolean newLine ) throws IOExcept
@Override
public void close() throws IOException
{
synchronized( m_openFiles )
{
m_openFiles.remove( this );
writer.close();
}
closeFile( this, writer );
}
@Override
@ -757,11 +772,7 @@ public void flush() throws IOException
writer.flush();
}
};
synchronized( m_openFiles )
{
m_openFiles.add( file );
}
return file;
return (IMountedFileNormal) openFile( file );
}
return null;
}
@ -790,11 +801,7 @@ public void write(int i) throws IOException
@Override
public void close() throws IOException
{
synchronized( m_openFiles )
{
m_openFiles.remove( this );
stream.close();
}
closeFile( this, stream );
}
@Override
@ -803,11 +810,7 @@ public void flush() throws IOException
throw new UnsupportedOperationException();
}
};
synchronized( m_openFiles )
{
m_openFiles.add( file );
}
return file;
return (IMountedFileBinary) openFile( file );
}
return null;
}
@ -836,11 +839,7 @@ public void write(int i) throws IOException
@Override
public void close() throws IOException
{
synchronized( m_openFiles )
{
m_openFiles.remove( this );
stream.close();
}
closeFile( this, stream );
}
@Override
@ -849,11 +848,7 @@ public void flush() throws IOException
stream.flush();
}
};
synchronized( m_openFiles )
{
m_openFiles.add( file );
}
return file;
return (IMountedFileBinary) openFile( file );
}
return null;
}