changelog shortlog graph tags branches changeset files revisions annotate raw help

Mercurial > core / lisp/lib/pod/client.lisp

changeset 698: 96958d3eb5b0
parent: 35a579313b80
author: Richard Westhaver <ellis@rwest.io>
date: Fri, 04 Oct 2024 22:04:59 -0400
permissions: -rw-r--r--
description: fixes
1 ;;; lib/pod/client.lisp --- Libpod API client
2 
3 ;;
4 
5 ;;; Code:
6 (in-package :pod)
7 
8 (defvar *podman-local-user-socket* (format nil "/var/run/user/~a/podman/podman.sock" (sb-posix:getuid)))
9 
10 (defvar *libpod-api-version* "4.8.2")
11 
12 ;;; TODO Socket
13 (defclass libpod-unix-socket (local-socket) ())
14 
15 (defclass libpod-tcp-socket (inet-socket) ())
16 
17 ;;; Client
18 (defclass libpod-client ()
19  ((socket :initarg :socket
20  :initform (make-instance 'local-socket :type :stream)
21  :type (or local-socket null)
22  :accessor client-socket)
23  (addr :initarg :addr
24  :initform nil
25  :accessor client-addr)
26  (peer :initarg :peer
27  :initform *podman-local-user-socket*
28  :accessor client-peer)))
29 
30 (defmethod make-load-form ((self libpod-client) &optional env)
31  (declare (ignore env))
32  `(make-instance 'libpod-client :socket nil :addr ,(client-addr self) :peer ,(client-peer self)))
33 
34 ;;; Net Client protocol
35 
36 ;;; Socket Protocol
37 (defmethod socket-connect ((self libpod-client) &rest addr)
38  (socket-connect (client-socket self) (or addr (client-peer self))))
39 
40 (defmethod socket-close ((self libpod-client) &key (abort t))
41  (socket-close (client-socket self) :abort abort))
42 
43 (defmethod socket-shutdown ((self libpod-client) &key (direction t))
44  (socket-shutdown self :direction direction))
45 
46 (defmethod socket-send ((self libpod-client) buffer length
47  &key address
48  external-format
49  oob
50  eor
51  dontroute
52  dontwait
53  nosignal
54  confirm
55  more)
56  (socket-send (client-socket self) buffer length
57  :address address
58  :external-format external-format
59  :oob oob
60  :eor eor
61  :dontroute dontroute
62  :dontwait dontwait
63  :nosignal nosignal
64  :confirm confirm
65  :more more))
66 
67 (defmethod socket-receive ((self libpod-client) buffer length
68  &key (oob t)
69  (peek t)
70  (waitall t)
71  (dontwait t)
72  (element-type 'character))
73  (socket-receive (client-socket self) buffer length
74  :element-type element-type
75  :oob oob
76  :dontwait dontwait
77  :waitall waitall
78  :peek peek))
79 
80 (defmethod socket-listen ((self libpod-client) backlog)
81  (socket-listen (client-socket self) backlog))
82 
83 (defmethod socket-bind ((self libpod-client) &rest addr)
84  (socket-bind (client-socket self) (or addr (client-addr self))))
85 
86 (defmethod socket-accept ((self libpod-client))
87  (socket-accept (client-socket self)))
88 
89 (defmethod socket-make-stream ((self libpod-client)
90  &key input output
91  (element-type 'character)
92  (external-format :default)
93  (buffering :full)
94  timeout
95  auto-close
96  serve-events)
97  (socket-make-stream (client-socket self)
98  :input input
99  :output output
100  :element-type element-type
101  :external-format external-format
102  :buffering buffering
103  :timeout timeout
104  :auto-close auto-close
105  :serve-events serve-events))
106 
107 (defmacro with-libpod-client ((cvar &optional c) &body body)
108  `(let ((,cvar ,(or c (make-instance 'libpod-client))))
109  (socket-connect ,cvar)
110  (unwind-protect (progn ,@body)
111  (socket-close ,cvar))))