Search code examples
androidvpnandroid-vpn-service

what is Android VpnService.Builder setBlocking


My question is: what does it really do? For instance, if I set it to true, what does it do to packages (datagrams?) that I want to write to the TUN device? As far as I noticed it does not mean that all packets to be written to the TUN device will be discarded rather than processed in another manner. Does it mean this?

So I can only track what it does only this far:

public Builder setBlocking(boolean blocking) {
    mConfig.blocking = blocking;
    return this;
}

And that

public class Builder {
    private final VpnConfig mConfig = new VpnConfig();
    //other stuff here ...
}

I also read the official description, but it is still unclear to me. Googling it will only lead to search results related to "how to bypass VPN blocking".


Solution

  • It does refer to blocking I/O and has nothing to do with blocking traffic or how packets are treated. Instead it changes how your program interacts with the file descriptor.

    In blocking mode, operations like read()/write() will block until some data has been transferred (or an error occurred) whereas in non-blocking mode the operations may return immediately (with EAGAIN or EWOULDBLOCK) if the file descriptor is currently not ready and the operation would block.