mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-07-07 05:06:37 +02:00
Making the addrinfo argument to open-net-io and with-net-io default to TCP/IP.
This commit is contained in:
parent
ddb6f31d58
commit
50ace689b4
3 changed files with 22 additions and 10 deletions
|
@ -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")
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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.
|
||||
;;/
|
||||
|
|
Loading…
Add table
Reference in a new issue