-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1627: CancelIoEx and overal review of Win32-network r=coot a=coot The primary goal of this PR was to add `CancelIoEx` to fix #1574. In doing so I changed the interface and the end result is that: * we don't use C type level wrappers for windows syscalls any more (apart from `GetQueuedCompletionStatus` where we need to use a windwo kernel C macro. * using `GADTs` to ensure that we use the right combination of `OVERLAPPED` / `WSAOVERLAPPED`, `HANDLE` / `SOCKET` and `ErrCode` / `WsaErrCode`. * there is a closed type family which ensures that some of the `castPtr` usage is actually safe, it is not exposed. It could be removed, but then using `castPtr` would leak out to various modules - so I preferred the more elegant and local, though type havier approach. * more tests, especially for error conditions in which we need to assure that we are not deallocating the stable pointer twice 💣 This PR is done on top of `coot/windows-vectored-io` (and it merges into that branch) - this makes the scope of this PR adequate for the proposed changes. For the moment the windows stuff is stacked on CI, but when devops will help with it I will be able to merge all the PRs in turn. Co-authored-by: Marcin Szamotulski <[email protected]>
- Loading branch information
Showing
21 changed files
with
1,433 additions
and
682 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Asynchronious IO for Windows | ||
|
||
`Win32-network` provides low level api for doing IO / networking on Windows | ||
using Overlapped (or asynchronous) IO. It supports: | ||
|
||
* `File` Api | ||
* `NamedPipes` Api | ||
* `winsock2` - Berkeley sockets api on Windows | ||
|
||
`NamedPipes` provide a good alternative for the lack of Unix Sockets on | ||
Windows, and there are ways of providing abstraction for both, though this is | ||
not present in this package. | ||
|
||
An application which is using this package should use `-threaded` option, as | ||
the io manager thread runs a blocking ffi call (e.g. | ||
[GetQueuedCompletionStatus](https://docs.microsoft.com/en-us/windows/win32/api/ioapiset/nf-ioapiset-getqueuedcompletionstatus)). | ||
|
||
## Acknowledgement | ||
|
||
The initial version of this library was based on | ||
[winio](https://hackage.haskell.org/package/winio) by Felix Martini. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ maintainer: [email protected], [email protected] | |
copyright: 2019 Input Output (Hong Kong) Ltd. | ||
category: System | ||
build-type: Simple | ||
-- extra-source-files: ChangeLog.md | ||
extra-source-files: include/Win32-network.h | ||
cabal-version: >=1.10 | ||
|
||
flag demo | ||
|
@@ -27,13 +27,14 @@ library | |
System.Win32.Async.File | ||
System.Win32.Async.ErrCode | ||
System.Win32.Async.IOManager | ||
System.Win32.Async.Internal | ||
System.Win32.Async.WSABuf | ||
System.Win32.Async.Socket | ||
System.Win32.Async.Socket.ByteString | ||
System.Win32.Async.Socket.ByteString.Lazy | ||
c-sources: cbits/Win32Async.c | ||
cbits/Win32Socket.c | ||
other-modules: System.Win32.Async.IOData | ||
System.Win32.Async.Overlapped | ||
System.Win32.Async.Socket.Syscalls | ||
System.Win32.Async.WSABuf | ||
include-dirs: include | ||
build-depends: base >= 4.5 && < 4.13, | ||
bytestring >= 0.10 && < 0.11, | ||
network >= 3.1 && < 3.2, | ||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#include <winsock2.h> | ||
#include <windows.h> | ||
#include <HsFFI.h> | ||
|
||
// each OVERLAPPED struct is wrapped in IO_DATA; It is important to keep | ||
// OVERLAPPED as the first member of the record. This allows us to cast | ||
// an OVERLAPPED pointer to _IODATA and recover the second member.. | ||
typedef struct _IODATA { | ||
OVERLAPPED iodOverlapped; | ||
HsStablePtr iodData; | ||
} IODATA; | ||
|
||
|
||
// As for _IODATA: it is vital to keep WSAOVERLAPPED as the first member of | ||
// the struct. | ||
typedef struct _WSAIODATA { | ||
WSAOVERLAPPED iodOverlapped; | ||
HsStablePtr iodData; | ||
} WSAIODATA; |
Oops, something went wrong.