-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtestmsgC
executable file
·63 lines (51 loc) · 1.56 KB
/
testmsgC
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/bin/bash
# -*- scheme -*-
# $ ./testmsgC
#|
LD_LIBRARY_PATH=`pwd`:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH
NYACC_DIR=$HOME/repo/sv/nyacc/nyacc-rel/nyacc-1.08
GUILE_LOAD_PATH=$NYACC_DIR/examples:$NYACC_DIR/module
GUILE_LOAD_PATH=`pwd`:$GUILE_LOAD_PATH
export GUILE_LOAD_PATH
GDB_PFX=""
if [ $# -gt 0 ]; then
case "$1" in
--debug) GDB_PFX="gdb --args"; shift ;;
esac
fi
exec $GDB_PFX guile $0
|#
!#
(use-modules (rnrs bytevectors))
(use-modules (sockmsg))
(use-modules (system foreign))
(define (sferr fmt . args) (apply simple-format #t fmt args))
(use-modules (wl-client))
(define socket-path "/var/tmp/abc")
(let* ((path socket-path)
(style (logior SOCK_STREAM SOCK_CLOEXEC))
(sock (socket PF_UNIX style 0))
(conn (connect sock AF_UNIX path))
(size 1024)
(port (let ((port (tmpfile))) (truncate-file port size) port))
(fd (port->fdes port))
(bv (mmap 0 size (logior PROT_READ PROT_WRITE) MAP_SHARED fd 0))
(io-buf (make-bytevector 120 #xff)))
(sferr "fd = ~S\n" fd)
(bytevector-copy! (string->utf8 "Hello, world!\n") 0 bv 0 14)
(bytevector-u8-set! bv 14 0)
(call-with-values
(lambda () (encode-wl_shm:create_pool 3 io-buf 0 10 fd size))
(lambda (size cm)
(sendmsg sock io-buf 0 size cm)))
(sleep 1)
(let* ((res (recvmsg! sock io-buf 0))
(cm (vector-ref res 1)))
(sferr "cm: ~S\n" (fmtbv/x cm 0 (bytevector-length cm) 4))
(sferr "fd: ~S\n" (dec-fd cm))
(sferr "SOL_SOCKET=~S SCM_RIGHTS=~S\n" SOL_SOCKET SCM_RIGHTS)
#t)
(sleep 100)
#f)
;; --- last line ---