Skip to content

Instantly share code, notes, and snippets.

@orthecreedence
Last active August 29, 2015 14:02
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 orthecreedence/a2b666419fe220bfae31 to your computer and use it in GitHub Desktop.
Save orthecreedence/a2b666419fe220bfae31 to your computer and use it in GitHub Desktop.
ECL socket failure (segfault) test
(ql:quickload :cl-async)
(defpackage :sock-test
(:use :cl)
(:export :delay
:request))
(in-package :sock-test)
(defun delay ()
"Use an async delay. This uses the standard cl-async callback mechanism, which
passes a cffi:callback type to libevent that when invoked (by he event loop)
looks up the lambda containing our format statement and runs it.
It works great."
(as:with-event-loop ()
(as:delay (lambda () (format t "~%~%---~%it worked!~%---~%")) :time 3)))
(defun request ()
"Do an async TCP request. This uses the same callback mechanism as as:delay,
but for some reason segfaults."
(as:with-event-loop ()
(as:tcp-connect "50.116.25.201" 80
(lambda (sock data)
(declare (ignore sock))
(format t "got data: ~a~%" data))
(lambda (ev)
(format t "(ev): ~a~%" ev))
:read-timeout 5
:data (format nil "GET /~c~c" #\return #\newline))))
;; EDIT: thanks Matt
(compile 'delay)
(compile 'request)
(delay)
(request)
@orthecreedence
Copy link
Author

GDB trace. Very helpful.

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 7768.0xc58]
0x00000143 in ?? ()
(gdb) bt
#0  0x00000143 in ?? ()
#1  0x003d0000 in ?? ()
#2  0x00000001 in ?? ()
#3  0x0000000d in ?? ()
#4  0x0000000d in ?? ()
#5  0x04a3b3d4 in ?? ()
Backtrace stopped: previous frame inner to this frame (corrupt stack?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment