Skip to content

Instantly share code, notes, and snippets.

@samdphillips
Last active October 18, 2023 19:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samdphillips/cb18c3975ef47c9e0584e7767ef1719b to your computer and use it in GitHub Desktop.
Save samdphillips/cb18c3975ef47c9e0584e7767ef1719b to your computer and use it in GitHub Desktop.
#lang racket/base
;; Works on Linux, doesn't work on Mac? More minimal version.
(require ffi/unsafe
ffi/unsafe/define)
(define-ffi-definer define-curl (ffi-lib "libcurl"))
(define 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-curl curl_easy_setopt_url
(_fun (h val) ::
(h : _curl) (_uint = 10002) (val : _string) -> _int)
#:c-id curl_easy_setopt)
(define-curl curl_easy_setopt_verbose
(_fun (h val) ::
(h : _curl) (_uint = 41) (val : _bool) -> _int)
#:c-id curl_easy_setopt)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(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