]> gitweb.factorcode.org Git - factor.git/blob - basis/io/backend/windows/windows.factor
Disposables are now registered in a global disposables set. To take advantage of...
[factor.git] / basis / io / backend / windows / windows.factor
1 ! Copyright (C) 2004, 2008 Mackenzie Straight, Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: alien alien.c-types arrays destructors io io.backend
4 io.buffers io.files io.ports io.binary io.timeouts system
5 strings kernel math namespaces sequences windows.errors
6 windows.kernel32 windows.shell32 windows.types windows.winsock
7 splitting continuations math.bitwise accessors init sets assocs ;
8 IN: io.backend.windows
9
10 TUPLE: win32-handle < disposable handle ;
11
12 : set-inherit ( handle ? -- )
13     [ handle>> HANDLE_FLAG_INHERIT ] dip
14     >BOOLEAN SetHandleInformation win32-error=0/f ;
15
16 : new-win32-handle ( handle class -- win32-handle )
17     new-disposable swap >>handle
18     dup f set-inherit ;
19
20 : <win32-handle> ( handle -- win32-handle )
21     win32-handle new-win32-handle ;
22
23 M: win32-handle dispose* ( handle -- )
24     handle>> CloseHandle win32-error=0/f ;
25
26 TUPLE: win32-file < win32-handle ptr ;
27
28 : <win32-file> ( handle -- win32-file )
29     win32-file new-win32-handle ;
30
31 M: win32-file dispose
32     dup disposed>> [ drop ] [
33         [ cancel-operation ] [ call-next-method ] bi
34     ] if ;
35
36 HOOK: CreateFile-flags io-backend ( DWORD -- DWORD )
37 HOOK: FileArgs-overlapped io-backend ( port -- overlapped/f )
38 HOOK: add-completion io-backend ( port -- )
39
40 : opened-file ( handle -- win32-file )
41     dup invalid-handle?
42     <win32-file> |dispose
43     dup add-completion ;
44
45 : share-mode ( -- n )
46     {
47         FILE_SHARE_READ
48         FILE_SHARE_WRITE
49         FILE_SHARE_DELETE
50     } flags ; foldable
51
52 : default-security-attributes ( -- obj )
53     "SECURITY_ATTRIBUTES" <c-object>
54     "SECURITY_ATTRIBUTES" heap-size
55     over set-SECURITY_ATTRIBUTES-nLength ;