/* _term_read_tn_cb(): telnet read callback.
*/
static void
_term_read_tn_cb(uv_stream_t* tcp_u,
                   ssize_t      siz_i,
                   const uv_buf_t *     buf_u)
{
  u2_utel* pty_u = (u2_utel*)(void*) tcp_u;

  u2_lo_open();
  {
    if ( siz_i == UV_EOF ) {
      // nothing
    } else if ( siz_i < 0 ) {
      uL(fprintf(uH, "term teln: read: %s\n", uv_strerror(siz_i)));
      uv_close((uv_handle_t*) tcp_u, _tel_close_cb);
      goto err;
    }
    else {
      telnet_receive(pty_u->tel_u, (const telnet_byte*) buf_u->base, siz_i, 0);
    }

  err:
    free(buf_u->base);
  }
  u2_lo_shut(u2_yes);
}
Beispiel #2
0
/* _unix_time_cb(): timer callback.
*/
static void
_unix_time_cb(uv_timer_t* tim_u, c3_i sas_i)
{
  u2_lo_open();
  {
    u2_reck_plan
      (u2A,
       u2nt(c3__gold, c3__clay, u2_nul),
       u2nc(c3__wake, u2_nul));
  }
  u2_lo_shut(u2_no);
}
Beispiel #3
0
/* _unix_sign_cb: signal callback.
*/
static void
_unix_sign_cb(uv_signal_t* sil_u, c3_i num_i)
{
  u2_lo_open();
  {
    switch ( num_i ) {
      case SIGTERM: u2_Host.liv = u2_no; break;
      case SIGINT: u2_term_ef_ctlc(); break;
      case SIGWINCH: u2_term_ef_winc(); break;
    }
  }
  u2_lo_shut(u2_yes);
}
Beispiel #4
0
/* _unix_time_cb(): timer callback.
*/
static void
_unix_time_cb(uv_timer_t* tim_u)
{
  if ( u2_nul == u2A->roe ) {
    u2_lo_open();
    {
      u2_reck_plan
        (u2A,
         u2nt(u2_blip, c3__clay, u2_nul),
         u2nc(c3__wake, u2_nul));
    }
    u2_lo_shut(u2_no);
  }
}
Beispiel #5
0
/* _unix_fs_event_cb(): filesystem event callback.
*/
static void
_unix_fs_event_cb(uv_fs_event_t* was_u,
                  const c3_c*    pax_c,
                  c3_i           sas_i,
                  c3_i           evt_i)
{
  u2_unod* nod_u = (void*)was_u;

  // uL(fprintf(uH, "fs: %s in %s\n", pax_c, nod_u->pax_c));
  u2_lo_open();
  {
    while ( nod_u ) {
      nod_u->dry = u2_no;
      nod_u = (u2_unod*) nod_u->par_u;
    }
  }
  u2_lo_shut(u2_yes);
}
Beispiel #6
0
/* _unix_sign_cb: signal callback.
*/
static void
_unix_sign_cb(uv_signal_t* sil_u, c3_i num_i)
{
  u2_lo_open();
  {
    switch ( num_i ) {
      default: fprintf(stderr, "\r\nmysterious signal %d\r\n", num_i); break;

      case SIGTERM:
        fprintf(stderr, "\r\ncaught signal %d\r\n", num_i);
        u2_Host.liv = u2_no;
        break;
      case SIGINT: u2_term_ef_ctlc(); break;
      case SIGWINCH: u2_term_ef_winc(); break;
      // case SIGCHLD: u2_save_ef_chld(); break;
    }
  }
  u2_lo_shut(u2_yes);
}
Beispiel #7
0
/* _term_poll_cb(): polling with old libev code.
*/
static void
_term_poll_cb(uv_poll_t* pol_u, c3_i sas_i, c3_i evt_i)
{
  u2_utty* uty_u = (void*)pol_u;

#if 0
  fprintf(stderr, "poll_cb read %d, write %d\r\n",
                  !!(UV_READABLE & evt_i),
                  !!(UV_WRITABLE & evt_i));
#endif
  if ( sas_i != 0 ) {
    uL(fprintf(uH, "term: poll: %s\n", uv_strerror(uv_last_error(u2L))));
  }
  else {
    if ( UV_READABLE & evt_i ) {
      u2_lo_open();
      while ( 1 ) {
        c3_y buf_y[4096];
        c3_i siz_i, i;

        if ( (siz_i = read(uty_u->fid_i, buf_y, 4096)) < 0) {
          if ( EAGAIN == errno ) {
            break;
          } else {
            c3_assert(!"term: read");
          }
        }
        for ( i=0; i < siz_i; i++ ) {
          _term_io_suck_char(uty_u, buf_y[i]);
        }
        if ( 4096 != siz_i ) {
          break;
        }
      }
      u2_lo_shut(u2_yes);
    }
    if ( UV_WRITABLE & evt_i ) {
      _term_it_do_writes(uty_u);
    }
  }
  _term_ef_poll(uty_u);
}
static inline void
_term_suck(u2_utty* uty_u, const c3_y* buf, ssize_t siz_i)
{
  u2_lo_open();
  {
    if ( siz_i == UV_EOF ) {
      // nothing
    } else   if ( siz_i < 0 ) {
      uL(fprintf(uH, "term %d: read: %s\n", uty_u->tid_l, uv_strerror(siz_i)));
    }
    else {
      c3_i i;

      for ( i=0; i < siz_i; i++ ) {
        _term_io_suck_char(uty_u, buf[i]);
      }
    }
  }
  u2_lo_shut(u2_yes);
}
Beispiel #9
0
/* _http_conn_read_cb(): server read callback.
*/
static void
_http_conn_read_cb(uv_stream_t* tcp_u,
                   ssize_t      siz_i,
                   uv_buf_t     buf_u)
{
  u2_hcon* hon_u = (u2_hcon*)(void*) tcp_u;

  u2_lo_open();
  {
    if ( siz_i < 0 ) {
      uv_err_t las_u = uv_last_error(u2L);

      if ( UV_EOF != las_u.code ) {
        uL(fprintf(uH, "http: read: %s\n", uv_strerror(las_u)));
      }
      _http_conn_dead(hon_u);
    }
    else {
      if ( !hon_u->ruc_u ) {
        hon_u->ruc_u = _http_req_new(hon_u);
      }

      if ( siz_i != http_parser_execute(hon_u->ruc_u->par_u,
                                        &_http_settings,
                                        (c3_c*)buf_u.base,
                                        siz_i) )
      {
        uL(fprintf(uH, "http: parse error\n"));
        _http_conn_dead(hon_u);
      }
    }
    if ( buf_u.base ) {
      free(buf_u.base);
    }
  }
  u2_lo_shut(u2_yes);
}
Beispiel #10
0
/* _term_read_cb(): server read callback.
*/
static void
_term_read_cb(uv_stream_t* str_u,
              ssize_t      siz_i,
              uv_buf_t     buf_u)
{
  u2_utty* uty_u = (u2_utty*)(void*)str_u;

  u2_lo_open();
  {
    if ( siz_i < 0 ) {
      uv_err_t las_u = uv_last_error(u2L);

      uL(fprintf(uH, "term: read: %s\n", uv_strerror(las_u)));
    }
    else {
      c3_i i;

      for ( i=0; i < siz_i; i++ ) {
        _term_io_suck_char(uty_u, buf_u.base[i]);
      }
    }
  }
  u2_lo_shut(u2_yes);
}
Beispiel #11
0
/* _term_it_do_writes():
*/
static void
_term_it_do_writes(u2_utty* uty_u)
{
  u2_lo_open();
  while ( uty_u->out_u ) {
    u2_ubuf* out_u = uty_u->out_u;
    c3_i     siz_i;

    if ( (siz_i = write(uty_u->fid_i,
                        uty_u->out_u->hun_y,
                        uty_u->out_u->len_w)) < 0 ) {
#if 0
      if ( EAGAIN == errno ) {
        break;
      } else {
        c3_assert(!"term: write");
      }
#else
      break;
#endif
    }
    if ( siz_i < out_u->len_w ) {
      _term_it_clip(out_u, siz_i);
      break;
    }
    else {
      uty_u->out_u = uty_u->out_u->nex_u;
      if ( 0 == uty_u->out_u ) {
        c3_assert(out_u == uty_u->tou_u);
        uty_u->tou_u = 0;
      }
      free(out_u);
    }
  }
  u2_lo_shut(u2_yes);
}
Beispiel #12
0
/* _unix_ef_sync(): check for files to sync.
 */
static void
_unix_ef_sync(uv_check_t* han_u)
{
  u2_lo_open();
  u2_lo_shut(u2_yes);
}
Beispiel #13
0
/* _unix_ef_sync(): check for files to sync.
 */
static void
_unix_ef_sync(uv_prepare_t* han_u, c3_i sas_i)
{
  u2_lo_open();
  u2_lo_shut(u2_yes);
}