awwx.ws

client-socket1

http://awwx.ws/client-socket1.arc:

(scheme (require openssl))

(scheme
 (xdef ar-init-socket
   (lambda (init-fn . args)
     (let ((oc (current-custodian))
           (nc (make-custodian)))
       (current-custodian nc)
       (apply
         (lambda (in out . tail)
           (current-custodian oc)
           (associate-custodian nc in out)
           (list* in out tail))
         (call-with-values
           init-fn
           (if (pair? args)
               (car args)
               list)))))))

(def socket-connect (host port)
  (ar-init-socket (fn () (scheme.tcp-connect host port))))

(def ssl-connect (host port)
  (ar-init-socket (fn () (scheme.ssl-connect host port))))

Authors

The original socket initialization code is from arc3.1 ac.scm.

The extraction of the initializaiton code into ar-init-socket and the provision of socket-connect was checked into Anarki in August 2009 by Justin Kendrick.

The addition of ssl-connect was checked into Anarki in December 2009 by Mark Huetsch.

Prerequisites

This hack depends on arc3.1 and scheme0.

Contact me

Twitter: awwx
Email: andrew.wilcox [at] gmail.com