ios: fix compilation with osx 10.6

Change-Id: Id0b28c0aab46237b60756f12be05e3d05df9c9e7
Reviewed-by: Fawzi Mohamed <fawzi.mohamed@digia.com>
Reviewed-by: Eike Ziller <eike.ziller@digia.com>
This commit is contained in:
Fawzi Mohamed
2013-10-04 01:28:47 +02:00
committed by Eike Ziller
parent 31b8fbbcbf
commit c39ec1e309
2 changed files with 35 additions and 8 deletions

View File

@@ -39,6 +39,7 @@
#include <QDebug> #include <QDebug>
#include <QCoreApplication> #include <QCoreApplication>
#include <QList> #include <QList>
#include <QScopedArrayPointer>
#include <sys/types.h> #include <sys/types.h>
#include <sys/socket.h> #include <sys/socket.h>
@@ -404,6 +405,17 @@ void IosToolHandlerPrivate::subprocessFinished(int exitCode, QProcess::ExitStatu
} }
} }
#ifndef CMSG_SPACE
size_t CMSG_SPACE(size_t len) {
msghdr msg;
cmsghdr cmsg;
msg.msg_control = &cmsg;
msg.msg_controllen = ~socklen_t(0); /* To maximize the chance that CMSG_NXTHDR won't return NULL */
cmsg.cmsg_len = CMSG_LEN(len);
return reinterpret_cast<unsigned char *>(CMSG_NXTHDR(&msg, &cmsg)) - reinterpret_cast<unsigned char *>(&cmsg);
}
#endif
int recv_fd(int socket) int recv_fd(int socket)
{ {
int sent_fd; int sent_fd;
@@ -421,10 +433,11 @@ int recv_fd(int socket)
socket_message.msg_iovlen = 1; socket_message.msg_iovlen = 1;
/* provide space for the ancillary data */ /* provide space for the ancillary data */
char ancillary_element_buffer[CMSG_SPACE(sizeof(int))]; size_t dimAncillaryEl = CMSG_SPACE(sizeof(int));
memset(ancillary_element_buffer, 0, CMSG_SPACE(sizeof(int))); QScopedArrayPointer<char> ancillary_element_buffer(new char[dimAncillaryEl]);
socket_message.msg_control = ancillary_element_buffer; memset(ancillary_element_buffer.data(), 0, dimAncillaryEl);
socket_message.msg_controllen = CMSG_SPACE(sizeof(int)); socket_message.msg_control = ancillary_element_buffer.data();
socket_message.msg_controllen = dimAncillaryEl;
int flags = 0; int flags = 0;
#ifdef MSG_CMSG_CLOEXEC #ifdef MSG_CMSG_CLOEXEC

View File

@@ -37,6 +37,8 @@
#include <QXmlStreamWriter> #include <QXmlStreamWriter>
#include <QFile> #include <QFile>
#include <QMapIterator> #include <QMapIterator>
#include <QScopedArrayPointer>
#include "iosdevicemanager.h" #include "iosdevicemanager.h"
#include <sys/types.h> #include <sys/types.h>
#include <sys/socket.h> #include <sys/socket.h>
@@ -226,10 +228,22 @@ void IosTool::isTransferringApp(const QString &bundlePath, const QString &device
outFile.flush(); outFile.flush();
} }
#ifndef CMSG_SPACE
size_t CMSG_SPACE(size_t len) {
msghdr msg;
cmsghdr cmsg;
msg.msg_control = &cmsg;
msg.msg_controllen = ~socklen_t(0); /* To maximize the chance that CMSG_NXTHDR won't return NULL */
cmsg.cmsg_len = CMSG_LEN(len);
return reinterpret_cast<unsigned char *>(CMSG_NXTHDR(&msg, &cmsg)) - reinterpret_cast<unsigned char *>(&cmsg);
}
#endif
int send_fd(int socket, int fd_to_send) int send_fd(int socket, int fd_to_send)
{ {
/* storage space needed for an ancillary element with a paylod of length is CMSG_SPACE(sizeof(length)) */ /* storage space needed for an ancillary element with a paylod of length is CMSG_SPACE(sizeof(length)) */
char ancillary_element_buffer[CMSG_SPACE(sizeof(int))]; size_t dimAncillaryBuffer = CMSG_SPACE(sizeof(int));
QScopedArrayPointer<char> ancillary_element_buffer(new char[dimAncillaryBuffer]);
int available_ancillary_element_buffer_space; int available_ancillary_element_buffer_space;
/* at least one vector of one byte must be sent */ /* at least one vector of one byte must be sent */
@@ -247,9 +261,9 @@ int send_fd(int socket, int fd_to_send)
socket_message.msg_iovlen = 1; socket_message.msg_iovlen = 1;
/* provide space for the ancillary data */ /* provide space for the ancillary data */
available_ancillary_element_buffer_space = CMSG_SPACE(sizeof(int)); available_ancillary_element_buffer_space = dimAncillaryBuffer;
memset(ancillary_element_buffer, 0, available_ancillary_element_buffer_space); memset(ancillary_element_buffer.data(), 0, available_ancillary_element_buffer_space);
socket_message.msg_control = ancillary_element_buffer; socket_message.msg_control = ancillary_element_buffer.data();
socket_message.msg_controllen = available_ancillary_element_buffer_space; socket_message.msg_controllen = available_ancillary_element_buffer_space;
/* initialize a single ancillary data element for fd passing */ /* initialize a single ancillary data element for fd passing */