[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[shepherd] 03/04: comm: Add 'open-server-socket'.
From: |
Ludovic Courtès |
Subject: |
[shepherd] 03/04: comm: Add 'open-server-socket'. |
Date: |
Sun, 12 Mar 2023 18:52:26 -0400 (EDT) |
civodul pushed a commit to branch master
in repository shepherd.
commit cd6f3fbbc864c432f99e362da2ec1da8f5eb9836
Author: Ludovic Courtès <ludo@gnu.org>
AuthorDate: Sun Mar 12 22:23:37 2023 +0100
comm: Add 'open-server-socket'.
* modules/shepherd.scm (open-server-socket): Move to...
* modules/shepherd/comm.scm (open-server-socket): ... here.
---
modules/shepherd.scm | 11 -----------
modules/shepherd/comm.scm | 14 +++++++++++++-
2 files changed, 13 insertions(+), 12 deletions(-)
diff --git a/modules/shepherd.scm b/modules/shepherd.scm
index 0a31d6a..c01419b 100644
--- a/modules/shepherd.scm
+++ b/modules/shepherd.scm
@@ -41,17 +41,6 @@
(define sleep (@ (fibers) sleep))
-(define (open-server-socket file-name)
- "Open a socket at FILE-NAME, and listen for connections there."
- (with-fluids ((%default-port-encoding "UTF-8"))
- (let ((sock (socket PF_UNIX
- (logior SOCK_STREAM SOCK_NONBLOCK SOCK_CLOEXEC)
- 0))
- (address (make-socket-address AF_UNIX file-name)))
- (bind sock address)
- (listen sock 10)
- sock)))
-
(define-syntax-rule (unwind-protect body ... conclude)
"Evaluate BODY... and return its result(s), but always evaluate CONCLUDE
before leaving, even if an exception is raised.
diff --git a/modules/shepherd/comm.scm b/modules/shepherd/comm.scm
index 255f6ea..0164686 100644
--- a/modules/shepherd/comm.scm
+++ b/modules/shepherd/comm.scm
@@ -1,5 +1,5 @@
;; comm.scm -- Communication between processes and general output.
-;; Copyright (C) 2013, 2014, 2016, 2018, 2019, 2022 Ludovic Courtès
<ludo@gnu.org>
+;; Copyright (C) 2013, 2014, 2016, 2018, 2019, 2022, 2023 Ludovic Courtès
<ludo@gnu.org>
;; Copyright (C) 2002, 2003 Wolfgang Jährling <wolfgang@pro-linux.de>
;; Copyright (C) 2018 Danny Milosavljevic <dannym@scratchpost.org>
;;
@@ -25,6 +25,7 @@
#:use-module (oop goops)
#:use-module (ice-9 match)
#:export (open-connection
+ open-server-socket
<shepherd-command>
shepherd-command?
@@ -93,6 +94,17 @@ return the socket."
(list errno) rest)))
sock)))
+(define (open-server-socket file-name)
+ "Open a socket at FILE-NAME, and listen for connections there."
+ (with-fluids ((%default-port-encoding "UTF-8"))
+ (let ((sock (socket PF_UNIX
+ (logior SOCK_STREAM SOCK_NONBLOCK SOCK_CLOEXEC)
+ 0))
+ (address (make-socket-address AF_UNIX file-name)))
+ (bind sock address)
+ (listen sock 10)
+ sock)))
+
(define (read-command port)
"Receive a command from PORT; return the command of #f if something went
wrong---premature end-of-file, invalid sexp, etc."