ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

static VOID AcceptConnections ( SOCKET  listeningSocket,
LPTHREAD_START_ROUTINE  lpService,
LPWSTR  lpName 
) [static]

Definition at line 54 of file skelserver.c.

Referenced by StartServer().

{
    SOCKADDR_IN client;
    SOCKET sock;
    HANDLE hThread;
    TIMEVAL timeVal;
    FD_SET readFD;
    WCHAR logBuf[256];
    INT timeOut = 2000;

    timeVal.tv_sec  = timeOut / 1000;
    timeVal.tv_usec = timeOut % 1000;

    while (!bShutdown)
    {
        INT selRet = 0;

        FD_ZERO(&readFD);
        FD_SET(listeningSocket, &readFD);

        selRet = select(0, &readFD, NULL, NULL, &timeVal);
        if (selRet > 0)
        {
            if (!bShutdown || FD_ISSET(listeningSocket, &readFD))
            {
                INT addrSize = sizeof(SOCKADDR_IN);

                sock = accept(listeningSocket, (SOCKADDR*)&client, &addrSize);
                if (sock != INVALID_SOCKET)
                {
                    _swprintf(logBuf,
                              L"Accepted connection to %s server from %S:%d",
                              lpName,
                              inet_ntoa(client.sin_addr),
                              ntohs(client.sin_port));
                    LogEvent(logBuf, 0, 0, LOG_FILE);

                    _swprintf(logBuf, L"Creating worker thread for %s", lpName);
                    LogEvent(logBuf, 0, 0, LOG_FILE);

                    if (!bShutdown)
                    {
                        hThread = CreateThread(0, 0, lpService, (void*)sock, 0, NULL);
                        if (hThread != NULL)
                        {
                            CloseHandle(hThread);
                        }
                        else
                        {
                            _swprintf(logBuf, L"Failed to start worker thread for the %s server",
                                      lpName);
                            LogEvent(logBuf, 0, 0, LOG_FILE);
                        }
                    }
                }
                else
                {
                    LogEvent(L"accept failed", WSAGetLastError(), 0, LOG_ERROR);
                }
            }
        }
        else if (selRet == SOCKET_ERROR)
        {
            LogEvent(L"select failed", WSAGetLastError(), 0, LOG_ERROR);
        }
    }
}

Generated on Sun May 27 2012 04:44:44 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.