Example #1
0
File: term.c Project: laanwj/urbit
/* _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)
{
  u3_utel* pty_u = (u3_utel*)(void*) tcp_u;

  u3_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);
  }
  u3_lo_shut(c3y);
}
Example #2
0
/*
 * `nread` (siz_w) is > 0 if there is data available, 0 if libuv is done reading for
 * now, or < 0 on error.
 *
 * The callee is responsible for closing the stream when an error happens
 * by calling uv_close(). Trying to read from the stream again is undefined.
 *
 * The callee is responsible for freeing the buffer, libuv does not reuse it.
 * The buffer may be a null buffer (where buf->base=NULL and buf->len=0) on
 * error.
 */
static void
_http_conn_read_cb(uv_stream_t* tcp_u,
                   ssize_t      siz_w,
                   const uv_buf_t *     buf_u)
{
  u3_hcon* hon_u = (u3_hcon*)(void*) tcp_u;

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

      if ( siz_w != http_parser_execute(hon_u->ruc_u->par_u,
                                        &_http_settings,
                                        (c3_c*)buf_u->base,
                                        siz_w) )
      {
        uL(fprintf(uH, "http: parse error\n"));
        _http_conn_dead(hon_u);
      }
    }
    if ( buf_u->base ) {
      free(buf_u->base);
    }
  }
  u3_lo_shut(c3y);
}
Example #3
0
/* _unix_time_cb: timer callback
*/
static void
_unix_time_cb(uv_timer_t* tim_u)
{
    u3_lo_open();
    {
        u3_Host.unx_u.alm = c3n;
        u3_Host.unx_u.dyr = c3y;
    }
    u3_lo_shut(c3y);
}
Example #4
0
File: temp.c Project: josl/urbit
/* _temp_time_cb(): timer callback.
*/
static void
_temp_time_cb(uv_timer_t* tim_u)
{
  u3_temp* teh_u = &u3_Host.teh_u;
  if(teh_u->run_w < 1024) {
    teh_u->run_w++;
  }

  u3_lo_open();
  {
    u3v_plan
      (u3nt(u3_blip, c3__temp, u3_nul),
       u3nc(c3__wake, u3_nul));
  }
  u3_lo_shut(c3n);
}
Example #5
0
File: term.c Project: laanwj/urbit
static inline void
_term_suck(u3_utty* uty_u, const c3_y* buf, ssize_t siz_i)
{
  u3_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]);
      }
    }
  }
  u3_lo_shut(c3y);
}
Example #6
0
/* _unix_sign_cb: signal callback.
*/
static void
_unix_sign_cb(uv_signal_t* sil_u, c3_i num_i)
{
    u3_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);
            u3_Host.liv = c3n;
            break;
        case SIGINT:
            fprintf(stderr, "\r\ninterrupt\r\n");
            u3_term_ef_ctlc();
            break;
        case SIGWINCH:
            u3_term_ef_winc();
            break;
        }
    }
    u3_lo_shut(c3y);
}
Example #7
0
/* _unix_ef_sync(): check for files to sync.
 */
static void
_unix_ef_sync(uv_check_t* han_u)
{
    u3_lo_open();
    u3_lo_shut(c3y);
}