コード例 #1
0
ファイル: Connection.cpp プロジェクト: Acidburn0zzz/mumble
/**
 * This function waits until a complete package is received and then emits it as a message.
 * It gets called everytime new data is available and interprets the message prefix header
 * to figure out the type and length. It then waits until the complete message is buffered
 * and emits it as a message so it can be handled by the corresponding message handler
 * routine.
 *
 * @see QSslSocket::readyRead()
 * @see void ServerHandler::message(unsigned int msgType, const QByteArray &qbaMsg)
 * @see void Server::message(unsigned int uiType, const QByteArray &qbaMsg, ServerUser *u)
 */
void Connection::socketRead() {
	while (true) {
		qint64 iAvailable = qtsSocket->bytesAvailable();
		if (iPacketLength == -1) {
			if (iAvailable < 6)
				return;

			unsigned char a_ucBuffer[6];

			qtsSocket->read(reinterpret_cast<char *>(a_ucBuffer), 6);
			uiType = qFromBigEndian<quint16>(&a_ucBuffer[0]);
			iPacketLength = qFromBigEndian<quint32>(&a_ucBuffer[2]);
			iAvailable -= 6;
		}

		if ((iPacketLength == -1) || (iAvailable < iPacketLength))
			return;

		if (iPacketLength > 0x7fffff) {
			qWarning() << "Host tried to send huge packet";
			disconnectSocket(true);
			return;
		}

		QByteArray qbaBuffer = qtsSocket->read(iPacketLength);
		iPacketLength = -1;
		iAvailable -= iPacketLength;

		emit message(uiType, qbaBuffer);
	}
}
コード例 #2
0
ファイル: httpserver.cpp プロジェクト: NanoSim/Porto
void HttpServer :: incomingConnection(qintptr socketDescriptor)
{
  auto socket = new QTcpSocket (this);
  connect (socket, SIGNAL(readyRead()), this, SLOT(readSocket()));
  connect (socket, SIGNAL(disconnected()), this, SLOT(disconnectSocket()));
  socket->setSocketDescriptor(socketDescriptor);
}
コード例 #3
0
void QApplicationConfig::stop()
{
    // cleanup here
    disconnectSocket();

    updateState(Disconnected);
    updateError(NoError, "");   // clear the error here
}
コード例 #4
0
ファイル: ofxNeuron.cpp プロジェクト: naus3a/ofxNeuron
void ofxNeuron::connect(){
	cout<<"ofxNeuron: trying to connect: ";
	if(isTCPSocketRunning()){
		cout<<"socket busy. Disconnecting.";
		disconnectSocket(sockTCPRef);
	}else{
		sockTCPRef = BRConnectTo("127.0.0.1",7001);
	}
	cout<<endl;
}
コード例 #5
0
ファイル: tcpconnector.cpp プロジェクト: mocap-ca/mayaMocap
// External call.  Disconnect and queue the connection request if already connected.
void TcpConnector::connectSocket()
{
    if(isConnected())
    {
        mConnect = true;
        disconnectSocket();
    }
    else
    {
        _connectSocket();
    }
}
コード例 #6
0
ファイル: rfcommclient.cpp プロジェクト: Camelek/qtmoko
RfcommClient::RfcommClient(QWidget *parent, Qt::WFlags f)
    : QMainWindow(parent, f)
{
    waiter = new QWaitWidget(this);
    connect(waiter, SIGNAL(cancelled()), this, SLOT(cancelConnect()));

    connectAction = new QAction(tr("Connect..."), this);
    connect(connectAction, SIGNAL(triggered()), this, SLOT(connectSocket()));
    QSoftMenuBar::menuFor(this)->addAction(connectAction);
    connectAction->setVisible(true);

    disconnectAction = new QAction(tr("Disconnect"), this);
    connect(disconnectAction, SIGNAL(triggered()), this, SLOT(disconnectSocket()));
    disconnectAction->setVisible(false);
    QSoftMenuBar::menuFor(this)->addAction(disconnectAction);

    sendAction = new QAction(tr("Send"), this);
    connect(sendAction, SIGNAL(triggered()), this, SLOT(newUserText()));
    sendAction->setVisible(false);
    QSoftMenuBar::menuFor(this)->addAction(sendAction);

    QWidget *frame = new QWidget(this);
    QVBoxLayout *layout = new QVBoxLayout;

    logArea = new QTextEdit(frame);
    layout->addWidget(logArea);
    logArea->append(tr("Not connected"));
    logArea->setReadOnly(true);
    logArea->setFocusPolicy(Qt::NoFocus);

    userEntry = new QLineEdit(frame);
    userEntry->setEnabled(false);
    connect(userEntry, SIGNAL(editingFinished()), this, SLOT(newUserText()));
    layout->addWidget(userEntry);

    frame->setLayout(layout);
    setCentralWidget(frame);

    socket = new QBluetoothRfcommSocket(this);
    connect(socket, SIGNAL(connected()), this, SLOT(socketConnected()));
    connect(socket, SIGNAL(readyRead()), this, SLOT(serverReplied()));

    setWindowTitle(tr("RFCOMM Client"));
}
コード例 #7
0
ファイル: kitsocket.cpp プロジェクト: icefox/kinkatta
void KitSocket::_worker(void)
{
	int bytes;
	sflap_frame frame;

	// send the server a keepalive every 15 minutes
	if(++keepalivecount >= (15 * 60 * 1000 / KITSOCKET_WORKER_PERIOD))
	{
		keepalivecount = 0;
		if(keepAlive) writeKeepAlive();
	}

	// check for stuff to read from the server
	bytes = ::read(sock(), (void *)&frame, 6);
	if(bytes < 0)
	{
		ERRNO_SWITCH(break,
		print_frame("KitSocket::_worker() -- reading -- bytes < 0", frame); disconnectSocket(); return);
	}
コード例 #8
0
void AbstractSocket::takeOverFrom(AbstractSocket * socket)
{
    if (!socket->m_socket)
    {
        return;
    }

    if (m_socket)
    {
        disconnectSocket();
        delete m_socket;
        m_socket = nullptr;
    }

    socket->disconnectSocket();

    m_socket = socket->m_socket;
    socket->m_socket = nullptr;

    connectSocket();

    socket->connection()->setSocket(this);
}
コード例 #9
0
ファイル: Client.cpp プロジェクト: ogdabou/Epita_Innov
Client::Client(QWidget *parent) :
	QWidget(parent),
	ui(new Ui::Client)
{
	ui->setupUi(this);

	defaultPseudo = QString("user%1").arg(qrand() % 9000 + 1000);
	ui->pseudoLineEdit->setPlaceholderText(defaultPseudo);

    wsSocket = new QtWebsocket::QWsSocket(this, NULL, QtWebsocket::WS_V13);

	socketStateChanged(wsSocket->state());

	QObject::connect(ui->sendButton, SIGNAL(pressed()), this, SLOT(sendMessage()));
	QObject::connect(ui->textLineEdit, SIGNAL(returnPressed()), this, SLOT(sendMessage()));
	QObject::connect(ui->connectButton, SIGNAL(pressed()), this, SLOT(connectSocket()));
	QObject::connect(ui->disconnectButton, SIGNAL(pressed()), this, SLOT(disconnectSocket()));
	QObject::connect(wsSocket, SIGNAL(stateChanged(QAbstractSocket::SocketState)), this, SLOT(socketStateChanged(QAbstractSocket::SocketState)));
	QObject::connect(wsSocket, SIGNAL(frameReceived(QString)), this, SLOT(displayMessage(QString)));
	QObject::connect(wsSocket, SIGNAL(connected()), this, SLOT(socketConnected()));
	QObject::connect(wsSocket, SIGNAL(disconnected()), this, SLOT(socketDisconnected()));
	QObject::connect(wsSocket, SIGNAL(sslErrors(const QList<QSslError>&)), this, SLOT(displaySslErrors(const QList<QSslError>&)));
}
コード例 #10
0
void MjpegStreamerClient::stop()
{
    m_framerateTimer->stop();
    disconnectSocket();
}
コード例 #11
0
ファイル: peer.cpp プロジェクト: Etrnls/evangel
void Peer::disconnectFromPeer()
{
    Q_ASSERT_X(state != UnconnectedState, Q_FUNC_INFO, "Not connected yet");
    disconnectSocket();
}
コード例 #12
0
ファイル: kitsocket.cpp プロジェクト: icefox/kinkatta
// * KitSocket -- public *
bool KitSocket::connect(void)
{
	if(connectSocket()) if(connectSFLAP()) return true;
	disconnectSocket();
	return false;
}
コード例 #13
0
ファイル: kitsocket.cpp プロジェクト: icefox/kinkatta
KitSocket::~KitSocket()
{
	timer.stop();
	disconnectSocket();
}
コード例 #14
0
int main_thread( SceSize args, void *argp )
{
	char ip[16], * argv[5];
	int port, entry;
	parseArgs( argv, args, ( char * )argp );
	//sceUtilityGetNetParam
	strcpy( ip, argv[1] );
	port = atoi( argv[2] );
	entry = atoi( argv[3] );
	block_size = atoi( argv[4] );
	log( "%s:%d entry %d\n", ip, port, entry );
	
	/*ctrl_opts.inited = sceUtilityLoadNetModule( PSP_NET_MODULE_COMMON );
	if ( ctrl_opts.inited != 0 )
	{
		log( "Error loading Net modules (0x%08x)\n", ctrl_opts.inited );
		goto net_term;
	}
	ctrl_opts.inited = sceUtilityLoadNetModule( PSP_NET_MODULE_INET );
	if ( ctrl_opts.inited != 0 )
	{
		log( "Error loading iNet module (0x%08x)\n", ctrl_opts.inited );
		goto net_term;
	}*/
	ctrl_opts.inited = sceNetInit( 0x10000, 0x20, 0x1000, 0x20, 0x1000 );
	if ( ctrl_opts.inited != 0 )
	{
		log( "Error Initing pspnet (0x%08x)\n", ctrl_opts.inited );
		goto net_term;
	}
	ctrl_opts.inited = sceNetInetInit();
	if ( ctrl_opts.inited != 0 )
	{
		log( "Error initing Inet (0x%08x)\n", ctrl_opts.inited );
		goto net_term;
	}
	ctrl_opts.inited = sceNetResolverInit();
	if( ctrl_opts.inited != 0 )
	{
		log( "Error initing Resolver (0x%08x)\n", ctrl_opts.inited );
		goto net_term;
	}
	ctrl_opts.inited = sceNetApctlInit( 0x1400, 0x42 );
	if ( ctrl_opts.inited != 0 )
	{
		log( "Error initing Apctl (0x%08x)\n", ctrl_opts.inited );
		goto net_term;
	}
	log( "pspnet init OK!\n" );
	
	ctrl_opts.inited = connectApctl( entry );
	if ( ctrl_opts.inited != 0 )
	{
		log( "Error connecting Apctl (0x%08x)\n", ctrl_opts.inited );
		goto net_term;
	}
	
	ctrl_opts.inited = connectSocket( ip, ( unsigned short )port );
	if ( ctrl_opts.inited != 0 )
	{
		log( "Error connecting Socket\n" );
		goto net_term;
	}
	ctrl_opts.inited = 1;
	
	sceKernelSleepThread();
	
net_term:
	log( "stopping wifi...\n" );
	disconnectSocket();
	disconnectApctl();
	sceNetApctlTerm();
	sceNetResolverTerm();
	sceNetInetTerm();
	sceNetTerm();
	//sceUtilityUnloadNetModule( PSP_NET_MODULE_INET );
	//sceUtilityUnloadNetModule( PSP_NET_MODULE_COMMON );
	ctrl_opts.thid = -1;
	ctrl_opts.inited = -1;
	return sceKernelExitDeleteThread( 0 );
}
コード例 #15
0
QApplicationConfig::~QApplicationConfig()
{
    disconnectSocket();
    cleanupFiles();
}
コード例 #16
0
ファイル: line_server.c プロジェクト: FabianHahn/kalisko
API void disconnectLineServerClient(LineServerClient *client)
{
    disconnectSocket(client->socket);
}
コード例 #17
0
MjpegStreamerClient::~MjpegStreamerClient()
{
    disconnectSocket();
}
コード例 #18
0
ファイル: irc_proxy.c プロジェクト: FabianHahn/kalisko
static void listener_clientLine(void *subject, const char *event, void *data, va_list args)
{
	IrcProxyClient *client = subject;
	IrcMessage *message = va_arg(args, IrcMessage *);

	if(!client->authenticated) { // not yet authenticated, wait for password
		if(g_strcmp0(message->command, "PASS") == 0) {
			char *password = NULL;

			if(message->params_count > 0 && message->params != NULL && message->params[0] != 0) { // password seems to be in the first param
				password = message->params[0];
			} else { // password must be in trailing space
				password = message->trailing;
			}

			if(password != NULL) {
				char **parts = g_strsplit(password, ":", 0);
				int count = 0;
				while(parts[count] != NULL) { // count parts
					count++;
				}

				if(count >= 2) { // there are at least two parts
					char *name = parts[0];
					IrcProxy *proxy;

					if((proxy = g_hash_table_lookup(proxies, name)) != NULL) { // it's a valid ID
						if(g_strcmp0(proxy->password, parts[1]) == 0) { // the password also matches
							logNotice("IRC proxy client %d authenticated successfully to IRC proxy '%s'", client->socket->fd, name);
							client->authenticated = true;

							// associate client and proxy
							client->proxy = proxy;
							g_queue_push_head(proxy->clients, client);

							proxyClientIrcSend(client, ":%s 001 %s :You were successfully authenticated and are now connected to the IRC server", proxy->irc->socket->host, proxy->irc->nick);
							proxyClientIrcSend(client, ":%s 251 %s :There are %d clients online on this bouncer", client->proxy->irc->socket->host, proxy->irc->nick, g_queue_get_length(proxy->clients));
							triggerEvent(proxy, "client_authenticated", client);
						} else {
							proxyClientIrcSend(client, ":kalisko.proxy NOTICE AUTH :*** Login incorrect for IRC proxy ID %c%s%c", (char) 2, name, (char) 2);
						}
					} else {
						proxyClientIrcSend(client, ":kalisko.proxy NOTICE AUTH :*** Invalid IRC proxy ID %c%s%c", (char) 2, name, (char) 2);
					}
				}

				g_strfreev(parts);
			}
		}
	} else if(g_strcmp0(message->command, "PING") == 0) { // reply to pings
		if(message->trailing != NULL) {
			proxyClientIrcSend(client, "PONG :%s", message->trailing);
		}
	} else if(g_strcmp0(message->command, "USER") == 0) { // prevent user command from being passed through
		return;
	} else if(g_strcmp0(message->command, "QUIT") == 0) { // client disconnects
		logInfo("IRC proxy client %d sent QUIT message, disconnecting...", client->socket->fd);
		disconnectSocket(client->socket);
	} else {
		if((g_strcmp0(message->command, "PRIVMSG") == 0 || g_strcmp0(message->command, "NOTICE") == 0) && message->params_count > 0) { // potential filtered command
			for(GList *iter = client->proxy->relay_exceptions->head; iter != NULL; iter = iter->next) {
				if(g_strcmp0(iter->data, message->params[0]) == 0) { // target matches, so don't relay!
					return;
				}
			}
		}

		// Relay message to IRC server
		ircSend(client->proxy->irc, "%s", message->raw_message);
	}
}
コード例 #19
0
ファイル: ofxNeuron.cpp プロジェクト: naus3a/ofxNeuron
void ofxNeuron::disconnect(){
	cout<<"ofxNeuron: disconnecting."<<endl;
	disconnectSocket(sockTCPRef);
}