⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jk_channel_un.c

📁 Tomcat 4.1与WebServer集成组件的源代码包.
💻 C
📖 第 1 页 / 共 2 页
字号:
                    return -errno;                }            }            break;        }    } else {        unixsock = socket(AF_UNIX, SOCK_STREAM, 0);        if (unixsock<0) {            env->l->jkLog(env, env->l, JK_LOG_ERROR,                          "channelUn.open(): can't create socket %d %s\n",                          errno, strerror( errno ) );            return JK_ERR;        }                if( ch->mbean->debug > 0 )             env->l->jkLog(env, env->l, JK_LOG_DEBUG,                          "channelUn.open(): create unix socket %s %d\n", socketInfo->file, unixsock );                if (connect(unixsock,(struct sockaddr *)&(socketInfo->unix_addr),                    sizeof(struct sockaddr_un))<0) {            close(unixsock);            env->l->jkLog(env, env->l, JK_LOG_ERROR,                          "channelUn.connect() connect failed %d %s\n",                          errno, strerror( errno ) );            return JK_ERR;        }    }#if defined(F_SETFD) && defined(FD_CLOEXEC)    /* Protect the socket so that it will not be inherited by child processes */    fcntl(unixsock, F_SETFD, FD_CLOEXEC);#endif    if( ch->mbean->debug > 0 )         env->l->jkLog(env, env->l, JK_LOG_DEBUG,                      "channelUn.open(): connect unix socket %d %s\n", unixsock, socketInfo->file );    /* store the channel information */    endpoint->sd=unixsock;    return JK_OK;}/** close the socket  ( was: jk2_close_socket )*/static int JK_METHOD jk2_channel_un_close(jk_env_t *env,jk_channel_t *ch,                                          jk_endpoint_t *endpoint){    env->l->jkLog(env, env->l, JK_LOG_INFO,                  "channelUn.close(): close unix socket %d \n",  endpoint->sd );    close( endpoint->sd );    endpoint->sd=-1;    return JK_OK;}/** send a long message * @param sd  opened socket. * @param b   buffer containing the data. * @param len length to send. * @return    -2: send returned 0 ? what this that ? *            -3: send failed. *            >0: total size send. * @bug       this fails on Unixes if len is too big for the underlying *             protocol. * @was: jk_tcp_socket_sendfull */static int JK_METHOD jk2_channel_un_send(jk_env_t *env, jk_channel_t *ch,                                         jk_endpoint_t *endpoint,                                         jk_msg_t *msg) {    unsigned char *b;    int len;    int  sent=0;    int this_time;    int unixsock;    msg->end( env, msg );    len=msg->len;    b=msg->buf;    unixsock=endpoint->sd;    if( unixsock < 0 ) {        env->l->jkLog(env, env->l, JK_LOG_INFO,                      "channel.apr:send() not connected %d\n", unixsock );        return JK_ERR;    }    while(sent < len) {        errno=0;        this_time = write(unixsock, (char *)b + sent , len - sent);        if( ch->mbean->debug > 0 )             env->l->jkLog(env, env->l, JK_LOG_DEBUG,                          "channel.apr:send() write() %d %d %s\n", this_time, errno,                          strerror( errno));        if(0 == this_time) {            return -2;        }        if(this_time < 0) {            return -3;        }        sent += this_time;    }    /*     return sent; */    return JK_OK;}/** receive len bytes. * @param sd  opened socket. * @param b   buffer to store the data. * @param len length to receive * @return    -1: receive failed or connection closed. *            >0: length of the received data. * Was: tcp_socket_recvfull */static int JK_METHOD jk2_channel_un_readN( jk_env_t *env,                                           jk_channel_t *ch,                                           jk_endpoint_t *endpoint,                                           unsigned char *b, int len ) {    int sd;    int rdlen;    sd=endpoint->sd;        if( sd < 0 ) {        env->l->jkLog(env, env->l, JK_LOG_INFO,                      "channel.apr:readN() not connected %d\n", sd );        return -3;    }    rdlen = 0;    while(rdlen < len) {        int this_time = recv(sd, (char *)b + rdlen,                              len - rdlen, 0);                if( this_time < 0 ) {            if(EAGAIN == errno) {                continue;            }             return -2;        }        if(0 == this_time) {            return -1;         }        rdlen += this_time;    }    return rdlen; }/** receive len bytes. * @param sd  opened socket. * @param b   buffer to store the data. * @param len length to receive. * @return    -1: receive failed or connection closed. *            >0: length of the received data. * Was: tcp_socket_recvfull */static int JK_METHOD jk2_channel_un_recv( jk_env_t *env, jk_channel_t *ch,                                             jk_endpoint_t *endpoint,                                             jk_msg_t *msg ){    int hlen=msg->headerLength;    int blen;    int rc=JK_OK;        blen=jk2_channel_un_readN( env, ch, endpoint, msg->buf, hlen );    if( blen <= 0 ) {        env->l->jkLog(env, env->l, JK_LOG_ERROR,                      "channelUn.receive(): error receiving %d %d %s %#lx %d\n",                      blen, errno, strerror( errno ), endpoint, endpoint->sd);        return JK_ERR;    }    blen=msg->checkHeader( env, msg, endpoint );    if( blen < 0 ) {        env->l->jkLog(env, env->l, JK_LOG_ERROR,                      "channelUn.receive(): Bad header\n" );        return JK_ERR;    }        rc= jk2_channel_un_readN( env, ch, endpoint, msg->buf + hlen, blen);    if(rc < 0) {        env->l->jkLog(env, env->l, JK_LOG_ERROR,               "channelUn.receive(): Error receiving message body %d %d\n",                      rc, errno);        return JK_ERR;    }    if( ch->mbean->debug > 0 )         env->l->jkLog(env, env->l, JK_LOG_DEBUG,                      "channelUn.receive(): Received len=%d type=%d\n",                      blen, (int)msg->buf[hlen]);    return JK_OK;}int JK_METHOD jk2_channel_un_factory(jk_env_t *env,                                     jk_pool_t *pool,                                      jk_bean_t *result,                                     const char *type, const char *name){    jk_channel_t *ch;        ch=(jk_channel_t *)pool->calloc(env, pool, sizeof( jk_channel_t));        ch->_privatePtr= (jk_channel_un_private_t *)        pool->calloc( env, pool, sizeof( jk_channel_un_private_t));    ch->recv= jk2_channel_un_recv;     ch->send= jk2_channel_un_send;     ch->open= jk2_channel_un_open;     ch->close= jk2_channel_un_close;     ch->is_stream=JK_TRUE;    ch->serverSide=JK_FALSE;        result->setAttribute= jk2_channel_un_setAttribute;     result->multiValueInfo=jk2_channel_un_multiValueInfo;    result->setAttributeInfo=jk2_channel_un_setAttributeInfo;    result->invoke=jk2_channel_invoke;    ch->mbean=result;    result->object= ch;    result->init= jk2_channel_un_init;     ch->workerEnv=env->getByName( env, "workerEnv" );    ch->workerEnv->addChannel( env, ch->workerEnv, ch );    return JK_OK;}#elseint JK_METHOD jk2_channel_un_factory(jk_env_t *env,                                     jk_pool_t *pool,                                      jk_bean_t *result,                                     const char *type, const char *name){    env->l->jkLog( env, env->l, JK_LOG_ERROR,                   "channelUn.factory(): Support for unix sockets is disabled, "                   "you need to set HAVE_UNIXSOCKETS at compile time\n");    result->disabled=1;    return JK_FALSE;}#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -