Skip to content

Instantly share code, notes, and snippets.

@michaelballantyne
Last active September 30, 2019 16:46
Show Gist options
  • Save michaelballantyne/1aeb9c56d56915e49d1eebe5d49ca466 to your computer and use it in GitHub Desktop.
Save michaelballantyne/1aeb9c56d56915e49d1eebe5d49ca466 to your computer and use it in GitHub Desktop.
close-output-port errors
#lang racket
(match-define (list pout pin id perr f) (process "exit"))
(with-handlers ([exn:fail? (lambda (e) (printf "error in write: \n~a\n" e) (void))])
(write-bytes #"foo" pin)
(flush-output pin)
(sleep 0.1)
(write-bytes #"bar" pin)
(flush-output pin))
(with-handlers ([exn:fail? (lambda (e) (printf "error in close: \n~a\n" e) (void))])
(close-output-port pin))
#lang racket
(define (server)
(define l (tcp-listen 8000))
(define-values (in out) (tcp-accept l))
(tcp-close l)
(close-input-port in)
(close-output-port out))
(define (client)
(define-values (in out) (tcp-connect "127.0.0.1" 8000))
(with-handlers ([exn:fail? (lambda (e) (printf "error in write: \n~a\n" e) (void))])
(write-bytes #"foo" out)
(flush-output out)
(sleep 0.1)
(write-bytes #"bar" out)
(flush-output out))
(with-handlers ([exn:fail? (lambda (e) (printf "error in close: \n~a\n" e) (void))])
(close-output-port out)))
(define t (thread server))
(sleep 0.1)
(client)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment