Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Asynchronous IO API #9111

Open
wants to merge 313 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
313 commits
Select commit Hold shift + click to select a range
580f776
more tests for FileSystem
RealyUniqueName Jul 17, 2020
e57545b
disable null safety for now
RealyUniqueName Jul 17, 2020
8f02df1
Merge branch 'development' into feature/asys-low
RealyUniqueName Jul 17, 2020
f4dda4e
Merge branch 'development' into feature/asys-low
RealyUniqueName Jul 17, 2020
6458d33
more FileSystem API adjustments
RealyUniqueName Jul 17, 2020
9c83e75
[php] wip FileSystem
RealyUniqueName Jul 17, 2020
dcfbaff
more tests for FileSystem
RealyUniqueName Jul 17, 2020
936c930
more API changes
RealyUniqueName Jul 23, 2020
84aef80
[php] more implementations
RealyUniqueName Jul 23, 2020
43f6c72
[tests] more tests
RealyUniqueName Jul 23, 2020
401d9aa
update tests
RealyUniqueName Jul 23, 2020
8fd663a
update API; implement FileInfo methods
RealyUniqueName Jul 28, 2020
180add3
[php] more implementations
RealyUniqueName Jul 28, 2020
4f397ab
tweak API; implement FilePermissions
RealyUniqueName Jul 28, 2020
022bfbd
[php] more implementations
RealyUniqueName Jul 28, 2020
20f1efe
more tests
RealyUniqueName Jul 28, 2020
eaaf491
Merge branch 'development' into feature/asys-low
RealyUniqueName Jul 28, 2020
9614e2f
update docs
RealyUniqueName Jul 31, 2020
8f37b5d
[php] more implementations
RealyUniqueName Jul 31, 2020
ffd59cc
more tests
RealyUniqueName Jul 31, 2020
ef027fd
added `assertType` for easier exceptions checking
RealyUniqueName Jul 31, 2020
266bebf
Merge branch 'development' into feature/asys-low
RealyUniqueName Jul 31, 2020
5330bc0
api changes
RealyUniqueName Jul 31, 2020
71776a9
[php] FileSystem.setOwner, setLinkOwner
RealyUniqueName Jul 31, 2020
7416471
test setOwner, setLinkOwner
RealyUniqueName Jul 31, 2020
8872dde
reorganize filesystem tests; test FilePermissions
RealyUniqueName Jul 31, 2020
7a5ca23
File API changes
RealyUniqueName Aug 1, 2020
8a8d1cc
[php] open & read files
RealyUniqueName Aug 1, 2020
8bb9d7c
test open & read files
RealyUniqueName Aug 1, 2020
96ab60d
update docs
RealyUniqueName Aug 2, 2020
ba4c7da
[php] File.write
RealyUniqueName Aug 2, 2020
dae6680
more tests
RealyUniqueName Aug 2, 2020
0e1334e
renamed C* enums to Posix*
RealyUniqueName Aug 2, 2020
9301927
update API
RealyUniqueName Aug 2, 2020
b66f66f
[php] File.seek
RealyUniqueName Aug 2, 2020
74a4051
more tests
RealyUniqueName Aug 2, 2020
5511e1b
Merge branch 'development' into feature/asys-low
RealyUniqueName Aug 2, 2020
e8b246f
update doc
RealyUniqueName Aug 2, 2020
75cf546
test openf file with AppendRead
RealyUniqueName Aug 2, 2020
9148470
minor API fix
RealyUniqueName Aug 3, 2020
07f3dc5
more tests
RealyUniqueName Aug 3, 2020
4ce4420
test the rest of FileOpenFlag
RealyUniqueName Aug 3, 2020
45c4c58
update API
RealyUniqueName Aug 3, 2020
4e30483
[php] finished File API
RealyUniqueName Aug 3, 2020
97330c0
more tests for File and FileSystem
RealyUniqueName Aug 3, 2020
beb4ffe
update filesystem-related API
RealyUniqueName Aug 4, 2020
3fc50f1
[php] finished filesystem API implementations
RealyUniqueName Aug 4, 2020
041a73f
finished filesystem tests
RealyUniqueName Aug 4, 2020
ca9e9ff
minor
RealyUniqueName Aug 5, 2020
c42766e
Merge branch 'development' into feature/asys-low
RealyUniqueName Aug 5, 2020
a96dc4e
[api] added `position` to File.read and File.write, removed File.seek…
RealyUniqueName Aug 6, 2020
43a27e0
[php] updated to API changes
RealyUniqueName Aug 6, 2020
2861895
[tests] updated to API changes
RealyUniqueName Aug 6, 2020
af998c8
added haxe.IJobExecutor
RealyUniqueName Aug 9, 2020
4457b8c
[php] changed FileSystem implementation to IJobExecutor
RealyUniqueName Aug 9, 2020
931e44e
Merge branch 'development' into feature/asys-low
RealyUniqueName Aug 12, 2020
831b002
asys.native.Native
RealyUniqueName Aug 13, 2020
8432a91
update IJobExecutor API
RealyUniqueName Aug 13, 2020
2d1b18a
[php] align to API changes
RealyUniqueName Aug 13, 2020
7c913b4
[java] default job executor implementation
RealyUniqueName Aug 13, 2020
5b0cb1a
[java] setup for tests
RealyUniqueName Aug 13, 2020
b7f4dcc
remove @:coreType from FilePath
RealyUniqueName Aug 16, 2020
4bd0ac5
[php] update FilePath
RealyUniqueName Aug 16, 2020
ff2b2b9
move FilePath.real to FileSystem.realPath
RealyUniqueName Aug 17, 2020
e3d00b6
wip
RealyUniqueName Aug 17, 2020
aaa44b6
removed FilePath.toReadableString()
RealyUniqueName Aug 19, 2020
808f9e2
[tests] minor tweaks
RealyUniqueName Aug 19, 2020
7b543bb
removed Bytes-related API from FilePath
RealyUniqueName Aug 20, 2020
7575b72
[java] FilePath impl
RealyUniqueName Aug 20, 2020
839952c
Merge branch 'development' into feature/asys-low
RealyUniqueName Aug 20, 2020
3d28329
update docs
RealyUniqueName Aug 21, 2020
4349e07
[java] wip FileSystem
RealyUniqueName Aug 21, 2020
1beafae
minor FilePath API tweaks
RealyUniqueName Aug 24, 2020
18b2cca
[php] update to API changes
RealyUniqueName Aug 24, 2020
5b66b9e
[java] wip, threading issues
RealyUniqueName Aug 24, 2020
5d03e9d
wip
RealyUniqueName Aug 26, 2020
e37b7ac
Merge branch 'development' into feature/asys-low
RealyUniqueName Aug 27, 2020
cd1394e
wip
RealyUniqueName Aug 27, 2020
0a8b45f
[wip] per-thread event loop
RealyUniqueName Aug 28, 2020
24bba6c
Merge branch 'development' into feature/asys-low
RealyUniqueName Sep 9, 2020
71bbcd1
[php] fixed FileSystem.resize
RealyUniqueName Sep 9, 2020
c09f17c
[java] update for new event loop API; implemented some methods in Fil…
RealyUniqueName Sep 10, 2020
b756fca
minor
RealyUniqueName Sep 10, 2020
b66edbc
bring back SystemUser & SystemGroup
RealyUniqueName Sep 10, 2020
4c4665e
[api] use native representation for FileInfo & FilePermissions
RealyUniqueName Sep 11, 2020
5652e95
update tests
RealyUniqueName Sep 11, 2020
1b36e3e
[java] SystemUser, SystemGroup, FileInfo, FIlePermissions
RealyUniqueName Sep 11, 2020
29fda31
update API
RealyUniqueName Sep 16, 2020
d582be8
[java] more implementations
RealyUniqueName Sep 16, 2020
4963144
changed FileSystem.move to fail on non-empty directories
RealyUniqueName Sep 17, 2020
ece2f4e
[java] TestFileSystem passes
RealyUniqueName Sep 17, 2020
7a219c4
cleanup
RealyUniqueName Sep 18, 2020
6279c32
[php] use the same job executor in File and Directory as in FileSystem
RealyUniqueName Sep 21, 2020
cb24d1d
update API
RealyUniqueName Sep 22, 2020
50e1dd9
[php] update to new API
RealyUniqueName Sep 22, 2020
0fd3116
[java] finished "filesystem" package
RealyUniqueName Sep 22, 2020
e08df8e
minor
RealyUniqueName Sep 24, 2020
e7ddb73
removed PosixErrorCode
RealyUniqueName Sep 24, 2020
4eb31d7
minor
RealyUniqueName Sep 24, 2020
c0c90a4
[eval] job executors for interp & macro
RealyUniqueName Sep 24, 2020
ad97119
[eval] FilePath implementation
RealyUniqueName Sep 25, 2020
314e243
[eval] fix job executor
RealyUniqueName Sep 25, 2020
6997bd5
[eval] NativeString, Unix
RealyUniqueName Sep 25, 2020
e8c5670
[eval] FilePath
RealyUniqueName Sep 25, 2020
69a1a79
[eval] started FileSystem implementation
RealyUniqueName Sep 25, 2020
d051e6c
minor API updates
RealyUniqueName Sep 29, 2020
e917437
[eval] FileSystem implementation
RealyUniqueName Sep 29, 2020
f4d8ec5
removed eval.Unix
RealyUniqueName Nov 2, 2020
9bef794
Merge branch 'development' into feature/asys-low
RealyUniqueName Nov 2, 2020
313e10a
API update
RealyUniqueName Nov 2, 2020
fc7d9c3
[eval] use `haxe.NoData` instead of `eval.luv.Result.NoData`
RealyUniqueName Nov 5, 2020
397feba
wip
RealyUniqueName Nov 5, 2020
caba39a
Merge branch 'development' into feature/asys-low
RealyUniqueName Nov 5, 2020
51081fe
split FilePermissions into FileMode and FilePermissions
RealyUniqueName Nov 5, 2020
4b6a9f3
[eval] FileSystem wip
RealyUniqueName Nov 5, 2020
aa4f91e
Merge branch 'development' into feature/asys-low
RealyUniqueName Nov 5, 2020
6a8ff20
added FilePath.isAbsolute() and .parent()
RealyUniqueName Nov 6, 2020
dc91b13
[eval] FileSystem wip
RealyUniqueName Nov 6, 2020
fe50e61
Merge branch 'development' into feature/asys-low
RealyUniqueName Nov 6, 2020
ade2e12
Merge branch 'development' into feature/asys-low
RealyUniqueName Nov 9, 2020
326f712
[eval] rework FilePath
RealyUniqueName Nov 9, 2020
50d7df7
[eval] finished FileSystem
RealyUniqueName Nov 9, 2020
05fee34
wip
RealyUniqueName Nov 9, 2020
4791d82
[api] added Directory.nextBatch
RealyUniqueName Nov 10, 2020
f970e78
[php][java] Directory.nextBatch
RealyUniqueName Nov 10, 2020
7c0418f
[eval] Directory implementation
RealyUniqueName Nov 10, 2020
6c8f03e
[eval] wip File
RealyUniqueName Nov 10, 2020
a40009d
Merge branch 'development' into feature/asys-low
RealyUniqueName Nov 11, 2020
4fb6726
[eval] wip File
RealyUniqueName Nov 11, 2020
b8058af
Merge branch 'development' into feature/asys-low
RealyUniqueName Nov 11, 2020
df49828
[api] commented out `File.lock` for now
RealyUniqueName Nov 11, 2020
17a3096
[eval] File implementation
RealyUniqueName Nov 11, 2020
1fb3324
Merge branch 'development' into feature/asys-low
RealyUniqueName Nov 11, 2020
ce835c2
[api] dropped IJobExecutor idea
RealyUniqueName Nov 12, 2020
55db9c1
[php] refactor away IJobExecutor
RealyUniqueName Nov 12, 2020
f48b0e9
[eval] refactor away IJobExecutor
RealyUniqueName Nov 12, 2020
ea9d852
Merge branch 'development' into feature/asys-low
RealyUniqueName Nov 14, 2020
199edb7
cleanup
RealyUniqueName Nov 14, 2020
dfef01f
IThreadPool.runFor(task, callback)
RealyUniqueName Nov 14, 2020
3128cbc
[jvm] refactor away IJovExecutor
RealyUniqueName Nov 14, 2020
bad08ff
[java] fixes for genjava
RealyUniqueName Nov 14, 2020
be0dd33
Merge branch 'development' into feature/asys-low
RealyUniqueName Mar 24, 2021
b7c3be5
update runci scripts
RealyUniqueName Mar 24, 2021
fabffbc
[java] update to Rest args changes
RealyUniqueName Mar 24, 2021
274dc5f
[neko] FilePath
RealyUniqueName Mar 26, 2021
0159e08
[java][php] update FilePath
RealyUniqueName Mar 26, 2021
4ab3792
changed spec of FilePath.parent(); more tests
RealyUniqueName Mar 27, 2021
ab4a805
[neko][java][php][eval] update FilePath
RealyUniqueName Mar 27, 2021
e5f270e
update TestFileSystem
RealyUniqueName Mar 28, 2021
e5209e1
[neko] wip FileSystem
RealyUniqueName Mar 28, 2021
b9d0148
[neko] wip FileSystem
RealyUniqueName Mar 29, 2021
0c8e93c
[php] fixed FilePath.parent('.hidden')
RealyUniqueName Mar 29, 2021
f5a433a
[tests] minor
RealyUniqueName Mar 29, 2021
e5eda19
[api] update FilePath doc
RealyUniqueName Mar 29, 2021
6f50fb2
[neko] minor tweak
RealyUniqueName Mar 29, 2021
1b9c7d7
[lua] update runci
RealyUniqueName Mar 29, 2021
5f3bb53
[lua] FilePath
RealyUniqueName Mar 29, 2021
c556ec5
[lua] wip FileSystem
RealyUniqueName Mar 29, 2021
1afb5f4
Merge branch 'development' into feature/asys-low
RealyUniqueName Mar 29, 2021
78ab5db
automatically insert a call to luv.Loop.run if "luv" module is loaded
RealyUniqueName Mar 30, 2021
65ce2ee
[lua] wip FileSystem
RealyUniqueName Mar 30, 2021
c4ffb96
Merge branch 'development' into feature/asys-low
RealyUniqueName Mar 30, 2021
748716f
Merge branch 'feature/lua-libuv-loop-autorun' into feature/asys-low
RealyUniqueName Mar 31, 2021
f3d4139
minor
RealyUniqueName Mar 31, 2021
bfcc2ae
[lua] FileSystem
RealyUniqueName Mar 31, 2021
f20025e
Merge branch 'development' into feature/asys-low
RealyUniqueName Mar 31, 2021
3f7e629
Merge branch 'development' into feature/asys-low
RealyUniqueName Apr 1, 2021
35791f1
minor
RealyUniqueName Apr 1, 2021
25956d1
[lua] finished FileSystem
RealyUniqueName Apr 1, 2021
e7bfaaf
added IoErrorType.BadFile
RealyUniqueName Apr 1, 2021
f99a505
minor
RealyUniqueName Apr 1, 2021
fa9ac44
[lua] File
RealyUniqueName Apr 1, 2021
2e0701f
changed Directory API
RealyUniqueName Apr 1, 2021
251297e
[java] update Directory
RealyUniqueName Apr 1, 2021
d2b7680
[eval] update Directory
RealyUniqueName Apr 1, 2021
1eedbad
update tests
RealyUniqueName Apr 1, 2021
ca773c8
[lua] File, Directory
RealyUniqueName Apr 1, 2021
c4bebb9
Merge branch 'development' into feature/asys-low
RealyUniqueName Apr 1, 2021
7055bc5
[php] update Directory
RealyUniqueName Apr 2, 2021
92affbd
tests for relative paths like `C:relative\path`
RealyUniqueName Apr 2, 2021
3f16220
[php] fixed handling of `C:relative\path` paths for windows
RealyUniqueName Apr 2, 2021
0cdbefc
[eva] fixed fixed handling of `C:relative\path` paths for windows
RealyUniqueName Apr 2, 2021
06ec4c6
more tests for FilePath
RealyUniqueName Apr 2, 2021
b9091a8
minor
RealyUniqueName Apr 2, 2021
fb8429c
[eva] another fix for `C:relative\path` paths on windows
RealyUniqueName Apr 2, 2021
6072e3d
minor doc update
RealyUniqueName Apr 2, 2021
e50d655
minor
RealyUniqueName Apr 2, 2021
03a1542
[cs] added asys tests to runci
RealyUniqueName Apr 2, 2021
80f0c63
[cs] FilePath
RealyUniqueName Apr 2, 2021
4aac2ec
minor
RealyUniqueName Apr 2, 2021
44e6dd6
[cs] wip FIleSystem
RealyUniqueName Apr 2, 2021
ac01d37
[neko] update Filesystem.openDirectory signature
RealyUniqueName Apr 3, 2021
4d06473
fix for docgen
RealyUniqueName Apr 3, 2021
dd09821
[tests] OS-independent path comparison
RealyUniqueName Apr 4, 2021
cec9ce9
fix FsTest.equalPaths for null paths
RealyUniqueName Apr 5, 2021
19cefdf
fixed test for FilePath.absolute('C:relative\\path')
RealyUniqueName Apr 5, 2021
53b8c3a
[php] fixed FIlePath.absolute('C:relative/path')
RealyUniqueName Apr 5, 2021
37d43b6
[eval] fixed FilePath.parent('C:\\')
RealyUniqueName Apr 5, 2021
8195b7c
reworked FilePath API
RealyUniqueName Apr 7, 2021
327fb85
[php] update FilePath
RealyUniqueName Apr 7, 2021
28aedbe
fix FilePath tests
RealyUniqueName Apr 8, 2021
21d67e0
[php] update FilePath
RealyUniqueName Apr 8, 2021
8dac027
[java] update FilePath
RealyUniqueName Apr 8, 2021
ab65ff5
more fixes of tests for FIlePath
RealyUniqueName Apr 8, 2021
12c94b9
[php] fixes for FilePath
RealyUniqueName Apr 8, 2021
f5fdfab
[lua] wip FIlePath update
RealyUniqueName Apr 12, 2021
30e139f
[lua] update FilePath to the latest API changes
RealyUniqueName May 10, 2021
e21eb28
[eval] update FilePath to the latest API changes
RealyUniqueName May 10, 2021
b89809c
Merge branch 'development' into feature/asys-low
RealyUniqueName May 10, 2021
080b0d4
Merge branch 'development' into feature/asys-low
RealyUniqueName May 17, 2021
aab4a1f
[neko] FilePath
RealyUniqueName May 17, 2021
4852133
[neko] FileSystem wip
RealyUniqueName May 17, 2021
9eb580a
[neko] FileSystem
RealyUniqueName May 18, 2021
24e8067
[neko] wip File
RealyUniqueName May 19, 2021
cb6c31d
Merge branch 'development' into feature/asys-low
RealyUniqueName Jun 25, 2021
8e61d9c
[python] FilePath
RealyUniqueName Jul 8, 2021
fec3edf
[python] FileSystem
RealyUniqueName Jul 13, 2021
17c3872
[python] File
RealyUniqueName Jul 14, 2021
69e2ae1
[python] various fixes; Directory
RealyUniqueName Jul 15, 2021
ab0b4d8
[java] fix tests by a workaround for java keywords in package names
RealyUniqueName Jul 15, 2021
f1a2ce4
[php][win] fixed FilePath
RealyUniqueName Nov 6, 2021
4181691
update FilePath tests
RealyUniqueName Nov 6, 2021
0ac7edc
fixed TestFileSystem.testRealPath
RealyUniqueName Nov 6, 2021
f80e1d7
Merge branch 'development' into feature/asys-low
RealyUniqueName Nov 6, 2021
34cc20c
update tests for windows
RealyUniqueName Nov 7, 2021
1a70905
[php] windows fixes
RealyUniqueName Nov 7, 2021
b03a919
Merge branch 'development' into feature/asys-low
RealyUniqueName Nov 7, 2021
81cdbc6
typo
RealyUniqueName Nov 7, 2021
397f1ff
[cs][wip] rework FilePath
RealyUniqueName Nov 16, 2021
ff60d1b
[cs] FilePath
RealyUniqueName Nov 18, 2021
e4142bf
[cs] FileSystem: writeString, writeBytes
RealyUniqueName Nov 18, 2021
c8e08ce
added FilePath.name() method
RealyUniqueName Nov 21, 2021
d1d9821
[cs][wip] FileSystem
RealyUniqueName Nov 21, 2021
48f5893
[cs][wip] FileSystem
RealyUniqueName Nov 22, 2021
9be5fe5
[cs][wip] FileSystem
RealyUniqueName Nov 22, 2021
f8a0688
[cs] finished FileSystem
RealyUniqueName Nov 23, 2021
ec53b36
[cs] Directory
RealyUniqueName Nov 23, 2021
6d65189
[cs] fix Directory
RealyUniqueName Nov 24, 2021
05208cb
[cs] File
RealyUniqueName Nov 24, 2021
0a60ecd
Merge branch 'development' into feature/asys-low
RealyUniqueName Nov 24, 2021
d017435
[hl] I64.ofInt
RealyUniqueName Dec 7, 2021
976a884
[hl] FilePath
RealyUniqueName Dec 7, 2021
7871ed3
[hl] FileSystem
RealyUniqueName Dec 7, 2021
bcf3252
[hl] File
RealyUniqueName Dec 7, 2021
6452f7d
[hl] Directory
RealyUniqueName Dec 7, 2021
e394eb9
Merge branch 'development' into feature/asys-low
Simn Apr 11, 2022
cf746f2
fixes
Simn Apr 11, 2022
8e20456
Update tests/runci/targets/Php.hx
Simn Apr 12, 2022
44d1891
Merge branch 'development' into feature/asys-low
Simn Apr 12, 2022
900dd50
Merge branch 'development' into feature/asys-low
Simn Nov 18, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
438 changes: 438 additions & 0 deletions std/asyncio/CErrNo.hx

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions std/asyncio/IDuplex.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package asyncio;

