Esempio n. 1
0
File: server.c Progetto: penser/grpc
static void channel_op(grpc_channel_element *elem,
                       grpc_channel_element *from_elem, grpc_channel_op *op) {
  channel_data *chand = elem->channel_data;
  grpc_server *server = chand->server;

  switch (op->type) {
    case GRPC_ACCEPT_CALL:
      /* create a call */
      grpc_call_create(chand->channel, NULL,
                       op->data.accept_call.transport_server_data, NULL, 0,
                       gpr_inf_future);
      break;
    case GRPC_TRANSPORT_CLOSED:
      /* if the transport is closed for a server channel, we destroy the
         channel */
      gpr_mu_lock(&server->mu);
      server_ref(server);
      destroy_channel(chand);
      gpr_mu_unlock(&server->mu);
      server_unref(server);
      break;
    case GRPC_TRANSPORT_GOAWAY:
      gpr_slice_unref(op->data.goaway.message);
      break;
    default:
      GPR_ASSERT(op->dir == GRPC_CALL_DOWN);
      grpc_channel_next_op(elem, op);
      break;
  }
}
Esempio n. 2
0
void grpc_channel_internal_unref(grpc_exec_ctx *exec_ctx, grpc_channel *channel,
                                 const char *reason) {
  gpr_log(GPR_DEBUG, "CHANNEL: unref %p %d -> %d [%s]", channel,
          channel->refs.count, channel->refs.count - 1, reason);
#else
void grpc_channel_internal_unref(grpc_exec_ctx *exec_ctx,
                                 grpc_channel *channel) {
#endif
  if (gpr_unref(&channel->refs)) {
    destroy_channel(exec_ctx, channel);
  }
}

void grpc_channel_destroy(grpc_channel *channel) {
  grpc_transport_op op;
  grpc_channel_element *elem;
  grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
  GRPC_API_TRACE("grpc_channel_destroy(channel=%p)", 1, (channel));
  memset(&op, 0, sizeof(op));
  op.disconnect = 1;
  elem = grpc_channel_stack_element(CHANNEL_STACK_FROM_CHANNEL(channel), 0);
  elem->filter->start_transport_op(&exec_ctx, elem, &op);

  GRPC_CHANNEL_INTERNAL_UNREF(&exec_ctx, channel, "channel");

  grpc_exec_ctx_finish(&exec_ctx);
}
Esempio n. 3
0
static void mcap_mdl_connected_cb(struct mcap_mdl *mdl, void *data)
{
	struct health_channel *channel = data;
	int fd;

	if (!channel->mdl)
		channel->mdl = mcap_mdl_ref(mdl);

	DBG("Data channel connected: mdl %p channel %p", mdl, channel);

	fd = mcap_mdl_get_fd(channel->mdl);
	if (fd < 0) {
		error("health: error retrieving fd");
		goto fail;
	}

	if (channel->mdep_id == MDEP_ECHO) {
		GIOChannel *io;

		io = g_io_channel_unix_new(fd);
		g_io_add_watch(io, G_IO_ERR | G_IO_HUP | G_IO_NVAL | G_IO_IN,
							serve_echo, channel);
		g_io_channel_unref(io);

		return;
	}

	send_channel_state_notify(channel, HAL_HEALTH_CHANNEL_CONNECTED, fd);

	return;
fail:
	/* TODO: mcap_mdl_abort */
	destroy_channel(channel);
}
Esempio n. 4
0
int main()
{
	int	i;

	for (i=0; i<10000; ++i) {
		if (i % 1000 == 0)
			printf("Connections: %d\n", i);
		create_channel(&channel, &client, NULL);
		create_dangling_policy_request();
		destroy_channel(channel, client);
	}
	return 0;
}
Esempio n. 5
0
static void mcap_mdl_deleted_cb(struct mcap_mdl *mdl, void *data)
{
	struct health_channel *channel;

	info("health: MDL deleted");

	channel = search_channel_by_mdl(mdl);
	if (!channel)
		return;

	DBG("channel %p mdl %p", channel, mdl);
	destroy_channel(channel);
}
Esempio n. 6
0
int aout_sles_close(rh_aout_itf * pself) {

	if(pself) {

		struct aout_instance * instance = (struct aout_instance *)*pself;

		if(instance) {

			destroy_channel(h);
			free(instance->interface);
			free(instance);
		}
		*pself = NULL;
	}
	return 0;
}
Esempio n. 7
0
static void channel_connectivity_changed(grpc_exec_ctx *exec_ctx, void *cd,
                                         grpc_error *error) {
  channel_data *chand = cd;
  grpc_server *server = chand->server;
  if (chand->connectivity_state != GRPC_CHANNEL_SHUTDOWN) {
    grpc_transport_op op;
    memset(&op, 0, sizeof(op));
    op.on_connectivity_state_change = &chand->channel_connectivity_changed,
    op.connectivity_state = &chand->connectivity_state;
    grpc_channel_next_op(exec_ctx,
                         grpc_channel_stack_element(
                             grpc_channel_get_channel_stack(chand->channel), 0),
                         &op);
  } else {
    gpr_mu_lock(&server->mu_global);
    destroy_channel(exec_ctx, chand);
    gpr_mu_unlock(&server->mu_global);
    GRPC_CHANNEL_INTERNAL_UNREF(exec_ctx, chand->channel, "connectivity");
  }
}
Esempio n. 8
0
static void mcap_mdl_deleted_cb(struct mcap_mdl *mdl, void *data)
{
	struct health_channel *channel = data;
	struct health_device *dev;

	if (!channel)
		return;

	dev = channel->dev;

	DBG("device %p channel %p mdl %p", dev, channel, mdl);

	/* mdl == NULL means, delete all mdls */
	if (!mdl) {
		queue_foreach(dev->channels, notify_channel, NULL);
		queue_remove_all(dev->channels, NULL, NULL,
						free_health_channel);
		return;
	}

	destroy_channel(channel);
}
Esempio n. 9
0
int aout_sles_open(rh_aout_itf self, unsigned int channels, unsigned int rate, unsigned int samplesize, unsigned int bigendian) {

	struct aout_instance * instance = (struct aout_instance *)self;

	if( instance != NULL ) {

		if(instance->channels == channels &&
		   instance->samplerate == rate &&
		   instance->samplesize == samplesize &&
		   instance->bigendian == bigendian) {
			return 0; // channel is already open, and the correct format.
		}

		// channel is open, but the wrong format, close it.
		destroy_channel(self);
	}

	// open new channel.
	{
		if( instance ) {

			instance->channels = channels;
			instance->samplerate = rate;
			instance->samplesize = samplesize;
			instance->bigendian = bigendian;

			buffer_queue_alloc( &instance->bq, 3, 32 * 1024 ); // 3 32k periods.
			buffer_queue_alloc_buffers(&instance->bq);

			create_channel(self);

			return 0;
		}
		return -1;
	}
}
Esempio n. 10
0
static int create_channel(rh_aout_itf self) {

	struct aout_instance * instance = (struct aout_instance *)self;

	off_t start;
	off_t length;

	struct sles_api_instance * api_instance =
		(struct sles_api_instance *)instance->api;

	if(instance->playerObject)
		return 0;

	{
		int e = 0;

		SLuint32 channelMask = _sles_get_channelmask(instance->channels);

		const SLInterfaceID ids[] = { SL_IID_SEEK, SL_IID_BUFFERQUEUE };
		const SLboolean req[] = { SL_BOOLEAN_FALSE, SL_BOOLEAN_TRUE };

		// configure audio source
		SLDataLocator_AndroidSimpleBufferQueue loc_bufq = {SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE, instance->bq.nb_buffers};
		SLDataFormat_PCM format_pcm =
		{
			SL_DATAFORMAT_PCM,
			instance->channels,
			instance->samplerate * 1000,
			instance->samplesize * 8,
			instance->samplesize * 8,
			channelMask,
			(instance->bigendian ? SL_BYTEORDER_BIGENDIAN : SL_BYTEORDER_LITTLEENDIAN )
		};
		SLDataSource audioSrc = {&loc_bufq, &format_pcm};

		// configure audio sink
		SLDataLocator_OutputMix loc_outmix = { SL_DATALOCATOR_OUTPUTMIX,
				api_instance->outputMix };
		SLDataSink audioSnk = { &loc_outmix, NULL };

		if (SL_RESULT_SUCCESS
				!= (*api_instance->engineItf)->CreateAudioPlayer(
						api_instance->engineItf,
						&instance->playerObject,
						&audioSrc, &audioSnk,
						sizeof(ids) / sizeof(ids[0]), ids, req))
			e = 1;
		else if (SL_RESULT_SUCCESS
				!= (*instance->playerObject)->Realize(instance->playerObject,
						SL_BOOLEAN_FALSE ))
			e = 2;
		else if (SL_RESULT_SUCCESS
				!= (*instance->playerObject)->GetInterface(instance->playerObject,
						SL_IID_PLAY, &instance->playItf))
			e = 3;
		else if(SL_RESULT_SUCCESS
			!= (*instance->playerObject)->GetInterface(instance->playerObject,
						SL_IID_BUFFERQUEUE, &instance->bufferQueueItf))
			e = 5;
		else if(SL_RESULT_SUCCESS
			!= (*instance->bufferQueueItf)->RegisterCallback(instance->bufferQueueItf,
						&_buffer_queue_cb, self))
			e = 6;
		else if (SL_RESULT_SUCCESS
				!= (*instance->playItf)->SetCallbackEventsMask(instance->playItf,
						SL_PLAYEVENT_HEADATEND ))
			e = 7;

		if (e) {

			destroy_channel(h);
			return -1;
		}
	}

	return 0;
}