Ejemplo n.º 1
0
void scm_init_port()
{
	scm_cur_input_port = make_port(stdin, INPORT);
	scm_cur_output_port = make_port(stdout, OUTPORT);
	
	scm_add_prim("input-port?", port_pred_input_port);
	scm_add_prim("output-port?", port_pred_output_port);
	scm_add_prim("current-input-port", port_current_input_port);
	scm_add_prim("current-output-port", port_current_output_port);
	scm_add_prim("open-input-file", port_open_input_file);
	scm_add_prim("open-output-file", port_open_output_file);
	scm_add_prim("close-input-port", port_close_input_port);
	scm_add_prim("close-output-port", port_close_output_port);
}
Ejemplo n.º 2
0
static void cmp_blob(blb* blob, bool sql_flag)
{
	blob->blb_ident = CMP_next_ident();
	blob->blb_buff_ident = CMP_next_ident();
	blob->blb_len_ident = CMP_next_ident();

	if (sql_flag)
	{
		for (ref* reference = blob->blb_reference; reference; reference = reference->ref_next)
		{
			reference->ref_port = make_port(reference->ref_context->ctx_request, reference);
		}
	}

	if (!blob->blb_const_to_type && !blob->blb_type)
		return;

	blob->blb_bpb_ident = CMP_next_ident();
	UCHAR* p = blob->blb_bpb;
	*p++ = isc_bpb_version1;

	if (blob->blb_const_to_type)
	{
		*p++ = isc_bpb_target_type;
		*p++ = 2;
		*p++ = (UCHAR) blob->blb_const_to_type;
		*p++ = blob->blb_const_to_type >> 8;
	}
Ejemplo n.º 3
0
/* Run the test.  */
static void *
do_start (void *arg)
{
  SCM port;
  scm_t_bits port_type;
  char buffer[PORT_BUFFER_SIZE + (PORT_BUFFER_SIZE / 2)];
  size_t read, last_read;

  port_type = scm_make_port_type ("custom-input-port", fill_input, NULL);
  port = make_port (port_type);

  read = 0;
  do
    {
      last_read = scm_c_read (port, &buffer[read], 123);
      assert (last_read <= 123);
      assert (zeroed_buffer_p (&buffer[read], last_read));

      read += last_read;
    }
  while (last_read > 0 && read < sizeof (buffer));

  /* We shouldn't be able to read more than what's in PORT's buffer.  */
  assert (read == PORT_BUFFER_SIZE);

  return NULL;
}
Ejemplo n.º 4
0
static void gen_routine( const act* action, int column)
{
	for (const gpre_req* request = (gpre_req*) action->act_object; request;
		request = request->req_routine)
	{
		for (const gpre_port* port = request->req_ports; port; port = port->por_next)
			make_port(port, column + INDENT);
	}
}
Ejemplo n.º 5
0
term_t bif_open_socket2(term_t LocIP, term_t LocPort, process_t *ctx)
{
	apr_status_t rs;
	apr_pool_t *p;
	apr_sockaddr_t *sa;
	apr_socket_t *socket;
	port_t *port;
	term_t id;

	const char *host;
	apr_port_t udp_port;

	if (LocIP != A_ANY && !is_binary(LocIP))
		return A_BADARG;
	if (!is_int(LocPort))
		return A_BADARG;

	host = (LocIP == A_ANY) ?0 :(const char *)bin_data(LocIP);
	udp_port = (apr_port_t)int_value(LocPort);

	apr_pool_create(&p, 0);

	rs = apr_sockaddr_info_get(&sa, host, APR_INET, udp_port, 0, p);
	if (rs == 0)
		rs = apr_socket_create(&socket,
			APR_INET, SOCK_DGRAM, APR_PROTO_UDP, p); //only APR_INET is supported, not APR_INET6
	if (rs == 0)
		rs = apr_socket_bind(socket, sa);
	if (rs == 0)
		rs = apr_socket_opt_set(socket, APR_SO_NONBLOCK, 1);

	if (rs != 0)
	{
		apr_pool_destroy(p);
		return decipher_status(rs);
	}

	port = port_udp_make(socket);	//takes care of pool p

	//add to poll ring
	port_register(port);

	//set initial port owner
	port->owner_in = port->owner_out = proc_pid(ctx, port->xp);

	id = make_port(my_node, port->key, my_creation, proc_gc_pool(ctx));
	result(id);
	return AI_OK;
}
Ejemplo n.º 6
0
/* Create a UDP port and add it ot the data plane. Returns
   the port. */
struct fp_port*
add_port(struct fp_dataplane* dp, short p)
{
    /* Make the port. */
    struct fp_port* port = make_port(p);
    if (!port)
        return NULL;

    /* Add the port ot the data plane. */
    fp_error_t err;
    fp_dataplane_add_port(dp, port, &err);
    if (fp_error(err)) {
        fprintf(stderr, "%s\n", fp_strerror(err));
        return NULL;
    }

    return port;
}
Ejemplo n.º 7
0
Archivo: io.c Proyecto: cmatei/yalfs
object io_file_as_port(object filename, unsigned long port_type)
{
	char *name;
	unsigned long namelen;
	FILE *f;

	namelen = string_length(filename);

	name = xmalloc(namelen + 1);
	memcpy(name, string_value(filename), namelen);
	name[namelen] = 0;

	if ((f = fopen(name, (port_type == PORT_TYPE_INPUT) ? "r" : "w+")) == NULL) {
		xfree(name);
		error("Cannot open file -- io-file-as-port", filename);
	}

	xfree(name);

	return make_port(f, port_type);
}
Ejemplo n.º 8
0
void CMP_compile_request( gpre_req* request)
{
	// if there isn't a request handle specified, make one!

	if (!request->req_handle && (request->req_type != REQ_procedure))
	{
		request->req_handle = (TEXT*) MSC_alloc(20);
		sprintf(request->req_handle, gpreGlob.ident_pattern, CMP_next_ident());
	}

	if (!request->req_trans)
		request->req_trans = gpreGlob.transaction_name;

	if (!request->req_request_level)
		request->req_request_level = "0";

	request->req_ident = CMP_next_ident();

	// If this is an SQL blob cursor, compile the blob and get out fast.

	if (request->req_flags & (REQ_sql_blob_open | REQ_sql_blob_create))
	{
		for (blb* blob = request->req_blobs; blob; blob = blob->blb_next)
			cmp_blob(blob, true);
		return;
	}

	// Before we get too far, make sure an eof field has been
	// constructed.  If not, do so now.

	ref* reference;
	if (!eof_field)
	{
		eof_field = MET_make_field(gpreGlob.utility_name, dtype_short, sizeof(SSHORT), false);
		count_field = MET_make_field(gpreGlob.count_name, dtype_long, sizeof(SLONG), false);
		slack_byte_field = MET_make_field(gpreGlob.slack_name, dtype_text, 1, false);
		reference = (ref*) MSC_alloc(REF_LEN);
		reference->ref_value = "0";
		lit0 = MSC_unary(nod_literal, (gpre_nod*) reference);

		reference = (ref*) MSC_alloc(REF_LEN);
		reference->ref_value = "1";
		lit1 = MSC_unary(nod_literal, (gpre_nod*) reference);
	}

	// Handle different request types differently

	switch (request->req_type)
	{
	case REQ_create_database:
	case REQ_ddl:
		CMD_compile_ddl(request);
		return;
	case REQ_slice:
		cmp_slice(request);
		return;

	case REQ_ready:
		cmp_ready(request);
		return;
	case REQ_procedure:
		cmp_procedure(request);
		return;
	}
	// expand any incomplete references or values

	expand_references(request->req_references);
	expand_references(request->req_values);

	// Initialize the blr string

	request->req_blr = request->req_base = MSC_alloc(500);
	request->req_length = 500;
	if (request->req_flags & REQ_blr_version4)
		request->add_byte(blr_version4);
	else
		request->add_byte(blr_version5);

	// If there are values to be transmitted, make a port
	// to hold them

	if (request->req_values)
		request->req_vport = make_port(request, request->req_values);

	// If this is a FOR type request, an eof field reference needs
	// to be generated.  Do it.

	switch (request->req_type)
	{
	case REQ_for:
	case REQ_cursor:
	case REQ_any:
		reference = (ref*) MSC_alloc(REF_LEN);
		reference->ref_field = eof_field;
		reference->ref_next = request->req_references;
		break;
	case REQ_mass_update:
		reference = (ref*) MSC_alloc(REF_LEN);
		reference->ref_field = count_field;
		reference->ref_next = request->req_references;
		break;
	default:
		reference = request->req_references;
	}

	// Assume that a general port needs to be constructed.

	gpre_port* port;
	if ((request->req_type != REQ_insert) && (request->req_type != REQ_store2) &&
		(request->req_type != REQ_set_generator))
	{
		request->req_primary = port = make_port(request, reference);
	}

	// Loop thru actions looking for something interesting to do.  Not
	// all action types are "interesting", so don't worry about missing
	// ones.

	upd* update;
	for (act* action = request->req_actions; action; action = action->act_next)
	{
		switch (action->act_type)
		{
		case ACT_modify:
		case ACT_erase:
		case ACT_update:
			update = (upd*) action->act_object;
			expand_references(update->upd_references);
			update->upd_port = make_port(request, update->upd_references);
			if (!request->req_sync)
				request->req_sync = make_port(request, 0);
			break;
		case ACT_store:
			if (request->req_type == REQ_store2)
			{
				request->req_primary = make_port(request, action->act_object);
				update_references(request->req_primary->por_references);
			}
			break;
		case ACT_store2:
			update = (upd*) action->act_object;
			expand_references(update->upd_references);
			update->upd_port = make_port(request, update->upd_references);
			update_references(update->upd_port->por_references);
			break;
		case ACT_select:
		case ACT_fetch:
			cmp_fetch(action);
			break;
		}
	}

	cmp_blr(request);
	request->add_byte(blr_eoc);

	// Compute out final blr lengths

	request->req_length = request->req_blr - request->req_base;
	request->req_blr = request->req_base;

	// Finally, assign identifiers to any blobs that may have been referenced

	for (blb* blob = request->req_blobs; blob; blob = blob->blb_next)
		cmp_blob(blob, false);
}
Ejemplo n.º 9
0
term_t port_id(port_t *self, xpool_t *xp)
{
	return make_port(my_node, self->key, my_creation, xp);
}