void log_and_free_dbus_error(DBusError* err, const char* function, DBusMessage* msg) { if (msg) { CHROMIUM_LOG("%s: D-Bus error in %s: %s (%s)", function, dbus_message_get_member((msg)), (err)->name, (err)->message); } else { CHROMIUM_LOG("%s: D-Bus error: %s (%s)", __FUNCTION__, (err)->name, (err)->message); } dbus_error_free((err)); }
void RilConsumer::OnDisconnect() { CHROMIUM_LOG("RIL[%lu]: %s\n", mClientId, __FUNCTION__); if (!mShutdown) { ConnectSocket(new RilConnector(mClientId), mAddress.get(), 1000); } }
void NfcConsumer::OnDisconnect() { CHROMIUM_LOG("NFC: %s\n", __FUNCTION__); if (!mShutdown) { ConnectSocket(new NfcConnector(), mAddress.get(), 1000); } }
void NfcConsumer::OnDisconnect() { CHROMIUM_LOG("NFC: %s\n", __FUNCTION__); if (!mShutdown) { ConnectSocket(new NfcConnector(), mAddress.get(), GetSuggestedConnectDelayMs()); } }
void DaemonSocket::Close() { if (!mIO) { CHROMIUM_LOG("HAL daemon already disconnected!"); return; } MOZ_ASSERT(mIO->IsConsumerThread()); mIO->ShutdownOnConsumerThread(); mIO->GetIOLoop()->PostTask(FROM_HERE, new SocketIOShutdownTask(mIO)); mIO = nullptr; NotifyDisconnect(); }
nsresult BluetoothDaemonConnection::Send(BluetoothDaemonPDU* aPDU) { MOZ_ASSERT(NS_IsMainThread()); if (!mIO) { CHROMIUM_LOG("Bluetooth daemon already connecting/connected!"); return NS_ERROR_FAILURE; } XRE_GetIOMessageLoop()->PostTask( FROM_HERE, new SocketIOSendTask<BluetoothDaemonConnectionIO, BluetoothDaemonPDU>(mIO, aPDU)); return NS_OK; }
void BluetoothDaemonConnection::CloseSocket() { MOZ_ASSERT(NS_IsMainThread()); if (!mIO) { CHROMIUM_LOG("Bluetooth daemon already disconnected!"); return; } XRE_GetIOMessageLoop()->PostTask(FROM_HERE, new SocketIOShutdownTask(mIO)); mIO = nullptr; NotifyDisconnect(); }
void PDUInitOp::WarnAboutTrailingData() const { size_t size = mPDU->GetSize(); if (MOZ_LIKELY(!size)) { return; } uint8_t service, opcode; uint16_t payloadSize; mPDU->GetHeader(service, opcode, payloadSize); CHROMIUM_LOG( "Unpacked PDU of type (%x,%x) still contains %zu Bytes of data.", service, opcode, size); }
nsresult BluetoothDaemonConnection::ConnectSocket(BluetoothDaemonPDUConsumer* aConsumer) { MOZ_ASSERT(NS_IsMainThread()); if (mIO) { CHROMIUM_LOG("Bluetooth daemon already connecting/connected!"); return NS_ERROR_FAILURE; } SetConnectionStatus(SOCKET_CONNECTING); MessageLoop* ioLoop = XRE_GetIOMessageLoop(); mIO = new BluetoothDaemonConnectionIO( ioLoop, -1, UnixSocketWatcher::SOCKET_IS_CONNECTING, this, aConsumer); ioLoop->PostTask(FROM_HERE, new BluetoothDaemonConnectTask(mIO)); return NS_OK; }
void BluetoothDaemonConnectionIO::Connect(const char* aSocketName) { static const size_t sNameOffset = 1; MOZ_ASSERT(aSocketName); // Create socket address struct sockaddr_un addr; size_t namesiz = strlen(aSocketName) + 1; if((sNameOffset + namesiz) > sizeof(addr.sun_path)) { CHROMIUM_LOG("Address too long for socket struct!"); return; } memset(addr.sun_path, '\0', sNameOffset); // abstract socket memcpy(addr.sun_path + sNameOffset, aSocketName, namesiz); addr.sun_family = AF_UNIX; socklen_t socklen = offsetof(struct sockaddr_un, sun_path) + 1 + namesiz; // Create socket int fd = socket(AF_UNIX, SOCK_SEQPACKET, 0); if (fd < 0) { OnError("socket", errno); return; } if (TEMP_FAILURE_RETRY(fcntl(fd, F_SETFL, O_NONBLOCK)) < 0) { OnError("fcntl", errno); ScopedClose cleanupFd(fd); return; } SetFd(fd); // Connect socket to address; calls OnConnected() // on success, or OnError() otherwise nsresult rv = UnixSocketWatcher::Connect( reinterpret_cast<struct sockaddr*>(&addr), socklen); NS_WARN_IF(NS_FAILED(rv)); }
void RilConsumer::OnConnectError() { CHROMIUM_LOG("RIL[%lu]: %s\n", mClientId, __FUNCTION__); CloseSocket(); }
void RilConsumer::OnConnectSuccess() { // Nothing to do here. CHROMIUM_LOG("RIL[%lu]: %s\n", mClientId, __FUNCTION__); }
void NfcConsumer::OnConnectError() { CHROMIUM_LOG("NFC: %s\n", __FUNCTION__); CloseSocket(); }
void NfcConsumer::OnConnectSuccess() { // Nothing to do here. CHROMIUM_LOG("NFC: %s\n", __FUNCTION__); }
void BluetoothDaemonPDU::OnError(const char* aFunction, int aErrno) { CHROMIUM_LOG("%s failed with error %d (%s)", aFunction, aErrno, strerror(aErrno)); }