import haxe.NoData;
RealyUniqueName marked this conversation as resolved.
Show resolved Hide resolved
import haxe.io.Bytes;
import haxe.Callback;

/**
An interface to read and write bytes.
If a class has to implement both `IReadable` and `IWritable` it is strongly
recommended to implement `IDuplex` instead.
**/
interface IDuplex extends IReadable extends IWritable {}
21 changes: 21 additions & 0 deletions std/asyncio/IReadable.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package asyncio;

import haxe.NoData;
import haxe.io.Bytes;
import haxe.Callback;

/**
An interface to read bytes from a source of bytes.
**/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps something like a (strictly advisory) prepare(size:Int) method would make sense?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean? from Int to Int?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RealyUniqueName I assume that comment was a reply to something else?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps something like a (strictly advisory) prepare(size:Int) method would make sense?

I don't know. Sounds like an implementation-specific.

interface IReadable {
/**
Read up to `length` bytes and write them into `buffer` starting from `offset`
position in `buffer`, then invoke `callback` with the amount of bytes read.
**/
function read(buffer:Bytes, offset:Int, length:Int, callback:Callback<Int>):Void;

/**
Close this stream.
**/
function close(callback:Callback<NoData>):Void;
}
26 changes: 26 additions & 0 deletions std/asyncio/IWritable.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package asyncio;

