Closed jhpark816 closed 8 years ago
먼저 ByteBuffer 에 대한 설명이 필요할 것 같습니다. ByteBuffer 에서 필요한 속성 개념이 position, limit, capacity 가 있습니다. (mark 도 있지만 제외하겠습니다.)
아래 그림은 ByteBuffer 를 8로 생성했을 때 입니다.
각 속성 값의 관계는 아래와 같습니다. 0 <= position <= limit <= capacity
ByteBuffer 에서 get 과 put 등을 호출하면 해당 position 에 작업을 처리하고 position 을 증가 시킵니다. remaining 은 limit - position 의 값을 return 해줍니다.
Operation 에 존재하는 cmd ByteBuffuer 에 있는 것을 Memcached Node 에 있는 write ByteBuffuer 로 옮기는 작업을 할 때 while 문을 이용하기 때문에 두 ByteBuffer 의 remaining 을 비교하는 것이 맞습니다.
@whchoi83 내가 remaining에 대해 잘못 이해하고 있었군요..
cmd byte buffer에는 cmd string을 put하고 나서 flip()을 한 상태라, remaining이 cmd byte buffer에 기록된 string의 길이를 의미하게 되는 거고, write buffer의 remaing은 아직 put할 수 있는 크기를 나타내는 거네요... write buffer에 cmd를 모두 채운 후에는 flip()하여 remaining 만큼 보내는 거고요..
Thank You..
아래 코드에서 bytesToCopy는 아래 둘 중의 작은 값으로 설정해야 하지 않나요 ?