mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Back out b21345c5027c (bug 843868) for build bustage
CLOSED TREE
This commit is contained in:
parent
b0d7eb4341
commit
eabae506e4
@ -35,7 +35,6 @@
|
|||||||
#include "BluetoothUnixSocketConnector.h"
|
#include "BluetoothUnixSocketConnector.h"
|
||||||
#include "nsThreadUtils.h"
|
#include "nsThreadUtils.h"
|
||||||
|
|
||||||
using namespace mozilla::ipc;
|
|
||||||
USING_BLUETOOTH_NAMESPACE
|
USING_BLUETOOTH_NAMESPACE
|
||||||
|
|
||||||
static const int RFCOMM_SO_SNDBUF = 70 * 1024; // 70 KB send buffer
|
static const int RFCOMM_SO_SNDBUF = 70 * 1024; // 70 KB send buffer
|
||||||
@ -140,10 +139,10 @@ BluetoothUnixSocketConnector::Create()
|
|||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
void
|
||||||
BluetoothUnixSocketConnector::CreateAddr(bool aIsServer,
|
BluetoothUnixSocketConnector::CreateAddr(bool aIsServer,
|
||||||
socklen_t& aAddrSize,
|
socklen_t& aAddrSize,
|
||||||
sockaddr_any& aAddr,
|
struct sockaddr* aAddr,
|
||||||
const char* aAddress)
|
const char* aAddress)
|
||||||
{
|
{
|
||||||
// Set to BDADDR_ANY, if it's not a server, we'll reset.
|
// Set to BDADDR_ANY, if it's not a server, we'll reset.
|
||||||
@ -152,7 +151,7 @@ BluetoothUnixSocketConnector::CreateAddr(bool aIsServer,
|
|||||||
if (!aIsServer && aAddress && strlen(aAddress) > 0) {
|
if (!aIsServer && aAddress && strlen(aAddress) > 0) {
|
||||||
if (get_bdaddr(aAddress, &bd_address_obj)) {
|
if (get_bdaddr(aAddress, &bd_address_obj)) {
|
||||||
NS_WARNING("Can't get bluetooth address!");
|
NS_WARNING("Can't get bluetooth address!");
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -160,37 +159,31 @@ BluetoothUnixSocketConnector::CreateAddr(bool aIsServer,
|
|||||||
case BluetoothSocketType::RFCOMM:
|
case BluetoothSocketType::RFCOMM:
|
||||||
struct sockaddr_rc addr_rc;
|
struct sockaddr_rc addr_rc;
|
||||||
aAddrSize = sizeof(addr_rc);
|
aAddrSize = sizeof(addr_rc);
|
||||||
aAddr.rc.rc_family = AF_BLUETOOTH;
|
memset(aAddr, 0, aAddrSize);
|
||||||
aAddr.rc.rc_channel = mChannel;
|
addr_rc.rc_family = AF_BLUETOOTH;
|
||||||
memcpy(&aAddr.rc.rc_bdaddr, &bd_address_obj, sizeof(bd_address_obj));
|
addr_rc.rc_channel = mChannel;
|
||||||
|
memcpy(&addr_rc.rc_bdaddr, &bd_address_obj, sizeof(bdaddr_t));
|
||||||
|
memcpy(aAddr, &addr_rc, sizeof(addr_rc));
|
||||||
break;
|
break;
|
||||||
case BluetoothSocketType::SCO:
|
case BluetoothSocketType::SCO:
|
||||||
struct sockaddr_sco addr_sco;
|
struct sockaddr_sco addr_sco;
|
||||||
aAddrSize = sizeof(addr_sco);
|
aAddrSize = sizeof(addr_sco);
|
||||||
aAddr.sco.sco_family = AF_BLUETOOTH;
|
|
||||||
memcpy(&aAddr.sco.sco_bdaddr, &bd_address_obj, sizeof(bd_address_obj));
|
memset(aAddr, 0, aAddrSize);
|
||||||
|
addr_sco.sco_family = AF_BLUETOOTH;
|
||||||
|
memcpy(&addr_sco.sco_bdaddr, &bd_address_obj, sizeof(bdaddr_t));
|
||||||
|
memcpy(aAddr, &addr_sco, sizeof(addr_sco));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
NS_WARNING("Socket type unknown!");
|
NS_WARNING("Socket type unknown!");
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
BluetoothUnixSocketConnector::GetSocketAddr(const sockaddr_any& aAddr,
|
BluetoothUnixSocketConnector::GetSocketAddr(const sockaddr& aAddr,
|
||||||
nsAString& aAddrStr)
|
nsAString& aAddrStr)
|
||||||
{
|
{
|
||||||
char addr[18];
|
char addr[18];
|
||||||
switch (mType) {
|
get_bdaddr_as_string((bdaddr_t*)aAddr.sa_data, addr);
|
||||||
case BluetoothSocketType::RFCOMM:
|
|
||||||
get_bdaddr_as_string((bdaddr_t*)(&aAddr.rc.rc_bdaddr), addr);
|
|
||||||
break;
|
|
||||||
case BluetoothSocketType::SCO:
|
|
||||||
get_bdaddr_as_string((bdaddr_t*)(&aAddr.sco.sco_bdaddr), addr);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
MOZ_NOT_REACHED("Socket should be either RFCOMM or SCO!");
|
|
||||||
}
|
|
||||||
aAddrStr.AssignASCII(addr);
|
aAddrStr.AssignASCII(addr);
|
||||||
}
|
}
|
||||||
|
@ -21,12 +21,12 @@ public:
|
|||||||
virtual ~BluetoothUnixSocketConnector()
|
virtual ~BluetoothUnixSocketConnector()
|
||||||
{}
|
{}
|
||||||
virtual int Create() MOZ_OVERRIDE;
|
virtual int Create() MOZ_OVERRIDE;
|
||||||
virtual bool CreateAddr(bool aIsServer,
|
virtual void CreateAddr(bool aIsServer,
|
||||||
socklen_t& aAddrSize,
|
socklen_t& aAddrSize,
|
||||||
mozilla::ipc::sockaddr_any& aAddr,
|
struct sockaddr* aAddr,
|
||||||
const char* aAddress) MOZ_OVERRIDE;
|
const char* aAddress) MOZ_OVERRIDE;
|
||||||
virtual bool SetUp(int aFd) MOZ_OVERRIDE;
|
virtual bool SetUp(int aFd) MOZ_OVERRIDE;
|
||||||
virtual void GetSocketAddr(const mozilla::ipc::sockaddr_any& aAddr,
|
virtual void GetSocketAddr(const sockaddr& aAddr,
|
||||||
nsAString& aAddrStr) MOZ_OVERRIDE;
|
nsAString& aAddrStr) MOZ_OVERRIDE;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -71,12 +71,12 @@ public:
|
|||||||
{}
|
{}
|
||||||
|
|
||||||
virtual int Create();
|
virtual int Create();
|
||||||
virtual bool CreateAddr(bool aIsServer,
|
virtual void CreateAddr(bool aIsServer,
|
||||||
socklen_t& aAddrSize,
|
socklen_t& aAddrSize,
|
||||||
sockaddr_any& aAddr,
|
struct sockaddr *aAddr,
|
||||||
const char* aAddress);
|
const char* aAddress);
|
||||||
virtual bool SetUp(int aFd);
|
virtual bool SetUp(int aFd);
|
||||||
virtual void GetSocketAddr(const sockaddr_any& aAddr,
|
virtual void GetSocketAddr(const sockaddr& aAddr,
|
||||||
nsAString& aAddrStr);
|
nsAString& aAddrStr);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -93,8 +93,12 @@ RilConnector::Create()
|
|||||||
#if defined(MOZ_WIDGET_GONK)
|
#if defined(MOZ_WIDGET_GONK)
|
||||||
fd = socket(AF_LOCAL, SOCK_STREAM, 0);
|
fd = socket(AF_LOCAL, SOCK_STREAM, 0);
|
||||||
#else
|
#else
|
||||||
// If we can't hit a local loopback, fail later in connect.
|
struct hostent *hp;
|
||||||
fd = socket(AF_INET, SOCK_STREAM, 0);
|
|
||||||
|
hp = gethostbyname("localhost");
|
||||||
|
if (hp) {
|
||||||
|
fd = socket(hp->h_addrtype, SOCK_STREAM, 0);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
@ -108,41 +112,41 @@ RilConnector::Create()
|
|||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
void
|
||||||
RilConnector::CreateAddr(bool aIsServer,
|
RilConnector::CreateAddr(bool aIsServer,
|
||||||
socklen_t& aAddrSize,
|
socklen_t& aAddrSize,
|
||||||
sockaddr_any& aAddr,
|
struct sockaddr *aAddr,
|
||||||
const char* aAddress)
|
const char* aAddress)
|
||||||
{
|
{
|
||||||
// We never open ril socket as server.
|
// We never open ril socket as server.
|
||||||
MOZ_ASSERT(!aIsServer);
|
MOZ_ASSERT(!aIsServer);
|
||||||
uint32_t af;
|
|
||||||
#if defined(MOZ_WIDGET_GONK)
|
#if defined(MOZ_WIDGET_GONK)
|
||||||
af = AF_LOCAL;
|
struct sockaddr_un addr_un;
|
||||||
|
|
||||||
|
memset(&addr_un, 0, sizeof(addr_un));
|
||||||
|
strcpy(addr_un.sun_path, aAddress);
|
||||||
|
addr_un.sun_family = AF_LOCAL;
|
||||||
|
|
||||||
|
aAddrSize = strlen(aAddress) + offsetof(struct sockaddr_un, sun_path) + 1;
|
||||||
|
memcpy(aAddr, &addr_un, aAddrSize);
|
||||||
#else
|
#else
|
||||||
af = AF_INET;
|
struct hostent *hp;
|
||||||
#endif
|
struct sockaddr_in addr_in;
|
||||||
switch (af) {
|
|
||||||
case AF_LOCAL:
|
hp = gethostbyname("localhost");
|
||||||
aAddr.un.sun_family = af;
|
if (!hp) {
|
||||||
if(strlen(aAddress) > sizeof(aAddr.un.sun_path)) {
|
return;
|
||||||
NS_WARNING("Address too long for socket struct!");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
strcpy((char*)&aAddr.un.sun_path, aAddress);
|
|
||||||
aAddrSize = strlen(aAddress) + offsetof(struct sockaddr_un, sun_path) + 1;
|
|
||||||
break;
|
|
||||||
case AF_INET:
|
|
||||||
aAddr.in.sin_family = af;
|
|
||||||
aAddr.in.sin_port = htons(RIL_TEST_PORT + mClientId);
|
|
||||||
aAddr.in.sin_addr.s_addr = htons(INADDR_LOOPBACK);
|
|
||||||
aAddrSize = sizeof(sockaddr_in);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
NS_WARNING("Socket type not handled by connector!");
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
|
memset(&addr_in, 0, sizeof(addr_in));
|
||||||
|
addr_in.sin_family = hp->h_addrtype;
|
||||||
|
addr_in.sin_port = htons(RIL_TEST_PORT + mClientId);
|
||||||
|
memcpy(&addr_in.sin_addr, hp->h_addr, hp->h_length);
|
||||||
|
|
||||||
|
aAddrSize = sizeof(addr_in);
|
||||||
|
memcpy(aAddr, &addr_in, aAddrSize);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
@ -153,7 +157,7 @@ RilConnector::SetUp(int aFd)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
RilConnector::GetSocketAddr(const sockaddr_any& aAddr,
|
RilConnector::GetSocketAddr(const sockaddr& aAddr,
|
||||||
nsAString& aAddrStr)
|
nsAString& aAddrStr)
|
||||||
{
|
{
|
||||||
// Unused.
|
// Unused.
|
||||||
|
@ -218,7 +218,7 @@ private:
|
|||||||
/**
|
/**
|
||||||
* Address struct of the socket currently in use
|
* Address struct of the socket currently in use
|
||||||
*/
|
*/
|
||||||
sockaddr_any mAddr;
|
sockaddr mAddr;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
@ -441,12 +441,9 @@ UnixSocketImpl::Accept()
|
|||||||
|
|
||||||
// This will set things we don't particularly care about, but it will hand
|
// This will set things we don't particularly care about, but it will hand
|
||||||
// back the correct structure size which is what we do care about.
|
// back the correct structure size which is what we do care about.
|
||||||
if (!mConnector->CreateAddr(true, mAddrSize, mAddr, nullptr)) {
|
mConnector->CreateAddr(true, mAddrSize, &mAddr, nullptr);
|
||||||
NS_WARNING("Cannot create socket address!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mFd.get() < 0)
|
if(mFd.get() < 0)
|
||||||
{
|
{
|
||||||
mFd = mConnector->Create();
|
mFd = mConnector->Create();
|
||||||
if (mFd.get() < 0) {
|
if (mFd.get() < 0) {
|
||||||
@ -457,7 +454,7 @@ UnixSocketImpl::Accept()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bind(mFd.get(), (struct sockaddr*)&mAddr, mAddrSize)) {
|
if (bind(mFd.get(), &mAddr, mAddrSize)) {
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
LOG("...bind(%d) gave errno %d", mFd.get(), errno);
|
LOG("...bind(%d) gave errno %d", mFd.get(), errno);
|
||||||
#endif
|
#endif
|
||||||
@ -496,12 +493,9 @@ UnixSocketImpl::Connect()
|
|||||||
|
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (!mConnector->CreateAddr(false, mAddrSize, mAddr, mAddress.get())) {
|
mConnector->CreateAddr(false, mAddrSize, &mAddr, mAddress.get());
|
||||||
NS_WARNING("Cannot create socket address!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = connect(mFd.get(), (struct sockaddr*)&mAddr, mAddrSize);
|
ret = connect(mFd.get(), &mAddr, mAddrSize);
|
||||||
|
|
||||||
if (ret) {
|
if (ret) {
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
@ -666,7 +660,7 @@ UnixSocketImpl::OnFileCanReadWithoutBlocking(int aFd)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (status == SOCKET_LISTENING) {
|
if (status == SOCKET_LISTENING) {
|
||||||
int client_fd = accept(mFd.get(), (struct sockaddr*)&mAddr, &mAddrSize);
|
int client_fd = accept(mFd.get(), &mAddr, &mAddrSize);
|
||||||
|
|
||||||
if (client_fd < 0) {
|
if (client_fd < 0) {
|
||||||
return;
|
return;
|
||||||
|
@ -7,15 +7,7 @@
|
|||||||
#ifndef mozilla_ipc_UnixSocket_h
|
#ifndef mozilla_ipc_UnixSocket_h
|
||||||
#define mozilla_ipc_UnixSocket_h
|
#define mozilla_ipc_UnixSocket_h
|
||||||
|
|
||||||
|
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/un.h>
|
|
||||||
#ifdef MOZ_B2G_BT
|
|
||||||
#include <bluetooth/bluetooth.h>
|
|
||||||
#include <bluetooth/sco.h>
|
|
||||||
#include <bluetooth/rfcomm.h>
|
|
||||||
#endif
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "nsString.h"
|
#include "nsString.h"
|
||||||
#include "nsAutoPtr.h"
|
#include "nsAutoPtr.h"
|
||||||
@ -24,18 +16,6 @@
|
|||||||
namespace mozilla {
|
namespace mozilla {
|
||||||
namespace ipc {
|
namespace ipc {
|
||||||
|
|
||||||
union sockaddr_any {
|
|
||||||
sockaddr_storage storage; // address-family only
|
|
||||||
sockaddr_un un;
|
|
||||||
sockaddr_in in;
|
|
||||||
sockaddr_in6 in6;
|
|
||||||
#ifdef MOZ_B2G_BT
|
|
||||||
sockaddr_sco sco;
|
|
||||||
sockaddr_rc rc;
|
|
||||||
#endif
|
|
||||||
// ... others
|
|
||||||
};
|
|
||||||
|
|
||||||
class UnixSocketRawData
|
class UnixSocketRawData
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -98,12 +78,10 @@ public:
|
|||||||
* @param aAddrSize Size of the struct
|
* @param aAddrSize Size of the struct
|
||||||
* @param aAddr Struct to fill
|
* @param aAddr Struct to fill
|
||||||
* @param aAddress If aIsServer is false, Address to connect to. nullptr otherwise.
|
* @param aAddress If aIsServer is false, Address to connect to. nullptr otherwise.
|
||||||
*
|
|
||||||
* @return True if address is filled correctly, false otherwise
|
|
||||||
*/
|
*/
|
||||||
virtual bool CreateAddr(bool aIsServer,
|
virtual void CreateAddr(bool aIsServer,
|
||||||
socklen_t& aAddrSize,
|
socklen_t& aAddrSize,
|
||||||
sockaddr_any& aAddr,
|
struct sockaddr *aAddr,
|
||||||
const char* aAddress) = 0;
|
const char* aAddress) = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -122,7 +100,7 @@ public:
|
|||||||
* @param aAddr Address struct
|
* @param aAddr Address struct
|
||||||
* @param aAddrStr String to store address to
|
* @param aAddrStr String to store address to
|
||||||
*/
|
*/
|
||||||
virtual void GetSocketAddr(const sockaddr_any& aAddr,
|
virtual void GetSocketAddr(const sockaddr& aAddr,
|
||||||
nsAString& aAddrStr) = 0;
|
nsAString& aAddrStr) = 0;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user