<commit_before>// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package org.chromium;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.InterfaceAddress;
import java.net.MulticastSocket;
import java.net.NetworkInterface;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.util.Collection;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

import org.apache.cordova.CordovaArgs;
import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.PluginResult;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.util.Log;

public class ChromeSocket extends CordovaPlugin {

    private static final String LOG_TAG = "ChromeSocket";

    private static Map<Integer, SocketData> sockets = new HashMap<Integer, SocketData>();
    private static int nextSocket = 1;

    @Override
    public boolean execute(String action, CordovaArgs args, final CallbackContext callbackContext) throws JSONException {
        if ("create".equals(action)) {
            create(args, callbackContext);
        } else if ("connect".equals(action)) {
            connect(args, callbackContext);
        } else if ("bind".equals(action)) {
            bind(args, callbackContext);
        } else if ("write".equals(action)) {
            write(args, callbackContext);
        } else if ("read".equals(action)) {
            read(args, callbackContext);
        } else if ("sendTo".equals(action)) {
            sendTo(args, callbackContext);
        } else if ("recvFrom".equals(action)) {
            recvFrom(args, callbackContext);
        } else if ("disconnect".equals(action)) {
            disconnect(args, callbackContext);
        } else if ("destroy".equals(action)) {
            destroy(args, callbackContext);
        } else if ("listen".equals(action)) {
            listen(args, callbackContext);
        } else if ("accept".equals(action)) {
            accept(args, callbackContext);
        } else if ("getInfo".equals(action)) {
            getInfo(args, callbackContext);
        } else if ("getNetworkList".equals(action)) {
            getNetworkList(args, callbackContext);
        } else if ("joinGroup".equals(action)) {
            joinGroup(args, callbackContext);
        } else if ("leaveGroup".equals(action)) {
            leaveGroup(args, callbackContext);
        } else if ("setMulticastTimeToLive".equals(action)) {
            setMulticastTimeToLive(args, callbackContext);
        } else if ("setMulticastLoopbackMode".equals(action)) {
            setMulticastLoopbackMode(args, callbackContext);
        } else if ("getJoinedGroups".equals(action)) {
            getJoinedGroups(args, callbackContext);
        } else {
            return false;
        }
        return true;
    }
<commit_msg>Destroy all lingering sockets onStop/onReset<commit_after>// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package org.chromium;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.InterfaceAddress;
import java.net.MulticastSocket;
import java.net.NetworkInterface;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.util.Collection;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

import org.apache.cordova.CordovaArgs;
import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.PluginResult;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.util.Log;

public class ChromeSocket extends CordovaPlugin {

    private static final String LOG_TAG = "ChromeSocket";

    private static Map<Integer, SocketData> sockets = new HashMap<Integer, SocketData>();
    private static int nextSocket = 1;

    @Override
    public boolean execute(String action, CordovaArgs args, final CallbackContext callbackContext) throws JSONException {
        if ("create".equals(action)) {
            create(args, callbackContext);
        } else if ("connect".equals(action)) {
            connect(args, callbackContext);
        } else if ("bind".equals(action)) {
            bind(args, callbackContext);
        } else if ("write".equals(action)) {
            write(args, callbackContext);
        } else if ("read".equals(action)) {
            read(args, callbackContext);
        } else if ("sendTo".equals(action)) {
            sendTo(args, callbackContext);
        } else if ("recvFrom".equals(action)) {
            recvFrom(args, callbackContext);
        } else if ("disconnect".equals(action)) {
            disconnect(args, callbackContext);
        } else if ("destroy".equals(action)) {
            destroy(args, callbackContext);
        } else if ("listen".equals(action)) {
            listen(args, callbackContext);
        } else if ("accept".equals(action)) {
            accept(args, callbackContext);
        } else if ("getInfo".equals(action)) {
            getInfo(args, callbackContext);
        } else if ("getNetworkList".equals(action)) {
            getNetworkList(args, callbackContext);
        } else if ("joinGroup".equals(action)) {
            joinGroup(args, callbackContext);
        } else if ("leaveGroup".equals(action)) {
            leaveGroup(args, callbackContext);
        } else if ("setMulticastTimeToLive".equals(action)) {
            setMulticastTimeToLive(args, callbackContext);
        } else if ("setMulticastLoopbackMode".equals(action)) {
            setMulticastLoopbackMode(args, callbackContext);
        } else if ("getJoinedGroups".equals(action)) {
            getJoinedGroups(args, callbackContext);
        } else {
            return false;
        }
        return true;
    }

    public void onStop() {
        destroyAllSockets();
    }

    public void onReset() {
        destroyAllSockets();
    }

    private void destroyAllSockets() {
        Log.i(LOG_TAG, "Destroying all open sockets");

        for (Map.Entry<Integer, SocketData> entry : sockets.entrySet())
        {
            SocketData sd = entry.getValue();
            sd.destroy();
        }
        sockets.clear();
    }

{'fraction_non_alphanumeric': 0.11174539745968318, 'fraction_numerical': 0.0014271442842871413, 'mean_word_length': 3.0934579439252334, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3371157', 'n_tokens_mistral': 1915, 'n_tokens_neox': 1883, 'n_words': 460}