#| -*-Scheme-*-
-$Id: genio.scm,v 1.46 2006/11/01 05:09:42 cph Exp $
+$Id: genio.scm,v 1.47 2006/11/22 18:51:09 cph Exp $
Copyright 1991,1993,1995,1996,1999,2002 Massachusetts Institute of Technology
Copyright 2003,2004,2005,2006 Massachusetts Institute of Technology
(declare (usual-integrations))
\f
-(define (make-generic-i/o-port source sink)
+(define (make-generic-i/o-port source sink #!optional type)
(if (not (or source sink))
(error "Missing arguments."))
(let ((port
- (make-port (generic-i/o-port-type (source-type source)
- (sink-type sink))
+ (make-port (if (default-object? type)
+ (generic-i/o-port-type (source-type source)
+ (sink-type sink))
+ type)
(make-gstate source sink 'TEXT 'TEXT))))
(let ((ib (port-input-buffer port)))
(if ib
(and ib
(input-buffer-open? ib))))
+(define (generic-io/io-open? port)
+ (and (generic-io/input-open? port)
+ (generic-io/output-open? port)))
+
(define (generic-io/write-self port output-port)
(cond ((i/o-port? port)
(write-string " for channels: " output-port)
#| -*-Scheme-*-
-$Id: make.scm,v 14.105 2006/09/16 11:19:09 gjr Exp $
+$Id: make.scm,v 14.106 2006/11/22 18:51:11 cph Exp $
Copyright 1988,1989,1990,1991,1992,1993 Massachusetts Institute of Technology
Copyright 1994,1995,1996,1997,1998,2000 Massachusetts Institute of Technology
(RUNTIME GENERIC-I/O-PORT)
(RUNTIME FILE-I/O-PORT)
(RUNTIME CONSOLE-I/O-PORT)
+ (RUNTIME SOCKET)
(RUNTIME TRANSCRIPT)
(RUNTIME STRING-INPUT)
(RUNTIME STRING-OUTPUT)
#| -*-Scheme-*-
-$Id: runtime.pkg,v 14.605 2006/11/09 20:04:57 cph Exp $
+$Id: runtime.pkg,v 14.606 2006/11/22 18:51:12 cph Exp $
Copyright 1988,1989,1990,1991,1992,1993 Massachusetts Institute of Technology
Copyright 1994,1995,1996,1997,1998,1999 Massachusetts Institute of Technology
(files "genio")
(parent (runtime))
(export ()
- make-generic-i/o-port)
- (export (runtime console-i/o-port)
generic-i/o-port-type
generic-io/char-ready?
+ generic-io/close-input
+ generic-io/close-output
generic-io/flush-output
+ generic-io/io-open?
generic-io/read-char
+ make-generic-i/o-port)
+ (export (runtime console-i/o-port)
input-buffer-contents
make-gstate
port-input-buffer
set-input-buffer-contents!)
(export (runtime file-i/o-port)
- generic-i/o-port-type
clear-input-buffer
input-buffer-encoded-character-size
input-buffer-free-bytes
port-input-buffer
port-output-buffer)
(export (runtime string-input)
- generic-i/o-port-type
make-gstate
make-non-channel-source)
(export (runtime string-output)
- generic-i/o-port-type
make-gstate
make-non-channel-sink)
(export (runtime truncated-string-output)
- generic-i/o-port-type
make-gstate
make-non-channel-sink)
(initialization (initialize-package!)))
open-unix-stream-socket
open-unix-stream-socket-channel
os/hostname
- tcp-server-connection-accept))
+ tcp-server-connection-accept)
+ (initialization (initialize-package!)))
(define-package (runtime subprocess)
(file-case options
#| -*-Scheme-*-
-$Id: socket.scm,v 1.28 2006/06/11 03:04:17 cph Exp $
+$Id: socket.scm,v 1.29 2006/11/22 18:51:14 cph Exp $
Copyright 1996,1997,1998,1999,2001,2002 Massachusetts Institute of Technology
Copyright 2003,2004,2005,2006 Massachusetts Institute of Technology
(let loop () (do-test loop))
(do-test (lambda () #f))))))))
(and channel
- (make-generic-i/o-port channel channel))))
+ (make-socket-port channel))))
\f
(define (open-tcp-stream-socket host-name service)
(let ((channel (open-tcp-stream-socket-channel host-name service)))
- (make-generic-i/o-port channel channel)))
+ (make-socket-port channel)))
(define (open-unix-stream-socket filename)
(let ((channel (open-unix-stream-socket-channel filename)))
- (make-generic-i/o-port channel channel)))
+ (make-socket-port channel)))
(define (open-tcp-stream-socket-channel host-name service)
(let ((host
(lambda ()
((ucode-primitive new-open-unix-stream-socket 2) filename p))))))
+(define (make-socket-port channel)
+ (make-generic-i/o-port channel channel socket-port-type))
+
+(define socket-port-type)
+(define (initialize-package!)
+ (set! socket-port-type
+ (make-port-type `((CLOSE-INPUT ,socket/close-input)
+ (CLOSE-OUTPUT ,socket/close-output))
+ (generic-i/o-port-type 'CHANNEL 'CHANNEL)))
+ unspecific)
+
+(define (socket/close-input port)
+ (if (generic-io/io-open? port)
+ ((ucode-primitive shutdown-socket 2)
+ (channel-descriptor (port/input-channel port))
+ 1))
+ (generic-io/close-input port))
+
+(define (socket/close-output port)
+ (if (generic-io/io-open? port)
+ ((ucode-primitive shutdown-socket 2)
+ (channel-descriptor (port/input-channel port))
+ 2))
+ (generic-io/close-output port))
+\f
(define (get-host-by-name host-name)
(with-thread-timer-stopped
(lambda ()