Welcome to the CHICKEN Scheme pasting service

error in list-tail pasted by certainty on Fri Jul 8 09:43:20 2011

(use zmq)

(define (startup #!key (publisher-endpoint "tcp://*:6868") (control-endpoint "tcp://*:6767"))
  (let* ((control    (make-poll-item (make-socket 'rep)))
         (publisher  (make-poll-item (make-socket 'pub)))
         (frontends  (list))
         (poll-items (list control publisher)))
    
    (bind-socket (poll-item-socket control)   control-endpoint)
    (bind-socket (poll-item-socket publisher) publisher-endpoint)


    (let loop ((ready (poll poll-items 1)))
      (when ready
        (printf "Item ready !~%"))
      (loop (poll poll-items 1)))))


(startup)

with fixnum return pasted by certainty on Fri Jul 8 09:56:49 2011

(use zmq)

(define (startup #!key (publisher-endpoint "tcp://*:6868") (control-endpoint "tcp://*:6767"))
  (let* ((control    (make-poll-item (make-socket 'rep)))
         (publisher  (make-poll-item (make-socket 'pub)))
         (frontends  (list))
         (poll-items (list control publisher)))
    
    (bind-socket (poll-item-socket control)   control-endpoint)
    (bind-socket (poll-item-socket publisher) publisher-endpoint)


    (let loop ((ready-items (poll poll-items 1)))
      (unless (zero? ready-items)
        (printf "Item ready !~%"))
      (loop (poll poll-items 1)))))


(startup)

my version with error pasted by c-keen on Fri Jul 8 09:57:45 2011

(use zmq)

(define (startup #!key (publisher-endpoint "tcp://*:6868") (control-endpoint "tcp://*:6767"))
  (let* ((control    (make-poll-item (make-socket 'rep)))
         (publisher  (make-poll-item (make-socket 'pub)))
         (frontends  (list))
         (poll-items (list control publisher)))
    
    (bind-socket (poll-item-socket control)   control-endpoint)
    (bind-socket (poll-item-socket publisher) publisher-endpoint)


    (let loop ((ready (poll poll-items 1)))
	      (when (< 0 ready)
		(printf "Item ready ~a!~%" ready))
	      (loop (poll poll-items 1)))))


(startup)

zmq poll pasted by certainty on Fri Jul 8 10:14:36 2011

(define %poll-sockets
  (foreign-safe-lambda* int
                        ((scheme-object poll_item_ref)
                         (unsigned-int length)
                         (long timeout))
                        "zmq_pollitem_t items[length];
                         zmq_pollitem_t *item_ptrs[length];
                         int i;

                         for (i = 0; i < length; i++) {
                           C_save(C_fix(i));
                           item_ptrs[i] = (zmq_pollitem_t *)C_pointer_address(C_callback(poll_item_ref, 1));
                         }

                         for (i = 0; i < length; i++) {
                           items[i] = *item_ptrs[i];
                         }

                         int rc = zmq_poll(items, length, timeout);

                         if (rc != -1) {
                           for (i = 0; i < length; i++) {
                             (*item_ptrs[i]).revents = items[i].revents;
                           }
                         }

                         C_return(rc);"))

(define (poll poll-items timeout/block)
  (if (null? poll-items)
      (error 'poll "null list passed for poll-items")
      (let ((result (%poll-sockets (lambda (i) 
                                     (poll-item-pointer (list-ref poll-items i))) ;; <---- HERE it is
                                   (length poll-items)
                                   (case timeout/block
                                     ((#f) 0)
                                     ((#t) -1)
                                     (else timeout/block)))))
        (if (= result -1)
            (zmq-error 'poll)
            result))))

with debug output pasted by certainty on Fri Jul 8 10:24:43 2011



(define (poll poll-items timeout/block)
  (if (null? poll-items)
      (error 'poll "null list passed for poll-items")
      (let ((result (%poll-sockets (lambda (i)
                                     (printf "Items: ~A~%" poll-items)
                                     (printf "Getting: ~A ~%" i)
                                     (poll-item-pointer (list-ref poll-items i)))
                                   (length poll-items)
                                   (case timeout/block
                                     ((#f) 0)
                                     ((#t) -1)
                                     (else timeout/block)))))
        (if (= result -1)
            (zmq-error 'poll)
            result))))
)


;; output
......
.....
Getting: 0 
Items: (#<poll-item> #<poll-item>)
Getting: 1 
Items: (#<poll-item> #<poll-item>)
Getting: 0 
Items: (#<poll-item> #<poll-item>)
Getting: 1 
Items: (#<poll-item> #<poll-item>)
Getting: 0 
Items: (#<poll-item> #<poll-item>)
Getting: 1 
Items: (#<poll-item> #<poll-item>)
Getting: 0 
Items: #<invalid forwarded object>
Getting: 1 

immediate failure added by certainty on Fri Jul 8 10:41:46 2011

(define caller
  (foreign-safe-lambda* int ((scheme-object proc) (unsigned-int length))
                        "
                        int i;
                        for(i = 0; i < length; i++){
                          C_save(C_fix(i));
                          C_callback(proc,1);
                        }
                        C_return(0);" ))

(define (poll-test items)
  (caller (lambda (i) (list-ref items i)) (length items)))


(let ((items (list 1 2)))
  (let loop ((ignored (poll-test items)))
    (loop (poll-test items))))

Your annotation:

Enter a new annotation:

Your nick:
The title of your paste:
Your paste (mandatory) :
Which module provides `foreign-declare'?
Visually impaired? Let me spell it for you (wav file) download WAV