zoukankan      html  css  js  c++  java
  • 关于sun JDK nio在linux下的实现。

    这是6.0之前的poll模型。
    solaris\native\sun\nio\ch\SocketChannelImpl.c
    JNIEXPORT jint JNICALL
    Java_sun_nio_ch_SocketChannelImpl_checkConnect(JNIEnv 
    *env, jobject this,
                               jobject fdo, jboolean block,
                                                   jboolean ready)
    {
        
    int error = 0;
        
    int n = sizeof(int);
        jint fd 
    = fdval(env, fdo);
        
    int result = 0;
        struct pollfd poller;

        poller.revents 
    = 1;
        
    if (!ready) {
            poller.fd 
    = fd;
            poller.events 
    = POLLOUT;
            poller.revents 
    = 0;
            result 
    = poll(&poller, 1, block ? -1 : 0);
            
    if (result < 0) {
                JNU_ThrowIOExceptionWithLastError(env, 
    "Poll failed");
                
    return IOS_THROWN;
            }
        
    if (!block && (result == 0))
            
    return IOS_UNAVAILABLE;
        }

        
    if (poller.revents) {
            errno 
    = 0;
            result 
    = getsockopt(fd, SOL_SOCKET, SO_ERROR, &error, &n);
            
    if (result < 0) {
                handleSocketError(env, errno);
                
    return JNI_FALSE;
            } 
    else if (error) {
                handleSocketError(env, error);
                
    return JNI_FALSE;
            }
            
    return 1;
        }
        
    return 0;
    }


    6.0缺省的模型是使用epoll
    E:\Java\jdk-6-rc-src\j2se\src\solaris\native\sun\nio\ch\EPollArrayWrapper.c

    JNIEXPORT void JNICALL
    Java_sun_nio_ch_EPollArrayWrapper_init(JNIEnv 
    *env, jclass this
    {
        epoll_create_func 
    = (epoll_create_t) dlsym(RTLD_DEFAULT, "epoll_create");
        epoll_ctl_func    
    = (epoll_ctl_t)    dlsym(RTLD_DEFAULT, "epoll_ctl");
        epoll_wait_func   
    = (epoll_wait_t)   dlsym(RTLD_DEFAULT, "epoll_wait");
                                                                                                       
        
    if ((epoll_create_func == NULL) || (epoll_ctl_func == NULL) ||
            (epoll_wait_func 
    == NULL)) {
            JNU_ThrowInternalError(env, 
    "unable to get address of epoll functions, pre-2.6 kernel?");
        }
    }


    具体程序的流程我还是不够清楚,还有待进一步深入了解。

    温少的日志 2006-11-22 01:34 发表评论
  • 相关阅读:
    redux-simple 简化版的redux
    react服务端渲染(同构)
    使用systemd管理程序进程
    使用Dockerfile构建镜像
    centos7使用supermin制作centos7的docker镜像包
    DNS-dnsmasq安装配置
    kubernetes-部署(单机,使用证书)
    DNS-bind+namedmanager安装
    python3第一个脚本(hello world!)
    Python3 基础语法
  • 原文地址:https://www.cnblogs.com/jobs/p/568022.html
Copyright © 2011-2022 走看看