From aa48ae0df546d78602962096b3b9578fae47b645 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Thu, 13 Oct 2016 19:05:49 -0700 Subject: Adding family slot to socket addresses. A static slot indicating the address family simplifies code which wants to map a socket address to its family. * lisplib.c (sock_instantiate): Call sock_load_init before loading socket.tl rather than after, because socket.tl now references variables defined inside sock_load_init. * share/txr/stdlib/socket.tl (sockaddr, sockaddr-in, sockaddr-in6, sockaddr-un): New static slot, family. * txr.1: Documented family slots. --- lisplib.c | 2 +- share/txr/stdlib/socket.tl | 12 ++++++++---- txr.1 | 32 ++++++++++++++++++++++++++++---- 3 files changed, 37 insertions(+), 9 deletions(-) diff --git a/lisplib.c b/lisplib.c index 33f8b9b4..56c97076 100644 --- a/lisplib.c +++ b/lisplib.c @@ -306,8 +306,8 @@ static val sock_set_entries(val dlt, val fun) static val sock_instantiate(val set_fun) { funcall1(set_fun, nil); - load(format(nil, lit("~asocket.tl"), stdlib_path, nao)); sock_load_init(); + load(format(nil, lit("~asocket.tl"), stdlib_path, nao)); return nil; } diff --git a/share/txr/stdlib/socket.tl b/share/txr/stdlib/socket.tl index 187f9c52..45a9cc73 100644 --- a/share/txr/stdlib/socket.tl +++ b/share/txr/stdlib/socket.tl @@ -24,16 +24,20 @@ ;; OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ;; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -(defstruct sockaddr nil) +(defstruct sockaddr nil + (:static family nil)) (defstruct sockaddr-in sockaddr - (addr 0) (port 0)) + (addr 0) (port 0) + (:static family af-inet)) (defstruct sockaddr-in6 sockaddr - (addr 0) (port 0) (flow-info 0) (scope-id 0)) + (addr 0) (port 0) (flow-info 0) (scope-id 0) + (:static family af-inet6)) (defstruct sockaddr-un sockaddr - path) + path + (:static family af-unix)) (defstruct addrinfo nil (flags 0) diff --git a/txr.1 b/txr.1 index 051eafff..2f410c14 100644 --- a/txr.1 +++ b/txr.1 @@ -43009,7 +43009,8 @@ newly created datagram socket which is returned. .coNP Structure @ sockaddr .synb -.mets (defstruct sockaddr nil) +.mets (defstruct sockaddr nil +.mets \ \ (:static family nil)) .syne .desc The @@ -43021,10 +43022,16 @@ several other types are derived: and .codn sockaddr-un . +It has a single slot called +.code family +which is static, and initialized to +.codn nil . + .coNP Structure @ sockaddr-in .synb .mets (defstruct sockaddr-in sockaddr -.mets \ \ (addr 0) (port 0)) +.mets \ \ (addr 0) (port 0) +.mets \ \ (:static family af-inet)) .syne .desc The @@ -43056,10 +43063,16 @@ for instance, when the function is used with the aim of looking up the address of a host, without caring about the port number. +The +.code family +static slot holds the value +.codn af-inet . + .coNP Structure @ sockaddr-in6 .synb .mets (defstruct sockaddr-in6 sockaddr -.mets \ \ (addr 0) (port 0) (flow-info 0) (scope-id 0)) +.mets \ \ (addr 0) (port 0) (flow-info 0) (scope-id 0) +.mets \ \ (:static family af-inet6)) .syne .desc The @@ -43092,10 +43105,16 @@ members of the .code sockaddr_in6 C language structure. Their meaning and use are beyond the scope of this document. +The +.code family +static slot holds the value +.codn af-inet . + .coNP Structure @ sockaddr-un .synb .mets (defstruct sockaddr-un sockaddr -.mets \ \ path) +.mets \ \ path +.mets \ \ (:static family af-unix)) .syne .desc The @@ -43144,6 +43163,11 @@ is valid and represents an abstract address consisting of the three bytes .str "foo" followed by null padding bytes. +The +.code family +static slot holds the value +.codn af-inet . + .coNP Structure @ addrinfo .synb .mets (defstruct addrinfo nil -- cgit v1.2.3