wlan signal via libnl

Thomas Haller thaller at redhat.com
Tue May 24 07:14:28 PDT 2016


On Tue, 2016-05-24 at 11:30 +0000, Vaittinen, Ville (GE Healthcare)
wrote:
> Hi,

Hi,




> we are trying to use libnl for querying wlan signal strength
> and have got it basically working. 
> 
> Our basic calling pattern is
>     nl_send_auto_complete(m_socket, msg);
> 
>     nl_cb* callback = nl_socket_get_cb(m_socket);
> 
>     int ret = nl_recvmsgs(m_socket, callback);
> 
> And in the callback function we parse the message / signal strength.
> 
> Due to the lacking knowledge of lower level implementation details we
> are wondering,
> if it actually can happen that due to some internals nl_recvmsgs()
> might actually block
> and never return? And if so, what would be the counter-measure
> (configuring a timeout possible?, non-blocking socket).

If the file descriptor is set to blocking, it blocks until there is
something to read. That is fine, if you don't have any other event you
are waiting for (e.g. timeout, UI interaction, etc).
Note, that a blocking read might always be interrupted by a signal, so
usually you would do something like:

again:
     i = nl_recvmsgs(fd);
     if (i == -NLE_EAGAIN)
         goto again;


Otherwise:

(1) either, make the socket non-blocking and react on NLE_EAGAIN,
    which in this case means, there is nothing to read currently
    (nl_socket_set_nonblocking()).

(2) or, select/poll on the filedescribtor so that you know something
    is available to read.


Actually, (1) and (2) is not either-or, because even if you make the
socket non-blocking, it is not clear when there is something available
to read. So, usually also when using non-blocking IO, you still must
select/poll to know when something is read.



> Furthermore is it sufficient in this case to call nl_recvmsgs() once
> or should it be called
> in while loop along the lines iw tool does it that sets additional
> callbacks of types NL_CB_FINISH, NL_CB_ACK and
> checks the output in them to stop the while loop.

nl_recvmsgs() documentation says:

Stops reading if one of the callbacks returns NL_STOP or nl_recv
returns either 0 or a negative error code.

So, it will return a bunch of messages, but stop on the first error (or
NL_STOP).



Thomas
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part
URL: <http://lists.infradead.org/pipermail/libnl/attachments/20160524/9c7ea6a8/attachment.sig>


More information about the libnl mailing list