示例#1
0
void SocketStreamHandle::pacExecutionCallback(void* client, CFArrayRef proxyList, CFErrorRef)
{
    SocketStreamHandle* handle = static_cast<SocketStreamHandle*>(client);
    MainThreadPACCallbackInfo info(handle, proxyList);
    // If we're already on main thread (e.g. on Mac), callOnMainThreadAndWait() will be just a function call.
    callOnMainThreadAndWait(pacExecutionCallbackMainThread, &info);
}
示例#2
0
void SocketStreamHandle::writeStreamCallback(CFWriteStreamRef stream, CFStreamEventType type, void* clientCallBackInfo)
{
    SocketStreamHandle* handle = static_cast<SocketStreamHandle*>(clientCallBackInfo);
    ASSERT_UNUSED(stream, stream == handle->m_writeStream.get());
#if PLATFORM(WIN)
    MainThreadEventCallbackInfo info(type, handle);
    callOnMainThreadAndWait(writeStreamCallbackMainThread, &info);
#else
    ASSERT(isMainThread());
    handle->writeStreamCallback(type);
#endif
}
示例#3
0
DWORD
__stdcall TcpServerWin::ClientLoop(void * data)
{
    SOCKET *serverFd = (SOCKET*)data;

    //CRANK-ME Need to protect the m_state since it called from call backs too.
    // Fixme: 
    //  This thread will not exit until STATE_CLOSE.
    //  STATE_CLOSE will not happen until the destructor is called.
    //  This instance is statically initialized.
    //  On windows, the destructor will not be called until all the threads exits.
    while (!global_inspector_server_done) {
        EnterCriticalSection(&m_stateMutex);
        int state = m_state;
        LeaveCriticalSection(&m_stateMutex);

        switch (state) {
        case STATE_INIT:
        {
            Sleep(2000);
            break;
        }
        case STATE_LISTENING:
        {
            int connectionFd = -1;
            struct timeval tv;
            fd_set rfds;

            memset(&rfds, 0, sizeof(rfds));

            FD_SET(*serverFd, &rfds);

            tv.tv_sec = 1;
            tv.tv_usec = 0;

            int n = select(*serverFd + 1, &rfds, NULL, NULL, &tv);

            ClientAcceptInfo acceptInfo = {0, 0};
            int sizeOfAddress = sizeof(acceptInfo.address);
            if (n > 0)
                acceptInfo.sockfd = accept(*serverFd, &acceptInfo.address, &sizeOfAddress);

            if (acceptInfo.sockfd > 0) {
                //Send Events
//CRANK TF: Let someone know we've got things going on here
#if 0
                WinWebInspectorServerAcceptEvent *event = new WinWebInspectorServerAcceptEvent((int)connectionFd);
                if (event)
                    WebKitSendEvent(event);
                else
                    closesocket(connectionFd);
#else
                callOnMainThreadAndWait(mainThreadAcceptFunction, &acceptInfo);
#endif
            }
            break;
        }
        case STATE_CLOSE:
        {
            printf("TcpServerWin, shutting down\n");
            //closesocket(m_serverFd);
            EnterCriticalSection(&m_stateMutex);
            m_state = STATE_CLOSE;
            LeaveCriticalSection(&m_stateMutex);
            return true;
        }
        default:
        {
            Sleep(2000);
            break;
        }
        }
    }

    //Should never get here ...
    return true;
}