static void HandleWatchRemove(DBusThread* aDbt) { int removeFD; unsigned int flags; if (read(aDbt->mControlFdR.get(), &removeFD, sizeof(int)) < 0) { LOG("Cannot read DBus watch remove descriptor data from socket!\n"); return; } if (read(aDbt->mControlFdR.get(), &flags, sizeof(unsigned int)) < 0) { LOG("Cannot read DBus watch remove flag data from socket!\n"); return; } short events = DBusFlagsToUnixEvents(flags); pollfd p; p.fd = removeFD; p.events = events; int index = aDbt->mPollData.IndexOf(p, 0, PollFdComparator()); // There are times where removes can be requested for watches that // haven't been added (for example, whenever gecko comes up after // adapters have already been enabled), so check to make sure we're // using the watch in the first place if (index < 0) { LOG("DBus requested watch removal of non-existant socket, ignoring..."); return; } aDbt->mPollData.RemoveElementAt(index); // DBusWatch pointers are maintained by DBus, so we won't leak by // removing. aDbt->mWatchData.RemoveElementAt(index); }
static void HandleWatchAdd(DBusThread* aDbt) { DBusWatch *watch; int newFD; unsigned int flags; if (read(aDbt->mControlFdR.get(), &newFD, sizeof(int)) < 0) { LOG("Cannot read DBus watch add descriptor data from socket!\n"); return; } if (read(aDbt->mControlFdR.get(), &flags, sizeof(unsigned int)) < 0) { LOG("Cannot read DBus watch add flag data from socket!\n"); return; } if (read(aDbt->mControlFdR.get(), &watch, sizeof(DBusWatch *)) < 0) { LOG("Cannot read DBus watch add watch data from socket!\n"); return; } short events = DBusFlagsToUnixEvents(flags); pollfd p; p.fd = newFD; p.revents = 0; p.events = events; if (aDbt->mPollData.Contains(p, PollFdComparator())) return; aDbt->mPollData.AppendElement(p); aDbt->mWatchData.AppendElement(watch); }
void DBusWatcher::HandleWatchAdd() { int fd; ssize_t res = TEMP_FAILURE_RETRY(read(mControlFdR.get(), &fd, sizeof(fd))); if (res < 0) { LOG("Cannot read DBus watch add descriptor data from socket!\n"); return; } unsigned int flags; res = TEMP_FAILURE_RETRY(read(mControlFdR.get(), &flags, sizeof(flags))); if (res < 0) { LOG("Cannot read DBus watch add flag data from socket!\n"); return; } DBusWatch* watch; res = TEMP_FAILURE_RETRY(read(mControlFdR.get(), &watch, sizeof(watch))); if (res < 0) { LOG("Cannot read DBus watch add watch data from socket!\n"); return; } struct pollfd p = { fd, // .fd DBusFlagsToUnixEvents(flags), // .events 0 // .revents }; if (mPollData.Contains(p, PollFdComparator())) { return; } mPollData.AppendElement(p); mWatchData.AppendElement(watch); }
void DBusWatcher::HandleWatchRemove() { int fd; ssize_t res = TEMP_FAILURE_RETRY(read(mControlFdR.get(), &fd, sizeof(fd))); if (res < 0) { LOG("Cannot read DBus watch remove descriptor data from socket!\n"); return; } unsigned int flags; res = TEMP_FAILURE_RETRY(read(mControlFdR.get(), &flags, sizeof(flags))); if (res < 0) { LOG("Cannot read DBus watch remove flag data from socket!\n"); return; } struct pollfd p = { fd, // .fd DBusFlagsToUnixEvents(flags), // .events 0 // .revents }; int index = mPollData.IndexOf(p, 0, PollFdComparator()); // There are times where removes can be requested for watches that // haven't been added (for example, whenever gecko comes up after // adapters have already been enabled), so check to make sure we're // using the watch in the first place if (index < 0) { LOG("DBus requested watch removal of non-existant socket, ignoring..."); return; } mPollData.RemoveElementAt(index); // DBusWatch pointers are maintained by DBus, so we won't leak by // removing. mWatchData.RemoveElementAt(index); }