From 50ace689b41454c5d919e324520f27965bc3e8d5 Mon Sep 17 00:00:00 2001 From: Alex Shinn Date: Sat, 6 Aug 2011 15:20:17 +0900 Subject: [PATCH] Making the addrinfo argument to open-net-io and with-net-io default to TCP/IP. --- lib/chibi/net.module | 3 ++- lib/chibi/net.scm | 20 +++++++++++++++----- lib/chibi/net.stub | 9 +++++---- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/lib/chibi/net.module b/lib/chibi/net.module index 7943f5c9..62a27691 100644 --- a/lib/chibi/net.module +++ b/lib/chibi/net.module @@ -6,7 +6,8 @@ address-info-family address-info-socket-type address-info-protocol address-info-address address-info-address-length address-info-next address-family/unix address-family/inet - socket-type/stream socket-type/datagram socket-type/raw) + socket-type/stream socket-type/datagram socket-type/raw + ip-proto/tcp ip-proto/udp) (import (scheme)) (import (chibi filesystem)) (include-shared "net") diff --git a/lib/chibi/net.scm b/lib/chibi/net.scm index 65998bde..e0aa14a1 100644 --- a/lib/chibi/net.scm +++ b/lib/chibi/net.scm @@ -1,6 +1,20 @@ ;; Copyright (c) 2010-2011 Alex Shinn. All rights reserved. ;; BSD-style license: http://synthcode.com/license.txt +;;> @subsubsubsection{@scheme{(get-address-info host service [addrinfo])}} + +;;> Create and return a new addrinfo structure for the given host +;;> and service. @var{host} should be a string and @var{service} a +;;> string or integer. The optional @var{addrinfo} defaults to +;;> a TCP/IP stream setting. + +(define (get-address-info host service . o) + (%get-address-info host + (if (integer? service) (number->string service) service) + (make-address-info address-family/inet + socket-type/stream + ip-proto/tcp))) + ;;> Opens a client net connection to @var{host}, a string, ;;> on port @var{service}, which can be a string such as ;;> @scheme{"http"} or an integer. Returns a list of two @@ -8,11 +22,7 @@ ;;> or @scheme{#f} on failure. (define (open-net-io host service) - (let lp ((addr (get-address-info host - (if (integer? service) - (number->string service) - service) - #f))) + (let lp ((addr (get-address-info host service #f))) (if (not addr) (error "couldn't find address" host service) (let ((sock (socket (address-info-family addr) diff --git a/lib/chibi/net.stub b/lib/chibi/net.stub index 45642fc8..e598e48b 100644 --- a/lib/chibi/net.stub +++ b/lib/chibi/net.stub @@ -20,10 +20,7 @@ ;;> The addrinfo struct accessors. ;;/ -;;> Create and return a new addrinfo structure for the -;;> given host and service. - -(define-c errno (get-address-info getaddrinfo) +(define-c errno (%get-address-info getaddrinfo) (string string (maybe-null addrinfo) (result free addrinfo))) ;;> Bind a name to a socket. @@ -51,4 +48,8 @@ (define-c-const int (socket-type/stream "SOCK_STREAM")) (define-c-const int (socket-type/datagram "SOCK_DGRAM")) (define-c-const int (socket-type/raw "SOCK_RAW")) +(define-c-const int (ip-proto/tcp "IPPROTO_TCP")) +(define-c-const int (ip-proto/udp "IPPROTO_UDP")) +;;> The constants for the addrinfo struct. +;;/