Skip to content

Commit

Permalink
Throw error when reaching internal file descriptor limit
Browse files Browse the repository at this point in the history
and add corresponding notes to the documentation
  • Loading branch information
zickgraf authored and fingolfin committed Oct 26, 2022
1 parent 3cc456e commit e0fc6d7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
8 changes: 8 additions & 0 deletions lib/streams.gd
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,10 @@ DeclareOperation( "InputTextString", [ IsString ] );
## handles windows-style line endings. This means it should <E>not</E> be used for
## binary data. The <Ref BookName="IO" Oper="IO_File" /> function from the <Package>IO</Package>
## package should be used to access binary data.
## <P/>
## Note: At most 256 files may be open for reading or writing at the same time.
## Use <Ref Oper="CloseStream"/> to close the input stream once you have finished
## reading from it.
## </Description>
## </ManSection>
## <#/GAPDoc>
Expand Down Expand Up @@ -751,6 +755,10 @@ DeclareOperation( "OutputTextString", [ IsList, IsBool ] );
## <C>OutputGzipFile</C> acts identically to <C>OutputTextFile</C>, except it compresses
## the output with gzip.
## <P/>
## Note: At most 256 files may be open for reading or writing at the same time.
## Use <Ref Oper="CloseStream"/> to close the output stream once you have finished
## writing to it.
## <P/>
## <Example><![CDATA[
## gap> # use a temporary directory
## gap> name := Filename( DirectoryTemporary(), "test" );;
Expand Down
1 change: 1 addition & 0 deletions src/sysfiles.c
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,7 @@ Int SyFopen(const Char * name, const Char * mode, BOOL transparent_compress)

if ( fid == ARRAY_SIZE(syBuf) ) {
HashUnlock(&syBuf);
ErrorReturnVoid("Too many open files (internal file descriptor limit reached)", 0, 0, "you can 'return;'");
return (Int)-1;
}

Expand Down
10 changes: 9 additions & 1 deletion tst/testinstall/streams.tst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#@local dir,fname,file,line,stream,tmpdir,res
#@local dir,fname,file,line,stream,tmpdir,res,streams,i
gap> START_TEST("streams.tst");

#
Expand Down Expand Up @@ -209,5 +209,13 @@ Error, <byte> must an integer between 0 and 255
gap> SetPrintFormattingStatus(stream, fail);
Error, Print formatting status must be true or false

# too many open files
gap> streams := [ ];;
gap> for i in [ 1 .. 300 ] do
> Add( streams, OutputTextFile( fname, false ) );
> od;;
Error, Too many open files (internal file descriptor limit reached)
gap> Perform( streams, CloseStream );

#
gap> STOP_TEST( "streams.tst", 1);

0 comments on commit e0fc6d7

Please sign in to comment.