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

📄 plumbing.c

📁 openmap java写的开源数字地图程序. 用applet实现,可以像google map 那样放大缩小地图.
💻 C
📖 第 1 页 / 共 2 页
字号:
    int result;        result = InitFds();#ifdef TK    eventMode = EventMode_Tk;#endif    return result;}void WeedOutBadFds(){    int fd;        if(initialized == 0) InitFds();    for(fd = 0; fd < MaxFds; fd++)    {        if(ifds[fd].fd == -1)        {            DisconnectInputFd(fd);        }        if(ofds[fd].fd == -1)        {            DisconnectOutputFd(fd);        }        if(socket_test(fd) < 0)        {            DisconnectOutputFd(fd);            DisconnectInputFd(fd);        }    }}void Plumbing_TkInputEvent (ClientData data, int mask){#ifdef TK    int fd, nBytes, status;    fd = (int)data;    if (Debug(plumbing))    {        sprintf(msgBuf, "Tk Input Event on fd %d", fd);        DEBUG_MESSAGE(msgBuf);    }    if(ifds[fd].callback != (FdCBProc) 0)    {        if(Debug(plumbing))        {            nBytes = socket_count(fd);            sprintf(msgBuf, "Calling %s(%d...) ( %05d bytes )",                     ifds[fd].callbackName, fd, nBytes);            DEBUG_MESSAGE(msgBuf);            if(ifds[fd].flag & TraceData)            {                if(nBytes > sizeof(peekBuf))                    nBytes = sizeof(peekBuf);                socket_peek(fd, peekBuf, nBytes);                PrintTrace(fd, peekBuf, nBytes, 'I');            }        }        status = (*(ifds[fd].callback)) (fd, ifds[fd].clientData);        if(status == ErrorReturn)        {            DisconnectInputFd(fd);            DisconnectOutputFd(fd);        }    }#endif}/* ------------------------------------------------------------------------ *  * ConnectInputFd()     Allows user to hook a callback to input ready *                      events on a file descriptor. *  * RETURNS:             The file descriptor. * * NOTE:                Clobbers the old input fd to callback association. *                      This is how you change what the callback or clientdata *                      that's hung off a fd is. * ------------------------------------------------------------------------ */int ConnectInputFd(                   int fd,                   FdCBProc callback,                   const char *callbackName,                   char *clientData){    if(initialized == 0) InitFds();    if(Debug(plumbing))    {        sprintf(msgBuf, "ConnectInputFd(%d, %s, 0x%08x)",                fd, callbackName, clientData);        DEBUG_MESSAGE(msgBuf);    }        /*     * If it's a new slot, bump up the nFds counter.     * If it's an old slot, the old guy loses but nFds stays     * the same.     */    if(ifds[fd].fd == -1)        nFds++;        /*     * Keep track of the biggest one we have on hand     */    if(fd > maxFd)        maxFd = fd;        /*     * Init the various fields     */    ifds[fd].fd           = fd;    ifds[fd].callback     = callback;    ifds[fd].callbackName = callbackName;    ifds[fd].clientData   = clientData;        FD_SET(fd, &readFds);#ifdef TK    if (eventMode == EventMode_Tk)    {        if (Debug(plumbing))        {            sprintf(msgBuf, "Adding fd %d to TK Event list", fd);            DEBUG_MESSAGE(msgBuf);        }        Tk_CreateFileHandler(fd, TK_READABLE, Plumbing_TkInputEvent,                             (ClientData)fd);    }#endif    return(fd);}/* ------------------------------------------------------------------------ *  * ConnectOutputFd()    Allows user to hook a callback to output ready *                      events on a file descriptor. *  * RETURNS:             The file descriptor. * * NOTE:                Clobbers the old output fd to callback association. *                      This is how you change what the callback or clientdata *                      that's hung off a fd is. * ------------------------------------------------------------------------ */int ConnectOutputFd(                    int fd,                    FdCBProc callback,                    const char *callbackName,                    char *clientData){    if(initialized == 0) InitFds();    if(Debug(plumbing))    {        sprintf(msgBuf, "ConnectOuputFd(%d, %s, 0x%08x)",                fd, callbackName, clientData);        DEBUG_MESSAGE(msgBuf);    }        /*     * If it's a new slot, bump up the nFds counter.     * If it's an old slot, the old guy loses but nFds stays     * the same.     */    if(ofds[fd].fd == -1)        nFds++;        /*     * Keep track of the biggest one we have on hand     */    if(fd > maxFd)        maxFd = fd;        /*     * Init the various fields     */    ofds[fd].fd           = fd;    ofds[fd].callback     = callback;    ofds[fd].callbackName = callbackName;    ofds[fd].clientData   = clientData;        FD_SET(fd, &writeFds);    return(fd);}int SetTraceFd(               int fd,               int direction,               int flag){    if(initialized == 0) InitFds();    if(flag == True)    {        if(direction)            ifds[fd].flag |= TraceData;        else            ofds[fd].flag |= TraceData;    }    else    {        if(direction)            ifds[fd].flag &= ~TraceData;        else            ofds[fd].flag &= ~TraceData;    }        return(fd);}int GetTraceFd(               int fd,               int direction){    if(initialized == 0) InitFds();    if(direction)        return(ifds[fd].flag & TraceData);    else        return(ofds[fd].flag & TraceData);}/* ------------------------------------------------------------------------ *  * DisconnectFd()       Detaches the callback from a file descriptor. *  * RETURNS:     The file descriptor. *            * ------------------------------------------------------------------------ */void DisconnectInputFd(int fd){    if(initialized == 0) InitFds();    if(Debug(plumbing))    {        sprintf(msgBuf, "DisconnectInputFd(%d)", fd);        DEBUG_MESSAGE(msgBuf);    }    FD_CLR(fd, &readFds);        ifds[fd].fd       = -1;    ifds[fd].callback = (FdCBProc) 0;#ifdef TK    if (eventMode == EventMode_Tk)    {        if (Debug(plumbing))        {            sprintf(msgBuf, "Removing fd %d from TK Event list", fd);            DEBUG_MESSAGE(msgBuf);        }        Tk_DeleteFileHandler(fd);    }#endif}void DisconnectOutputFd(int fd){    if(initialized == 0) InitFds();    if(Debug(plumbing))    {        sprintf(msgBuf, "DisconnectOutputFd(%d)", fd);        DEBUG_MESSAGE(msgBuf);    }        FD_CLR(fd, &writeFds);        ofds[fd].fd       = -1;    ofds[fd].callback = (FdCBProc) 0;}void DisableInputFd(int fd){    if(initialized == 0) InitFds();    if(Debug(plumbing))    {        sprintf(msgBuf, "DisableInputFd(%d)", fd);        DEBUG_MESSAGE(msgBuf);    }    FD_CLR(fd, &readFds);}void EnableInputFd(int fd){    if(initialized == 0) InitFds();    if(Debug(plumbing))    {        sprintf(msgBuf, "EnableInputFd(%d)", fd);        DEBUG_MESSAGE(msgBuf);    }    FD_SET(fd, &readFds);}void DisableOutputFd(int fd){    if(initialized == 0) InitFds();    if(Debug(plumbing))    {        sprintf(msgBuf, "DisableOutputFd(%d)", fd);        DEBUG_MESSAGE(msgBuf);    }    FD_CLR(fd, &writeFds);}void EnableOutputFd(int fd){    if(initialized == 0) InitFds();    if(Debug(plumbing))    {        sprintf(msgBuf, "EnableOutputFd(%d)", fd);        DEBUG_MESSAGE(msgBuf);    }    FD_SET(fd, &writeFds);}

⌨️ 快捷键说明

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