Merge branch 'develop' into 'develop'
Fix GET-PROTOCOL-BY-NAME with unknown protocols See merge request embeddable-common-lisp/ecl!233
This commit is contained in:
commit
3d4af11001
3 changed files with 29 additions and 11 deletions
|
|
@ -17,6 +17,7 @@
|
||||||
"SOCKET-PEERNAME" "SOCKET-NAME" "SOCKET-LISTEN"
|
"SOCKET-PEERNAME" "SOCKET-NAME" "SOCKET-LISTEN"
|
||||||
"SOCKET-RECEIVE" "SOCKET-CLOSE" "SOCKET-MAKE-STREAM"
|
"SOCKET-RECEIVE" "SOCKET-CLOSE" "SOCKET-MAKE-STREAM"
|
||||||
"GET-PROTOCOL-BY-NAME" "MAKE-INET-ADDRESS" "LOCAL-SOCKET"
|
"GET-PROTOCOL-BY-NAME" "MAKE-INET-ADDRESS" "LOCAL-SOCKET"
|
||||||
|
"UNKNOWN-PROTOCOL" "UNKNOWN-PROTOCOL-NAME"
|
||||||
"SOCKET" "INET-SOCKET" "SOCKET-FILE-DESCRIPTOR" #+:win32 "NAMED-PIPE-SOCKET"
|
"SOCKET" "INET-SOCKET" "SOCKET-FILE-DESCRIPTOR" #+:win32 "NAMED-PIPE-SOCKET"
|
||||||
"SOCKET-FAMILY" "SOCKET-PROTOCOL" "SOCKET-TYPE"
|
"SOCKET-FAMILY" "SOCKET-PROTOCOL" "SOCKET-TYPE"
|
||||||
"SOCKET-ERROR" "NAME-SERVICE-ERROR" "NON-BLOCKING-MODE"
|
"SOCKET-ERROR" "NAME-SERVICE-ERROR" "NON-BLOCKING-MODE"
|
||||||
|
|
|
||||||
|
|
@ -571,17 +571,27 @@ safe_buffer_pointer(cl_object x, cl_index size)
|
||||||
;; We could refactor a lot here, if we pass sockaddr_foo structs around in Lisp. But
|
;; We could refactor a lot here, if we pass sockaddr_foo structs around in Lisp. But
|
||||||
;; I do not feel comfortable with that.
|
;; I do not feel comfortable with that.
|
||||||
|
|
||||||
|
(define-condition unknown-protocol (error)
|
||||||
|
((name :initarg :name
|
||||||
|
:reader unknown-protocol-name))
|
||||||
|
(:report (lambda (condition stream)
|
||||||
|
(format stream "Protocol not found: ~A"
|
||||||
|
(prin1-to-string (unknown-protocol-name condition))))))
|
||||||
|
|
||||||
(defun get-protocol-by-name (string-or-symbol)
|
(defun get-protocol-by-name (string-or-symbol)
|
||||||
"Calls getprotobyname"
|
"Calls getprotobyname"
|
||||||
#-:android
|
#-:android
|
||||||
(let ((string (string string-or-symbol)))
|
(let* ((string (string string-or-symbol))
|
||||||
(c-inline (string) (:cstring) :int
|
(proto-num (c-inline (string) (:cstring) :int
|
||||||
"{
|
"{
|
||||||
struct protoent *pe;
|
struct protoent *pe;
|
||||||
pe = getprotobyname(#0);
|
pe = getprotobyname(#0);
|
||||||
@(return 0) = pe ? pe->p_proto : -1;
|
@(return 0) = pe ? pe->p_proto : -1;
|
||||||
}
|
}
|
||||||
"))
|
")))
|
||||||
|
(if (= proto-num -1)
|
||||||
|
(error 'unknown-protocol :name string)
|
||||||
|
proto-num))
|
||||||
;; getprotobyname is not yet implemented on bionic
|
;; getprotobyname is not yet implemented on bionic
|
||||||
#+:android
|
#+:android
|
||||||
(let ((proto (string-downcase (if (symbolp string-or-symbol)
|
(let ((proto (string-downcase (if (symbolp string-or-symbol)
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,13 @@
|
||||||
(equalp (make-inet-address "242.1.211.3") #(242 1 211 3))
|
(equalp (make-inet-address "242.1.211.3") #(242 1 211 3))
|
||||||
t)
|
t)
|
||||||
|
|
||||||
|
(deftest get-protocol-by-name-unknown-protocol
|
||||||
|
(let ((protocol-name "totally-unknown-protocol"))
|
||||||
|
(handler-case (get-protocol-by-name protocol-name)
|
||||||
|
(unknown-protocol (c) (string= protocol-name (unknown-protocol-name c)))
|
||||||
|
(:no-error (&rest args) (declare (ignore args)) nil)))
|
||||||
|
t)
|
||||||
|
|
||||||
(deftest make-inet-socket
|
(deftest make-inet-socket
|
||||||
;; make a socket
|
;; make a socket
|
||||||
(let ((s (make-instance 'inet-socket :type :stream :protocol (get-protocol-by-name "tcp"))))
|
(let ((s (make-instance 'inet-socket :type :stream :protocol (get-protocol-by-name "tcp"))))
|
||||||
|
|
@ -46,7 +53,7 @@
|
||||||
(make-instance 'inet-socket :type :stream :protocol (get-protocol-by-name "udp"))
|
(make-instance 'inet-socket :type :stream :protocol (get-protocol-by-name "udp"))
|
||||||
((or socket-type-not-supported-error protocol-not-supported-error) (c)
|
((or socket-type-not-supported-error protocol-not-supported-error) (c)
|
||||||
(declare (ignorable c)) t)
|
(declare (ignorable c)) t)
|
||||||
(:no-error nil))
|
(:no-error (&rest args) (declare (ignore args)) nil))
|
||||||
t)
|
t)
|
||||||
|
|
||||||
(deftest make-inet-socket-keyword-wrong
|
(deftest make-inet-socket-keyword-wrong
|
||||||
|
|
@ -55,7 +62,7 @@
|
||||||
(make-instance 'inet-socket :type :stream :protocol :udp)
|
(make-instance 'inet-socket :type :stream :protocol :udp)
|
||||||
((or protocol-not-supported-error socket-type-not-supported-error) (c)
|
((or protocol-not-supported-error socket-type-not-supported-error) (c)
|
||||||
(declare (ignorable c)) t)
|
(declare (ignorable c)) t)
|
||||||
(:no-error nil))
|
(:no-error (&rest args) (declare (ignore args)) nil))
|
||||||
t)
|
t)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -194,7 +201,7 @@
|
||||||
(handler-case
|
(handler-case
|
||||||
(get-host-by-name "foo.tninkpad.telent.net")
|
(get-host-by-name "foo.tninkpad.telent.net")
|
||||||
(NAME-SERVICE-ERROR () t)
|
(NAME-SERVICE-ERROR () t)
|
||||||
(:no-error nil))
|
(:no-error (&rest args) (declare (ignore args)) nil))
|
||||||
t)
|
t)
|
||||||
|
|
||||||
(defun http-stream (host port request)
|
(defun http-stream (host port request)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue