Exemplo n.º 1
0
int
cmyth_conn_connect_recorder(cmyth_recorder_t rec, unsigned buflen,
			    int tcp_rcvbuf)
{
	cmyth_conn_t conn;
	char *server;
	unsigned short port;

	if (!rec) {
		cmyth_dbg(CMYTH_DBG_ERROR, "%s: rec is NULL\n", __FUNCTION__);
		return -1;
	}

	server = rec->rec_server;
	port = rec->rec_port;

	cmyth_dbg(CMYTH_DBG_PROTO, "%s: connecting recorder control\n",
		  __FUNCTION__);
	conn = cmyth_conn_connect_ctrl(server, port, buflen, tcp_rcvbuf);
	cmyth_dbg(CMYTH_DBG_PROTO,
		  "%s: done connecting recorder control, conn = %p\n",
		  __FUNCTION__, conn);
	if (!conn) {
		cmyth_dbg(CMYTH_DBG_ERROR,
			  "%s: cmyth_connect(%s, %d, %d) failed\n",
			  __FUNCTION__, server, port, buflen);
		return -1;
	}

	if (rec->rec_conn)
		ref_release(rec->rec_conn);
	rec->rec_conn = conn;

	return 0;
}
Exemplo n.º 2
0
static int
do_open(cmyth_proginfo_t prog, struct fuse_file_info *fi, int i)
{
	cmyth_conn_t c = NULL;
	cmyth_file_t f = NULL;
	char *host;

	if ((host=cmyth_proginfo_host(prog)) == NULL) {
		return -1;
	}

	if ((c=cmyth_conn_connect_ctrl(host, port, 16*1024,
				       tcp_control)) == NULL) {
		return -1;
	}

	if ((f=cmyth_conn_connect_file(prog, c, MAX_BSIZE,
				       tcp_program)) == NULL) {
		return -1;
	}

	ref_release(host);
	ref_release(c);

	files[i].file = f;
	files[i].buf = malloc(MAX_BSIZE);
	files[i].start = 0;
	files[i].n = 0;

	fi->fh = i;

	return 0;
}
Exemplo n.º 3
0
static int
is_alive(char *host)
{

	if ((control=cmyth_conn_connect_ctrl(host, 6543,
					     16*1024, 4096)) == NULL) {
		return 0;
	}

	return 1;
}
Exemplo n.º 4
0
Arquivo: mythfuse.c Projeto: tsp/cmyth
static int
lookup_server(char *host)
{
	intptr_t i, j = -1;
	cmyth_conn_t control, event;

	debug("%s(): host '%s'\n", __FUNCTION__, host);

	for (i=0; i<MAX_CONN; i++) {
		if (conn[i].host && (strcmp(conn[i].host, host) == 0)) {
			break;
		}
		if ((j < 0) && (!conn[i].used)) {
			j = i;
		}
	}

	if (i == MAX_CONN) {
		if (j < 0) {
			debug("%s(): error at %d\n", __FUNCTION__, __LINE__);
			return -1;
		}
		conn[j].used = 1;
	}

	if (i == MAX_CONN) {
		if ((control=cmyth_conn_connect_ctrl(host, port, 16*1024,
						     tcp_control)) == NULL) {
			debug("%s(): error at %d\n", __FUNCTION__, __LINE__);
			conn[j].used = 0;
			return -1;
		}
		if ((event=cmyth_conn_connect_event(host, port, 16*1024,
						    tcp_control)) == NULL) {
			debug("%s(): error at %d\n", __FUNCTION__, __LINE__);
			conn[j].used = 0;
			return -1;
		}

		conn[j].host = strdup(host);
		conn[j].control = control;
		conn[j].event = event;
		conn[j].list = NULL;

		pthread_create(&conn[j].thread, NULL, event_loop, (void*)j);

		i = j;
	}

	return i;
}
Exemplo n.º 5
0
int
cmyth_chain_switch_to_locked(cmyth_chain_t chain, int index)
{
	int rc = -1;

	if ((index >= 0) && (index < (int)chain->chain_count)) {
		cmyth_conn_t conn;
		cmyth_file_t file;
		cmyth_proginfo_t prog;
		char *path, *title;

		if (chain->chain_list[index]->file != NULL) {
			chain->chain_current = index;
			return 0;
		}

		prog = chain->chain_list[index]->prog;

		if (prog == NULL) {
			return -1;
		}

		conn = cmyth_conn_connect_ctrl(prog->proginfo_hostname,
					       prog->proginfo_port,
					       16*1024, 4096);
		if (conn == NULL) {
			return -1;
		}

		path = cmyth_proginfo_pathname(prog);
		title = cmyth_proginfo_title(prog);
		cmyth_dbg(CMYTH_DBG_DEBUG, "%s(): connect to file %s [%s]\n",
			  __FUNCTION__, path, title);
		ref_release(path);
		ref_release(title);

		file = cmyth_conn_connect_file(prog, conn, 128*1024, 128*1024);

		if (file) {
			chain->chain_current = index;
			chain->chain_list[index]->file = file;
		}

		ref_release(conn);

		rc = 0;
	}

	return rc;
}