File: clozure.lisp

package info (click to toggle)
acl2 7.2dfsg-3
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 198,968 kB
  • ctags: 182,300
  • sloc: lisp: 2,415,261; ansic: 5,675; perl: 5,577; xml: 3,576; sh: 3,255; cpp: 2,835; makefile: 2,440; ruby: 2,402; python: 778; ml: 763; yacc: 709; csh: 355; php: 171; lex: 162; tcl: 44; java: 24; asm: 23; haskell: 17
file content (73 lines) | stat: -rw-r--r-- 2,858 bytes parent folder | download | duplicates (5)
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
;;;; See LICENSE for licensing information.

;;;; Functions for CCL 1.11 (IPv6) only, see openmcl.lisp for rest of functions.

(in-package :usocket)

#+ipv6
(defun socket-connect (host port &key (protocol :stream) element-type
                                   timeout deadline nodelay
                                   local-host local-port)
  (when (eq nodelay :if-supported)
    (setf nodelay t))
  (with-mapped-conditions ()
    (let* ((remote (when (and host port)
		     (openmcl-socket:resolve-address :host (host-to-hostname host)
						     :port port
						     :socket-type protocol)))
	   (local  (when (and local-host local-port)
		     (openmcl-socket:resolve-address :host (host-to-hostname local-host)
						     :port local-port
						     :socket-type protocol)))
	   (mcl-sock (apply #'openmcl-socket:make-socket
			    `(:type ,protocol
			      ,@(when (or remote local)
				  `(:address-family ,(openmcl-socket:socket-address-family (or remote local))))
			      ,@(when remote
				  `(:remote-address ,remote))
			      ,@(when local
				  `(:local-address ,local))
			      :format ,(to-format element-type protocol)
			      :external-format ,ccl:*default-external-format*
			      :deadline ,deadline
			      :nodelay ,nodelay
			      :connect-timeout ,timeout
			      :input-timeout ,timeout))))
      (ecase protocol
        (:stream
         (make-stream-socket :stream mcl-sock :socket mcl-sock))
        (:datagram
         (make-datagram-socket mcl-sock :connected-p (and remote t)))))))

#+ipv6
(defun socket-listen (host port
                      &key
                        (reuse-address nil reuse-address-supplied-p)
                        (reuseaddress (when reuse-address-supplied-p reuse-address))
                        (backlog 5)
                        (element-type 'character))
  (let ((local-address (openmcl-socket:resolve-address :host (host-to-hostname host)
						       :port port :connect :passive)))
    (with-mapped-conditions ()
      (make-stream-server-socket
        (openmcl-socket:make-socket :connect :passive
				    :address-family (openmcl-socket:socket-address-family local-address)
				    :local-address local-address
				    :reuse-address reuseaddress
				    :backlog backlog
				    :format (to-format element-type :stream))
	:element-type element-type))))

#+ipv6
(defmethod socket-send ((usocket datagram-usocket) buffer size &key host port (offset 0))
  (let* ((ccl-socket (socket usocket))
	 (socket-keys (ccl::socket-keys ccl-socket)))
    (with-mapped-conditions (usocket)
      (if (and host port)
	  (openmcl-socket:send-to ccl-socket buffer size
				  :remote-host (host-to-hostname host)
				  :remote-port port
				  :offset offset)
	  (openmcl-socket:send-to ccl-socket buffer size
				  :remote-address (getf socket-keys :remote-address)
				  :offset offset)))))