Changeset 7603 for trunk/src


Ignore:
Timestamp:
Dec 10, 2001, 12:29:01 PM (24 years ago)
Author:
sandervl
Message:

overlapped io updates + removed unused network function

Location:
trunk/src/kernel32
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kernel32/network.cpp

    r3804 r7603  
    1 /* $Id: network.cpp,v 1.10 2000-07-06 21:18:43 sandervl Exp $ */
     1/* $Id: network.cpp,v 1.11 2001-12-10 11:28:59 sandervl Exp $ */
    22/*
    33 * Win32 Network apis
     
    6767//******************************************************************************
    6868//******************************************************************************
    69 BOOL WIN32API GetComputerName32W(LPWSTR name, LPDWORD size)
    70 {
    71   LPSTR nameA = NULL;
    72   BOOL  ret;
    73 
    74   if (name) nameA=(LPSTR)malloc(2**size);
    75 
    76   ret = GetComputerNameA(nameA,size);
    77 
    78   if (ret) AsciiToUnicode(nameA, name);
    79 
    80   free(nameA);
    81 
    82   return ret;
    83 }
    84 //******************************************************************************
    85 //******************************************************************************
  • trunk/src/kernel32/overlappedio.cpp

    r7598 r7603  
    1 /* $Id: overlappedio.cpp,v 1.9 2001-12-09 21:55:17 sandervl Exp $ */
     1/* $Id: overlappedio.cpp,v 1.10 2001-12-10 11:29:01 sandervl Exp $ */
    22
    33/*
     
    198198    hEvents[1] = hEventExit;
    199199
    200     while(TRUE) {
     200    while(TRUE)
     201    {
    201202        ret = WaitForMultipleObjects(2, hEvents, FALSE, INFINITE);
    202203        if(ret == WAIT_FAILED) {
     
    209210            break;
    210211        }
    211         ::EnterCriticalSection(&critsect);
    212         if(pending[index] == NULL) {
    213             //oh, oh
     212        //process all pending jobs
     213        while(TRUE)
     214        {
     215            ::EnterCriticalSection(&critsect);
     216            if(pending[index] == NULL) {
     217                ::LeaveCriticalSection(&critsect);
     218                break;
     219            }
     220            lpRequest       = pending[index];
     221            pending[index]  = lpRequest->next;
     222
     223            //add to in process list
     224            lpRequest->next = pending[ASYNC_INDEX_BUSY];
     225            pending[ASYNC_INDEX_BUSY] = lpRequest;
    214226            ::LeaveCriticalSection(&critsect);
    215             dprintf(("!ERROR!: overlapped thread woken up, but no tasks pending!!"));
    216             DebugInt3();
    217             continue;
    218         }
    219         lpRequest       = pending[index];
    220         pending[index]  = lpRequest->next;
    221 
    222         //add to in process list
    223         lpRequest->next = pending[ASYNC_INDEX_BUSY];
    224         pending[ASYNC_INDEX_BUSY] = lpRequest;
    225         ::LeaveCriticalSection(&critsect);
    226 
    227         lpOverlapped = lpRequest->lpOverlapped;;
    228         hHandle      = lpRequest->hHandle;
    229 
    230         switch(dwOperation) {
    231         case ASYNCIO_READ:
    232         case ASYNCIO_READWRITE:
    233             if(lpRequest->dwAsyncType == ASYNCIO_READ || lpWriteHandler == NULL) {
    234                  lpRequest->dwLastError = lpReadHandler(lpRequest, &dwResult, NULL);
    235             }
    236             else lpRequest->dwLastError = lpWriteHandler(lpRequest, &dwResult, NULL);
    237 
    238             lpOverlapped->Internal     = lpRequest->dwLastError;
    239             lpOverlapped->InternalHigh = dwResult;
    240             if(lpRequest->lpdwResult) {
    241                 *lpRequest->lpdwResult = dwResult;
    242             }
    243             if(lpRequest->dwAsyncType == ASYNCIO_READ) {
    244                  dprintf(("ASYNCIO_READ %x finished; result %x, last error %d", lpOverlapped, dwResult, lpRequest->dwLastError));
    245             }
    246             else dprintf(("ASYNCIO_WRITE %x finished; result %x, last error %d", lpOverlapped, dwResult, lpRequest->dwLastError));
    247             //wake up user thread
    248             ::SetEvent(lpOverlapped->hEvent);
    249             break;
    250 
    251         case ASYNCIO_WRITE:
    252             lpRequest->dwLastError = lpWriteHandler(lpRequest, &dwResult, NULL);
    253             lpOverlapped->Internal     = lpRequest->dwLastError;
    254             lpOverlapped->InternalHigh = dwResult;
    255             if(lpRequest->lpdwResult) {
    256                 *lpRequest->lpdwResult = dwResult;
    257             }
    258             dprintf(("ASYNCIO_WRITE %x finished; result %x, last error %d", lpOverlapped, dwResult, lpRequest->dwLastError));
    259             //wake up user thread
    260             ::SetEvent(lpOverlapped->hEvent);
    261             break;
    262 
    263         case ASYNCIO_POLL:
    264             hEventsWait[0] = lpRequest->hEventCancel;
    265             hEventsWait[1] = hEventExit;
    266             ret = WAIT_TIMEOUT;
    267             while(TRUE)
    268             {
    269                 dwTimeOut = 0;
    270                 lpRequest->dwLastError = lpPollHandler(lpRequest, &dwResult, &dwTimeOut);
    271                 if(lpRequest->dwLastError != ERROR_IO_PENDING) {
    272                     break;
     227
     228            lpOverlapped = lpRequest->lpOverlapped;;
     229            hHandle      = lpRequest->hHandle;
     230
     231            switch(dwOperation) {
     232            case ASYNCIO_READ:
     233            case ASYNCIO_READWRITE:
     234            case ASYNCIO_WRITE:
     235                if(lpRequest->dwAsyncType == ASYNCIO_READ || lpWriteHandler == NULL) {
     236                     lpRequest->dwLastError = lpReadHandler(lpRequest, &dwResult, NULL);
    273237                }
    274                 if(dwTimeOut == 0) {
    275                     dprintf(("!ERROR!: lpPollHandler returned timeout 0!!"));
    276                     DebugInt3();
    277                     break;
    278                 }
    279                 //sleep a while to avoid wasting too many cpu cycles; we are woken up when a timeout occurs,
    280                 //when the operation is cancelled or when the process exits
    281                 ret = WaitForMultipleObjects(2, hEventsWait, FALSE, dwTimeOut);
    282                 if(ret != WAIT_TIMEOUT) {
    283                     dprintf(("ASYNCIO_POLL: WaitForSingleObject didn't time out, abort (ret = %x)", ret));
    284                     break;
    285                 }
    286             }
    287             //Don't access the overlapped & result memory when CancelIo was used to cancel the operation
    288             if(ret == WAIT_TIMEOUT)
    289             {
    290                 dprintf(("ASYNCIO_POLL %x: result %x, last error %d", lpOverlapped, dwResult, lpRequest->dwLastError));
     238                else lpRequest->dwLastError = lpWriteHandler(lpRequest, &dwResult, NULL);
     239
    291240                lpOverlapped->Internal     = lpRequest->dwLastError;
    292241                lpOverlapped->InternalHigh = dwResult;
     
    294243                    *lpRequest->lpdwResult = dwResult;
    295244                }
     245#ifdef DEBUG
     246                if(lpRequest->dwAsyncType == ASYNCIO_READ) {
     247                     dprintf(("ASYNCIO_READ %x finished; result %x, last error %d", lpOverlapped, dwResult, lpRequest->dwLastError));
     248                }
     249                else dprintf(("ASYNCIO_WRITE %x finished; result %x, last error %d", lpOverlapped, dwResult, lpRequest->dwLastError));
     250#endif
    296251                //wake up user thread
    297252                ::SetEvent(lpOverlapped->hEvent);
     253                break;
     254
     255            case ASYNCIO_POLL:
     256                hEventsWait[0] = lpRequest->hEventCancel;
     257                hEventsWait[1] = hEventExit;
     258                ret = WAIT_TIMEOUT;
     259                while(TRUE)
     260                {
     261                    dwTimeOut = 0;
     262                    lpRequest->dwLastError = lpPollHandler(lpRequest, &dwResult, &dwTimeOut);
     263                    if(lpRequest->dwLastError != ERROR_IO_PENDING) {
     264                        break;
     265                    }
     266                    if(dwTimeOut == 0) {
     267                        dprintf(("!ERROR!: lpPollHandler returned timeout 0!!"));
     268                        DebugInt3();
     269                        break;
     270                    }
     271                    //sleep a while to avoid wasting too many cpu cycles; we are woken up when a timeout occurs,
     272                    //when the operation is cancelled or when the process exits
     273                    ret = WaitForMultipleObjects(2, hEventsWait, FALSE, dwTimeOut);
     274                    if(ret != WAIT_TIMEOUT) {
     275                        dprintf(("ASYNCIO_POLL: WaitForSingleObject didn't time out, abort (ret = %x)", ret));
     276                        break;
     277                    }
     278                }
     279                //Don't access the overlapped & result memory when CancelIo was used to cancel the operation
     280                if(ret == WAIT_TIMEOUT)
     281                {
     282                    dprintf(("ASYNCIO_POLL %x: result %x, last error %d", lpOverlapped, dwResult, lpRequest->dwLastError));
     283                    lpOverlapped->Internal     = lpRequest->dwLastError;
     284                    lpOverlapped->InternalHigh = dwResult;
     285                    if(lpRequest->lpdwResult) {
     286                        *lpRequest->lpdwResult = dwResult;
     287                    }
     288                    //wake up user thread
     289                    ::SetEvent(lpOverlapped->hEvent);
     290                }
     291                break;
    298292            }
    299             break;
    300         }
    301         //remove from in-process list and delete async request object
    302         findAndRemoveRequest(ASYNC_INDEX_BUSY, hHandle);
    303         delete lpRequest;
     293            //remove from in-process list and delete async request object
     294            findAndRemoveRequest(ASYNC_INDEX_BUSY, hHandle);
     295            delete lpRequest;
     296        } //while(TRUE)
    304297    }
    305298    return 0;
     
    476469    //immediately
    477470    dwLastError = lpPollHandler(lpRequest, &dwResult, &dwTimeOut);
    478     if(dwLastError != ERROR_IO_PENDING) 
     471    if(dwLastError != ERROR_IO_PENDING)
    479472    {
    480473        dprintf(("OverlappedIOHandler::WaitForEvent %x: result %x, last error %d", lpOverlapped, dwResult, dwLastError));
Note: See TracChangeset for help on using the changeset viewer.