<div dir="ltr"><div><div><div>I settled for the following implementation, which is spec compliant:<br><a href="https://github.com/vyzo/gerbil/blob/master/src/lang/scheme/base-ports.ss#L88">https://github.com/vyzo/gerbil/blob/master/src/lang/scheme/base-ports.ss#L88</a><br><br></div>It first checks the roptions/woptions with macro-closed?, and then if it is a device port it checks the read/write_stage.<br></div>It doesn't understand permanent-close, but the spec only requires that close-* has been called on the port and has no notion of either threads or non-permenantly closed ports.<br><br></div>-- vyzo<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Mar 24, 2018 at 2:25 PM, Dimitris Vyzovitis <span dir="ltr"><<a href="mailto:vyzo@hackzen.org" target="_blank">vyzo@hackzen.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div>What about using the port roptions/woptions in conjunction with the permanent-close property?<br></div>This could work for u8vector/string/vector ports, but I don't know about pipes.<br><br></div>-- vyzo<br></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Mar 24, 2018 at 1:59 PM, Dimitris Vyzovitis <span dir="ltr"><<a href="mailto:vyzo@hackzen.org" target="_blank">vyzo@hackzen.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div>that's a very good point, i keep forgetting about the non-permanent closure of pipes and its usability.<br></div>snarfing the read/write stage from the device may be ok, although we won't be able to tell for pure scheme ports.<br><br></div><div>-- vyzo<br></div></div><div class="m_-8147568488745479403HOEnZb"><div class="m_-8147568488745479403h5"><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Mar 24, 2018 at 1:56 PM, Marc Feeley <span dir="ltr"><<a href="mailto:feeley@iro.umontreal.ca" target="_blank">feeley@iro.umontreal.ca</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Knowing that close-port was called on a port is not sufficient to tell if the port is “closed” or not.  Apart from what it means for a port to be “closed”, there are ports that don’t close permanently when close-port is called on them.  See the example below of a pipe used for the communication between two threads.  It allows using close-port to send an “end-of-file” to the other thread multiple times.<br>
<br>
For “device” ports however, there is a state in the port object at the C level.  The fields read_stage and write_stage will be different from ___STAGE_OPEN when the device port no longer accepts reading or writing.  Perhaps that is the information you want.  Note that not all ports are device ports.<br>
<br>
Marc<br>
<br>
<br>
(define in #f)<br>
(define out #f)<br>
<br>
(receive (i o) (open-string-pipe (list permanent-close: #f))<br>
  (set! in i)<br>
  (set! out o))<br>
<br>
(define (send x)<br>
  (write x out)<br>
  (newline out)<br>
  (force-output out)<br>
  (thread-sleep! 0.5))<br>
<br>
(define (close)<br>
  (close-output-port out)<br>
  (thread-sleep! 0.5))<br>
<br>
(thread-start!<br>
 (make-thread<br>
  (lambda ()<br>
    (let loop ()<br>
      (let ((x (read in)))<br>
        (pp x)<br>
        (loop))))))<br>
<br>
(send '(11))<br>
(send '(22))<br>
<br>
(close)<br>
<br>
(send '(33))<br>
(send '(44))<br>
<br>
(close)<br>
(close)<br>
<br>
(send '(55))<br>
<br>
;; output:<br>
;; (11)<br>
;; (22)<br>
;; #!eof<br>
;; (33)<br>
;; (44)<br>
;; #!eof<br>
;; #!eof<br>
;; (55)<br>
<div class="m_-8147568488745479403m_-2773434253786603421HOEnZb"><div class="m_-8147568488745479403m_-2773434253786603421h5"><br>
<br>
> On Mar 24, 2018, at 5:51 AM, Dimitris Vyzovitis <<a href="mailto:vyzo@hackzen.org" target="_blank">vyzo@hackzen.org</a>> wrote:<br>
><br>
> You can't tell if a file descriptor is closed in general, that's not what I am after.<br>
> I just want to know if close-port was applied to the port.<br>
><br>
> -- vyzo<br>
><br>
> On Sat, Mar 24, 2018 at 11:43 AM, Adam <<a href="mailto:adam.mlmb@gmail.com" target="_blank">adam.mlmb@gmail.com</a>> wrote:<br>
> The BSD/unix API does not allow this for TCP sockets, as in tapping into the OS' knowledge of whether a connection was closed, the only way to learn that is by trying to write to it.<br>
><br>
> However with respect to Gambit knowing whether |close-port| was applied on a port, of course you should be able to retrieve that.<br>
><br>
> 2018-03-24 16:29 GMT+08:00 Dimitris Vyzovitis <<a href="mailto:vyzo@hackzen.org" target="_blank">vyzo@hackzen.org</a>>:<br>
> Is there a reasonable way to detect whether a port has been closed?<br>
> I want to implement input-port-open? and output-port-open? for r7rs coverage...<br>
><br>
> -- vyzo<br>
><br>
> ______________________________<wbr>_________________<br>
> Gambit-list mailing list<br>
> <a href="mailto:Gambit-list@iro.umontreal.ca" target="_blank">Gambit-list@iro.umontreal.ca</a><br>
> <a href="https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list" rel="noreferrer" target="_blank">https://webmail.iro.umontreal.<wbr>ca/mailman/listinfo/gambit-lis<wbr>t</a><br>
><br>
><br>
><br>
<br>
</div></div></blockquote></div><br></div>
</div></div></blockquote></div><br></div>
</div></div></blockquote></div><br></div>