public void destroy() {
        ListIterator<Socket> itr = sockets.listIterator();
        while (itr.hasNext()) {
            destroySocket(itr.next());
        }
        sockets.clear();

        // Only terminate context if we are on the main thread
        if (isMain() && context != null)
            context.term();

    }