Unverified Commit 0e2c2319 authored by Eugene Zaikonnikov's avatar Eugene Zaikonnikov Committed by GitHub
Browse files

Add UDP broadcast support for LispWorks (#70)

* add broadcast socket option for lispworks

* add get/set-broadcast calls for lispworks

* add broadcast flags for udp socket-connect chain

* unhack the broadcast option in favor of internal hostaddr check

* remove the unneeded package qualifier

* implement socket-option get/set for broadcast in LW
parent ccc63142
......@@ -101,6 +101,11 @@
(tv-sec :long)
(tv-usec :long))
(defconstant *sockopt_so_broadcast*
#-linux #x0020
#+linux 6
"Socket broadcast")
;;; ssize_t
;;; recvfrom(int socket, void *restrict buffer, size_t length, int flags,
;;; struct sockaddr *restrict address, socklen_t *restrict address_len);
......@@ -285,6 +290,33 @@
zero-or-one 0))) ; on error, return 0
(defun get-socket-broadcast (socket-fd)
"Get socket option: SO_BROADCAST, return value is a fixnum (0 or 1)"
(declare (type integer socket-fd))
(fli:with-dynamic-foreign-objects ((zero-or-one :int)
(len :int))
(if (zerop (comm::getsockopt socket-fd
(fli:copy-pointer zero-or-one
:type '(:pointer #+win32 :char #-win32 :void))
zero-or-one 0)))
(defun set-socket-broadcast (socket-fd new-value)
"Set socket option: SO_BROADCAST, argument is a fixnum (0 or 1)"
(declare (type integer socket-fd)
(type (integer 0 1) new-value))
(fli:with-dynamic-foreign-objects ((zero-or-one :int))
(setf (fli:dereference zero-or-one) new-value)
(when (zerop (comm::setsockopt socket-fd
(fli:copy-pointer zero-or-one
:type '(:pointer #+win32 :char #-win32 :void))
(fli:size-of :int)))
(defun initialize-dynamic-sockaddr (hostname service protocol &aux (original-hostname hostname))
(declare (ignorable original-hostname))
#+(or lispworks4 lispworks5 lispworks6.0)
......@@ -379,6 +411,10 @@
:local-port local-port
:read-timeout read-timeout
:address-family address-family)))
(when (string= hostname "")
;; LispWorks fails on connect if the broadcast option for broadcast
;; address is not set in advance
(set-socket-broadcast socket-fd 1))
(if socket-fd
(if (comm::connect socket-fd server-addr server-addr-length)
;; success, return socket fd
......@@ -235,7 +235,7 @@
#+(or ecl clasp)
() ; TODO
() ; TODO
(int->bool (get-socket-tcp-nodelay socket))
() ; TODO
......@@ -264,7 +264,7 @@
#+(or ecl clasp)
() ; TODO
() ; TODO
(set-socket-broadcast socket (bool->int new-value))
() ; TODO
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment