Commit dd085030 authored by David Schulz's avatar David Schulz Committed by Fawzi Mohamed
Browse files

Ios: Fix compilation on windows.



Change-Id: I90054041069d9aace6fc24f9094d46207b87e54e
Reviewed-by: default avatarFawzi Mohamed <fawzi.mohamed@digia.com>
parent bc9ac41e
......@@ -69,3 +69,4 @@ DEFINES += IOS_LIBRARY
RESOURCES += ios.qrc
win32: LIBS += -lws2_32
......@@ -63,7 +63,9 @@
#include <QStringListModel>
#include <QMessageBox>
#if defined(Q_OS_UNIX)
#include <unistd.h>
#endif
using namespace ProjectExplorer;
using namespace Utils;
......
......@@ -110,8 +110,8 @@ void IosRunner::start()
SLOT(handleErrorMsg(Ios::IosToolHandler*,QString)));
connect(m_toolHandler, SIGNAL(gotGdbserverSocket(Ios::IosToolHandler*,QString,QString,int)),
SLOT(handleGotGdbserverSocket(Ios::IosToolHandler*,QString,QString,int)));
connect(m_toolHandler, SIGNAL(gotInferiorPid(Ios::IosToolHandler*,QString,QString,pid_t)),
SLOT(handleGotInferiorPid(Ios::IosToolHandler*,QString,QString,pid_t)));
connect(m_toolHandler, SIGNAL(gotInferiorPid(Ios::IosToolHandler*,QString,QString,Q_PID)),
SLOT(handleGotInferiorPid(Ios::IosToolHandler*,QString,QString,Q_PID)));
connect(m_toolHandler, SIGNAL(toolExited(Ios::IosToolHandler*,int)),
SLOT(handleToolExited(Ios::IosToolHandler*,int)));
connect(m_toolHandler, SIGNAL(finished(Ios::IosToolHandler*)),
......@@ -142,7 +142,7 @@ void IosRunner::handleGotGdbserverSocket(IosToolHandler *handler, const QString
}
void IosRunner::handleGotInferiorPid(IosToolHandler *handler, const QString &bundlePath,
const QString &deviceId, pid_t pid)
const QString &deviceId, Q_PID pid)
{
Q_UNUSED(bundlePath); Q_UNUSED(deviceId);
if (m_toolHandler == handler)
......
......@@ -65,7 +65,7 @@ public slots:
signals:
void didStartApp(Ios::IosToolHandler::OpStatus status);
void gotGdbserverSocket(int gdbFd);
void gotInferiorPid(pid_t pid);
void gotInferiorPid(Q_PID pid);
void appOutput(const QString &output);
void errorMsg(const QString &msg);
void finished(bool cleanExit);
......@@ -75,7 +75,7 @@ private slots:
void handleGotGdbserverSocket(Ios::IosToolHandler *handler, const QString &bundlePath,
const QString &deviceId, int gdbFd);
void handleGotInferiorPid(Ios::IosToolHandler *handler, const QString &bundlePath,
const QString &deviceId, pid_t pid);
const QString &deviceId, Q_PID pid);
void handleAppOutput(Ios::IosToolHandler *handler, const QString &output);
void handleErrorMsg(Ios::IosToolHandler *handler, const QString &msg);
void handleToolExited(Ios::IosToolHandler *handler, int code);
......
......@@ -42,10 +42,14 @@
#include <QList>
#include <QScopedArrayPointer>
#if defined(Q_OS_UNIX)
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <unistd.h>
#else
#include <WinSock2.h>
#endif
#include <string.h>
#include <fcntl.h>
#include <errno.h>
......@@ -109,8 +113,9 @@ struct ParserState {
case Item:
case DeviceInfo:
case Exit:
return false;
break;
}
return false;
}
ParserState(Kind kind) :
......@@ -155,7 +160,7 @@ public:
void didStartApp(const QString &bundlePath, const QString &deviceId,
IosToolHandler::OpStatus status);
void gotGdbserverSocket(const QString &bundlePath, const QString &deviceId, int gdbFd);
void gotInferiorPid(const QString &bundlePath, const QString &deviceId, pid_t pid);
void gotInferiorPid(const QString &bundlePath, const QString &deviceId, Q_PID pid);
void deviceInfo(const QString &deviceId, const IosToolHandler::Dict &info);
void appOutput(const QString &output);
void errorMsg(const QString &msg);
......@@ -213,6 +218,7 @@ private:
void addDeviceArguments(QStringList &args) const;
};
#if defined(Q_OS_UNIX)
MyProcess::MyProcess(QObject *parent) : QProcess(parent)
{
if (socketpair(PF_UNIX, SOCK_STREAM, 0, &m_sockets[0]) == -1) {
......@@ -241,6 +247,25 @@ void MyProcess::setupChildProcess()
}
shutdown(1, SHUT_RD); // leave open for handshake when transferring fd?
}
#else
MyProcess::MyProcess(QObject *parent) : QProcess(parent)
{
}
int MyProcess::processOutputSocket()
{
return 0;
}
QSocketNotifier *MyProcess::notifier()
{
return m_notifier;
}
void MyProcess::setupChildProcess()
{
}
#endif
IosToolHandlerPrivate::IosToolHandlerPrivate(IosToolHandler::DeviceType devType,
Ios::IosToolHandler *q) :
......@@ -252,10 +277,12 @@ IosToolHandlerPrivate::IosToolHandlerPrivate(IosToolHandler::DeviceType devType,
q, SLOT(subprocessFinished(int,QProcess::ExitStatus)));
QObject::connect(&process, SIGNAL(error(QProcess::ProcessError)),
q, SLOT(subprocessError(QProcess::ProcessError)));
#if defined(Q_OS_UNIX)
int accessFlags = fcntl(process.processOutputSocket(), F_GETFL);
if (fcntl(process.processOutputSocket(), F_SETFL, accessFlags | O_NONBLOCK) == -1)
qDebug() << "IosToolHandler fcntl F_SETFL failed to set non blocking mode"
<< qt_error_string(errno);
#endif
}
bool IosToolHandlerPrivate::isRunning()
......@@ -278,7 +305,9 @@ void IosToolHandlerPrivate::stop()
if (debugToolHandler)
qDebug() << "IosToolHandlerPrivate::stop";
if (process.state() != QProcess::NotRunning) {
#if defined(Q_OS_UNIX)
close(process.processOutputSocket());
#endif
process.close();
process.kill();
if (debugToolHandler)
......@@ -316,7 +345,7 @@ void IosToolHandlerPrivate::gotGdbserverSocket(const QString &bundlePath, const
}
void IosToolHandlerPrivate::gotInferiorPid(const QString &bundlePath, const QString &deviceId,
pid_t pid)
Q_PID pid)
{
emit q->gotInferiorPid(q, bundlePath, deviceId, pid);
}
......@@ -409,6 +438,7 @@ void IosToolHandlerPrivate::subprocessFinished(int exitCode, QProcess::ExitStatu
}
}
#if defined(Q_OS_UNIX)
#ifndef CMSG_SPACE
size_t CMSG_SPACE(size_t len) {
msghdr msg;
......@@ -474,6 +504,13 @@ int recv_fd(int socket)
return -1;
}
#else
int recv_fd(int socket)
{
Q_UNUSED(socket);
return -1;
}
#endif
int IosToolHandlerPrivate::checkForXmlEnd()
{
......@@ -623,7 +660,7 @@ void IosToolHandlerPrivate::processXml()
case ParserState::Exit:
break;
case ParserState::InferiorPid:
gotInferiorPid(bundlePath, deviceId, pid_t(p.chars.toInt()));
gotInferiorPid(bundlePath, deviceId, Q_PID(p.chars.toInt()));
break;
}
break;
......@@ -684,7 +721,7 @@ void IosToolHandlerPrivate::subprocessHasData(int socket)
iBegin = iEnd;
}
currentData.clear();
ssize_t reallyRead = recv(socket, buffer.data() + iBegin, lookaheadSize, 0);
qptrdiff reallyRead = recv(socket, buffer.data() + iBegin, lookaheadSize, 0);
if (reallyRead == 0) { // eof
stop();
return;
......@@ -739,8 +776,8 @@ void IosToolHandlerPrivate::subprocessHasData(int socket)
spacerStart -= iBegin;
currentData = buffer.mid(0, lastXmlSize); // remove this??
}
ssize_t toRead = lookaheadSize - (iEnd - spacerStart);
ssize_t reallyRead = recv(socket, buffer.data() + iBegin, toRead, 0);
qptrdiff toRead = lookaheadSize - (iEnd - spacerStart);
qptrdiff reallyRead = recv(socket, buffer.data() + iBegin, toRead, 0);
if (reallyRead == 0) { // eof
stop();
return;
......
......@@ -86,7 +86,7 @@ signals:
void gotGdbserverSocket(Ios::IosToolHandler *handler, const QString &bundlePath,
const QString &deviceId, int gdbFd);
void gotInferiorPid(Ios::IosToolHandler *handler, const QString &bundlePath,
const QString &deviceId, pid_t pid);
const QString &deviceId, Q_PID pid);
void deviceInfo(Ios::IosToolHandler *handler, const QString &deviceId,
const Ios::IosToolHandler::Dict &info);
void appOutput(Ios::IosToolHandler *handler, const QString &output);
......
......@@ -263,8 +263,8 @@ public:
void stopService(ServiceSocket fd);
void startDeviceLookup(int timeout);
void addError(const QString &msg);
bool writeAll(ServiceSocket fd, const char *cmd, ssize_t len = -1);
bool sendGdbCommand(ServiceSocket fd, const char *cmd, ssize_t len = -1);
bool writeAll(ServiceSocket fd, const char *cmd, qptrdiff len = -1);
bool sendGdbCommand(ServiceSocket fd, const char *cmd, qptrdiff len = -1);
QByteArray readGdbReply(ServiceSocket fd);
bool expectGdbReply(ServiceSocket gdbFd, QByteArray expected);
bool expectGdbOkReply(ServiceSocket gdbFd);
......@@ -276,7 +276,7 @@ public:
int progressBase;
int unexpectedChars;
private:
bool checkRead(ssize_t nRead, int &maxRetry);
bool checkRead(qptrdiff nRead, int &maxRetry);
int handleChar(QByteArray &res, char c, int status);
};
......@@ -795,7 +795,7 @@ void CommandSession::addError(const QString &msg)
IosDeviceManagerPrivate::instance()->addError(commandName() + msg);
}
bool CommandSession::writeAll(ServiceSocket fd, const char *cmd, ssize_t len)
bool CommandSession::writeAll(ServiceSocket fd, const char *cmd, qptrdiff len)
{
if (len == -1)
len = strlen(cmd);
......@@ -804,10 +804,10 @@ bool CommandSession::writeAll(ServiceSocket fd, const char *cmd, ssize_t len)
qDebug() << "writeAll(" << fd << "," << QString::fromLocal8Bit(cmdBA.constData(), cmdBA.size())
<< " (" << cmdBA.toHex() << "))";
}
ssize_t i = 0;
qptrdiff i = 0;
int maxRetry = 10;
while (i < len) {
ssize_t nWritten = write(fd, cmd, len - i);
qptrdiff nWritten = write(fd, cmd, len - i);
if (nWritten < 1) {
--maxRetry;
if (nWritten == -1 && errno != 0 && errno != EINTR) {
......@@ -832,7 +832,7 @@ bool CommandSession::writeAll(ServiceSocket fd, const char *cmd, ssize_t len)
return true;
}
bool CommandSession::sendGdbCommand(ServiceSocket fd, const char *cmd, ssize_t len)
bool CommandSession::sendGdbCommand(ServiceSocket fd, const char *cmd, qptrdiff len)
{
if (len == -1)
len = strlen(cmd);
......@@ -852,7 +852,7 @@ bool CommandSession::sendGdbCommand(ServiceSocket fd, const char *cmd, ssize_t l
return !failure;
}
bool CommandSession::checkRead(ssize_t nRead, int &maxRetry)
bool CommandSession::checkRead(qptrdiff nRead, int &maxRetry)
{
if (nRead < 1 || nRead > 4) {
--maxRetry;
......@@ -932,14 +932,14 @@ QByteArray CommandSession::readGdbReply(ServiceSocket fd)
int status = 0;
int toRead = 4;
while (status < 4 && toRead > 0) {
ssize_t nRead = read(fd, buf, toRead);
qptrdiff nRead = read(fd, buf, toRead);
if (!checkRead(nRead, maxRetry))
return QByteArray();
if (debugGdbServer) {
buf[nRead] = 0;
qDebug() << "gdbReply read " << buf;
}
for (ssize_t i = 0; i< nRead; ++i)
for (qptrdiff i = 0; i< nRead; ++i)
status = handleChar(res, buf[i], status);
toRead = 4 - status;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment