Changeset ed502d
- Timestamp:
- 12/30/11 14:18:06 (17 months ago)
- Branches:
- ('master', '033cf796174446f5fff5bbfad1cbf1e4af35c0d8')('controller-upgrade', '72b31cc86eeeef18f1371a3067b6e8a5ca21abfc')('windows_service_fixes', 'df6bd2788365991d36d5af2a75833b8de2a5860f')
- Children:
- 72b31cc86eeeef18f1371a3067b6e8a5ca21abfc
- Parents:
- 86554b26ac832b1cd56c33d3731bad312f2177b6
- git-author:
- Carl Nettelblad <cnettel@tele2.se>2011-12-30 14:18:06+01:00
- git-committer:
- Micke Prag <micke.prag@telldus.se>2011-12-30 14:18:06+01:00
- Location:
- telldus-core
- Files:
-
- 2 edited
-
common/Socket_win.cpp (modified) (6 diffs)
-
service/ConnectionListener_win.cpp (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
telldus-core/common/Socket_win.cpp
r86554b red502d 38 38 if (d->hPipe != INVALID_HANDLE_VALUE) { 39 39 CloseHandle(d->hPipe); 40 d->hPipe = 0; 40 41 } 41 42 delete d; … … 90 91 memset(&oOverlap, 0, sizeof(OVERLAPPED)); 91 92 92 d->readEvent = CreateEvent(NULL, TRUE, TRUE, NULL);93 d->readEvent = CreateEvent(NULL, TRUE, FALSE, NULL); 93 94 oOverlap.hEvent = d->readEvent; 94 95 BOOL fSuccess = false; … … 106 107 if(!d->running){ 107 108 CancelIo(d->hPipe); 108 CloseHandle(d->readEvent); 109 WaitForSingleObject(oOverlap.hEvent, INFINITE); 110 d->readEvent = 0; 111 CloseHandle(oOverlap.hEvent); 109 112 return L""; 110 113 } … … 112 115 if (result == WAIT_TIMEOUT) { 113 116 CancelIo(d->hPipe); 114 CloseHandle(d->readEvent); 115 return L""; 117 // Cancel, we still need to cleanup 116 118 } 117 fSuccess = GetOverlappedResult(d->hPipe, &oOverlap, &cbBytesRead, false);119 fSuccess = GetOverlappedResult(d->hPipe, &oOverlap, &cbBytesRead, true); 118 120 119 121 if (!fSuccess) { … … 132 134 returnString.append(buf); 133 135 } 134 CancelIo(d->hPipe);135 CloseHandle( d->readEvent);136 d->readEvent = 0; 137 CloseHandle(oOverlap.hEvent); 136 138 return returnString; 137 139 } … … 142 144 DWORD bytesWritten = 0; 143 145 int result; 144 BOOL fSuccess ;146 BOOL fSuccess = false; 145 147 146 148 memset(&oOverlap, 0, sizeof(OVERLAPPED)); 147 149 148 HANDLE writeEvent = CreateEvent(NULL, TRUE, TRUE, NULL);150 HANDLE writeEvent = CreateEvent(NULL, TRUE, FALSE, NULL); 149 151 oOverlap.hEvent = writeEvent; 150 152 151 WriteFile(d->hPipe, msg.data(), (DWORD)msg.length()*sizeof(wchar_t), &bytesWritten, &oOverlap); 153 BOOL writeSuccess = WriteFile(d->hPipe, msg.data(), (DWORD)msg.length()*sizeof(wchar_t), &bytesWritten, &oOverlap); 154 result = GetLastError(); 155 if (writeSuccess || result == ERROR_IO_PENDING) { 156 result = WaitForSingleObject(writeEvent, 500); 157 if (result == WAIT_TIMEOUT) { 158 CancelIo(d->hPipe); 159 WaitForSingleObject(oOverlap.hEvent, INFINITE); 160 CloseHandle(writeEvent); 161 CloseHandle(d->hPipe); 162 d->hPipe = 0; 163 d->connected = false; 164 return; 165 } 166 fSuccess = GetOverlappedResult(d->hPipe, &oOverlap, &bytesWritten, TRUE); 167 } 152 168 153 result = WaitForSingleObject(writeEvent, 500);154 if (result == WAIT_TIMEOUT) {155 CancelIo(d->hPipe);156 CloseHandle(writeEvent);157 d->connected = false;158 return;159 }160 fSuccess = GetOverlappedResult(d->hPipe, &oOverlap, &bytesWritten, TRUE);161 169 CloseHandle(writeEvent); 162 170 if (!fSuccess) { 163 CancelIo(d->hPipe); 171 CloseHandle(d->hPipe); 172 d->hPipe = 0; 164 173 d->connected = false; 165 174 return; -
telldus-core/service/ConnectionListener_win.cpp
r184d2e red502d 92 92 d->hEvent = CreateEvent(NULL, true, false, NULL); 93 93 oOverlap.hEvent = d->hEvent; 94 bool recreate = true; 94 95 95 96 while (1) { 96 hPipe = CreateNamedPipe( 97 (const wchar_t *)d->pipename.c_str(), // pipe name 98 PIPE_ACCESS_DUPLEX | // read/write access 99 FILE_FLAG_OVERLAPPED, //Overlapped mode 100 PIPE_TYPE_MESSAGE | // message type pipe 101 PIPE_READMODE_MESSAGE | // message-read mode 102 PIPE_WAIT, // blocking mode 103 PIPE_UNLIMITED_INSTANCES, // max. instances 104 BUFSIZE, // output buffer size 105 BUFSIZE, // input buffer size 106 0, // client time-out 107 &d->sa); // default security attribute 97 if (recreate) { 98 hPipe = CreateNamedPipe( 99 (const wchar_t *)d->pipename.c_str(), // pipe name 100 PIPE_ACCESS_DUPLEX | // read/write access 101 FILE_FLAG_OVERLAPPED, //Overlapped mode 102 PIPE_TYPE_MESSAGE | // message type pipe 103 PIPE_READMODE_MESSAGE | // message-read mode 104 PIPE_WAIT, // blocking mode 105 PIPE_UNLIMITED_INSTANCES, // max. instances 106 BUFSIZE, // output buffer size 107 BUFSIZE, // input buffer size 108 0, // client time-out 109 &d->sa); // default security attribute 108 110 109 if (hPipe == INVALID_HANDLE_VALUE) { 110 //TelldusCore::logMessage("Could not create named pipe"); 111 return; 111 if (hPipe == INVALID_HANDLE_VALUE) { 112 return; 113 } 114 115 ConnectNamedPipe(hPipe, &oOverlap); 116 recreate = false; 112 117 } 113 114 ConnectNamedPipe(hPipe, &oOverlap);115 116 118 DWORD result = WaitForSingleObject(oOverlap.hEvent, 1000); 117 119 118 120 if (!d->running) { 121 CancelIo(hPipe); 122 WaitForSingleObject(oOverlap.hEvent, INFINITE); 119 123 break; 120 124 } 121 125 if(result == WAIT_TIMEOUT){ 122 CloseHandle(hPipe);126 //CloseHandle(hPipe); 123 127 continue; 124 128 } … … 130 134 } 131 135 ConnectionListenerEventData *data = new ConnectionListenerEventData(); 136 ResetEvent(oOverlap.hEvent); 132 137 data->socket = new TelldusCore::Socket(hPipe); 133 138 d->waitEvent->signal(data); 139 140 recreate = true; 134 141 } 135 142
Note: See TracChangeset
for help on using the changeset viewer.
