(declare (block) (standard-bindings) (extended-bindings))
(begin
  (define std/net/socket/basic-server#!io-state:::init!
    (lambda (_self914_)
      (if (let ((__tmp6013
                 (let () (declare (not safe)) (##vector-length _self914_))))
            (declare (not safe))
            (##fx< '3 __tmp6013))
          (begin
            (let () (declare (not safe)) (##vector-set! _self914_ '1 'blocked))
            (let ((__tmp6014 (make-mutex)))
              (declare (not safe))
              (##vector-set! _self914_ '2 __tmp6014))
            (let ((__tmp6015 (make-condition-variable)))
              (declare (not safe))
              (##vector-set! _self914_ '3 __tmp6015)))
          (error '"struct-instance-init!: too many arguments for struct"
                 _self914_))))
  (bind-method!
   std/net/socket/base#!io-state::t
   ':init!
   std/net/socket/basic-server#!io-state:::init!
   '#f)
  (define std/net/socket/basic-server#server-poll
    (lambda (_server779_ _io780_)
      (let _lp782_ ()
        (let () (declare (not safe)) (##wait-for-io! _io780_ '#t))
        (let ((_token785_
               (let ()
                 (declare (not safe))
                 (##structure std/actor/proto#!token::t)))
              (_dest787_ _server779_))
          (std/actor/message#send-message__%
           _dest787_
           (let ((__tmp6016
                  (let ()
                    (declare (not safe))
                    (##structure std/net/socket/base#socket-server.poll::t))))
             (declare (not safe))
             (##structure std/actor/proto#!call::t __tmp6016 _token785_))
           '#f
           '#t)
          (std/actor/proto#!!call-recv _token785_ _dest787_))
        (_lp782_))))
  (define std/net/socket/basic-server#server-loop
    (lambda (_poll-io525_
             _do-poll526_
             _add-socket527_
             _close-socket528_
             _shutdown!529_)
      (letrec* ((_poll-thread531_
                 (if _poll-io525_
                     (gerbil/gambit/threads#spawn/name
                      'server-poll
                      std/net/socket/basic-server#server-poll
                      (current-thread)
                      _poll-io525_)
                     '#f)))
        (with-unwind-protect
         (lambda ()
           (with-exception-catcher
            (lambda (_g532535_)
              (if '#t
                  (let ((_e538_ _g532535_))
                    (std/logger#log-error '"socket-server error" _e538_)
                    (_shutdown!529_)
                    (raise _e538_))
                  (raise _g532535_)))
            (lambda ()
              (let _loop541_ ()
                (let _loop543545_ ()
                  (let ((_next549_ (thread-mailbox-next)))
                    ((lambda (_$message552_)
                       (let* ((_$message554564_ _$message552_)
                              (_else556572_ (lambda () (_loop543545_)))
                              (_K558755_
                               (lambda (_$options575_
                                        _$dest577_
                                        _$source579_
                                        _$value581_)
                                 (let* ((_$value603628_ _$value581_)
                                        (_else609636_
                                         (lambda () (_loop543545_))))
                                   (let ((_K624744_
                                          (lambda (_k742_)
                                            (thread-mailbox-extract-and-rewind)
                                            (_do-poll526_)
                                            (std/actor/message#send-message__%
                                             _$source579_
                                             (let ()
                                               (declare (not safe))
                                               (##structure
                                                std/actor/proto#!value::t
                                                '#!void
                                                _k742_))
                                             '#f
                                             '#f)
                                            (_loop541_)))
                                         (_K620723_
                                          (lambda (_k711_ _sock712_)
                                            (thread-mailbox-extract-and-rewind)
                                            (with-exception-catcher
                                             (lambda (_g713715_)
                                               (if '#t
                                                   (let ((_e718_ _g713715_))
                                                     (std/logger#log-error
                                                      '"socket-server.add"
                                                      _e718_)
                                                     (std/actor/message#send-message__%
                                                      _$source579_
                                                      (let ()
                                                        (declare (not safe))
                                                        (##structure
                                                         std/actor/proto#!error::t
                                                         _e718_
                                                         _k711_))
                                                      '#f
                                                      '#f))
                                                   (raise _g713715_)))
                                             (lambda ()
                                               (let ((_ssock721_
                                                      (_add-socket527_
                                                       _sock712_)))
                                                 (std/actor/message#send-message__%
                                                  _$source579_
                                                  (let ()
                                                    (declare (not safe))
                                                    (##structure
                                                     std/actor/proto#!value::t
                                                     _ssock721_
                                                     _k711_))
                                                  '#f
                                                  '#f))))
                                            (_loop541_)))
                                         (_K615686_
                                          (lambda (_shutdown675_
                                                   _dir676_
                                                   _ssock677_)
                                            (thread-mailbox-extract-and-rewind)
                                            (with-exception-catcher
                                             (lambda (_g678680_)
                                               (if '#t
                                                   (let ((_e683_ _g678680_))
                                                     (std/logger#log-error
                                                      '"socket-server.close"
                                                      _e683_))
                                                   (raise _g678680_)))
                                             (lambda ()
                                               (_close-socket528_
                                                _ssock677_
                                                _dir676_
                                                _shutdown675_)))
                                            (_loop541_)))
                                         (_K612660_
                                          (lambda (_k651_)
                                            (thread-mailbox-extract-and-rewind)
                                            (with-exception-catcher
                                             (lambda (_g652654_)
                                               (if '#t
                                                   (let ((_e657_ _g652654_))
                                                     (std/logger#log-error
                                                      '"socket-server.shutdown!"
                                                      _e657_)
                                                     (std/actor/message#send-message__%
                                                      _$source579_
                                                      (let ()
                                                        (declare (not safe))
                                                        (##structure
                                                         std/actor/proto#!error::t
                                                         _e657_
                                                         _k651_))
                                                      '#f
                                                      '#f))
                                                   (raise _g652654_)))
                                             (lambda ()
                                               (_shutdown!529_)
                                               (std/actor/message#send-message__%
                                                _$source579_
                                                (let ()
                                                  (declare (not safe))
                                                  (##structure
                                                   std/actor/proto#!value::t
                                                   '#!void
                                                   _k651_))
                                                '#f
                                                '#f)))))
                                         (_K611642_
                                          (lambda (_msg640_)
                                            (thread-mailbox-extract-and-rewind)
                                            (std/logger#warning
                                             '"Unexpected message: ~a"
                                             _msg640_)
                                            (_loop541_))))
                                     (let ((_try-match606707_
                                            (lambda ()
                                              (if (let ()
                                                    (declare (not safe))
                                                    (##structure-direct-instance-of?
                                                     _$value603628_
                                                     'std/actor/proto#!event::t))
                                                  (let ((_e616689_
                                                         (let ()
                                                           (declare (not safe))
                                                           (##vector-ref
                                                            _$value603628_
                                                            '1))))
                                                    (if (let ()
                                                          (declare (not safe))
                                                          (##structure-direct-instance-of?
                                                           _e616689_
                                                           'std/net/socket/base#socket-server.close::t))
                                                        (let* ((_e617692_
                                                                (let ()
;;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
                          (declare (not safe))
                          (##vector-ref _e616689_ '1)))
                       (_e618697_
                        (let ()
                          (declare (not safe))
                          (##vector-ref _e616689_ '2)))
                       (_e619702_
                        (let ()
                          (declare (not safe))
                          (##vector-ref _e616689_ '3))))
                  (let ((_ssock695_ _e617692_)
                        (_dir700_ _e618697_)
                        (_shutdown705_ _e619702_))
                    (_K615686_ _shutdown705_ _dir700_ _ssock695_)))
                (let ((_msg645_ _$value603628_)) (_K611642_ _msg645_))))
;;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
                                                  (let ((_msg645_
                                                         _$value603628_))
                                                    (_K611642_ _msg645_))))))
                                       (if (let ()
                                             (declare (not safe))
                                             (##structure-direct-instance-of?
                                              _$value603628_
                                              'std/actor/proto#!call::t))
                                           (let ((_e625747_
                                                  (let ()
                                                    (declare (not safe))
                                                    (##vector-ref
                                                     _$value603628_
                                                     '1))))
                                             (if (let ()
                                                   (declare (not safe))
                                                   (##structure-direct-instance-of?
                                                    _e625747_
                                                    'std/net/socket/base#socket-server.poll::t))
                                                 (let* ((_e626750_
                                                         (let ()
                                                           (declare (not safe))
                                                           (##vector-ref
                                                            _$value603628_
                                                            '2)))
                                                        (_k753_ _e626750_))
                                                   (_K624744_ _k753_))
                                                 (if (let ()
                                                       (declare (not safe))
                                                       (##structure-direct-instance-of?
                                                        _e625747_
                                                        'std/net/socket/base#socket-server.add::t))
                                                     (let* ((_e623729_
                                                             (let ()
                                                               (declare
;;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
                         (not safe))
                       (##vector-ref _e625747_ '1)))
                    (_e622734_
                     (let ()
                       (declare (not safe))
                       (##vector-ref _$value603628_ '2))))
               (let ((_sock732_ _e623729_) (_k737_ _e622734_))
                 (_K620723_ _k737_ _sock732_)))
;;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
                                                     (if (let ()
                                                           (declare (not safe))
                                                           (##structure-direct-instance-of?
                                                            _e625747_
                                                            'std/net/socket/base#socket-server.shutdown!::t))
                                                         (let* ((_e614666_
;;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
                         (let ()
                           (declare (not safe))
                           (##vector-ref _$value603628_ '2)))
                        (_k669_ _e614666_))
                   (_K612660_ _k669_))
                 (let ((_msg645_ _$value603628_)) (_K611642_ _msg645_))))))
;;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
                                           (_try-match606707_))))))))
                         (if (let ()
                               (declare (not safe))
                               (##structure-direct-instance-of?
                                _$message554564_
                                'std/actor/message#message::t))
                             (let* ((_e559758_
                                     (let ()
                                       (declare (not safe))
                                       (##vector-ref _$message554564_ '1)))
                                    (_$value761_ _e559758_)
                                    (_e560763_
                                     (let ()
                                       (declare (not safe))
                                       (##vector-ref _$message554564_ '2)))
                                    (_$source766_ _e560763_)
                                    (_e561768_
                                     (let ()
                                       (declare (not safe))
                                       (##vector-ref _$message554564_ '3)))
                                    (_$dest771_ _e561768_)
                                    (_e562773_
                                     (let ()
                                       (declare (not safe))
                                       (##vector-ref _$message554564_ '4)))
                                    (_$options776_ _e562773_))
                               (_K558755_
                                _$options776_
                                _$dest771_
                                _$source766_
                                _$value761_))
                             (_loop543545_))))
                     _next549_)))))))
         (lambda ()
           (if _poll-thread531_
               (thread-terminate! _poll-thread531_)
               '#!void))))))
  (define std/net/socket/basic-server#io-state-signal-ready!
    (lambda (_iostate489_ _how490_)
      (let* ((_iostate491499_ _iostate489_)
             (_E493503_
              (lambda () (error '"No clause matching" _iostate491499_)))
             (_K494509_
              (lambda (_cv506_ _mx507_)
                (mutex-lock! _mx507_)
                (##direct-structure-set!
                 _iostate489_
                 _how490_
                 '1
                 std/net/socket/base#!io-state::t
                 '#f)
                (condition-variable-broadcast! _cv506_)
                (mutex-unlock! _mx507_))))
        (if (let ()
              (declare (not safe))
              (##structure-direct-instance-of?
               _iostate491499_
               'std/net/socket/base#!io-state::t))
            (let* ((_e495512_
                    (let ()
                      (declare (not safe))
                      (##vector-ref _iostate491499_ '1)))
                   (_e496515_
                    (let ()
                      (declare (not safe))
                      (##vector-ref _iostate491499_ '2)))
                   (_mx518_ _e496515_)
                   (_e497520_
                    (let ()
                      (declare (not safe))
                      (##vector-ref _iostate491499_ '3)))
                   (_cv523_ _e497520_))
              (_K494509_ _cv523_ _mx518_))
            (_E493503_)))))
  (define std/net/socket/basic-server#io-state-wait-io!
    (lambda (_iostate443_ _timeo444_ _how445_)
      (let* ((_iostate446454_ _iostate443_)
             (_E448458_
              (lambda () (error '"No clause matching" _iostate446454_)))
             (_K449473_
              (lambda (_cv461_ _mx462_)
                (let _lp464_ ()
                  (mutex-lock! _mx462_)
                  (let ((_$e467_ (##direct-structure-ref
                                  _iostate443_
                                  '1
                                  std/net/socket/base#!io-state::t
                                  '#f)))
                    (if (eq? 'closed _$e467_)
                        (begin
                          (mutex-unlock! _mx462_)
                          (error '"Socket direction has been closed" _how445_))
                        (if (eq? 'ready _$e467_)
                            (begin
                              (##direct-structure-set!
                               _iostate443_
                               _how445_
                               '1
                               std/net/socket/base#!io-state::t
                               '#f)
                              (mutex-unlock! _mx462_)
                              '#!void)
                            (begin
                              (##direct-structure-set!
                               _iostate443_
                               'blocked
                               '1
                               std/net/socket/base#!io-state::t
                               '#f)
                              (if (mutex-unlock!
                                   _mx462_
                                   _cv461_
                                   (or _timeo444_ absent-obj))
                                  (_lp464_)
                                  '#f)))))))))
        (if (let ()
              (declare (not safe))
              (##structure-direct-instance-of?
               _iostate446454_
               'std/net/socket/base#!io-state::t))
            (let* ((_e450476_
                    (let ()
                      (declare (not safe))
                      (##vector-ref _iostate446454_ '1)))
                   (_e451479_
                    (let ()
                      (declare (not safe))
                      (##vector-ref _iostate446454_ '2)))
                   (_mx482_ _e451479_)
                   (_e452484_
                    (let ()
                      (declare (not safe))
                      (##vector-ref _iostate446454_ '3)))
                   (_cv487_ _e452484_))
              (_K449473_ _cv487_ _mx482_))
            (_E448458_)))))
  (define std/net/socket/basic-server#io-state-close-in!
    (lambda (_iostate439_ _sock440_ _shutdown441_)
      (if _shutdown441_
          (std/net/socket/basic-server#shutdown-socket!
           _sock440_
           _shutdown441_)
          (close-input-port _sock440_))
      (std/net/socket/basic-server#io-state-signal-ready!
       _iostate439_
       'closed)))
  (define std/net/socket/basic-server#io-state-close-out!
    (lambda (_iostate435_ _sock436_ _shutdown437_)
      (if _shutdown437_
          (std/net/socket/basic-server#shutdown-socket!
           _sock436_
           _shutdown437_)
          (close-output-port _sock436_))
      (std/net/socket/basic-server#io-state-signal-ready!
       _iostate435_
       'closed)))
  (define std/net/socket/basic-server#shutdown-socket!
    (lambda (_sock425_ _how426_)
      (with-exception-catcher
       (lambda (_g427429_)
         (if '#t
             (let ((_e432_ _g427429_))
               (std/logger#log-error '"socket-server.shutdown-socket!" _e432_))
             (raise _g427429_)))
       (lambda () (std/os/socket#socket-shutdown _sock425_ _how426_))))))
