コード例 #1
0
 /**
  * Perform a read into buffer.
  *
  * @return true if the read succeeded, false if there was an error or the connection closed.
  */
 private boolean internalRead() {
   try {
     if (trans_.read(buffer_) < 0) {
       return false;
     }
     return true;
   } catch (IOException e) {
     Log.w("Thrift", "Got an IOException in internalRead!", e);
     return false;
   }
 }
コード例 #2
0
 /** Shut the connection down. */
 public void close() {
   // if we're being closed due to an error, we might have allocated a
   // buffer that we need to subtract for our memory accounting.
   if (state_ == FrameBufferState.READING_FRAME
       || state_ == FrameBufferState.READ_FRAME_COMPLETE) {
     readBufferBytesAllocated.addAndGet(-buffer_.array().length);
   }
   trans_.close();
   if (eventHandler_ != null) {
     eventHandler_.deleteContext(context_, inProt_, outProt_);
   }
 }
コード例 #3
0
    /** Give this FrameBuffer a chance to write its output to the final client. */
    public boolean write() {
      if (state_ == FrameBufferState.WRITING) {
        try {
          if (trans_.write(buffer_) < 0) {
            return false;
          }
        } catch (IOException e) {
          Log.w("Thrift", "Got an IOException during write!", e);
          return false;
        }

        // we're done writing. now we need to switch back to reading.
        if (buffer_.remaining() == 0) {
          prepareRead();
        }
        return true;
      }

      Log.e("Protocol", "Write was called, but state is invalid (" + state_ + ")");
      return false;
    }