Next Prev Up Top Contents Index

socket-stream

Class
Summary

The socket stream class.

Superclasses

stream

Initargs

:socket

A socket handle.

:direction

One of :input , :output , or :io .

:element-type

An element type.

:read-timeout

A positive number or nil .

Accessors

socket-stream-socket
stream:stream-read-timeout

Description

The socket-stream class implements a buffered stream connected to a socket. The socket handle, specified by :socket , and the direction, specified by :direction , must be passed for a meaningful stream to be constructed. Common Lisp input functions such as read-char will see end-of-file if the other end of the socket is closed. The :element-type keyword specifies the expected element type of the stream traffic. The : read-timeout initarg specifies the read-timeout in seconds, or is nil , meaning there are no timeouts during reads (this is the default).

The read-timeout property is intended for use when a socket connection might hang during a call to any Common Lisp input function. The read-timeout can be set by make-instance or by open-tcp-stream . It can also be modified by (setf stream:stream-read-timeout) . When read-timeout is nil , there is no timeout during reads and the call may hang. When read-timeout is not nil , and there is no input from the socket for more than read-timeout seconds, any reading function returns end-of-file . The read-timeout does not limit the time inside read , but the time between successful extractions of data from the socket. Therefore, if the reading needs several rounds it may take longer than read-timeout .

Using (setf stream:stream-read-timeout) on the stream while it is inside a read function has undefined effects. However, the setf function can be used between calls to read functions. The read-timeout property of a stream can be read by (stream:stream-read-timeout stream)

Example

The following makes a bidirectional stream connected to a socket specified by handle .

(make-instance 'comm:socket-stream
               :socket handle
               :direction :io
               :element-type 'base-char)

This example creates a socket stream with a read-timeout:

(make-instance 'comm:socket-stream
               :handle 
handle
               :direction :input
               :read-timeout 42)
See also

open-tcp-stream
start-up-server
stream-read-timeout


LispWorks Reference Manual (Windows version) - 14 Dec 2001

Next Prev Up Top Contents Index