Set netlink scan handle in non-blocking state 16/179816/4
authorMayank Haarit <mayank.h@samsung.com>
Tue, 22 May 2018 11:59:45 +0000 (17:29 +0530)
committerMayank Haarit <mayank.h@samsung.com>
Fri, 25 May 2018 10:30:38 +0000 (16:00 +0530)
This patch is to set nl socket handle in non-blocking
state.

Change-Id: I7bb6b295445d9967a3d9cb725d76e01b7c2a08ca
Signed-off-by: Mayank Haarit <mayank.h@samsung.com>
src/wifi-netlink-scan.c

index 5fb87f7..f4fb530 100755 (executable)
@@ -111,6 +111,7 @@ static int ack_handler(struct nl_msg *msg, void *user_data)
 {
        int *err = user_data;
        *err = 0;
+       DBG("");
        return NL_STOP;
 }
 
@@ -680,9 +681,12 @@ static int __netconfig_request_netlink_scan(struct nl_sock *socket,
        nl_cb_set(cb, NL_CB_FINISH, NL_CB_CUSTOM, finish_handler, &err);
        nl_cb_set(cb, NL_CB_ACK, NL_CB_CUSTOM, ack_handler, &err);
        nl_cb_set(cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, no_seq_check, NULL);
+       ret = nl_socket_set_nonblocking(socket);
+       DBG("Set the non-blocking mode [%d]", ret);
 
        /** Send NL80211_CMD_TRIGGER_SCAN to start the scan. */
        ret = nl_send_auto_complete(socket, msg);
+
        if (ret < 0) {
                DBG("nl_send_auto_complete() error: (%s)", nl_geterror(-ret));
                goto out;
@@ -691,19 +695,26 @@ static int __netconfig_request_netlink_scan(struct nl_sock *socket,
        DBG("Sent %d bytes to the kernel", ret);
        ssid_found = FALSE;
 
-       while (err > 0)
+       while (err > 0) {
                ret = nl_recvmsgs(socket, cb);
-
-       if (ret < 0) {
-               DBG("nl_recvmsgs() ret: %d (%s)", ret, nl_geterror(-ret));
-               goto out;
+               if (ret < 0) {
+                       DBG("nl_recvmsgs() ret: %d (%s)", ret, nl_geterror(-ret));
+                       goto out;
+               }
        }
 
-       while (!results.done)
-               nl_recvmsgs(socket, cb);
+       while (!results.done) {
+               ret = nl_recvmsgs(socket, cb);
+               if (ret < 0 || err < 0) {
+                       DBG("scan failed");
+                       ret = -1;
+                       goto out;
+               }
+       }
 
        if (results.aborted) {
                DBG("scan aborted");
+               ret = -1;
                goto out;
        }