<commit_before>/*
 * Copyright (c) 2005-2006 Digital Bazaar, Inc.  All rights reserved.
 */
package com.db.net;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PushbackInputStream;
import java.net.Socket;
import java.net.SocketAddress;
import java.net.SocketException;
import java.net.SocketTimeoutException;

import com.db.logging.Logger;
import com.db.logging.LoggerManager;

/**
 * This class represents a generic web connection to a web server.
 * 
 * @author <NAME>
 */
public class GenericWebConnection implements WebConnection
{
   /**
    * The worker socket for this web connection.
    */
   protected Socket mWorkerSocket;
   
   /**
    * The remote IP address for this web connection.
    */
   protected String mRemoteIP;
   
   /**
    * The remote port for this web connection.
    */
   protected int mRemotePort;
   
   /**
    * Whether or not this web connection has been marked as secure.
    */
   protected boolean mSecure;
   
   /**
    * The stream used to read from the web connection.
    */
   protected PushbackInputStream mReadStream;
   
   /**
    * The stream used to write to the web connection.
    */
   protected OutputStream mWriteStream;
   
   /**
    * The number of bytes read so far.
    */
   protected long mBytesRead;
   
   /**
    * The number of bytes written so far.
    */
   protected long mBytesWritten;
   
   /**
    * The read bandwidth throttler.
    */
   protected BandwidthThrottler mReadBandwidthThrottler;
   
   /**
    * The write bandwidth throttler.
    */
   protected BandwidthThrottler mWriteBandwidthThrottler;

   /**
    * The read timeout for this web connection. This is the amount of
    * time that must pass while doing a blocking read before timing out. 
    */
   protected long mReadTimeout;
   
   /**
    * Creates a new generic web connection.
    * 
    * @param workerSocket the worker socket for this web connection.
    */
   public GenericWebConnection(Socket workerSocket)
   {
      // store worker socket
      mWorkerSocket = workerSocket;
      
      try
      {
         // set read timeout (short timeouts will be caught and tossed if the
         // read timeout for this web connection hasn't been reached)
         mWorkerSocket.setSoTimeout(500);
      }
      catch(SocketException ignore)
      {
         // only thrown if the socket is closed or an invalid timeout was
         // specified, neither of which we are concerned about here
      }
      
      // set IP and port
      setRemoteIP(getRemoteIP(workerSocket));
      setRemotePort(getRemotePort(workerSocket));
      
      // not secure by default
      mSecure = false;

      // no bytes read or written yet
      mBytesRead = 0;<commit_msg>Shorted socket read timeout to 250 ms -- this is not the read time out for the web connection, just for reading from a socket. That means that the web connection read method will report back whenever data hasn't been sent in 250 milliseconds. This allows for the web connection to be more easily interrupted.<commit_after>/*
 * Copyright (c) 2005-2006 Digital Bazaar, Inc.  All rights reserved.
 */
package com.db.net;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PushbackInputStream;
import java.net.Socket;
import java.net.SocketAddress;
import java.net.SocketException;
import java.net.SocketTimeoutException;

import com.db.logging.Logger;
import com.db.logging.LoggerManager;

/**
 * This class represents a generic web connection to a web server.
 * 
 * @author <NAME>
 */
public class GenericWebConnection implements WebConnection
{
   /**
    * The worker socket for this web connection.
    */
   protected Socket mWorkerSocket;
   
   /**
    * The remote IP address for this web connection.
    */
   protected String mRemoteIP;
   
   /**
    * The remote port for this web connection.
    */
   protected int mRemotePort;
   
   /**
    * Whether or not this web connection has been marked as secure.
    */
   protected boolean mSecure;
   
   /**
    * The stream used to read from the web connection.
    */
   protected PushbackInputStream mReadStream;
   
   /**
    * The stream used to write to the web connection.
    */
   protected OutputStream mWriteStream;
   
   /**
    * The number of bytes read so far.
    */
   protected long mBytesRead;
   
   /**
    * The number of bytes written so far.
    */
   protected long mBytesWritten;
   
   /**
    * The read bandwidth throttler.
    */
   protected BandwidthThrottler mReadBandwidthThrottler;
   
   /**
    * The write bandwidth throttler.
    */
   protected BandwidthThrottler mWriteBandwidthThrottler;

   /**
    * The read timeout for this web connection. This is the amount of
    * time that must pass while doing a blocking read before timing out. 
    */
   protected long mReadTimeout;
   
   /**
    * Creates a new generic web connection.
    * 
    * @param workerSocket the worker socket for this web connection.
    */
   public GenericWebConnection(Socket workerSocket)
   {
      // store worker socket
      mWorkerSocket = workerSocket;
      
      try
      {
         // set read timeout (short timeouts will be caught and tossed if the
         // read timeout for this web connection hasn't been reached)
         mWorkerSocket.setSoTimeout(250);
      }
      catch(SocketException ignore)
      {
         // only thrown if the socket is closed or an invalid timeout was
         // specified, neither of which we are concerned about here
      }
      
      // set IP and port
      setRemoteIP(getRemoteIP(workerSocket));
      setRemotePort(getRemotePort(workerSocket));
      
      // not secure by default
      mSecure = false;

      // no bytes read or written yet
      mBytesRead = 0;
{'fraction_non_alphanumeric': 0.07401682981281127, 'fraction_numerical': 0.005151983513652756, 'mean_word_length': 2.4584323040380047, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '3101000', 'n_tokens_mistral': 1594, 'n_tokens_neox': 1548, 'n_words': 590}