[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 10/10: Non-blocking accept/connect Scheme support
From: |
Andy Wingo |
Subject: |
[Guile-commits] 10/10: Non-blocking accept/connect Scheme support |
Date: |
Thu, 9 Jun 2016 09:01:13 +0000 (UTC) |
wingo pushed a commit to branch master
in repository guile.
commit 6788faba7a36bf767fda0376025f5847222ef761
Author: Andy Wingo <address@hidden>
Date: Thu Jun 2 23:02:21 2016 +0200
Non-blocking accept/connect Scheme support
* module/ice-9/sports.scm (accept, connect): New Scheme functions.
---
module/ice-9/suspendable-ports.scm | 23 ++++++++++++++++++++++-
1 file changed, 22 insertions(+), 1 deletion(-)
diff --git a/module/ice-9/suspendable-ports.scm
b/module/ice-9/suspendable-ports.scm
index 6d3d405..bc84a4a 100644
--- a/module/ice-9/suspendable-ports.scm
+++ b/module/ice-9/suspendable-ports.scm
@@ -671,10 +671,31 @@
(when (and (eqv? char #\newline) (port-line-buffered? port))
(flush-output port))))
+(define accept
+ (let ((%accept (@ (guile) accept)))
+ (lambda (port)
+ (let lp ()
+ (or (%accept port)
+ (begin
+ (wait-for-readable port)
+ (lp)))))))
+
+(define connect
+ (let ((%connect (@ (guile) connect)))
+ (lambda (port sockaddr . args)
+ (unless (apply %connect port sockaddr args)
+ ;; Clownshoes semantics; see connect(2).
+ (wait-for-writable port)
+ (let ((err (getsockopt port SOL_SOCKET SO_ERROR)))
+ (unless (zero? err)
+ (scm-error 'system-error "connect" "~A"
+ (list (strerror err)) #f)))))))
+
(define saved-port-bindings #f)
(define port-bindings
'(((guile)
- read-char peek-char force-output close-port)
+ read-char peek-char force-output close-port
+ accept connect)
((ice-9 binary-ports)
get-u8 lookahead-u8 get-bytevector-n
put-u8 put-bytevector)
- [Guile-commits] branch master updated (9454068 -> 6788fab), Andy Wingo, 2016/06/09
- [Guile-commits] 01/10: socket: TCP_CORK, TCP_NODELAY, Andy Wingo, 2016/06/09
- [Guile-commits] 07/10: put-char in Scheme, Andy Wingo, 2016/06/09
- [Guile-commits] 04/10: Undocument (ice-9 rw), Andy Wingo, 2016/06/09
- [Guile-commits] 09/10: Support `connect' on nonblocking sockets, Andy Wingo, 2016/06/09
- [Guile-commits] 10/10: Non-blocking accept/connect Scheme support,
Andy Wingo <=
- [Guile-commits] 08/10: `accept' on nonblocking socket can return #f, Andy Wingo, 2016/06/09
- [Guile-commits] 02/10: put-char, put-string in (ice-9 ports internals), Andy Wingo, 2016/06/09
- [Guile-commits] 03/10: Add (ice-9 textual-ports), Andy Wingo, 2016/06/09
- [Guile-commits] 06/10: Update port documentation, rename sports to suspendable ports, Andy Wingo, 2016/06/09
- [Guile-commits] 05/10: Big ports documentation update, Andy Wingo, 2016/06/09