Ignore:
Timestamp:
08/13/20 19:24:25 (3 years ago)
Author:
Mark Evenson
Message:

abcl-introspect: EXT:STREAM-UNIX-FD returns integer file descriptor

The integer can be passed meaningfully by passed to syscalls like
fdopen().

TODO: implement in the core application, current strategy needs JSS to

reliably finad access private member fields

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/abcl/contrib/abcl-introspect/util.lisp

    r15356 r15367  
    2222      (java:jnew-array-from-array "byte" array))))
    2323 
    24  
    2524(export '(write-class
    2625          read-class)
    2726        :extensions)
    2827
     28;;;  Determining the underlying unix file descriptor depends on
     29;;;  navigating private member structures dependent on the hosting
     30;;;  JVMs wrapping of native socket. The JAVA package currently does
     31;;;  not have a means for such aggressive intropsection, so we add it
     32;;;  as a utility here
     33;;;
     34;;;  TODO test under :msdog
     35;;;  TODO Should be in socket.lisp
     36(defun stream-unix-fd (stream)
     37  "Return the integer of the underlying unix file descriptor for STREAM
     38
     39Added by ABCL-INTROSPECT."
     40  (check-type stream 'system::socket-stream)
     41  (flet ((get-java-fields (object fields) ;; Thanks to Cyrus Harmon
     42           (reduce (lambda (x y)
     43                     (jss:get-java-field x y t))
     44                          fields
     45                          :initial-value object))
     46                (jvm-version ()
     47                  (read
     48                   (make-string-input-stream
     49                    (java:jstatic "getProperty" "java.lang.System"
     50                                  "java.specification.version")))))
     51           (ignore-errors
     52            (get-java-fields (java:jcall "getWrappedInputStream"  ;; TODO: define this as a constant
     53                                         (two-way-stream-input-stream stream))
     54                             (if (< (jvm-version) 14)
     55                                 '("in" "ch" "fdVal")
     56                                 '("in" "this$0" "sc" "fd" "fd"))))))
     57
     58(export '(stream-unix-fd) :extensions)
Note: See TracChangeset for help on using the changeset viewer.