Ejemplo n.º 1
0
void zmq::socket_base_t::process_term (int linger_)
{
    //  Unregister all inproc endpoints associated with this socket.
    //  Doing this we make sure that no new pipes from other sockets (inproc)
    //  will be initiated.
    unregister_endpoints (this);

    //  Continue the termination process immediately.
    own_t::process_term (linger_);
}
void zmq::socket_base_t::process_term (int linger_)
{
    //  Unregister all inproc endpoints associated with this socket.
    //  Doing this we make sure that no new pipes from other sockets (inproc)
    //  will be initiated.
    unregister_endpoints (this);

    //  Ask all attached pipes to terminate.
    for (pipes_t::size_type i = 0; i != pipes.size (); ++i)
        pipes [i]->terminate (false);
    register_term_acks ((int) pipes.size ());

    //  Continue the termination process immediately.
    own_t::process_term (linger_);
}
Ejemplo n.º 3
0
static int audio_close(hw_device_t *device)
{
	struct a2dp_audio_dev *a2dp_dev = (struct a2dp_audio_dev *)device;

	DBG("");

	unregister_endpoints();

	queue_destroy(loaded_codecs, unload_codec);
	loaded_codecs = NULL;

	shutdown(listen_sk, SHUT_RDWR);
	shutdown(audio_sk, SHUT_RDWR);

	pthread_join(ipc_th, NULL);

	close(listen_sk);
	listen_sk = -1;

	free(a2dp_dev);
	return 0;
}
Ejemplo n.º 4
0
static void *ipc_handler(void *data)
{
	bool done = false;
	struct pollfd pfd;
	int sk;

	DBG("");

	while (!done) {
		DBG("Waiting for connection ...");

		sk = accept(listen_sk, NULL, NULL);
		if (sk < 0) {
			int err = errno;

			if (err == EINTR)
				continue;

			if (err != ECONNABORTED && err != EINVAL)
				error("audio: Failed to accept socket: %d (%s)",
							err, strerror(err));

			break;
		}

		pthread_mutex_lock(&sk_mutex);
		audio_sk = sk;
		pthread_mutex_unlock(&sk_mutex);

		DBG("Audio IPC: Connected");

		if (register_endpoints() != AUDIO_STATUS_SUCCESS) {
			error("audio: Failed to register endpoints");

			unregister_endpoints();

			pthread_mutex_lock(&sk_mutex);
			shutdown(audio_sk, SHUT_RDWR);
			close(audio_sk);
			audio_sk = -1;
			pthread_mutex_unlock(&sk_mutex);

			continue;
		}

		memset(&pfd, 0, sizeof(pfd));
		pfd.fd = audio_sk;
		pfd.events = POLLHUP | POLLERR | POLLNVAL;

		/* Check if socket is still alive. Empty while loop.*/
		while (poll(&pfd, 1, -1) < 0 && errno == EINTR);

		if (pfd.revents & (POLLHUP | POLLERR | POLLNVAL)) {
			info("Audio HAL: Socket closed");

			pthread_mutex_lock(&sk_mutex);
			close(audio_sk);
			audio_sk = -1;
			pthread_mutex_unlock(&sk_mutex);
		}
	}

	/* audio_sk is closed at this point, just cleanup endpoints states */
	memset(audio_endpoints, 0, sizeof(audio_endpoints));

	info("Closing Audio IPC thread");
	return NULL;
}