예제 #1
0
void yahoo_callback(struct conn_handler *c, yahoo_input_condition cond)
{
	LOG("yahoo_callback\n");
	int ret=1;
	char buff[1024]={0};

	if(c->id < 0) {
		connect_complete(c->data, c->con, cond);
	} else {
		if(cond & YAHOO_INPUT_READ)
			ret = yahoo_read_ready(c->id, c->con, c->data);
		if(ret>0 && cond & YAHOO_INPUT_WRITE)
			ret = yahoo_write_ready(c->id, c->con, c->data);

		if(ret == -1)
			snprintf(buff, sizeof(buff), 
				"Yahoo read error (%d): %s", errno, strerror(errno));
		else if(ret == 0)
			snprintf(buff, sizeof(buff), 
				"Yahoo read error: Server closed socket");

		if(buff[0])
			LOG((buff));
	}
}
예제 #2
0
void yahoo_callback(struct fd_conn *c, yahoo_input_condition cond)
{
	int ret=1;
	char buff[1024]={0};
	
	if(c->id < 0) {
		connect_complete(c->data, c->fd, cond);
		LOG(kProtocolName, liDebug, "calling connect_complete()");
	} else {
		if(cond & YAHOO_INPUT_READ) {
			ret = yahoo_read_ready(c->id, c->fd, c->data);
//			LOG(kProtocolName, liDebug, "Data read fd: %d, tag: %d, cond: %d", c->fd, c->tag, c->cond);
		}
		if(ret>0 && cond & YAHOO_INPUT_WRITE) {
			ret = yahoo_write_ready(c->id, c->fd, c->data);
//			LOG(kProtocolName, liDebug, "Data written fd: %d, tag: %d, cond: %d", c->fd, c->tag, c->cond);
		}

		if(ret == -1)
			snprintf(buff, sizeof(buff), 
				"Yahoo read error (%d): %s", errno, strerror(errno));
		else if(ret == 0)
			snprintf(buff, sizeof(buff), 
				"Yahoo read error: Server closed socket");
		
		if(buff[0])
			LOG(kProtocolName, liDebug, "Error: %s", buff);
	}
}
예제 #3
0
파일: hciemu.c 프로젝트: intgr/bluez
static void accept_connection(uint8_t *data)
{
	accept_conn_req_cp *cp = (void *) data;
	struct vhci_conn *conn;

	if (!(conn = conn_get_by_bdaddr(&cp->bdaddr)))
		return;

	connect_complete(conn);
}
예제 #4
0
static void accept_connection(uint8_t *data)
{
	accept_conn_req_cp *cp = (void *) data;
	struct vhci_conn *conn;

	if (!(conn = conn_get_by_bdaddr(&cp->bdaddr)))
		return;

	connect_complete(conn);

	g_io_add_watch(conn->chan, G_IO_IN | G_IO_NVAL | G_IO_HUP,
			io_acl_data, (gpointer) conn);
}
예제 #5
0
static void create_connection(uint8_t *data)
{
	create_conn_cp *cp = (void *) data;
	struct vhci_link_info info;
	struct vhci_conn *conn;
	struct sockaddr_in sa;
	int h, sk, opt;
	bdaddr_t ba;

	for (h = 0; h < VHCI_MAX_CONN; h++)
		if (!vconn[h])
			goto do_connect;

	syslog(LOG_ERR, "Too many connections");
	return;

do_connect:
	if ((sk = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
		syslog(LOG_ERR, "Can't create socket: %s (%d)",
						strerror(errno), errno);
		return;
	}

	opt = 1;
	setsockopt(sk, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));

	baswap(&ba, &vdev.bdaddr);
	sa.sin_family = AF_INET;
	sa.sin_addr.s_addr = INADDR_ANY;	// *(uint32_t *) &ba;
	sa.sin_port = 0;			// *(uint16_t *) &ba.b[4];
	if (bind(sk, (struct sockaddr *) &sa, sizeof(sa))) {
		syslog(LOG_ERR, "Can't bind socket: %s (%d)",
						strerror(errno), errno);
		close(sk);
		return;
	}

	baswap(&ba, &cp->bdaddr);
	sa.sin_family = AF_INET;
	memcpy(&sa.sin_addr.s_addr, &ba, sizeof(sa.sin_addr.s_addr));
	sa.sin_port = *(uint16_t *) &ba.b[4];
	if (connect(sk, (struct sockaddr *) &sa, sizeof(sa)) < 0) {
		syslog(LOG_ERR, "Can't connect: %s (%d)",
						strerror(errno), errno);
		close(sk);
		return;
	}

	/* Send info */
	memset(&info, 0, sizeof(info));
	bacpy(&info.bdaddr, &vdev.bdaddr);
	info.link_type = ACL_LINK;
	info.role = 1;
	write_n(sk, (void *) &info, sizeof(info));

	if (!(conn = malloc(sizeof(*conn)))) {
		syslog(LOG_ERR, "Can't alloc new connection: %s (%d)",
						strerror(errno), errno);
		close(sk);
		return;
	}

	memcpy((uint8_t *) &ba, (uint8_t *) &sa.sin_addr, 4);
	memcpy((uint8_t *) &ba.b[4], (uint8_t *) &sa.sin_port, 2);
	baswap(&conn->dest, &ba);

	vconn[h] = conn;
	conn->handle = h + 1;
	conn->chan = g_io_channel_unix_new(sk);

	connect_complete(conn);
	g_io_add_watch(conn->chan, G_IO_IN | G_IO_NVAL | G_IO_HUP,
				io_acl_data, (gpointer) conn);
	return;
}
void QGenieConnectToWlanThread::run()
{
#ifdef Q_OS_WIN
    bool bassociate = false;

    if( (0 == diagnose_inf) ||  m_strnicguid.isEmpty() || m_strssid.isEmpty() /*|| m_strpwd.isEmpty()*/ )
    {
        emit connect_complete(false);
        return;
    }

    if(m_buseprofile)
    {
        //        if(diagnose_inf->TryConnect2WlanWithProfile(m_strssid))
        //        {
        //            QThread::msleep(5000);
        //
        //            emit connect_complete(true);
        //        }
        //        else
        //        {
        //            emit connect_complete(false);
        //        }
        bassociate = diagnose_inf->TryConnect2WlanWithProfile(m_strssid);
        int times = 30;
        if(bassociate)
        {
            bassociate = false;

            do
            {
                if(1 == diagnose_inf->IsWlanNicConnected(m_strnicguid))
                {
                    bassociate = true;
                    break;
                }

                QThread::msleep(1000);

            }while(--times);
        }
    }
    else
    {
        //        if(diagnose_inf->ConnectToWlan(m_strnicguid,m_strssid,m_strpwd))
        //        {
        //            emit connect_complete(true);
        //        }
        //        else
        //        {
        //            emit connect_complete(false);
        //        }
        bassociate = diagnose_inf->ConnectToWlan(m_strnicguid,m_strssid,m_strpwd,false);
    }

    if(bassociate)
    {
        emit connect_complete(waitdhcp_forgateway(m_strnicguid));
    }
    else
    {
        emit connect_complete(bassociate);
    }

#elif defined Q_OS_MACX

    bool bassociate = false;

    if((0 == wifiApi_inf) ||  m_strnicguid.isEmpty() || m_strssid.isEmpty() )
    {
        emit connect_complete(bassociate);
        return;
    }

    if(m_buseprofile)
    {
        //mac os x can never reach here
        assert (false);
    }
    else
    {
        bassociate = wifiApi_inf->AssociateToNetwork(m_strnicguid,m_strssid,m_strpwd);
    }

    emit connect_complete(bassociate);

#endif

}