Skip to content

Commit

Permalink
Merge #1627
Browse files Browse the repository at this point in the history
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
iohk-bors[bot] and coot authored Mar 24, 2020
2 parents ea9aae7 + e22a9bc commit 5c253f7
Show file tree
Hide file tree
Showing 21 changed files with 1,433 additions and 682 deletions.
6 changes: 1 addition & 5 deletions Win32-network/NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,9 @@ Copyright 2019 Input Output (Hong Kong) Ltd.
limitations under the License.


Parts of this project is based on
The project was initially based on:
http://hackage.haskell.org/package/winio-0.1

The following license applies to:
* ./cbits/Win32Async.c
* ./src/System/Win32/Async.hs

Copyright 2007-2009 Felix Martini.

Redistribution and use in source and binary forms, with or without
Expand Down
21 changes: 21 additions & 0 deletions Win32-network/README.md
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.
11 changes: 6 additions & 5 deletions Win32-network/Win32-network.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
185 changes: 0 additions & 185 deletions Win32-network/cbits/Win32Async.c

This file was deleted.

80 changes: 0 additions & 80 deletions Win32-network/cbits/Win32Socket.c

This file was deleted.

19 changes: 19 additions & 0 deletions Win32-network/include/Win32-network.h
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;
Loading

0 comments on commit 5c253f7

Please sign in to comment.