Changeset 8033 in project


Ignore:
Timestamp:
02/01/08 23:11:38 (12 years ago)
Author:
sjamaan
Message:

Take iounit size into account for read/write messages and remove some nasty hardcoded sizes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • release/3/9p/trunk/9p-client.scm

    r8031 r8033  
    9898;; File IDs and handles
    9999(define-record 9p:handle
    100   connection fid position)
     100  connection fid position iounit)
    101101
    102102;; Allocate the lowest fid that's not in use yet and return a handle to it
     
    111111     (else
    112112      (9p:connection-open-fids-set! con (bit-vector-set! fids highest #t))
    113       (make-9p:handle con highest 0)))))
     113      ;; 23 is the biggest size of a message (write), but libixp uses 24, so we do too to stay safe
     114      (make-9p:handle con highest 0 (- (9p:connection-message-size con) 24))))))
    114115
    115116;; Deallocate the given handle from the list (does _not_ clunk it)
     
    119120  (9p:handle-connection-set! h #f)
    120121  (9p:handle-fid-set! h #f)
     122  (9p:handle-iounit-set! h #f)
    121123  (void))
    122124
     
    155157;; Probably want to roll walk and other file ops into one
    156158(define (9p:file-open con name mode)
    157   (let ((h (9p:path-walk con name)))
    158     (9p:request (9p:handle-connection h) 'Topen (9p:handle-fid h) mode)
     159  (let* ((h (9p:path-walk con name))
     160         (response (9p:request (9p:handle-connection h) 'Topen (9p:handle-fid h) mode))
     161         (iounit (second (9p:message-contents response))))
     162    (unless (zero? iounit)
     163      (9p:handle-iounit-set! h iounit)) ; Otherwise just keep it at the default
    159164    h))
    160165
     
    188193        (list (blob->string (u8vector->blob/shared (apply u8vector-append! (reverse result)))) total) ; file-read also returns a list of data + length
    189194        (let* ((pos (9p:handle-position h))
    190                (con (9p:handle-connection h))
    191                (receive-size (min bytes-left (- (9p:connection-message-size con) 11))) ; 11 is message size of a Rread message - data
     195               (receive-size (min bytes-left (9p:handle-iounit h)))
    192196               (response (9p:request (9p:handle-connection h) 'Tread (9p:handle-fid h) pos receive-size))
    193197               (data (car (9p:message-contents response)))
     
    203207            (loop (- bytes-left read) (+ total read) (cons data result))))))))
    204208
    205 ;; XXX Hardcoding the message sizes is ugly!
    206209(define (9p:file-write h buffer . rest)
    207210  (let ((buffer (if (string? buffer)
    208211                    (blob->u8vector/shared (string->blob buffer))
    209                     buffer))
    210         (con (9p:handle-connection h)))
     212                    buffer)))
    211213    (let-optionals rest ((size (u8vector-length buffer)))
    212214      (let loop ((bytes-left size)
     
    215217            total
    216218            (let* ((pos (9p:handle-position h))
    217                    (send-size (min bytes-left (- (9p:connection-message-size con) 23))) ;; 23 is message size of a Twrite message - data
    218                    (response (9p:request con 'Twrite (9p:handle-fid h) pos (u8vector-slice buffer total send-size)))
     219                   (send-size (min bytes-left (9p:handle-iounit h)))
     220                   (response (9p:request (9p:handle-connection h) 'Twrite (9p:handle-fid h) pos (u8vector-slice buffer total send-size)))
    219221                   (written (car (9p:message-contents response))))
    220222              (9p:handle-position-set! h (+ pos written))
    221               (if (zero? written)
    222                   total    ;; Throw an error instead?
    223                   (loop (- bytes-left written) (+ total written)))))))))
     223              (if (not (= written send-size))
     224                  (9p:server-error 'Twrite (sprintf "Unexpected bytecount ~A in Rwrite response (not a proper server error message)" written)))
     225              (printf "WRITTEN: ~S\n" written)
     226              (loop (- bytes-left written) (+ total written))))))))
    224227
    225228; (qid permission-mode time time filesize string string string string)
     
    316319(define (9p:read-directory h show-dotfiles?)
    317320  (let loop ((result (list))
    318              (pos 0)
    319              (con (9p:handle-connection h)))
    320     (let* ((response (9p:request con 'Tread (9p:handle-fid h) pos (- (9p:connection-message-size con) 11))) ; 11 is message size of a Rread message - data
     321             (pos 0))
     322    (let* ((response (9p:request (9p:handle-connection h) 'Tread (9p:handle-fid h) pos (9p:handle-iounit h)))
    321323           (data (car (9p:message-contents response)))
    322324           (read (u8vector-length data)))
    323325      (if (zero? read)
    324326          (9p:data->directory-listing (apply u8vector-append! (reverse result)) show-dotfiles?)
    325           (loop (cons data result) (+ pos read) con)))))
     327          (loop (cons data result) (+ pos read))))))
    326328
    327329(define (9p:open-output-file con file)
Note: See TracChangeset for help on using the changeset viewer.