[잡담] sample 만 보고 API 를 이해했다고 이야기 하지 말아야 겠네요.

emptynote의 이미지

자바 NIO Gather & Scatter 예제만 보면 참 쉽지요.

하지만 API 설명에 아래와 같은 문구가 있나 부다 하고 넘어 갔는데,

갑자기 메시지 데이터를 다 못 받기에 몬 일인가 원인을 찾아 보니,

API 에서 해준말 그대로 중간 보내다 말아 버렸네요.

바이트 버퍼 배열로 보내는데 중간 보내다 말면 어쩌라는건가요.

API 라는것이 샘플 보면 그렇게 쉬운것이 없는데

막상 실전에서 사용하다 보면 내가 이 놈을 알고 있는 것 일까? 의문이 드네요.

돈주고 산 책에서도 샘플 소스 담론만 해 주고 있으니

개밥은 먹어봐야 하는것이네요.

---- http://docs.oracle.com/javase/6/docs/api/ Class SocketChannel ::
---- public abstract long write(ByteBuffer[] srcs,int offset, int length)
---- throws IOException 메소드 설명 부분 인용

Unless otherwise specified, a write operation will return only after writing all of the r requested bytes. Some types of channels, depending upon their state, may write only some of the bytes or possibly none at all. A socket channel in non-blocking mode, for example, cannot write any more bytes than are free in the socket's output buffer.
--------------------------------