示例#1
0
extern "C" void ext_yahoo_remove_handler(int id, int tag)
{
	LOG("ext_yahoo_remove_handler %d\n", id);

	if (!tag)
		return;

	assert(gYahooConnections[id] != NULL);
	
	YahooConnection * conn = gYahooConnections[id];
	
	for (int i=0; i < conn->CountConnections(); i++) {
		struct conn_handler *c = conn->ConnectionAt(i);
		if(c->tag == tag) {
			/* don't actually remove it, just mark it for removal */
			/* we'll remove when we start the next poll cycle */
			LOG("  Marking id:%d con:%p tag:%d for removal\n", c->id, c->con, c->tag);
			c->remove = 1;
			return;
		}
	}
}
示例#2
0
extern "C" void ext_yahoo_remove_handler(int id, int tag)
{
//	LOG(kProtocolName, liDebug, "ext_yahoo_remove_handler %d", id);
	
	if ( id < 0 )
	{
		return;
	}
	
	assert( gYahooConnections[id] != NULL );
	
	YahooConnection * conn = gYahooConnections[id];
	
	for (int i=0; i < conn->CountConnections(); i++) {
		struct fd_conn *c = conn->ConnectionAt(i);
		if(c->tag == tag) {
			/* don't actually remove it, just mark it for removal */
			/* we'll remove when we start the next poll cycle */
//			LOG(kProtocolName, liDebug, "  Marking id:%d fd:%d tag:%d for removal", c->id, c->fd, c->tag);
			c->remove = 1;
			return;
		}
	}
}
示例#3
0
int32
yahoo_io_thread( void * _data )
{
	YahooConnection * conn = (YahooConnection*)_data;
	register_callbacks();

	conn->fID = yahoo_init_with_attributes(conn->fYahooID, conn->fPassword,
				"local_host", "95.252.70.62",
				"pager_port", 5050, NULL);

	LOG("yahoo_io_thread: id: %s, pass: %s\n", conn->fYahooID, conn->fPassword );

	gYahooConnections[conn->fID] = conn;

	yahoo_login(conn->fID, YAHOO_STATUS_AVAILABLE);

	int lfd = 0;

	fd_set inp, outp;
	struct timeval tv;

	while (conn->IsAlive()) {
		snooze(10000);
		FD_ZERO(&inp);
		FD_ZERO(&outp);

		tv.tv_sec=3;
		tv.tv_usec=1E4;
		lfd=0;
		int i;
		
		for(i = 0; i < conn->CountConnections(); i++) {
			struct conn_handler *c = conn->ConnectionAt(i);
			if(c->remove) {
				conn->RemoveConnection(c);
				c->remove = 0;
				free(c);
			} else {
				if(c->cond & YAHOO_INPUT_READ)
					FD_SET(c->con->fd, &inp);
				if(c->cond & YAHOO_INPUT_WRITE)
					FD_SET(c->con->fd, &outp);
				if(lfd < c->con->fd)
					lfd = c->con->fd;
			}
		}

		select(lfd + 1, &inp, &outp, NULL, &tv);
		time(&curTime);

		for(i = 0; i < conn->CountConnections(); i++) {
			struct conn_handler *c = conn->ConnectionAt(i);
			if(c->con->remove) {
				free(c->con);
				c->con = NULL;
				break;
			}
			if(c->remove)
				continue;
			if(FD_ISSET(c->con->fd, &inp))
				yahoo_callback(c, YAHOO_INPUT_READ);
			if(FD_ISSET(c->con->fd, &outp))
				yahoo_callback(c, YAHOO_INPUT_WRITE);
		}

		if(expired(pingTimer))
			yahoo_ping_timeout_callback(conn->fID);
	//	if(expired(webcamTimer))	yahoo_webcam_timeout_callback(webcam_id);
	}
	LOG("Exited loop");

	for(int i = 0; i < conn->CountConnections(); i++) {
		struct conn_handler *c = conn->ConnectionAt(i);
		free(c);
		conn->RemoveConnection(c);
	}
	return 0;
}
示例#4
0
int32
yahoo_io_thread( void * _data )
{
	YahooConnection * conn = (YahooConnection*)_data;
	
/*	conn->fID = yahoo_init_with_attributes(
		conn->fYahooID, conn->fPassword,
		//"local_host", local_host,
		"pager_port", 23,
		NULL
	);
*/	
	conn->fID = yahoo_init(
		conn->fYahooID, conn->fPassword
	);
	
	LOG(kProtocolName, liDebug, "yahoo_io_thread: id: %s, pass: %s", conn->fYahooID, conn->fPassword );
	
	gYahooConnections[conn->fID] = conn;
	
	yahoo_login( conn->fID, YAHOO_STATUS_AVAILABLE );

	int lfd=0;
	
	fd_set inp, outp;
	struct timeval tv;
	
	LOG(kProtocolName, liDebug, "yahoo_io_thread: Starting loop");
	
	while( conn->IsAlive() ) {
		FD_ZERO(&inp);
		FD_ZERO(&outp);
		tv.tv_sec=1;
		tv.tv_usec=0;
		lfd=0;
		
		for(int i=0; i<conn->CountConnections(); i++) {
			struct fd_conn *c = conn->ConnectionAt(i);
			
			if(c->remove) {
//				LOG(kProtocolName, liDebug, "yahoo_io_thread: Removing id:%d fd:%d", c->id, c->fd);
				conn->RemoveConnection(c);
				free(c);
			} else {
				if(c->cond & YAHOO_INPUT_READ) {
					FD_SET(c->fd, &inp);
				}
				if(c->cond & YAHOO_INPUT_WRITE) {
					FD_SET(c->fd, &outp);
				}
				if(lfd < c->fd)
					lfd = c->fd;
			}
		}
		
		select(lfd + 1, &inp, &outp, NULL, &tv);
		time(&curTime);
		
		for(int i=0; i<conn->CountConnections(); i++) {
			struct fd_conn *c = conn->ConnectionAt(i);
			if(c->remove)
				continue;
			if(FD_ISSET(c->fd, &inp)) {
//				LOG(kProtocolName, liDebug, "yahoo_io_thread: data to read");
				yahoo_callback(c, YAHOO_INPUT_READ);
				FD_CLR(c->fd, &inp);
			}
			if(FD_ISSET(c->fd, &outp)) {
				//LOG(kProtocolName, liDebug, "yahoo_io_thread: data to write");
				yahoo_callback(c, YAHOO_INPUT_WRITE);
				FD_CLR(c->fd, &outp);
			}
		}
		
		if(expired(pingTimer))
			yahoo_ping_timeout_callback(conn->fID, pingTimer);
	}
	LOG(kProtocolName, liDebug, "yahoo_io_thread: Exited loop");
	
	while( conn->CountConnections() > 0 ) {
		struct fd_conn * c = conn->ConnectionAt(0);
		conn->RemoveConnection(c);
		close(c->fd);
		FREE(c);
	}
	
	return 0;
}