/usr/share/common-lisp/source/usocket/test/test-datagram.lisp is in cl-usocket 0.6.3.2-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | (in-package :usocket-test)
(defvar *echo-server*)
(defvar *echo-server-port*)
(defun start-server ()
(multiple-value-bind (thread socket)
(usocket:socket-server "127.0.0.1" 0 #'identity nil
:in-new-thread t
:protocol :datagram)
(setq *echo-server* thread
*echo-server-port* (usocket:get-local-port socket))))
(defparameter *max-buffer-size* 32)
(defvar *send-buffer*
(make-array *max-buffer-size* :element-type '(unsigned-byte 8) :initial-element 0))
(defvar *receive-buffer*
(make-array *max-buffer-size* :element-type '(unsigned-byte 8) :initial-element 0))
(defun clean-buffers ()
(fill *send-buffer* 0)
(fill *receive-buffer* 0))
;;; UDP Send Test #1: connected socket
(deftest udp-send.1
(progn
(unless (and *echo-server* *echo-server-port*)
(start-server))
(let ((s (usocket:socket-connect "127.0.0.1" *echo-server-port* :protocol :datagram)))
(clean-buffers)
(replace *send-buffer* #(1 2 3 4 5))
(usocket:socket-send s *send-buffer* 5)
(usocket:wait-for-input s :timeout 3)
(multiple-value-bind (buffer size host port)
(usocket:socket-receive s *receive-buffer* *max-buffer-size*)
(declare (ignore buffer size host port))
(reduce #'+ *receive-buffer* :start 0 :end 5))))
15)
;;; UDP Send Test #2: unconnected socket
(deftest udp-send.2
(progn
(unless (and *echo-server* *echo-server-port*)
(start-server))
(let ((s (usocket:socket-connect nil nil :protocol :datagram)))
(clean-buffers)
(replace *send-buffer* #(1 2 3 4 5))
(usocket:socket-send s *send-buffer* 5 :host "127.0.0.1" :port *echo-server-port*)
(usocket:wait-for-input s :timeout 3)
(multiple-value-bind (buffer size host port)
(usocket:socket-receive s *receive-buffer* *max-buffer-size*)
(declare (ignore buffer size host port))
(reduce #'+ *receive-buffer* :start 0 :end 5))))
15)
(deftest mark-h-david ; Mark H. David's remarkable UDP test code
(let* ((host "localhost")
(port 1111)
(server-sock
(usocket:socket-connect nil nil :protocol ':datagram :local-host host :local-port port))
(client-sock
(usocket:socket-connect host port :protocol ':datagram))
(octet-vector
(make-array 2 :element-type '(unsigned-byte 8) :initial-contents `(,(char-code #\O) ,(char-code #\K))))
(recv-octet-vector
(make-array 2 :element-type '(unsigned-byte 8))))
(usocket:socket-send client-sock octet-vector 2)
(usocket:socket-receive server-sock recv-octet-vector 2)
(prog1 (and (equalp octet-vector recv-octet-vector)
recv-octet-vector)
(usocket:socket-close server-sock)
(usocket:socket-close client-sock)))
#(79 75))
(deftest frank-james ; Frank James' test code for LispWorks/UDP
(with-caught-conditions (#+win32 USOCKET:CONNECTION-RESET-ERROR
#-win32 USOCKET:CONNECTION-REFUSED-ERROR
nil)
(let ((sock (usocket:socket-connect "localhost" 1234
:protocol ':datagram :element-type '(unsigned-byte 8))))
(unwind-protect
(progn
(usocket:socket-send sock (make-array 16 :element-type '(unsigned-byte 8) :initial-element 0) 16)
(let ((buffer (make-array 16 :element-type '(unsigned-byte 8) :initial-element 0)))
(usocket:socket-receive sock buffer 16)))
(usocket:socket-close sock))))
nil)
|