Last active
October 18, 2023 16:42
-
-
Save samdphillips/26f78e17da72fff6d69b272b71bae013 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang racket/base | |
;; Works on Linux, doesn't work on Mac? | |
(require ffi/unsafe | |
ffi/unsafe/define) | |
(define-ffi-definer define-curl (ffi-lib "libcurl") | |
#:provide provide-protected) | |
(define-syntax-rule (define/provide name val) | |
(begin (define name val) (provide name))) | |
(define/provide CURL_GLOBAL_ALL #b11) | |
(define-curl curl_global_init (_fun _long -> _int)) | |
(define-curl curl_global_cleanup (_fun -> _void)) | |
(define-cpointer-type _curl) | |
(define-curl curl_easy_init (_fun -> _curl)) | |
(define-curl curl_easy_cleanup (_fun _curl -> _void)) | |
(define-curl curl_easy_perform (_fun _curl -> _int)) | |
(define-syntax-rule (define-curl-setopt name _type enum-expr) | |
(define-curl name | |
(let ([enum-value enum-expr]) | |
(_fun (h option-value) :: | |
(h : _curl) (_uint = enum-value) (option-value : _type) | |
-> _int)) | |
#:c-id curl_easy_setopt)) | |
(define CURLOPTTYPE_LONG 0) | |
(define CURLOPTTYPE_OBJECTPOINT 10000) | |
(define CURLOPTTYPE_FUNCTIONPOINT 20000) | |
(define CURLOPTTYPE_STRINGPOINT CURLOPTTYPE_OBJECTPOINT) | |
(define CURLOPTTYPE_CBPOINT CURLOPTTYPE_OBJECTPOINT) | |
(define-curl-setopt curl_easy_setopt_url _string (+ CURLOPTTYPE_STRINGPOINT 2)) | |
(define-curl-setopt curl_easy_setopt_verbose _bool (+ CURLOPTTYPE_LONG 41)) | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
(curl_global_init CURL_GLOBAL_ALL) | |
(define url "https://www.google.com") | |
(define h (curl_easy_init)) | |
(curl_easy_setopt_verbose h #t) | |
(curl_easy_setopt_url h url) | |
(curl_easy_perform h) | |
(curl_easy_cleanup h) | |
(curl_global_cleanup) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment