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