Paste: unix pipe thread messaging

Author: Phil Dawes
Mode: factor
Date: Wed, 28 Oct 2009 20:59:53
Plain Text |
USING: accessors command-line io io.encodings.binary
io.pipes io.ports kernel math.parser native-thread-test sequences
serialize io.backend.unix ;
IN: pipe-race

: pipe>output-handle ( pipe -- integer ) 
    out>> handle>> fd>> ;

: handle>output-stream ( integer -- stream )
    <fd> <output-port> ;

: make-handle-arg ( handle -- str )
    number>string "-handle=" prepend  ; 

: read-forever ( -- )
    [ deserialize "." write flush ] loop ;

: run-test ( -- )
    binary <pipe>
    [ pipe>output-handle make-handle-arg
      { "-run=pipe-race" "-quiet" } swap suffix start-vm-in-os-thread drop ] 
    [ [ read-forever ] with-input-stream* ] bi ;


: child-main ( -- )
    (command-line) [ "-handle=" head? ] find nip
    8 tail string>number handle>output-stream
    [ [ "hello!" serialize flush t ] loop ] with-output-stream* ;
    

MAIN: child-main

New Annotation

Summary:
Author:
Mode:
Body: