Changeset 22:d13fbc745959 in xplcommon
- Timestamp:
- 01/02/13 06:43:16 (12 years ago)
- Branch:
- default
- Phase:
- public
- Location:
- src/xplcommon/win32
- Files:
-
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
src/xplcommon/win32/BufferedStream.cc
r21 r22 64 64 { 65 65 DWORD numRead = 0; 66 overlapped->reset();67 bool result = ReadFile(handle, dest, length, 0, overlapped->get());68 //(overlapped==0) ? &numRead : 0,69 //(overlapped==0) ? 0 : overlapped->get());66 if (overlapped!=0) overlapped->reset(); 67 bool result = ReadFile(handle, dest, length, 68 (overlapped==0) ? &numRead : 0, 69 (overlapped==0) ? 0 : overlapped->get()); 70 70 DWORD error = GetLastError(); 71 if (!result && (overlapped==0 || 72 (error!=ERROR_IO_PENDING && error!=ERROR_IO_INCOMPLETE))) 71 if (!result && 72 (overlapped==0 || 73 (error!=ERROR_IO_PENDING && error!=ERROR_IO_INCOMPLETE))) 73 74 { 74 75 setErrorCode(error); … … 86 87 Overlapped* overlapped) 87 88 { 89 if (overlapped!=0) overlapped->reset(); 88 90 bool result = WriteFile(handle, src, length, 0, 89 91 (overlapped==0) ? 0 : overlapped->get()); 90 92 DWORD error = GetLastError(); 91 if (!result && (overlapped==0 || 92 (error!=ERROR_IO_PENDING && error!=ERROR_IO_INCOMPLETE))) 93 if (!result && 94 (overlapped==0 || 95 (error!=ERROR_IO_PENDING && error!=ERROR_IO_INCOMPLETE))) 93 96 { 94 97 setErrorCode(error); -
src/xplcommon/win32/Completer.h
r21 r22 51 51 protected: 52 52 /** 53 * The overlappable object this completer belongs to. 54 */ 55 Overlappable& overlappable; 56 57 /** 53 58 * The overlapped object. 54 59 */ … … 64 69 * Destroy the completer. 65 70 */ 66 ~Completer();71 virtual ~Completer(); 67 72 68 73 /** … … 88 93 * @see Overlapped::getResult 89 94 */ 90 bool getResult(DWORD& size, HANDLE file); 95 bool getResult(DWORD& size); 96 97 /** 98 * Check whether we are waiting for an overlapped result and if 99 * so, return that. 100 * 101 * @param result will contain the result to return if we are 102 * waiting for an overlapped result. 103 * 104 * @return whether we are waiting for an overlapped result 105 */ 106 bool checkWaitedResult(bool& result); 107 108 /** 109 * Handle the given result coming from an overlapped object. 110 */ 111 virtual void handleWaitedResult(DWORD size) = 0; 91 112 }; 92 113 … … 96 117 97 118 inline Completer::Completer(Overlappable* overlappable) : 119 overlappable(*overlappable), 98 120 overlapped((overlappable->waiter==0) ? 0 : new Overlapped(*overlappable)) 99 121 { … … 130 152 //------------------------------------------------------------------------------ 131 153 132 inline bool Completer::getResult(DWORD& size , HANDLE file)154 inline bool Completer::getResult(DWORD& size) 133 155 { 134 return overlapped!=0 && overlapped->getResult(size, file); 156 return overlapped!=0 && overlapped->getResult(size, overlappable.handle); 157 } 158 159 //------------------------------------------------------------------------------ 160 161 inline bool Completer::checkWaitedResult(bool& result) 162 { 163 if (!isWaited()) { 164 return false; 165 } 166 167 DWORD size = 0; 168 result = getResult(size); 169 170 if (result) { 171 removeFromWaiter(); 172 handleWaitedResult(size); 173 } else if (overlappable.failed()) { 174 removeFromWaiter(); 175 } 176 177 return true; 135 178 } 136 179 -
src/xplcommon/win32/LocalAcceptor.cc
r21 r22 43 43 accepted(false) 44 44 { 45 LocalSocket::setup Name(this->name, name);45 LocalSocket::setupPath(path, name); 46 46 } 47 47 … … 50 50 bool LocalAcceptor::accept() 51 51 { 52 if (failed()) return false; 52 53 if (accepted) return true; 53 54 54 if (isWaited()) { 55 DWORD size = 0; 56 if (getResult(size, socket.handle)) { 57 removeFromWaiter(); 58 accepted = true; 59 return true; 60 } else { 61 if (socket.failed()) { 62 removeFromWaiter(); 63 } 64 return false; 65 } 55 bool result = false; 56 if (checkWaitedResult(result)) { 57 return result; 66 58 } 67 59 68 69 if (!socket.createNamedPipe(name)) { 60 if (!socket.createNamedPipe(path)) { 70 61 return false; 71 62 } 72 63 73 boolresult = socket.connectNamedPipe(overlapped);64 result = socket.connectNamedPipe(overlapped); 74 65 if (result) { 75 66 accepted = true; … … 83 74 //------------------------------------------------------------------------------ 84 75 76 void LocalAcceptor::handleWaitedResult(DWORD /*size*/) 77 { 78 accepted = true; 79 } 80 81 //------------------------------------------------------------------------------ 82 85 83 // Local Variables: 86 84 // mode: C++ -
src/xplcommon/win32/LocalAcceptor.h
r21 r22 57 57 58 58 /** 59 * The nameof the pipe to accept.59 * The path of the pipe to accept. 60 60 */ 61 char name[256];61 char path[256]; 62 62 63 63 /** … … 103 103 104 104 105 protected: 106 /** 107 * Set the indicator of an accepted connection to true. 108 * 109 * @see Completer::handleWaitedResult 110 */ 111 virtual void handleWaitedResult(DWORD size); 112 105 113 private: 106 114 /** … … 128 136 if (!accepted) return 0; 129 137 130 LocalSocket* s = new LocalSocket(waiter, socket.releaseHandle(),131 readingCapacity, writingCapacity);138 LocalSocket* s = new LocalSocket(waiter, socket.releaseHandle(), 139 readingCapacity, writingCapacity); 132 140 accepted = false; 133 141 return s; -
src/xplcommon/win32/LocalClientSocket.cc
r21 r22 38 38 //------------------------------------------------------------------------------ 39 39 40 HANDLE LocalClientSocket::create(const char* name, bool overlapped)41 {42 char buf[256];43 setupName(buf, name);44 45 return CreateFile(buf, GENERIC_READ|GENERIC_WRITE,46 0, 0, OPEN_EXISTING,47 FILE_FLAG_NO_BUFFERING | FILE_FLAG_OVERLAPPED, 0);48 }49 50 //------------------------------------------------------------------------------51 52 40 // Local Variables: 53 41 // mode: C++ -
src/xplcommon/win32/LocalClientSocket.h
r21 r22 51 51 private: 52 52 /** 53 * Create a named pipe for the given user-specified name.54 */55 static HANDLE create(const char* name, bool overlapped);56 57 /**58 53 * The local connector. 59 54 */ -
src/xplcommon/win32/LocalConnector.cc
r21 r22 42 42 bool LocalConnector::connect() 43 43 { 44 printf("LocalConnector::connect0\n");45 44 if (connected) return true; 45 if (failed()) return false; 46 46 47 printf("LocalConnector::connect3\n"); 48 49 HANDLE handle = CreateFile(name, GENERIC_READ|GENERIC_WRITE, 50 0, 0, OPEN_EXISTING, 51 FILE_FLAG_NO_BUFFERING | FILE_FLAG_OVERLAPPED, 0); 52 printf("LocalConnector::connect4\n"); 53 if (handle!=0) { 54 printf("LocalConnector::connect5\n"); 55 socket.handle = handle; 47 if (socket.connect(path)) { 56 48 connected = true; 57 49 return true; 58 50 } else { 59 printf("LocalConnector::connect6\n");60 socket.setErrorCode(GetLastError());61 51 return false; 62 52 } -
src/xplcommon/win32/LocalConnector.h
r21 r22 52 52 53 53 /** 54 * The nameof the pipe to connect to.54 * The path of the pipe to connect to. 55 55 */ 56 char name[256];56 char path[256]; 57 57 58 58 /** … … 105 105 connected(false) 106 106 { 107 LocalSocket::setup Name(this->name, name);107 LocalSocket::setupPath(path, name); 108 108 } 109 109 -
src/xplcommon/win32/LocalServerSocketBase.cc
r21 r22 40 40 //------------------------------------------------------------------------------ 41 41 42 bool LocalServerSocketBase::createNamedPipe(const char* name)42 bool LocalServerSocketBase::createNamedPipe(const char* path) 43 43 { 44 handle = CreateNamedPipe( name, PIPE_ACCESS_DUPLEX |44 handle = CreateNamedPipe(path, PIPE_ACCESS_DUPLEX | 45 45 ((waiter==0) ? 0 : FILE_FLAG_OVERLAPPED), 46 46 PIPE_TYPE_BYTE | PIPE_READMODE_BYTE, … … 59 59 bool LocalServerSocketBase::connectNamedPipe(Overlapped* overlapped) 60 60 { 61 if (overlapped!=0) overlapped->reset(); 61 62 bool result = LocalSocket::connectNamedPipe(handle, overlapped); 62 63 if (!result && overlapped==0) { -
src/xplcommon/win32/LocalServerSocketBase.h
r21 r22 60 60 * this object will be set to the created handle. 61 61 * 62 * @param name the nameof the pipe to create. It should be the63 * final name, not the user-given one.62 * @param path the path of the pipe to create. It should be the 63 * final path, not the user-given name. 64 64 * 65 65 * @return whether the pipe could be created 66 66 */ 67 bool createNamedPipe(const char* name);67 bool createNamedPipe(const char* path); 68 68 69 69 /** -
src/xplcommon/win32/LocalSocket.h
r21 r22 51 51 public: 52 52 /** 53 * Create a concrete pipe namefrom the given user-specified name.53 * Create a concrete pipe path from the given user-specified name. 54 54 * 55 55 * @param dest the destination buffer, which should be at least 56 56 * 256 bytes long. 57 57 */ 58 static void setup Name(char* dest, const char* name);58 static void setupPath(char* dest, const char* name); 59 59 60 60 /** … … 90 90 protected: 91 91 /** 92 * Connect the named pipe with the current handle of this object. 93 * 94 * @return whether the connection succeeded. If not, it may be a 95 * failure, which is then indicated, or it may be an overlapped 96 * operation which needs to wait. 92 * Connect the client socket to the server. 97 93 */ 98 bool connect( Overlapped* overlapped);94 bool connect(const char* path); 99 95 100 96 friend class LocalAcceptor; … … 106 102 //------------------------------------------------------------------------------ 107 103 108 inline void LocalSocket::setup Name(char* dest, const char* name)104 inline void LocalSocket::setupPath(char* dest, const char* name) 109 105 { 110 106 snprintf(dest, 256, "\\\\.\\pipe\\%s", name); … … 134 130 //------------------------------------------------------------------------------ 135 131 136 inline bool LocalSocket::connect( Overlapped* overlapped)132 inline bool LocalSocket::connect(const char* path) 137 133 { 138 bool result = connectNamedPipe(handle, overlapped); 139 if (!result && overlapped==0) { 134 handle = CreateFile(path, GENERIC_READ|GENERIC_WRITE, 135 0, 0, OPEN_EXISTING, 136 FILE_FLAG_NO_BUFFERING | FILE_FLAG_OVERLAPPED, 0); 137 if (handle==0) { 140 138 setErrorCode(GetLastError()); 141 139 } 142 return result; 140 141 return handle!=0; 143 142 } 144 143 -
src/xplcommon/win32/Overlapped.cc
r21 r22 42 42 memset(&overlapped, 0, sizeof(overlapped)); 43 43 overlapped.hEvent = getHandle(); 44 clear(); 44 45 } 45 46 … … 52 53 DWORD error = GetLastError(); 53 54 if (error!=ERROR_IO_PENDING && error!=ERROR_IO_INCOMPLETE) { 54 reset();55 55 setErrorCode(error); 56 56 } 57 } else {58 reset();59 57 } 60 58 return result; -
src/xplcommon/win32/Overlapped.h
r21 r22 62 62 63 63 /** 64 * Reset the overlapped structure and set its event handle. 64 * Reset the overlapped structure and set its event handle. The 65 * event is also cleared. 65 66 */ 66 67 void reset(); … … 100 101 Event(eventFailable) 101 102 { 102 reset();103 103 } 104 104 -
src/xplcommon/win32/ReadingBuffer.cc
r21 r22 48 48 } 49 49 50 if (isWaited()) { 51 DWORD size = 0; 52 if (getResult(size, stream.handle)) { 53 removeFromWaiter(); 54 overlapped->clear(); 55 addLength(size); 56 return true; 57 } else { 58 if (stream.failed()) { 59 overlapped->clear(); 60 removeFromWaiter(); 61 } 62 return false; 63 } 50 bool result = false; 51 if (checkWaitedResult(result)) { 52 return result; 64 53 } 65 54 66 ssize_t result= stream.read(getData(), getCapacity(), overlapped);67 if ( result<0) {55 ssize_t numRead = stream.read(getData(), getCapacity(), overlapped); 56 if (numRead<0) { 68 57 if (!stream.failed()) { 69 58 addTo(stream.getWaiter()); 70 } else {71 overlapped->reset();72 59 } 73 60 } else { 74 overlapped->reset(); 75 addLength(result); 61 addLength(numRead); 76 62 } 77 return result>=0; 63 return numRead>=0; 64 } 65 66 //------------------------------------------------------------------------------ 67 68 void ReadingBuffer::handleWaitedResult(DWORD size) 69 { 70 addLength(size); 78 71 } 79 72 -
src/xplcommon/win32/ReadingBuffer.h
r21 r22 77 77 bool read(); 78 78 79 protected: 80 /** 81 * Set the buffer's length to the given value. 82 * 83 * @see Completer::handleWaitedResult 84 */ 85 virtual void handleWaitedResult(DWORD size); 86 79 87 friend class BufferedStream; 80 88 }; -
src/xplcommon/win32/WritingBuffer.cc
r21 r22 46 46 } 47 47 48 if (isWaited()) { 49 DWORD size = 0; 50 if (getResult(size, stream.handle)) { 51 removeFromWaiter(); 52 overlapped->clear(); 53 reset(); 54 return true; 55 } else { 56 if (stream.failed()) { 57 removeFromWaiter(); 58 overlapped->clear(); 59 } 60 return false; 61 } 48 bool result; 49 if (checkWaitedResult(result)) { 50 return result; 62 51 } 63 52 64 boolresult = stream.write(getData(), getLength(), overlapped);53 result = stream.write(getData(), getLength(), overlapped); 65 54 if (result) { 66 55 reset(); … … 74 63 //------------------------------------------------------------------------------ 75 64 65 void WritingBuffer::handleWaitedResult(DWORD /*size*/) 66 { 67 reset(); 68 } 69 70 //------------------------------------------------------------------------------ 71 76 72 // Local Variables: 77 73 // mode: C++ -
src/xplcommon/win32/WritingBuffer.h
r21 r22 77 77 bool write(); 78 78 79 protected: 80 /** 81 * Reset the buffer to signify that its contents have been written. 82 * 83 * @see Completer::handleWaitedResult 84 */ 85 virtual void handleWaitedResult(DWORD size); 86 79 87 friend class BufferedStream; 80 88 };
Note:
See TracChangeset
for help on using the changeset viewer.