blob: 3ec9d9dfdb0c2ea76316787f5746aa60eda8fff7 [file] [log] [blame]
San Mehat168415b2009-05-06 11:14:21 -07001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#include <errno.h>
17
18#include <sys/types.h>
19#include <sys/socket.h>
San Mehat3d407292009-05-07 08:49:30 -070020#include <string.h>
San Mehat168415b2009-05-06 11:14:21 -070021
22#define LOG_TAG "NetlinkListener"
23#include <cutils/log.h>
24
25#include <sysutils/NetlinkListener.h>
26#include <sysutils/NetlinkEvent.h>
27
28NetlinkListener::NetlinkListener(int socket) :
29 SocketListener(socket, false) {
30}
31
San Mehatfa644ff2009-05-08 11:15:53 -070032bool NetlinkListener::onDataAvailable(SocketClient *cli)
San Mehat168415b2009-05-06 11:14:21 -070033{
San Mehatfa644ff2009-05-08 11:15:53 -070034 int socket = cli->getSocket();
San Mehat168415b2009-05-06 11:14:21 -070035 LOGD("NetlinkListener::onDataAvailable()");
36
37 int count;
38
39 if ((count = recv(socket, mBuffer, sizeof(mBuffer), 0)) < 0) {
40 LOGE("recv failed (%s)", strerror(errno));
41 return false;
42 }
43
44 NetlinkEvent *evt = new NetlinkEvent();
45 if (!evt->decode(mBuffer, count)) {
46 LOGE("Error decoding NetlinkEvent");
47 goto out;
48 }
49
50 LOGD("Ignoring '%s' netlink event", evt->getSubsystem());
51
52out:
53 delete evt;
54 return true;
55}