コード例 #1
0
ファイル: KCToolServer.cpp プロジェクト: ElliotZ/KanColleTool
void KCToolServer::onSocketReadyRead()
{
	QTcpSocket *socket = qobject_cast<QTcpSocket*>(QObject::sender());

	// Parse the first line
	if(!socket->property("firstLineRead").toBool())
	{
		QString line(socket->readLine());
		int sepPos1(line.indexOf(" "));
		int sepPos2(line.indexOf(" ", sepPos1+1));
		QString method(line.left(sepPos1));
		QString path(line.mid(sepPos1+1, sepPos2 - sepPos1 - 1));
		socket->setProperty("method", method);
		socket->setProperty("path", path);
		socket->setProperty("firstLineRead", true);
	}

	// Parse Headers!
	if(!socket->property("headerRead").toBool()) {
		QVariantMap headers(socket->property("headers").toMap());

		while(socket->canReadLine()) {
			QString line = QString(socket->readLine()).trimmed();

			// The header section is terminated by an empty line
			if(line == "") {
				socket->setProperty("headerRead", true);
				break;
			}

			// Split it up
			int sepPos(line.indexOf(":"));
			QString key(line.left(sepPos).trimmed());
			QString val(line.mid(sepPos+1).trimmed());
			headers.insertMulti(key, val);
		}

		socket->setProperty("headers", headers);
	}

	qint64 contentLength = socket->property("headers").toMap().value("Content-Length").toLongLong();
	// Read the body into a buffer
	if(socket->bytesAvailable()) {
		QByteArray buffer(socket->property("buffer").toByteArray());
		qint64 toRead = contentLength - buffer.size();
		buffer.append(socket->read(toRead));
		socket->setProperty("buffer", buffer);
		socket->setProperty("toRead", contentLength - buffer.size());

		// If we have a Content-Length (toLong() fails with 0)
		if(contentLength > 0 && buffer.size() >= contentLength)
			this->handleRequest(socket);
	} else if(contentLength == -1 || contentLength == 0) {
		this->handleRequest(socket);
	}
}
コード例 #2
0
ファイル: serverskt.cpp プロジェクト: sdlylshl/sokit
void ServerSktTcp::newData()
{
	QTcpSocket* client = qobject_cast<QTcpSocket*>(sender());
	if (!client) return;

	Conn* conn = (Conn*)client->property(PROP_CONN).value<void*>();
	if (!conn) return;

	qint64 bufLen = client->bytesAvailable();
	char* buf = TK::createBuffer(bufLen, MAXBUFFER);
	if (!buf) return;

	qint64 readLen = 0;
	qint64 ioLen = client->read(buf, bufLen);

	while (ioLen > 0)
	{
		readLen += ioLen;
		ioLen = client->read(buf+readLen, bufLen-readLen);
	}

	if (ioLen >= 0)
	{
		recordRecv(readLen);
		dump(buf, readLen, false, conn->key);
	}

	TK::releaseBuffer(buf);
}
コード例 #3
0
ファイル: webproxy.cpp プロジェクト: peder2key/gpsbook
    /*------------------------------------------------------------------------------*

     *------------------------------------------------------------------------------*/
    void WebProxy::closeConnection() {
        QTcpSocket *proxySocket = qobject_cast<QTcpSocket*>(sender());
        if (proxySocket) {
            QTcpSocket *socket = qobject_cast<QTcpSocket*>(proxySocket->parent());
            if (socket)
                socket->disconnectFromHost();
            if (proxySocket->error() != QTcpSocket::RemoteHostClosedError)
                qWarning() << "Error for:" << proxySocket->property("url").toUrl() << proxySocket->errorString();
            proxySocket->deleteLater();;
        }
    } //WebProxy::closeConnection
コード例 #4
0
ファイル: Server.cpp プロジェクト: Andersbakken/Genesis
void Server::onReadyRead()
{
    QTcpSocket *socket = qobject_cast<QTcpSocket*>(sender());
    Q_ASSERT(socket);
    QVariant variant = socket->property("pending");
    qint32 pending;
    if (variant.isNull()) {
        if (socket->bytesAvailable() < int(sizeof(qint32))) {
            return;
        }
        QDataStream ds(socket);
        ds >> pending;
        if (socket->bytesAvailable() < pending) {
            socket->setProperty("pending", pending);
            return;
        }
    } else {
コード例 #5
0
void HttpProxy::onProxySocketConnected()
{
    QTcpSocket *proxySocket = qobject_cast<QTcpSocket *>(sender());
    QByteArray reqData = proxySocket->property("reqData").toByteArray();
    proxySocket->write(reqData);
}
コード例 #6
0
ファイル: webproxy.cpp プロジェクト: peder2key/gpsbook
    /*------------------------------------------------------------------------------*

     *------------------------------------------------------------------------------*/
    void WebProxy::sendRequest() {
        QTcpSocket *proxySocket = qobject_cast<QTcpSocket*>(sender());
        QByteArray requestData = proxySocket->property("requestData").toByteArray();
        proxySocket->write(requestData);
    } //WebProxy::sendRequest
コード例 #7
0
ファイル: galconserver.cpp プロジェクト: TeamFirst/Galcon
void CGalconServer::removeSocket()
{
   QTcpSocket* pClientSocket = (QTcpSocket*)sender();
   SocketID ID = pClientSocket->property(socketID).toUInt();
   m_connectedSockets.erase(ID);
}