Bug 979668 - [Bluetooth] Sender name is not shown in transfer requests, f=tzimmermann, r=kyle

This commit is contained in:
Ben Tian 2014-03-10 10:11:27 +08:00
parent 404bdbb154
commit 40af3a9adb
4 changed files with 44 additions and 32 deletions

View File

@ -98,11 +98,14 @@ UnixSocketWatcher::OnFileCanReadWithoutBlocking(int aFd)
if (mConnectionStatus == SOCKET_IS_CONNECTED) {
OnSocketCanReceiveWithoutBlocking();
} else if (mConnectionStatus == SOCKET_IS_LISTENING) {
int fd = TEMP_FAILURE_RETRY(accept(GetFd(), NULL, NULL));
sockaddr_any addr;
socklen_t addrLen = sizeof(addr);
int fd = TEMP_FAILURE_RETRY(accept(GetFd(),
reinterpret_cast<struct sockaddr*>(&addr), &addrLen));
if (fd < 0) {
OnError("accept", errno);
} else {
OnAccepted(fd);
OnAccepted(fd, &addr, addrLen);
}
} else {
NS_NOTREACHED("invalid connection state for reading");

View File

@ -7,11 +7,34 @@
#ifndef mozilla_ipc_UnixSocketWatcher_h
#define mozilla_ipc_UnixSocketWatcher_h
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/un.h>
#include <netinet/in.h>
#ifdef MOZ_B2G_BT_BLUEZ
#include <bluetooth/bluetooth.h>
#include <bluetooth/sco.h>
#include <bluetooth/l2cap.h>
#include <bluetooth/rfcomm.h>
#endif
#include "UnixFdWatcher.h"
namespace mozilla {
namespace ipc {
union sockaddr_any {
sockaddr_storage storage; // address-family only
sockaddr_un un;
sockaddr_in in;
sockaddr_in6 in6;
#ifdef MOZ_B2G_BT_BLUEZ
sockaddr_sco sco;
sockaddr_rc rc;
sockaddr_l2 l2;
#endif
// ... others
};
class UnixSocketWatcher : public UnixFdWatcher
{
public:
@ -34,11 +57,12 @@ public:
// Connect to a peer
nsresult Connect(const struct sockaddr* aAddr, socklen_t aAddrLen);
// Listen on socket for incomming connection requests
// Listen on socket for incoming connection requests
nsresult Listen(const struct sockaddr* aAddr, socklen_t aAddrLen);
// Callback method for accepted connections
virtual void OnAccepted(int aFd) {};
virtual void OnAccepted(int aFd, const sockaddr_any* aAddr,
socklen_t aAddrLen) {};
// Callback method for successful connection requests
virtual void OnConnected() {};

View File

@ -5,7 +5,6 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "UnixSocket.h"
#include "mozilla/ipc/UnixSocketWatcher.h"
#include "nsTArray.h"
#include "nsXULAppAPI.h"
#include <fcntl.h>
@ -119,7 +118,8 @@ public:
*/
RefPtr<UnixSocketConsumer> mConsumer;
void OnAccepted(int aFd) MOZ_OVERRIDE;
void OnAccepted(int aFd, const sockaddr_any* aAddr,
socklen_t aAddrLen) MOZ_OVERRIDE;
void OnConnected() MOZ_OVERRIDE;
void OnError(const char* aFunction, int aErrno) MOZ_OVERRIDE;
void OnListening() MOZ_OVERRIDE;
@ -553,10 +553,17 @@ UnixSocketImpl::SetSocketFlags(int aFd)
}
void
UnixSocketImpl::OnAccepted(int aFd)
UnixSocketImpl::OnAccepted(int aFd,
const sockaddr_any* aAddr,
socklen_t aAddrLen)
{
MOZ_ASSERT(MessageLoopForIO::current() == GetIOLoop());
MOZ_ASSERT(GetConnectionStatus() == SOCKET_IS_LISTENING);
MOZ_ASSERT(aAddr);
MOZ_ASSERT(aAddrLen <= sizeof(mAddr));
memcpy (&mAddr, aAddr, aAddrLen);
mAddrSize = aAddrLen;
if (!mConnector->SetUp(aFd)) {
NS_WARNING("Could not set up socket!");

View File

@ -8,38 +8,16 @@
#define mozilla_ipc_UnixSocket_h
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/un.h>
#include <netinet/in.h>
#ifdef MOZ_B2G_BT_BLUEZ
#include <bluetooth/bluetooth.h>
#include <bluetooth/sco.h>
#include <bluetooth/l2cap.h>
#include <bluetooth/rfcomm.h>
#endif
#include <stdlib.h>
#include "nsString.h"
#include "nsAutoPtr.h"
#include "mozilla/RefPtr.h"
#include "nsString.h"
#include "nsThreadUtils.h"
#include "mozilla/ipc/UnixSocketWatcher.h"
#include "mozilla/RefPtr.h"
namespace mozilla {
namespace ipc {
union sockaddr_any {
sockaddr_storage storage; // address-family only
sockaddr_un un;
sockaddr_in in;
sockaddr_in6 in6;
#ifdef MOZ_B2G_BT_BLUEZ
sockaddr_sco sco;
sockaddr_rc rc;
sockaddr_l2 l2;
#endif
// ... others
};
class UnixSocketRawData
{
public: