All Manuals > LispWorks® User Guide and Reference Manual > 32 The COMM Package

replace-socket-stream-socket Function

Summary

Replaces the socket in a socket-stream, returning the existing socket object without closing it.

Package

comm

Signature

replace-socket-stream-socket socket-stream socket => socket-or-nil

Arguments
socket-stream
socket
A socket object or nil.
Values
socket-or-nil
A socket object or nil.
Description

The function replace-socket-stream-socket replaces the socket in the socket-stream socket-stream, returning the existing socket object without closing it.

A socket object is typcially a socket handle, which is an integer representing an file descriptor socket on Unix-like systems or a SOCKET on Microsoft Windows, but when using the Java interface it can also be a Java socket (a jobject of Java class java.net.Socket).

replace-socket-stream-socket sets the socket in socket-stream to the argument socket, and then returns the old socket object without closing it.

Notes
  1. Getting the old socket using the socket-stream accessor socket-stream-socket and then using (setf socket-stream-socket) to set the new one is different, because the cl:setf will close the old socket.
  2. Passing nil as the socket allows you to close the stream while retaining the socket.
  3. The new socket does not need to be the same kind of socket as the old one.
  4. If socket-or-nil is non-nil then it needs to be closed when it is no longer needed. If it is stored into another socket-stream or async-io-state, then it will be closed automatically when this object is closed. Otherwise, you need to call close-socket-handle to close it when you have finished with it.
See also

socket-stream
close-socket-handle
25 TCP and UDP socket communication and SSL


LispWorks® User Guide and Reference Manual - 01 Dec 2021 19:30:26