import haxe.NoData;
import haxe.io.Bytes;
import haxe.Callback;

/**
An interface to write bytes into an out-going stream of bytes.
**/
interface IWritable {
RealyUniqueName marked this conversation as resolved.
Show resolved Hide resolved
/**
Write up to `length` bytes from `buffer` (starting from buffer `offset`),
then invoke `callback` with the amount of bytes written.
**/
function write(buffer:Bytes, offset:Int, length:Int, callback:Callback<Int>):Void;

/**
Force all buffered data to be committed.
**/
function flush(callback:Callback<NoData>):Void;

/**
Close this stream.
**/
function close(callback:Callback<NoData>):Void;
}
17 changes: 17 additions & 0 deletions std/asyncio/IoError.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package asyncio;

import asyncio.IoErrorType;
import haxe.Error;
import haxe.PosInfos;

class IoError extends Error {
/**
Error type
**/
public final type:IoErrorType;

public function new(type:IoErrorType, ?pos:PosInfos) {
super(type.toString(), pos);
this.type = type;
}
}
80 changes: 80 additions & 0 deletions std/asyncio/IoErrorType.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package asyncio;

import asyncio.CErrNo;

/**
Error types
**/
@:using(asyncio.IoErrorType.IoErrorTypeTools)
enum IoErrorType {
/** File or directory not found */
FileNotFound;
/** File or directory already exist */
FileExists;
/** No such process */
ProcessNotFound;
/** Permission denied */
AccessDenied;
/** The given path was not a directory as expected */
NotDirectory;
/** The given path is a directory, but a file was expected */
IsDirectory;
/** Too many open files */
TooManyOpenFiles;
/** Broken pipe */
BrokenPipe;
/** Directory not empty */
NotEmpty;
/** Requested address is not available */
AddressNotAvailable;
/** Connection reset by peer */
ConnectionReset;
/** Operation timed out */
TimedOut;
/** Connection refused */
ConnectionRefused;
/** Other errors from system calls described in <error.h> */
CError(errNo:CErrNo);
/** Any other error */
CustomError(message:String);
}

