Module: Ebb::FFI

Defined in:
ext/ebb_ffi.c

Constant Summary collapse

VERSION =
rb_str_new2("BLANK")

Class Method Summary collapse

Class Method Details

.connection_schedule_close(rb_connection) ⇒ Object



486
487
488
489
490
491
492
493
# File 'ext/ebb_ffi.c', line 486

static VALUE 
connection_schedule_close(VALUE _, VALUE rb_connection) 
{
  ebb_connection *connection; 
  Data_Get_Struct(rb_connection, ebb_connection, connection);
  ebb_connection_schedule_close(connection);
  return Qnil;
}

.connection_write(rb_connection, chunk) ⇒ Object



470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
# File 'ext/ebb_ffi.c', line 470

static VALUE 
connection_write(VALUE _, VALUE rb_connection, VALUE chunk) 
{
  ebb_connection *connection; 
  Data_Get_Struct(rb_connection, ebb_connection, connection);
  
  int r = 
  ebb_connection_write( connection
                      , RSTRING_PTR(chunk)
                      , RSTRING_LEN(chunk)
                      , after_write
                      );
  assert(r);
  return chunk;
}

.request_read(rb_request, want) ⇒ Object



310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
# File 'ext/ebb_ffi.c', line 310

static VALUE
request_read(VALUE x, VALUE rb_request, VALUE want)
{
  ebb_request *request;
  Data_Get_Struct(rb_request, ebb_request, request);
  ebb_connection *connection = request_get_connection(request);
  if(connection == NULL)
    return Qnil;

  VALUE body = rb_iv_get(rb_request, "@body");

  if(RARRAY_LEN(body) > 0) {
    /* ignore how much they want! haha */
    return rb_ary_shift(body);
    
  } if(ebb_request_has_body(request)) {
    return Qnil;

  } else {
    fd_set set;
    FD_ZERO(&set);
    FD_SET(connection->fd, &set);
    rb_thread_select(connection->fd+1, &set, 0, 0, NULL);
    /* hairy! wait for read - invoke the ev callback inside libebb */
    ev_invoke(loop, &connection->read_watcher, EV_READ);
    /* return empty string, next read call will get data -
     * if all goes okay ! :) 
     */ 
    return g_empty_str;
  }
}

.request_should_keep_alive?(rb_request) ⇒ Boolean

Returns:

  • (Boolean)


495
496
497
498
499
500
501
# File 'ext/ebb_ffi.c', line 495

static VALUE 
request_should_keep_alive(VALUE _, VALUE rb_request) 
{
  ebb_request *request;
  Data_Get_Struct(rb_request, ebb_request, request);
  return ebb_request_should_keep_alive(request) ? Qtrue : Qfalse;
}

.server_listen_on_fd(sfd) ⇒ Object



406
407
408
409
410
411
412
# File 'ext/ebb_ffi.c', line 406

static VALUE 
server_listen_on_fd(VALUE _, VALUE sfd)
{
  if(ebb_server_listen_on_fd(&server, FIX2INT(sfd)) < 0)
    rb_sys_fail("Problem listening on FD");
  return Qnil;
}

.server_listen_on_port(port) ⇒ Object



414
415
416
417
418
419
420
# File 'ext/ebb_ffi.c', line 414

static VALUE 
server_listen_on_port(VALUE _, VALUE port)
{
  if(ebb_server_listen_on_port(&server, FIX2INT(port)) < 0)
    rb_sys_fail("Problem listening on port");
  return Qnil;
}

.server_open?Boolean

Returns:

  • (Boolean)


439
440
441
442
443
# File 'ext/ebb_ffi.c', line 439

static VALUE 
server_open(VALUE _)
{
  return server.listening ? Qtrue : Qfalse;
}

.server_process_connectionsObject



422
423
424
425
426
427
428
429
# File 'ext/ebb_ffi.c', line 422

static VALUE 
server_process_connections(VALUE _)
{
  TRAP_BEG;
  ev_loop(loop, EVLOOP_ONESHOT);
  TRAP_END;
  return Qnil;
}

.server_set_secure(cert_file, key_file) ⇒ Object



446
447
448
449
450
451
452
453
454
# File 'ext/ebb_ffi.c', line 446

static VALUE
server_set_secure(VALUE _, VALUE cert_file, VALUE key_file)
{
  ebb_server_set_secure( &server
                       , RSTRING_PTR(cert_file)
                       , RSTRING_PTR(key_file)
                       );
  return Qnil;
}

.server_unlistenObject



432
433
434
435
436
437
# File 'ext/ebb_ffi.c', line 432

static VALUE 
server_unlisten(VALUE _)
{
  ebb_server_unlisten(&server);
  return Qnil;
}

.server_waiting_requestsObject



457
458
459
460
461
# File 'ext/ebb_ffi.c', line 457

static VALUE 
server_waiting_requests(VALUE _)
{
  return waiting_requests;
}