I create a non-blocking socket inside the thread spawned inside the fiber with the following code:
(define-module (nonblocking-socket)
#:use-module (ice-9 threads)
#:use-module (fibers)
#:export (create-socket))
(define* (create-socket
#:key (port 1134))
(define (make-default-socket family addr port)
(let ((sock (socket PF_INET SOCK_STREAM 0)))
;; (fcntl sock F_SETFD FD_CLOEXEC)
(fcntl sock F_SETFL (logior O_NONBLOCK (fcntl sock F_GETFL)))
sock))
(define tmp-socket
(make-default-socket AF_INET INADDR_LOOPBACK 1234))
(connect tmp-socket (make-socket-address AF_INET INADDR_LOOPBACK port))
(close-port tmp-socket))
(define-public (tmp)
(run-fibers
(lambda ()
(call-with-new-thread
(lambda () (create-socket)))
(sleep 1)
'yay)))
and I receive
In nonblocking-socket.scm:
13:2 3 (_)
In ice-9/suspendable-ports.scm:
68:33 2 (_ #<input-output: socket 63> _ . _)
In fibers/scheduler.scm:
355:13 1 WARNING: (nonblocking-socket): imported module (fibers) overrides core binding `sleep'
(suspend-current-task #<procedure 7f71a8f45c40 at fiber...>)
In ice-9/boot-9.scm:
1676:22 0 (raise-exception _ #:continuable? _)
ice-9/boot-9.scm:1676:22: In procedure raise-exception:
In procedure struct-vtable: Wrong type argument in position 1 (expecting struct): #f
Expected behavior is to get Connection refused or succesfully connect if another socket on target port is listening.