class IoErrorTypeTools {
/**
Error type description
**/
static public function toString(type:IoErrorType):String {
return switch type {
case FileNotFound:
"File or directory not found";
case FileExists:
"File or directory already exists";
case ProcessNotFound:
"No such process";
case AccessDenied:
"Permission denied";
case NotDirectory:
"The given path was not a directory as expected";
case IsDirectory:
"The given path is a directory, but a file was expected";
case TooManyOpenFiles:
"Too many open files";
case BrokenPipe:
"Broken pipe";
case NotEmpty:
"Directory not empty";
case AddressNotAvailable:
"Address already in use";
case ConnectionReset:
"Connection reset by peer";
case TimedOut:
"Operation timed out";
case ConnectionRefused:
"Connection refused";
case CError(errNo):
errNo.toString();
case CustomError(message):
message;
}
}
}
17 changes: 17 additions & 0 deletions std/asyncio/Stream.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package asyncio;

import asyncio.IDuplex;
import asyncio.IReadable;
import asyncio.IWritable;

/**
Enum which is used to stay type-safe when a stream can be of any type.
**/
enum Stream {
/** Read-only stream. */
Read(stream:IReadable);
/** Write-only stream. */
Write(stream:IWritable);
/** The stream is both readable and writable. */
ReadWrite(stream:IDuplex);
}
39 changes: 39 additions & 0 deletions std/asyncio/filesystem/Directory.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package asyncio.filesystem;

