diff options
author | Christian Pointner <equinox@anytun.org> | 2009-01-19 22:34:18 +0000 |
---|---|---|
committer | Christian Pointner <equinox@anytun.org> | 2009-01-19 22:34:18 +0000 |
commit | 90b6a6771e101ad05e375e5c69ade3e749d1322b (patch) | |
tree | 4db954aeb7de6f1e91cf03ab114897aa4d8ad4be /src/win32 | |
parent | first working version of windows TunDevice (currently only tap) (diff) |
fixed overlapped handling of read and write at windows tundevice
Diffstat (limited to 'src/win32')
-rw-r--r-- | src/win32/tunDevice.cpp | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/src/win32/tunDevice.cpp b/src/win32/tunDevice.cpp index 3049c24..af9b194 100644 --- a/src/win32/tunDevice.cpp +++ b/src/win32/tunDevice.cpp @@ -135,13 +135,13 @@ int TunDevice::read(u_int8_t* buf, u_int32_t len) DWORD err = GetLastError(); if(err == ERROR_IO_PENDING) { WaitForSingleObject(overlapped.hEvent, INFINITE); - if(!GetOverlappedResult(handle_, &overlapped, &lenout, FALSE)) + if(!GetOverlappedResult(handle_, &overlapped, &lenout, FALSE)) { cLog.msg(Log::PRIO_ERR) << "Error while trying to get overlapped result: " << LogErrno(GetLastError()); - - return lenout; + return -1; + } } else - cLog.msg(Log::PRIO_ERR) << "Error while reading from: " << LogErrno(GetLastError()); + cLog.msg(Log::PRIO_ERR) << "Error while reading from device: " << LogErrno(GetLastError()); return -1; } @@ -151,12 +151,26 @@ int TunDevice::read(u_int8_t* buf, u_int32_t len) int TunDevice::write(u_int8_t* buf, u_int32_t len) { DWORD lenout; - OVERLAPPED overlapped = {0}; + OVERLAPPED overlapped; + overlapped.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); + overlapped.Offset = 0; + overlapped.OffsetHigh = 0; +// ResetEvent(overlapped.hEvent); if(!WriteFile(handle_, buf, len, &lenout, &overlapped)) { - cLog.msg(Log::PRIO_ERR) << "Error while writing to device: " << LogErrno(GetLastError()); - return -1; - } + DWORD err = GetLastError(); + if(err == ERROR_IO_PENDING) { + WaitForSingleObject(overlapped.hEvent, INFINITE); + if(!GetOverlappedResult(handle_, &overlapped, &lenout, FALSE)) { + cLog.msg(Log::PRIO_ERR) << "Error while trying to get overlapped result: " << LogErrno(GetLastError()); + return -1; + } + } + else + cLog.msg(Log::PRIO_ERR) << "Error while writing to device: " << LogErrno(GetLastError()); + + return -1; + } return lenout; } |