Example #1
0
void ViewerWindow::on_actionCapturar_triggered()
{
    //Stop movie if running
    if (movie_->state() == QMovie::Paused || movie_->state() == QMovie::Running)
    {
        movie_->stop();
    }

    //(Re)create camera
    if (camera != NULL) delete camera;
    camera = new QCamera(selected_camera);

    //Set up camera and start
    camera->setViewfinder(captureBuffer);
    camera->setCaptureMode(QCamera::CaptureViewfinder);

    //Connect to server
    QSettings settings("GS", "viewer");

    QString host = settings.value("Host", "127.0.0.1").toString();
    quint16 port = settings.value("Port", 7890).toUInt();

    connect(tcpSocket, SIGNAL(connected()), this, SLOT(on_connected()));
    connect(tcpSocket, SIGNAL(disconnected()), this, SLOT(on_disconnected()));

    tcpSocket->connectToHost(host, port);

}
Example #2
0
void Connection::ssl_handshake() {
  if (!ssl_session_->is_handshake_done()) {
    ssl_session_->do_handshake();
    if (ssl_session_->has_error()) {
      notify_error("Error during SSL handshake: " + ssl_session_->error_message(), CONNECTION_ERROR_SSL);
      return;
    }
  }

  char buf[SslHandshakeWriter::MAX_BUFFER_SIZE];
  size_t size = ssl_session_->outgoing().read(buf, sizeof(buf));
  if (size > 0) {
    if (!SslHandshakeWriter::write(this, buf, size)) {
      notify_error("Error writing data during SSL handshake");
      return;
    }
  }

  if (ssl_session_->is_handshake_done()) {
    ssl_session_->verify();
    if (ssl_session_->has_error()) {
      notify_error("Error verifying peer certificate: " + ssl_session_->error_message(), CONNECTION_ERROR_SSL);
      return;
    }
    on_connected();
  }
}
Light::Light()
{
    QObject::connect(&m_connection, SIGNAL(connected()), SLOT(on_connected()));
    QObject::connect(&m_connection, SIGNAL(error()), SLOT(on_error()));
    QObject::connect(&m_connection, SIGNAL(disconnected()), SLOT(on_disconnected()));
    QObject::connect(&m_connection, SIGNAL(readyRead()), SLOT(on_readyRead()));
}
Example #4
0
Client::Client(QObject *parent) :
    QObject(parent)
{
    socket = new QTcpSocket(this);
    connect(socket, SIGNAL(connected()),
            this, SLOT(on_connected()));
}
Example #5
0
int main(int argc,char **argv){
	signal(SIGPIPE,SIG_IGN);
	e = engine_new();
	sockaddr_ server;
	easy_sockaddr_ip4(&server,argv[1],atoi(argv[2]));
	uint32_t size = atoi(argv[3]);
	uint32_t i = 0;
	for( ; i < size; ++i){
		int32_t fd = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
		easy_noblock(fd,1);
		int32_t ret;
		if(0 == (ret = easy_connect(fd,&server,NULL)))
			on_connected(fd,0,e);
		else if(ret == -EINPROGRESS){
			connector *c = connector_new(fd,e,2000);
			engine_associate(e,c,on_connected);			
		}else{
			close(fd);
			printf("connect to %s %d error\n",argv[1],atoi(argv[2]));
		}
	}
	//engine_regtimer(e,1000,timer_callback,NULL);
	engine_run(e);
	return 0;
}
Example #6
0
IRC_Session::IRC_Session(ServerProfile profile, QObject *parent = 0, QTreeWidget *sParent = 0)  : Irc::Session(parent) {

    ChanList.insert("status",new irc_channel);
    ServerItem = new QTreeWidgetItem(sParent);
    ServerItem->setText(0,profile.HostName);
    Message temp = ChanList["status"]->append("INIT","*","Initializing protocol..");
    emit init_message(this,temp);

    connect(this, SIGNAL(connected()), SLOT(on_connected()));
    connect(this, SIGNAL(disconnected()), SLOT(on_disconnected()));
    connect(this, SIGNAL(msgQuit(QString, QString)), SLOT(on_msgQuit(QString, QString)));
    connect(this, SIGNAL(msgJoined(QString, QString)), SLOT(on_msgJoined(QString, QString)));
    connect(this, SIGNAL(msgNickChanged(QString, QString)), SLOT(on_msgNickChanged(QString, QString)));
    connect(this, SIGNAL(msgParted(QString, QString, QString)), SLOT(on_msgParted(QString, QString, QString)));
    connect(this, SIGNAL(msgInvited(QString, QString, QString)), SLOT(on_msgInvited(QString, QString, QString)));
    connect(this, SIGNAL(msgCtcpReplyReceived(QString, QString)), SLOT(on_msgCtcpReplyReceived(QString, QString)));
    connect(this, SIGNAL(msgCtcpRequestReceived(QString, QString)), SLOT(on_msgCtcpRequestReceived(QString, QString)));
    connect(this, SIGNAL(msgTopicChanged(QString, QString, QString)), SLOT(on_msgTopicChanged(QString, QString, QString)));
    connect(this, SIGNAL(msgNoticeReceived(QString, QString, QString)), SLOT(on_msgNoticeReceived(QString, QString, QString)));
    connect(this, SIGNAL(msgKicked(QString, QString, QString, QString)), SLOT(on_msgKicked(QString, QString, QString, QString)));
    connect(this, SIGNAL(msgMessageReceived(QString, QString, QString)), SLOT(on_msgMessageReceived(QString, QString, QString)));
    connect(this, SIGNAL(msgUnknownMessageReceived(QString, QStringList)), SLOT(on_msgUnknownMessageReceived(QString, QStringList)));
    connect(this, SIGNAL(msgCtcpActionReceived(QString, QString, QString)), SLOT(on_msgCtcpActionReceived(QString, QString, QString)));
    connect(this, SIGNAL(msgModeChanged(QString, QString, QString, QString)), SLOT(on_msgModeChanged(QString, QString, QString, QString)));
    connect(this, SIGNAL(msgNumericMessageReceived(QString, uint, QStringList)), SLOT(on_msgNumericMessageReceived(QString, uint, QStringList)));

    temp = ChanList["status"]->append("INIT","*","Setting up server environment..");
    emit init_message(this,temp);

    setAutoJoinChannels(Profile->AutoJoinChannels);

    if(ClientProfile->RealName)
        setRealName(ClientProfile->RealName);

}
Example #7
0
MyIrcSession::MyIrcSession(const std::string &user, NetworkPlugin *np, const std::string &suffix, QObject* parent) : IrcSession(parent)
{
	this->np = np;
	this->user = user;
	this->suffix = suffix;
	m_connected = false;
	rooms = 0;
	connect(this, SIGNAL(disconnected()), SLOT(on_disconnected()));
	connect(this, SIGNAL(connected()), SLOT(on_connected()));
	connect(this, SIGNAL(messageReceived(IrcMessage*)), this, SLOT(onMessageReceived(IrcMessage*)));
}
Example #8
0
int  loop_run(int timeout)
{
    int error;
    DWORD bytes = 0;
    PER_HANDLE_DATA* handle_data = NULL;
    WSAOVERLAPPED* overlap = NULL;

    error = GetQueuedCompletionStatus(default_loop.completion_port, &bytes,
        (ULONG_PTR*)&handle_data, &overlap, timeout);
    if (error == 0)
    {
        error = GetLastError();
        if (error == WAIT_TIMEOUT)
        {
            return 1;
        }
        fprintf(stderr, "%d: %s", error, LAST_ERROR_MSG);
        if (overlap != NULL)
        {
            handle_data->opertype = OperClose;
        }
        else
        {
            if (error == ERROR_INVALID_HANDLE)
            {
                return 0;
            }
            return 1;
        }
    }

    switch(handle_data->opertype)
    {
    case OperConnect:
        on_connected(handle_data);
        break;

    case OperRecv:
        on_recv(handle_data);
        break;

    case OperSend:
        after_sent(handle_data);
        break;

    case OperClose:
        on_close(handle_data);
        break;

    default:
        assert(0);
    }
    return 1;
}
Example #9
0
gboolean MiracBroker::listen_cb (gint fd, GIOCondition condition)
{
    try {
        connection(network_->Accept());
        WDS_LOG("connection from: %s", connection_->GetPeerAddress().c_str());
        on_connected();
    } catch (const std::exception &x) {
        WDS_WARNING("exception: %s", x.what());
    }

    return G_SOURCE_CONTINUE;
}
Example #10
0
connection::connection(QObject *parent) :
    QObject(parent)
{
    ableToWrite=false;
    socket = new QTcpSocket(this);
    connect(socket,SIGNAL(error(QAbstractSocket::SocketError)),this,SLOT(printError(QAbstractSocket::SocketError)));
    connect(socket, SIGNAL(connected()), this, SLOT(on_connected()));
    connect(socket,SIGNAL(disconnected()), this, SLOT(on_disconnected()));
    connect(socket,SIGNAL(readyRead()),this,SLOT(incommingData()));

    UDPsocket = new QUdpSocket(this);
    UDPsocket->bind(6666, QUdpSocket::ShareAddress);
    connect(UDPsocket, SIGNAL(readyRead()),this, SLOT(chatData()));
}
Example #11
0
MyIrcSession::MyIrcSession(const std::string &user, IRCNetworkPlugin *np, const std::string &suffix, QObject* parent) : IrcSession(parent)
{
	this->np = np;
	this->user = user;
	this->suffix = suffix;
	m_connected = false;
	rooms = 0;
	connect(this, SIGNAL(disconnected()), SLOT(on_disconnected()));
	connect(this, SIGNAL(socketError(QAbstractSocket::SocketError)), SLOT(on_socketError(QAbstractSocket::SocketError)));
	connect(this, SIGNAL(connected()), SLOT(on_connected()));
	connect(this, SIGNAL(messageReceived(IrcMessage*)), this, SLOT(onMessageReceived(IrcMessage*)));

	m_awayTimer = new QTimer(this);
	connect(m_awayTimer, SIGNAL(timeout()), this, SLOT(awayTimeout()));
	m_awayTimer->start(5*1000);
}
Example #12
0
void tcp_data_handler::update_status(int status,int error_type,int error_no)
{
    int old_status = m_connect_status ;
    m_connect_status = status ;
    if(old_status != STATUS_CONNECTED && status == STATUS_CONNECTED )
    {
        on_connected() ;
        return ;
    }
    else if( old_status != STATUS_CLOSED && status == STATUS_CLOSED )
    {
        on_closed(error_type,error_no) ;
        return ;
    }
    

}
static void
dispatch_socket(struct master *m, const struct skynet_socket_message *msg, int sz) {
	int id = socket_id(m, msg->id);
	switch(msg->type) {
	case SKYNET_SOCKET_TYPE_CONNECT:
		assert(id);
		on_connected(m, id);
		break;
	case SKYNET_SOCKET_TYPE_ERROR:
		skynet_error(m->ctx, "socket error on harbor %d", id);
		// go though, close socket
	case SKYNET_SOCKET_TYPE_CLOSE:
		close_harbor(m, id);
		break;
	default:
		skynet_error(m->ctx, "Invalid socket message type %d", msg->type);
		break;
	}
}
Example #14
0
gboolean MiracBroker::connect_cb (gint fd, GIOCondition condition)
{
    try {
        if (!network_->Connect(NULL, NULL))
            return G_SOURCE_CONTINUE;
        WDS_LOG("connection success to: %s", network_->GetPeerAddress().c_str());
        connection(network_.release());

        /* make sure any network event sources are removed */
        network(NULL);

        on_connected();
    } catch (const std::exception &x) {
        gdouble elapsed = 1000 * g_timer_elapsed(connect_timer_, NULL);
        if (elapsed + connect_wait_ > connect_timeout_) {
            on_connection_failure(CONNECTION_TIMEOUT);
        } else {
            connect_wait_id_ = g_timeout_add (connect_wait_, try_connect, this);
        }
    }
    return G_SOURCE_REMOVE;
}
Example #15
0
	void netstream_threaded::operator()()
	{	binary_data tmp_data;

		// Post disconnect once the disconnect
		sem_disconnect.post();

		while(1)
		{
			// Wait for new socket
			sem_newsocket.wait();

			// On zombie-mode exit thread
			if (b_zombie)
				return;

			// We must be connected
			b_connected = true;
			on_connected();
			sem_connect.post();

			try{

				while(1)
				{
					tmp_data = netstream::receive(1024);
					on_data_received(tmp_data);
				}
			}
			catch(std::exception){}

			// We got disconnected
			b_connected = false;
			netstream::disconnect();	// Disconnect for sure
			on_disconnected();

			// Post event
			sem_disconnect.post();
		}
	}
