Revision: 5992
Author: iratqq
Date: Sat Aug 29 23:23:42 2009
Log: * scm/socket.scm (tcp-connect):
- Copy from (http:get).
(unix-domain-socket-connect):
- Copy from (prime-open-unix-domain-socket).
* scm/http-client.scm (http:open):
- Remove.
(http:get):
- Use (tcp-connect).
* scm/prime.scm (prime-open-with-tcp-socket):
- Use (tcp-connect).
(prime-connection-init):
- Use unix-domain-socket-connect.
http://code.google.com/p/uim/source/detail?r=5992
Modified:
/trunk/scm/http-client.scm
/trunk/scm/prime.scm
/trunk/scm/socket.scm
=======================================
--- /trunk/scm/http-client.scm Sat Aug 29 22:15:10 2009
+++ /trunk/scm/http-client.scm Sat Aug 29 23:23:42 2009
@@ -35,31 +35,6 @@
(require "input-parse.scm")
(require "openssl.scm")
-(define (http:open hostname servname)
- (call-with-getaddrinfo-hints
- '($AI_PASSIVE) '$PF_UNSPEC '$SOCK_STREAM #f
- (lambda (hints)
- (call-with-getaddrinfo
- hostname servname hints
- (lambda (res)
- (call/cc
- (lambda (fd)
- (map (lambda (res0)
- (let ((s (socket (addrinfo-ai-family? res0)
- (addrinfo-ai-socktype? res0)
- (addrinfo-ai-protocol? res0))))
- (if (< s 0)
- #f
- (if (< (connect s
- (addrinfo-ai-addr? res0)
- (addrinfo-ai-addrlen? res0))
- 0)
- (begin
- (file-close s)
- #f)
- (fd s)))))
- res))))))))
-
(define (http:encode-uri-string str)
(define
hex '("0" "1" "2" "3" "4" "5" "6" "7" "8" "9" "A" "B" "C" "D" "E" "F"))
(define (hex-format2 x)
@@ -220,10 +195,10 @@
(call-with-open-openssl-file-port file (method? ssl)
thunk))
call-with-open-file-port))
(file (if (http-proxy? proxy)
- (http:open (hostname? proxy) (port? proxy))
+ (tcp-connect (hostname? proxy) (port? proxy))
(if with-ssl?
- (http:open hostname (port? ssl))
- (http:open hostname servname)))))
+ (tcp-connect hostname (port? ssl))
+ (tcp-connect hostname servname)))))
(if (not file)
(uim-notify-fatal (N_ "cannot connect server")))
(call-with-open-file-port-function
=======================================
--- /trunk/scm/prime.scm Mon Mar 2 21:46:35 2009
+++ /trunk/scm/prime.scm Sat Aug 29 23:23:42 2009
@@ -816,21 +816,8 @@
(define prime-open-unix-domain-socket
(lambda (socket-path)
- (let ((s (socket (addrinfo-ai-family-number '$PF_LOCAL)
- (addrinfo-ai-socktype-number '$SOCK_STREAM)
- 0)))
- (if (< s 0)
- #f
- (call-with-sockaddr-un
- (addrinfo-ai-family-number '$PF_LOCAL)
- socket-path
- (lambda (sun)
- (if (< (connect s sun (sun-len sun))
- 0)
- (begin
- (file-close s)
- #f)
- (cons s s))))))))
+ (and-let* ((fd (unix-domain-socket-connect socket-path)))
+ (cons fd fd))))
(define prime-open-with-unix-domain-socket
(lambda (socket-path)
@@ -864,29 +851,8 @@
(define prime-open-with-tcp-socket
(lambda (hostname servname)
- (call-with-getaddrinfo-hints
- '($AI_PASSIVE) '$PF_UNSPEC '$SOCK_STREAM #f
- (lambda (hints)
- (call-with-getaddrinfo
- hostname servname hints
- (lambda (res)
- (call/cc
- (lambda (fds)
- (map (lambda (res0)
- (let ((s (socket (addrinfo-ai-family? res0)
- (addrinfo-ai-socktype? res0)
- (addrinfo-ai-protocol? res0))))
- (if (< s 0)
- #f
- (if (< (connect s
- (addrinfo-ai-addr? res0)
- (addrinfo-ai-addrlen? res0))
- 0)
- (begin
- (file-close s)
- #f)
- (fds (cons s s))))))
- res)))))))))
+ (and-let* ((fd (tcp-connect prime-tcpserver-name
prime-tcpserver-port)))
+ (cons fd fd))))
(define prime-open-with-pipe
(lambda (path)
=======================================
--- /trunk/scm/socket.scm Sun Mar 15 22:56:22 2009
+++ /trunk/scm/socket.scm Sat Aug 29 23:23:42 2009
@@ -85,3 +85,45 @@
ret))
(define shutdown-how-alist (shutdown-how-alist?))
+
+(define (tcp-connect hostname servname)
+ (call-with-getaddrinfo-hints
+ '($AI_PASSIVE) '$PF_UNSPEC '$SOCK_STREAM #f
+ (lambda (hints)
+ (call-with-getaddrinfo
+ hostname servname hints
+ (lambda (res)
+ (call/cc
+ (lambda (fd)
+ (map (lambda (res0)
+ (let ((s (socket (addrinfo-ai-family? res0)
+ (addrinfo-ai-socktype? res0)
+ (addrinfo-ai-protocol? res0))))
+ (if (< s 0)
+ #f
+ (if (< (connect s
+ (addrinfo-ai-addr? res0)
+ (addrinfo-ai-addrlen? res0))
+ 0)
+ (begin
+ (file-close s)
+ #f)
+ (fd s)))))
+ res))))))))
+
+(define (unix-domain-socket-connect socket-path)
+ (let ((s (socket (addrinfo-ai-family-number '$PF_LOCAL)
+ (addrinfo-ai-socktype-number '$SOCK_STREAM)
+ 0)))
+ (if (< s 0)
+ #f
+ (call-with-sockaddr-un
+ (addrinfo-ai-family-number '$PF_LOCAL)
+ socket-path
+ (lambda (sun)
+ (if (< (connect s sun (sun-len sun))
+ 0)
+ (begin
+ (file-close s)
+ #f)
+ s))))))