Skip to content

Commit

Permalink
tests: Use SOCK_NONBLOCK instead of extra 'fcntl' calls.
Browse files Browse the repository at this point in the history
* tests/ports.scm: Pass SOCK_NONBLOCK in 'socket' and 'accept' calls and
remove 'fcntl' calls.
  • Loading branch information
civodul committed Nov 9, 2022
1 parent 3c7c861 commit 6e87122
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions tests/ports.scm
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,19 @@
;; waiter list and epoll set are properly updated when a file
;; descriptor with the same value is reused, allowing the eventual
;; 'accept' call to succeed.
(let ((sock (socket AF_INET SOCK_STREAM 0)))
(let ((sock (socket AF_INET (logior SOCK_NONBLOCK SOCK_STREAM)
0)))
(pk 'listening-socket sock)
(setsockopt sock SOL_SOCKET SO_REUSEADDR 1)
(bind* sock address)
(listen sock 1)
(fcntl sock F_SETFL
(logior O_NONBLOCK (fcntl sock F_GETFL)))

(if (zero? n)
(begin
;; Let's go.
(put-message notification 'ready!)
(match (pk 'accepted-connection (accept sock))
(match (pk 'accepted-connection (accept sock SOCK_NONBLOCK))
((connection . _)
(fcntl connection F_SETFL
(logior O_NONBLOCK (fcntl connection F_GETFL)))
(display (pk 'received (read-line connection)) connection)
(newline connection)
(close-port connection))))
Expand Down Expand Up @@ -101,9 +98,8 @@
(match (get-message notification)
('ready!
;; Connect, send a message, and receive its echo.
(let ((sock (socket AF_INET SOCK_STREAM 0)))
(fcntl sock F_SETFL
(logior O_NONBLOCK (fcntl sock F_GETFL)))
(let ((sock (socket AF_INET (logior SOCK_NONBLOCK SOCK_STREAM)
0)))
(connect sock address)
(pk 'connected address)
(display "hello!\n" sock)
Expand Down

0 comments on commit 6e87122

Please sign in to comment.