/**
   * Sends the prepared PDU packet to the manager and updates the data structure to expect a
   * response. It acquires a lock on the socket to prevent a case where a response arrives before
   * this thread could insert the request into the wait queue.
   *
   * @exception IOException Signals that an I/O exception of some sort has occurred.
   */
  final void sendPduPacket(byte[] buffer, int length) throws java.io.IOException {

    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
      SNMP_ADAPTOR_LOGGER.logp(
          Level.FINER,
          SnmpInformRequest.class.getName(),
          "sendPduPacket",
          "Send to peer. Peer/Port : "
              + address.getHostName()
              + "/"
              + port
              + ". Length = "
              + length
              + "\nDump : \n"
              + SnmpMessage.dumpHexBuffer(buffer, 0, length));
    }
    SnmpSocket theSocket = informSession.getSocket();
    synchronized (theSocket) {
      theSocket.sendPacket(buffer, length, address, port);
      setRequestSentTime(System.currentTimeMillis());
    }
  }
  boolean sendPdu() {
    try {
      responsePdu = null;

      SnmpPduFactory pduFactory = adaptor.getPduFactory();
      SnmpMessage msg =
          (SnmpMessage)
              pduFactory.encodeSnmpPdu(
                  (SnmpPduPacket) requestPdu, adaptor.getBufferSize().intValue());

      if (msg == null) {
        if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
          SNMP_ADAPTOR_LOGGER.logp(
              Level.FINEST,
              SnmpInformRequest.class.getName(),
              "sendPdu",
              "pdu factory returned a null value");
        }
        throw new SnmpStatusException(snmpReqUnknownError);
        // This exception will caught hereafter and reported as an snmpReqUnknownError
        // FIXME: may be it's not the best behaviour ?
      }

      int maxPktSize = adaptor.getBufferSize().intValue();
      byte[] encoding = new byte[maxPktSize];
      int encodingLength = msg.encodeMessage(encoding);

      if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
        SNMP_ADAPTOR_LOGGER.logp(
            Level.FINER,
            SnmpInformRequest.class.getName(),
            "sendPdu",
            "Dump : \n" + msg.printMessage());
      }

      sendPduPacket(encoding, encodingLength);
      return true;
    } catch (SnmpTooBigException ar) {

      if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
        SNMP_ADAPTOR_LOGGER.logp(
            Level.FINEST,
            SnmpInformRequest.class.getName(),
            "sendPdu",
            "Got unexpected exception",
            ar);
      }

      setErrorStatusAndIndex(snmpReqPacketOverflow, ar.getVarBindCount());
      requestPdu = null;
      reason = ar.getMessage();
      if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
        SNMP_ADAPTOR_LOGGER.logp(
            Level.FINEST,
            SnmpInformRequest.class.getName(),
            "sendPdu",
            "Packet Overflow while building inform request");
      }
    } catch (java.io.IOException ioe) {
      setErrorStatusAndIndex(snmpReqSocketIOError, 0);
      reason = ioe.getMessage();
    } catch (Exception e) {
      if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
        SNMP_ADAPTOR_LOGGER.logp(
            Level.FINEST,
            SnmpInformRequest.class.getName(),
            "sendPdu",
            "Got unexpected exception",
            e);
      }
      setErrorStatusAndIndex(snmpReqUnknownError, 0);
      reason = e.getMessage();
    }
    return false;
  }