CCNNetworkChannel.java 文件源码

java
阅读 20 收藏 0 点赞 0 评论 0

项目:alien-ofelia-conet-ccnx 作者:
/**
 * Write to ccnd using methods based on the protocol type
 * @param src - ByteBuffer to write
 * @return - number of bytes written
 * @throws IOException
 */
public int write(ByteBuffer src) throws IOException {
    if (! isConnected())
        return -1; // XXX - is this documented?
    if (Log.isLoggable(Log.FAC_NETMANAGER, Level.FINEST))
        Log.finest(Log.FAC_NETMANAGER,
                "NetworkChannel {0}: write() on port {1}", _channelId, _ncLocalPort);

    try {
        if (_ncDGrmChannel != null) {
            return (_ncDGrmChannel.write(src));
        } else {
            // XXX -this depends on synchronization in caller, which is less than ideal.
            // Need to handle partial writes
            int written = 0;
            while (src.hasRemaining()) {
                if (! isConnected())
                    return -1;
                int b = _ncSockChannel.write(src);
                if (b > 0) {
                    written += b;
                } else {
                    _ncWriteSelector.selectedKeys().clear();
                    _ncWriteSelector.select();
                }
            }
            return written;
        }
    } catch (PortUnreachableException pue) {}
      catch (ClosedChannelException cce) {}
    Log.info(Log.FAC_NETMANAGER, "NetworkChannel {0}: closing due to error on write", _channelId);
    close(true);
    return -1;
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号