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 all 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
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,8 @@
],
"url": "./.vscode/schemas/meta.schema.json"
}
],
"haxe.configurations": [
["--cwd", "tests/asys", "build.hxml"]
]
}
2 changes: 0 additions & 2 deletions src/macro/eval/evalHash.ml
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,12 @@ let key_sys_net_Lock = hash "sys.thread.Lock"
let key_sys_net_Tls = hash "sys.thread.Tls"
let key_sys_net_Deque = hash "sys.thread.Deque"
let key_sys_thread_EventLoop = hash "sys.thread.EventLoop"

let key_mbedtls_Config = hash "mbedtls.Config"
let key_mbedtls_CtrDrbg = hash "mbedtls.CtrDrbg"
let key_mbedtls_Entropy = hash "mbedtls.Entropy"
let key_mbedtls_PkContext = hash "mbedtls.PkContext"
let key_mbedtls_Ssl = hash "mbedtls.Ssl"
let key_mbedtls_X509Crt = hash "mbedtls.X509Crt"

let key_eval_luv_Result = hash "eval.luv.Result"
let key_eval_luv_LuvException = hash "eval.luv.LuvException"
let key_eval_luv_ReceiveHandle = hash "eval.luv.ReceiveHandle"
Expand Down
11 changes: 11 additions & 0 deletions std/asys/native/IDuplex.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package asys.native;

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

/**
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 {}
22 changes: 22 additions & 0 deletions std/asys/native/IReadable.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package asys.native;

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

/**
An interface to read bytes from a source of bytes.
**/
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<Exception,Int>):Void;

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

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

/**
An interface to write bytes into an out-going stream of bytes.
**/
interface IWritable {
/**
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<Exception,Int>):Void;

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

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

/**
Error types.

TODO: add more error types
**/
@:using(asys.native.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;
/** Bad file descriptor */
BadFile;
/** 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 BadFile:
"Bad file descriptor";
case CustomError(message):
message;
}
}
}
16 changes: 16 additions & 0 deletions std/asys/native/IoException.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package asys.native;

import asys.native.IoErrorType;
import haxe.Exception;

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

public function new(type:IoErrorType, ?previous:Exception) {
super(type.toString(), previous);
this.type = type;
}
}
17 changes: 17 additions & 0 deletions std/asys/native/Stream.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package asys.native;

import asys.native.IDuplex;
import asys.native.IReadable;
import asys.native.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);
}
4 changes: 4 additions & 0 deletions std/asys/native/filesystem/Callback.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package asys.native.filesystem;

//TODO: remove after https://github.com/HaxeFoundation/haxe-evolution/pull/50 is implemented
typedef Callback<R> = haxe.Callback<haxe.Exception,R>;
38 changes: 38 additions & 0 deletions std/asys/native/filesystem/Directory.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package asys.native.filesystem;

import haxe.NoData;
import haxe.exceptions.NotImplementedException;

/**
Represents a directory.
**/
@:coreApi
class Directory {
/** The path of this directory as it was at the moment of opening the directory */
public final path:FilePath;

function new() {
path = 'stub';
}

/**
Read next batch of directory entries.
Passes an empty array to `callback` if no more entries left to read.
Ignores `.` and `..` entries.

The size of the array is always equal to or less than `maxBatchSize` value used
for opening this directory.

@see asys.native.filesystem.FileSystem.openDirectory
**/
public function next(callback:Callback<Array<FilePath>>):Void {
throw new NotImplementedException();
}

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

import haxe.Int64;
import haxe.io.Bytes;
import haxe.NoData;
import haxe.exceptions.NotImplementedException;
import asys.native.system.SystemUser;
import asys.native.system.SystemGroup;

/**
TODO:
Add methods for reading/writing `String` data because it may be more efficient
on some targets (lua) than reading/writing `haxe.io.Bytes`
**/
@:coreApi
class File {
/** The path of this file as it was at the moment of opening the file **/
public final path:FilePath;

function new():Void {
path = 'stub';
}

/**
Write up to `length` bytes from `buffer` starting at the buffer `offset`
to the file starting at the file `position`, then invoke `callback` with
the amount of bytes written.

If `position` is greater than the file size then the file will be grown
to the required size with the zero bytes before writing.

If `position` is negative or `offset` is outside of `buffer` bounds or
if `length` is negative, an error is passed to the `callback`.
**/
public function write(position:Int64, buffer:Bytes, offset:Int, length:Int, callback:Callback<Int>):Void {
throw new NotImplementedException();
}

/**
Read up to `length` bytes from the file `position` and write them into
`buffer` starting at `offset` position in `buffer`, then invoke `callback`
with the amount of bytes read.

If `position` is greater or equal to the file size at the moment of reading
then `0` is passed to the `callback` and `buffer` is unaffected.

If `position` is negative or `offset` is outside of `buffer` bounds, an
error is passed to the `callback`.
**/
public function read(position:Int64, buffer:Bytes, offset:Int, length:Int, callback:Callback<Int>):Void {
throw new NotImplementedException();
}

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

/**
Get file status information.
**/
public function info(callback:Callback<FileInfo>):Void {
throw new NotImplementedException();
}

/**
Set file permissions.
**/
public function setPermissions(permissions:FilePermissions, callback:Callback<NoData>):Void {
throw new NotImplementedException();
}

/**
Set file owner and group.
**/
public function setOwner(user:SystemUser, group:SystemGroup, callback:Callback<NoData>):Void {
throw new NotImplementedException();
}

/**
Shrink or expand the file to `newSize` bytes.

If the file is larger than `newSize`, the extra data is lost.
If the file is shorter, zero bytes are used to fill the added length.
**/
public function resize(newSize:Int, callback:Callback<NoData>):Void {
throw new NotImplementedException();
}

/**
Change access and modification times of the file.

TODO: Decide on type for `accessTime` and `modificationTime` - see TODO in `asys.native.filesystem.FileInfo.FileStat`
**/
public function setTimes(accessTime:Int, modificationTime:Int, callback:Callback<NoData>):Void {
throw new NotImplementedException();
}

/**
TODO: this requires a separate work for design and implementation
to find a solid cross-platform solution.

Acquire or release a file lock for the current process.

The `callback` is supplied with `true` if a lock was successfully acquired.

Modes:
- `Shared` - acquire a shared lock (usually used for reading)
- `Exclusive` - acquire an exclusive lock (usually used for writing)
- `Unlock` - release a lock.

By default (`wait` is `true`) `lock` waits until a lock can be acquired.
Pass `false` to `wait` to invoke `callback` with `false` if a lock cannot
be acquired immediately.

Although a lock may be released automatically on file closing, for a
consistent cross-platform behavior it is strongly recommended to always
release a lock manually.

This lock is _not_ suitable for controlling access to a file by multiple threads.
**/
// public function lock(mode:FileLock = Exclusive, wait:Bool = true, callback:Callback<Bool>):Void {
// throw new NotImplementedException();
// }

/**
Close the file.

Does not fail if the file is already closed.
**/
public function close(callback:Callback<NoData>):Void {
throw new NotImplementedException();
}
}
Loading