Example #16
0
bool SMTP_Connection::Connect(QString host, quint16 port){
    p_host = host;
    p_port = port;
    if(ssl){
        ssl_sock = new QSslSocket(this);
        ssl_sock->connectToHostEncrypted(host,port);
        sock = ssl_sock;
    }else{
        sock = new QTcpSocket(this);
        sock->connectToHost(host,port);
    }
    if (!sock->waitForConnected(CONNECT_TIMEOUT))
    {
        emit error_code("Невозможно поключиться к серверу SMTP: ");
        return false;
    }
    connect(sock, SIGNAL(connected()),this, SLOT(on_connected()));
    connect(sock, SIGNAL(readyRead()), this, SLOT(on_read()));
    connect(sock, SIGNAL(error(QAbstractSocket::SocketError)),this,SLOT(slotError(QAbstractSocket::SocketError)));
    t = new QTextStream(sock);
    state = Init;
    return true;
}
Example #17
0
 /// 连接成功
 void tcp_session::connect_invoke()
 {
     on_connected();
 }
Example #18
0
/**
 * process_incomming_data: handles a raw irc line minus the \r\n that
 * has already been removed in the handle_receive event.
 * @param line
 */
void Client::process_incomming_data(std::string &line) {
    session_t session;
    int pos;

    line = trim(line);

    //std::cout << "server->'" << line << "'" << std::endl;
        
    // Get the prefix
    if (line.at(0) == ':') {
        if ((pos = line.find(' ')) > 0) {
            session.prefix = line.substr(1, pos - 1);
            line = line.substr(pos);
        }
    }

    line = ltrim(line);

    // Get the code or the command
    session.code = 0;
    if (isdigit(line.at(0)) && isdigit(line.at(1)) && isdigit(line.at(2))) {
        session.code = atoi(line.substr(0, 3).c_str());
        line = line.substr(3);
    } else if ((pos = line.find(' ')) > 0) {
        session.command = line.substr(0, pos);
        line = line.substr(pos);
    } else {
        // just drop line for now.
        return;
    }

    line = ltrim(line);

    // Get the params
    session.param_count = 0;   
    while (line.length() > 0 && session.param_count < 15) {
        // Message
        if (line.at(0) == ':') {
            session.trailing = line.substr(1);
            break;
        }

        // Params
        if ((pos = line.find(' ')) > 0) {
            session.params[session.param_count] = line.substr(0, pos);
            session.param_count++;
            line = line.substr(pos);
            line = ltrim(line);
        } else {
            session.params[session.param_count] = line;
            session.param_count++;
            break;
        }
    }

    //std::cout << "prefix: '" << session.prefix << "', command: '" << session.command << "', code: " << session.code << ", message: '" << session.trailing << "', param_count: " << session.param_count << ", params[0]: '" << session.params[0] << "', params[1]: '" << session.params[1] << "', params[2]: '" << session.params[2] << "'" << std::endl;

    // Handle Codes
    switch (session.code) {
            // We use the MOTD as a signal that we are fully connected to IRC.
        case RPL_ENDOFMOTD:
        case ERR_NOMOTD:
            on_connected();
            break;
        case ERR_NONICKNAMEGIVEN:
        case ERR_ERRONEUSNICKNAME:
        case ERR_NICKNAMEINUSE:
        case ERR_NICKCOLLISION:
            on_nick_error(session);
    }

    // Handle Commands
    if (session.command == "JOIN") on_join(session);
    else if (session.command == "NICK") on_nick(session);
    else if (session.command == "NOTICE") on_notice(session);
    else if (session.command == "PART") on_part(session);
    else if (session.command == "PING") on_ping(session);
    else if (session.command == "PRIVMSG") on_privmsg(session);
    else if (session.command == "QUIT") on_quit(session);

    //std::cout << "---------------------------------------------------------------------------------------------------------------------------" << std::endl;

}