import haxe.NoData;
import haxe.errors.NotImplemented;
import haxe.Callback;

/**
Represents a directory.
**/
class Directory {
/**
Path to this directory.
**/
public final path:FilePath;
/**
How many entries are buffered internally when reading from the directory.
Higher numbers improve performance, but increase memory usage.
**/
public var buffer:Int = 32;

//TODO: this is a dummy constructor to make the compiler shut up about uninitialized finals.
function new() {
path = cast null;
}

/**
Read next directory entry.
**/
public function next(callback:Callback<Null<FilePath>>):Void {
callback.fail(new NotImplemented());
}

/**
Close the directory.
**/
public function close(callback:Callback<NoData>) {
callback.fail(new NotImplemented());
}
}
101 changes: 101 additions & 0 deletions std/asyncio/filesystem/File.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package asyncio.filesystem;

import haxe.Int64;
import haxe.io.Bytes;
import haxe.NoData;
import haxe.Callback;
import haxe.errors.NotImplemented;
import asyncio.IWritable;
import asyncio.IReadable;

class File implements IDuplex {
RealyUniqueName marked this conversation as resolved.
Show resolved Hide resolved
/**
Path to this file.
**/
public final path:FilePath;

//TODO: this is a dummy constructor to make the compiler shut up about uninitialized finals.
function new() {
path = cast null;
}

/**
Change file position pointer.
The pointer position is used in read and write operations as the starting byte
of reading or writing respectively.

If `whence` is `SeekSet(offset)` set the pointer to the exact position
specified by `offset`.
If `whence` is `SeekEnd` move the pointer to the end-of-file.
If `whence` is `SeekMove(offset)` move the pointer by `offset` bytes
relative to the current position.
**/
public function seek(whence:FileSeek) {
throw new NotImplemented();
}

/**
Get current position pointer offset.
**/
public function getOffset():Int64 {
throw new NotImplemented();
}

/**
Write up to `length` bytes from `buffer` (starting from buffer `offset`),
then invoke `callback` with the amount of bytes written.
**/
public function write(buffer:Bytes, offset:Int, length:Int, callback:Callback<Int>) {
callback.fail(new NotImplemented());
}

/**
Read up to `length` bytes and write them into `buffer` starting from `offset`
position in `buffer`, then invoke `callback` with the amount of bytes read.
**/
public function read(buffer:Bytes, offset:Int, length:Int, callback:Callback<Int>) {
callback.fail(new NotImplemented());
}

/**
Force all buffered data to be written to disk.
**/
public function flush(callback:Callback<NoData>) {
callback.fail(new NotImplemented());
}

/**
Synchronize file in-memory state with the storage device.
**/
public function sync(callback:Callback<NoData>) {
callback.fail(new NotImplemented());
}

/**
Close the file.
**/
public function close(callback:Callback<NoData>) {
callback.fail(new NotImplemented());
}
}

/**
Limits file operations to reading.
@see asyncio.filesystem.File
**/
@:forward(path,seek,read,close)
abstract FileRead(File) from File to IReadable {}

/**
Limits file operations to writing.
@see asyncio.filesystem.File
**/
@:forward(path,seek,write,flush,sync,close)
abstract FileWrite(File) from File to IWritable {}

/**
Limits file operations to writing at the end of file.
@see asyncio.filesystem.File
**/
@:forward(path,write,flush,sync,close)
abstract FileAppend(File) from File to IWritable {}
Loading