]> gitweb.factorcode.org Git - factor.git/blob - basis/io/pipes/windows/windows.factor
7a87df65e81d4c934c7cfbe0aabf4f9c5efc36c9
[factor.git] / basis / io / pipes / windows / windows.factor
1 ! Copyright (C) 2007, 2008 Doug Coleman, Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors alien alien.c-types arrays assocs combinators
4 destructors io io.files.windows io.pipes
5 io.ports kernel libc literals make math.bitwise math.parser
6 namespaces random sequences system windows windows.errors
7 windows.kernel32 windows.types ;
8 IN: io.pipes.windows
9
10 ! This code is based on
11 ! http://twistedmatrix.com/trac/browser/trunk/twisted/internet/iocpreactor/process.py
12
13 : create-named-pipe ( name -- handle )
14     flags{ PIPE_ACCESS_INBOUND FILE_FLAG_OVERLAPPED }
15     PIPE_TYPE_BYTE
16     1
17     4096
18     4096
19     0
20     default-security-attributes
21     CreateNamedPipe opened-file ;
22
23 : open-other-end ( name -- handle )
24     GENERIC_WRITE
25     flags{ FILE_SHARE_READ FILE_SHARE_WRITE }
26     default-security-attributes
27     OPEN_EXISTING
28     FILE_FLAG_OVERLAPPED
29     f
30     CreateFile opened-file ;
31
32 : unique-pipe-name ( -- string )
33     [
34         "\\\\.\\pipe\\factor-" %
35         pipe counter #
36         "-" %
37         32 random-bits #
38         "-" %
39         nano-count #
40     ] "" make ;
41
42 M: windows (pipe) ( -- pipe )
43     [
44         unique-pipe-name
45         [ create-named-pipe ] [ open-other-end ] bi
46         pipe boa
47     ] with-destructors ;