Changeset 7550 for trunk/src/kernel32


Ignore:
Timestamp:
Dec 5, 2001, 7:06:02 PM (24 years ago)
Author:
sandervl
Message:

overlapped io updates

Location:
trunk/src/kernel32
Files:
15 edited

Legend:

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

    r7549 r7550  
    1 /* $Id: Fileio.cpp,v 1.58 2001-12-05 14:15:55 sandervl Exp $ */
     1/* $Id: Fileio.cpp,v 1.59 2001-12-05 18:05:58 sandervl Exp $ */
    22
    33/*
     
    679679      return TRUE;
    680680  }
     681  if(!lpOverlapped || !lpCompletionRoutine) {
     682      dprintf(("!WARNING!: !lpOverlapped || !lpCompletionRoutine"));
     683      SetLastError(ERROR_INVALID_PARAMETER);
     684      return FALSE;
     685  }
     686  //SDK docs say ReadFileEx will fail if this condition is true
     687  if(GetFileType(hFile) == FILE_TYPE_PIPE && (lpOverlapped->Offset || lpOverlapped->OffsetHigh)) {
     688      dprintf(("!WARNING!: lpOverlapped->Offset & lpOverlapped->OffsetHigh must be ZERO for named pipes"));
     689      SetLastError(ERROR_INVALID_PARAMETER);
     690      return FALSE;
     691  }
    681692  return (HMReadFile(hFile,
    682693                     lpBuffer,
     
    739750      return TRUE;
    740751  }
    741 
     752  if(!lpOverlapped || !lpCompletionRoutine) {
     753      dprintf(("!WARNING!: !lpOverlapped || !lpCompletionRoutine"));
     754      SetLastError(ERROR_INVALID_PARAMETER);
     755      return FALSE;
     756  }
     757  //SDK docs say WriteFileEx will fail if this condition is true
     758  if(GetFileType(hFile) == FILE_TYPE_PIPE && (lpOverlapped->Offset || lpOverlapped->OffsetHigh)) {
     759      dprintf(("!WARNING!: lpOverlapped->Offset & lpOverlapped->OffsetHigh must be ZERO for named pipes"));
     760      SetLastError(ERROR_INVALID_PARAMETER);
     761      return FALSE;
     762  }
    742763  return (HMWriteFile(hFile,
    743764                      (LPVOID)lpBuffer,
  • trunk/src/kernel32/conbuffer.cpp

    r7549 r7550  
    1 /* $Id: conbuffer.cpp,v 1.16 2001-12-05 14:15:56 sandervl Exp $ */
     1/* $Id: conbuffer.cpp,v 1.17 2001-12-05 18:05:59 sandervl Exp $ */
    22
    33/*
     
    276276#endif
    277277
    278                       /* check if we're called with non-existing line buffer */
     278  if(lpCompletionRoutine) {
     279      dprintf(("!WARNING!: lpCompletionRoutine not supported -> fall back to sync IO"));
     280  }
     281
     282  /* check if we're called with non-existing line buffer */
    279283  if (pConsoleBuffer->ppszLine == NULL) {
    280284    SetLastError(ERROR_OUTOFMEMORY_W);
  • trunk/src/kernel32/conbuffervio.cpp

    r7549 r7550  
    1 /* $Id: conbuffervio.cpp,v 1.5 2001-12-05 14:15:57 sandervl Exp $ */
     1/* $Id: conbuffervio.cpp,v 1.6 2001-12-05 18:05:59 sandervl Exp $ */
    22
    33/*
     
    120120#endif
    121121
     122  if(lpCompletionRoutine) {
     123      dprintf(("!WARNING!: lpCompletionRoutine not supported -> fall back to sync IO"));
     124  }
     125
    122126  /* check if we're called with non-existing line buffer */
    123127  if (pConsoleBuffer->ppszLine == NULL) {
  • trunk/src/kernel32/conin.cpp

    r7549 r7550  
    1 /* $Id: conin.cpp,v 1.16 2001-12-05 14:15:58 sandervl Exp $ */
     1/* $Id: conin.cpp,v 1.17 2001-12-05 18:05:59 sandervl Exp $ */
    22
    33/*
     
    141141           lpOverlapped);
    142142#endif
     143
     144  if(lpCompletionRoutine) {
     145      dprintf(("!WARNING!: lpCompletionRoutine not supported -> fall back to sync IO"));
     146  }
    143147
    144148  ulCounter = 0;                              /* read ascii chars from queue */
  • trunk/src/kernel32/conout.cpp

    r7549 r7550  
    1 /* $Id: conout.cpp,v 1.13 2001-12-05 14:15:58 sandervl Exp $ */
     1/* $Id: conout.cpp,v 1.14 2001-12-05 18:06:00 sandervl Exp $ */
    22
    33/*
     
    249249#endif
    250250
    251         /* just prevent an endless loop, although this condition might never */
    252                                                                 /* be true ! */
     251  if(lpCompletionRoutine) {
     252      dprintf(("!WARNING!: lpCompletionRoutine not supported -> fall back to sync IO"));
     253  }
     254
     255  /* just prevent an endless loop, although this condition might never */
     256  /* be true ! */
    253257  if (pHMHandleData->hHMHandle != pConsoleGlobals->hConsoleBuffer)
    254258  {
  • trunk/src/kernel32/hmcomm.cpp

    r7549 r7550  
    1 /* $Id: hmcomm.cpp,v 1.26 2001-12-05 14:15:59 sandervl Exp $ */
     1/* $Id: hmcomm.cpp,v 1.27 2001-12-05 18:06:00 sandervl Exp $ */
    22
    33/*
     
    323323    dprintf(("Warning: lpOverlapped != NULL & !FILE_FLAG_OVERLAPPED; sync operation"));
    324324  }
     325  if(lpCompletionRoutine) {
     326      dprintf(("!WARNING!: lpCompletionRoutine not supported -> fall back to sync IO"));
     327  }
     328
    325329//testestestest
    326330  dprintf2(("Bytes to write:"));
     
    384388  if(!(pHMHandleData->dwFlags & FILE_FLAG_OVERLAPPED) && lpOverlapped) {
    385389    dprintf(("!WARNING!: lpOverlapped != NULL & !FILE_FLAG_OVERLAPPED; sync operation"));
     390  }
     391
     392  if(lpCompletionRoutine) {
     393      dprintf(("!WARNING!: lpCompletionRoutine not supported -> fall back to sync IO"));
    386394  }
    387395
  • trunk/src/kernel32/hmdisk.cpp

    r7549 r7550  
    1 /* $Id: hmdisk.cpp,v 1.34 2001-12-05 14:16:00 sandervl Exp $ */
     1/* $Id: hmdisk.cpp,v 1.35 2001-12-05 18:06:00 sandervl Exp $ */
    22
    33/*
     
    12111211  }
    12121212
     1213  if(lpCompletionRoutine) {
     1214      dprintf(("!WARNING!: lpCompletionRoutine not supported -> fall back to sync IO"));
     1215  }
     1216
    12131217  //If we didn't get an OS/2 handle for the disk before, get one now
    12141218  if(!pHMHandleData->hHMHandle) {
     
    13681372    dprintf(("Warning: lpOverlapped != NULL & !FILE_FLAG_OVERLAPPED; sync operation"));
    13691373  }
     1374  if(lpCompletionRoutine) {
     1375      dprintf(("!WARNING!: lpCompletionRoutine not supported -> fall back to sync IO"));
     1376  }
    13701377
    13711378  //If we didn't get an OS/2 handle for the disk before, get one now
  • trunk/src/kernel32/hmfile.cpp

    r7549 r7550  
    1 /* $Id: hmfile.cpp,v 1.32 2001-12-05 14:16:01 sandervl Exp $ */
     1/* $Id: hmfile.cpp,v 1.33 2001-12-05 18:06:01 sandervl Exp $ */
    22
    33/*
     
    464464    dprintf(("Warning: lpOverlapped != NULL & !FILE_FLAG_OVERLAPPED; sync operation"));
    465465  }
     466  if(lpCompletionRoutine) {
     467      dprintf(("!WARNING!: lpCompletionRoutine not supported -> fall back to sync IO"));
     468  }
    466469
    467470  //SvL: DosRead doesn't like writing to memory addresses returned by
  • trunk/src/kernel32/hmmailslot.cpp

    r7549 r7550  
    1 /* $Id: hmmailslot.cpp,v 1.6 2001-12-05 14:16:01 sandervl Exp $
     1/* $Id: hmmailslot.cpp,v 1.7 2001-12-05 18:06:01 sandervl Exp $
    22 *
    33 * Win32 mailslot APIs
     
    368368             lpNumberOfBytesRead, lpOverlapped));
    369369
     370    if(lpCompletionRoutine) {
     371        dprintf(("!WARNING!: lpCompletionRoutine not supported -> fall back to sync IO"));
     372    }
     373
    370374    if(lpNumberOfBytesRead)
    371375        *lpNumberOfBytesRead = 0;
     
    417421             lpNumberOfBytesWritten, lpOverlapped));
    418422
     423    if(lpCompletionRoutine) {
     424        dprintf(("!WARNING!: lpCompletionRoutine not supported -> fall back to sync IO"));
     425    }
     426
    419427    if(lpNumberOfBytesWritten)
    420428        *lpNumberOfBytesWritten = 0;
  • trunk/src/kernel32/hmnul.cpp

    r7549 r7550  
    1 /* $Id: hmnul.cpp,v 1.2 2001-12-05 14:16:02 sandervl Exp $ */
     1/* $Id: hmnul.cpp,v 1.3 2001-12-05 18:06:01 sandervl Exp $ */
    22
    33/*
     
    131131    dprintf(("Warning: lpOverlapped != NULL & !FILE_FLAG_OVERLAPPED; sync operation"));
    132132  }
     133
     134  if(lpCompletionRoutine) {
     135      dprintf(("!WARNING!: lpCompletionRoutine not supported -> fall back to sync IO"));
     136  }
    133137 
    134138  // this is real NUL I/O
     
    189193    dprintf(("Warning: lpOverlapped != NULL & !FILE_FLAG_OVERLAPPED; sync operation"));
    190194  }
     195
     196  if(lpCompletionRoutine) {
     197      dprintf(("!WARNING!: lpCompletionRoutine not supported -> fall back to sync IO"));
     198  }
    191199 
    192200  // this is real NUL I/O
  • trunk/src/kernel32/hmparport.cpp

    r7549 r7550  
    1 /* $Id: hmparport.cpp,v 1.16 2001-12-05 14:16:04 sandervl Exp $ */
     1/* $Id: hmparport.cpp,v 1.17 2001-12-05 18:06:02 sandervl Exp $ */
    22
    33/*
     
    352352    dprintf(("Warning: lpOverlapped != NULL & !FILE_FLAG_OVERLAPPED; sync operation"));
    353353  }
     354  if(lpCompletionRoutine) {
     355      dprintf(("!WARNING!: lpCompletionRoutine not supported -> fall back to sync IO"));
     356  }
    354357
    355358  ret = OSLibDosWrite(pHMHandleData->hHMHandle, (LPVOID)lpBuffer, nNumberOfBytesToWrite,
     
    407410  if(!(pHMHandleData->dwFlags & FILE_FLAG_OVERLAPPED) && lpOverlapped) {
    408411    dprintf(("Warning: lpOverlapped != NULL & !FILE_FLAG_OVERLAPPED; sync operation"));
     412  }
     413  if(lpCompletionRoutine) {
     414      dprintf(("!WARNING!: lpCompletionRoutine not supported -> fall back to sync IO"));
    409415  }
    410416
  • trunk/src/kernel32/hmstd.cpp

    r7549 r7550  
    1 /* $Id: hmstd.cpp,v 1.6 2001-12-05 14:16:05 sandervl Exp $ */
     1/* $Id: hmstd.cpp,v 1.7 2001-12-05 18:06:02 sandervl Exp $ */
    22
    33/*
     
    8282           lpOverlapped));
    8383
     84  if(lpCompletionRoutine) {
     85      dprintf(("!WARNING!: lpCompletionRoutine not supported -> fall back to sync IO"));
     86  }
    8487
    8588  if(lpNumberOfBytesRead == NULL) {
     
    130133     lpNumberOfBytesWritten = &byteswritten;
    131134  }
     135  if(lpCompletionRoutine) {
     136      dprintf(("!WARNING!: lpCompletionRoutine not supported -> fall back to sync IO"));
     137  }
     138
    132139  if(pHMHandleData->dwUserData == STD_INPUT_HANDLE) {
    133140     return FALSE;
  • trunk/src/kernel32/kernel32.mak

    r7480 r7550  
    1 # $Id: kernel32.mak,v 1.19 2001-11-29 10:31:07 phaller Exp $
     1# $Id: kernel32.mak,v 1.20 2001-12-05 18:06:02 sandervl Exp $
    22
    33#
     
    1717WRC_PREFIX_RESOURCE=1
    1818!include ../../makefile.inc
    19 
    2019
    2120#
     
    7170$(OBJDIR)\hmopen32.obj \
    7271$(OBJDIR)\hmobjects.obj \
     72$(OBJDIR)\overlappedio.obj \
    7373$(OBJDIR)\hmevent.obj \
    7474$(OBJDIR)\hmfile.obj \
  • trunk/src/kernel32/mmap.h

    r5011 r7550  
    1 /* $Id: mmap.h,v 1.19 2001-01-22 18:26:51 sandervl Exp $ */
     1/* $Id: mmap.h,v 1.20 2001-12-05 18:06:02 sandervl Exp $ */
    22
    33/*
     
    107107private:
    108108   static Win32MemMap *memmaps;
    109       Win32MemMap *next;
     109          Win32MemMap *next;
    110110};
    111111//******************************************************************************
  • trunk/src/kernel32/overlappedio.cpp

    r7549 r7550  
    1 /* $Id: overlappedio.cpp,v 1.1 2001-12-05 14:16:38 sandervl Exp $ */
     1/* $Id: overlappedio.cpp,v 1.2 2001-12-05 18:06:02 sandervl Exp $ */
    22
    33/*
     4 * Win32 overlapped IO class
     5 *
     6 * Copyright 2001 Sander van Leeuwen <sandervl@xs4all.nl>
     7 *
    48 * Project Odin Software License can be found in LICENSE.TXT
    5  *
    6  * Win32 COM device access class
    7  *
    8  * 1999 Achim Hasenmueller <achimha@innotek.de>
    9  * 2001 Sander van Leeuwen <sandervl@xs4all.nl>
    10  *
    11  * TODO: Overlapped IO only supports one request at a time
    12  * TODO: Overlapped IO not thread safe
    139 *
    1410 */
     
    1915#include <string.h>
    2016#include <handlemanager.h>
    21 #include "handlenames.h"
    2217#include <heapstring.h>
    23 #include "hmdevice.h"
    24 #include "hmcomm.h"
     18#include "overlappedio.h"
    2519#include "oslibdos.h"
    2620
     
    2923
    3024
    31 DWORD CALLBACK OverlappedIOEventThread(LPVOID lpThreadParam);
    32 DWORD CALLBACK OverlappedIOReadWriteThread(LPVOID lpThreadParam);
    33 
    34 //******************************************************************************
    35 //******************************************************************************
    36 
    37 
    38 //******************************************************************************
    39 //******************************************************************************
     25//******************************************************************************
     26//******************************************************************************
     27OverlappedIOHandler::OverlappedIOHandler(LPOVERLAPPED_HANDLER lpReadHandler,
     28                                         LPOVERLAPPED_HANDLER lpWriteHandler,
     29                                         LPOVERLAPPED_HANDLER lpPollHandler) :
     30                   hThreadRead(0), hThreadWrite(0), hThreadPoll(0)
     31{
     32    OverlappedIOError errcode = OutOfMemory;
     33
     34    pending                  = NULL;
     35    this->lpReadHandler      = lpReadHandler;
     36    this->lpWriteHandler     = lpWriteHandler;
     37    this->lpPollHandler      = lpPollHandler;
     38
     39    ::InitializeCriticalSection(&critsect);
     40    hEventPoll   = ::CreateEventA(NULL, TRUE, FALSE, NULL);
     41    hEventRead   = ::CreateEventA(NULL, TRUE, FALSE, NULL);
     42    hEventWrite  = ::CreateEventA(NULL, TRUE, FALSE, NULL);
     43    hEventExit   = ::CreateEventA(NULL, TRUE, FALSE, NULL);
     44    if(!hEventPoll || !hEventRead || !hEventWrite || !hEventExit)
     45    {
     46        DebugInt3();
     47        errcode = EventCreationFailed;
     48        goto failed;
     49    }
     50   
     51    DWORD dwThreadId;
     52    LPOVERLAPPED_THREAD_PARAM threadparam;
     53
     54    threadparam = (LPOVERLAPPED_THREAD_PARAM)malloc(sizeof(OVERLAPPED_THREAD_PARAM));
     55    if(!threadparam) goto outofmem;
     56
     57    threadparam->fEvent          = (lpWriteHandler) ? EVENT_READ : EVENT_READWRITE;
     58    threadparam->lpOverlappedObj = this;
     59    hThreadRead  = ::CreateThread(NULL, 32*1024, OverlappedIOThread, (LPVOID)threadparam, 0, &dwThreadId);
     60    if(lpWriteHandler) {
     61        threadparam = (LPOVERLAPPED_THREAD_PARAM)malloc(sizeof(OVERLAPPED_THREAD_PARAM));
     62        if(!threadparam) goto outofmem;
     63        threadparam->fEvent          = EVENT_WRITE;
     64        threadparam->lpOverlappedObj = this;
     65        hThreadWrite = ::CreateThread(NULL, 32*1024, OverlappedIOThread, (LPVOID)threadparam, 0, &dwThreadId);
     66    }
     67
     68    if(lpPollHandler) {
     69        threadparam = (LPOVERLAPPED_THREAD_PARAM)malloc(sizeof(OVERLAPPED_THREAD_PARAM));
     70        if(!threadparam) goto outofmem;
     71        threadparam->fEvent          = EVENT_POLL;
     72        threadparam->lpOverlappedObj = this;
     73        hThreadPoll  = ::CreateThread(NULL, 32*1024, OverlappedIOThread, (LPVOID)threadparam, 0, &dwThreadId);
     74    }
     75
     76    if((lpPollHandler && !hThreadPoll) || !hThreadRead || (lpWriteHandler && !hThreadWrite))
     77    {
     78        DebugInt3();
     79        errcode = ThreadCreationFailed;
     80        goto failed;
     81    }
     82    return;
     83
     84outofmem:
     85    errcode = OutOfMemory;
     86    //fall through
     87failed:
     88    //SvL: NOTE: We might not failed gracefully when threads have already been
     89    //           created. (thread accessing memory that has been freed)
     90    //           Don't feel like wasting time to fix this as this should never
     91    //           happen anyway.
     92    if(hEventExit) {
     93        ::SetEvent(hEventExit);
     94        ::CloseHandle(hEventExit);
     95    }
     96
     97    if(hEventRead)   ::CloseHandle(hEventRead);
     98    if(hEventWrite)  ::CloseHandle(hEventWrite);
     99    if(hEventPoll)   ::CloseHandle(hEventPoll);
     100
     101    if(hThreadRead)  ::CloseHandle(hThreadRead);
     102    if(hThreadPoll)  ::CloseHandle(hThreadPoll);
     103    if(hThreadWrite) ::CloseHandle(hThreadWrite);
     104    ::DeleteCriticalSection(&critsect);
     105
     106    throw(errcode);
     107}
     108//******************************************************************************
     109//******************************************************************************
     110OverlappedIOHandler::~OverlappedIOHandler()
     111{
     112    dprintf(("~OverlappedIOHandler: signalling overlapped serial threads"));
     113    ::SetEvent(hEventExit);
     114
     115    ::CloseHandle(hEventExit);
     116    ::CloseHandle(hEventRead);
     117    ::CloseHandle(hEventWrite);
     118    ::CloseHandle(hEventPoll);
     119
     120    ::CloseHandle(hThreadRead);
     121    if(hThreadPoll)  ::CloseHandle(hThreadPoll);
     122    if(hThreadWrite) ::CloseHandle(hThreadWrite);
     123
     124    DeleteCriticalSection(&critsect);
     125}
     126//******************************************************************************
     127//******************************************************************************
     128DWORD CALLBACK OverlappedIOThread(LPVOID lpThreadParam)
     129{
     130    LPOVERLAPPED_THREAD_PARAM threadparam = (LPOVERLAPPED_THREAD_PARAM)lpThreadParam;
     131    DWORD fEvent;
     132    OverlappedIOHandler *lpOverlappedObj;
     133
     134    if(threadparam == NULL) {
     135        DebugInt3();
     136        return 0;
     137    }
     138    lpOverlappedObj = threadparam->lpOverlappedObj;
     139    fEvent          = threadparam->fEvent;
     140    //free thread parameter first
     141    free(threadparam);
     142
     143    return lpOverlappedObj->threadHandler(fEvent);
     144}
     145//******************************************************************************
     146//******************************************************************************
     147DWORD OverlappedIOHandler::threadHandler(DWORD fEvent)
     148{
     149    HANDLE hEvents[2];
     150    DWORD  ret;
     151
     152    dprintf(("OverlappedIOThread: started for event %d", fEvent));
     153    switch(fEvent) {
     154    case EVENT_READ:
     155    case EVENT_READWRITE:
     156        hEvents[0] = hEventRead;
     157        break;
     158
     159    case EVENT_WRITE:
     160        hEvents[0] = hEventWrite;
     161        break;
     162
     163    case EVENT_POLL:
     164        hEvents[0] = hEventPoll;
     165        break;
     166    default:
     167        DebugInt3();
     168    }
     169    hEvents[1] = hEventExit;
     170
     171    while(TRUE) {
     172        ret = WaitForMultipleObjects(2, hEvents, FALSE, INFINITE);
     173        if(ret == WAIT_FAILED) {
     174            dprintf(("!WARNING!: WaitForMultipleObjects -> WAIT_FAILED!"));
     175            break;
     176        }
     177        if(ret == WAIT_FAILED) {
     178            dprintf(("!WARNING!: WaitForMultipleObjects -> WAIT_FAILED!"));
     179            break;
     180        }
     181        //if hEventExit has been signalled, then we are told to exit
     182        if(ret == (WAIT_OBJECT_0+1)) {
     183            dprintf(("end of threadHandler signalled"));
     184            break;
     185        }
     186    }
     187    return 0;
     188}
     189//******************************************************************************
     190//******************************************************************************
     191BOOL OverlappedIOHandler::WriteFile(HANDLE        hOS2Handle,
     192                                    LPCVOID       lpBuffer,
     193                                    DWORD         nNumberOfBytesToWrite,
     194                                    LPDWORD       lpNumberOfBytesWritten,
     195                                    LPOVERLAPPED  lpOverlapped,
     196                                    LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine)
     197{
     198    return FALSE;
     199}
     200//******************************************************************************
     201//******************************************************************************
     202BOOL OverlappedIOHandler::ReadFile(HANDLE        hOS2Handle,
     203                                   LPCVOID       lpBuffer,
     204                                   DWORD         nNumberOfBytesToRead,
     205                                   LPDWORD       lpNumberOfBytesRead,
     206                                   LPOVERLAPPED  lpOverlapped,
     207                                   LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine)
     208{
     209    return FALSE;
     210}
     211//******************************************************************************
     212//******************************************************************************
     213BOOL OverlappedIOHandler::CancelIo(HANDLE hOS2Handle)
     214{
     215    return FALSE;
     216}
     217//******************************************************************************
     218//******************************************************************************
     219BOOL OverlappedIOHandler::GetOverlappedResult(HANDLE        hOS2Handle,
     220                                              LPOVERLAPPED  lpoOverlapped,
     221                                              LPDWORD       lpcbTransfer,
     222                                              DWORD         dwTimeout)
     223{
     224    return FALSE;
     225}
     226//******************************************************************************
     227//******************************************************************************
Note: See TracChangeset for help on using the changeset viewer.