非阻塞写入Java SocketChannel

时间:2016-06-09 04:49:06

标签: java sockets socketchannel

如果我获得设置为非阻塞模式的proc sql; create table want as select loan_desc, case when loan_desc in ("home_loan", "auto_loan") then "Loan" when loan_desc = "Multi" then "Multi options" else "Unknown" end as product_summary from have; quit; ,当我写入通道并且底层套接字缓冲区已满时会发生什么,因为另一方无法跟上?数据会被丢弃还是会出现这种情况?

1 个答案:

答案 0 :(得分:1)

write()方法返回零,数据保留在ByteBuffer。此时,您应该为OP_WRITE注册通道,记住输出缓冲区,返回到选择循环。当通道变为可写时,重试写入,这次只要它完成,即不返回零或小于要写入的缓冲区中的剩余字节,请取消注册OP_WRITE