factor/basis/io/pipes/windows/nt/nt.factor

47 lines
1.2 KiB
Factor
Raw Normal View History

2008-02-14 03:20:20 -05:00
! Copyright (C) 2007, 2008 Doug Coleman, Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: alien alien.c-types arrays destructors io io.backend.windows libc
2008-09-05 20:29:14 -04:00
windows.types math.bitwise windows.kernel32 windows namespaces
2008-09-11 02:27:23 -04:00
make kernel sequences windows.errors assocs math.parser system
random combinators accessors io.pipes io.ports ;
IN: io.pipes.windows.nt
2007-11-21 03:18:28 -05:00
! This code is based on
! http://twistedmatrix.com/trac/browser/trunk/twisted/internet/iocpreactor/process.py
: create-named-pipe ( name -- handle )
{ PIPE_ACCESS_INBOUND FILE_FLAG_OVERLAPPED } flags
PIPE_TYPE_BYTE
1
4096
4096
0
default-security-attributes
CreateNamedPipe opened-file ;
: open-other-end ( name -- handle )
GENERIC_WRITE
{ FILE_SHARE_READ FILE_SHARE_WRITE } flags
default-security-attributes
OPEN_EXISTING
FILE_FLAG_OVERLAPPED
f
CreateFile opened-file ;
: unique-pipe-name ( -- string )
[
"\\\\.\\pipe\\factor-" %
pipe counter #
"-" %
2008-03-19 22:41:39 -04:00
32 random-bits #
"-" %
micros #
] "" make ;
M: winnt (pipe) ( -- pipe )
[
unique-pipe-name
2008-05-15 02:45:32 -04:00
[ create-named-pipe ] [ open-other-end ] bi
pipe boa
] with-destructors ;