Commits

Anonymous committed 648adfc

Add definition of struct OVERLAPPED, to be ready to use overlapped io

  • Participants
  • Parent commits 049986b
  • Branches dev

Comments (0)

Files changed (2)

 syntax: glob
 *.pyc
 .*.sw?
+*~

File pypesocketwin.py

 _LPVOID = ctypes.wintypes.LPVOID
 _LPDWORD = _POINTER(ctypes.wintypes.DWORD)
 
+class _OVERLAPPED_INNERS(Structure):
+    _fields_ = [
+        ("Offset",          _DWORD),
+        ("OffsetHigh",      _DWORD),
+    ]
+
+class _OVERLAPPED_INNERU(Union):
+    _fields_ = [
+        ("s",               _OVERLAPPED_INNERS),
+        ("Pointer",         _LPVOID),
+    ]
+    _anonymous_ = ("s",)
+
+class _OVERLAPPED(Structure):
+    _fields_ = [
+        ("Internal",        _POINTER(ULONG)),
+        ("InternalHigh",    _POINTER(ULONG)),
+        ("u",               _OVERLAPPED_INNERU),
+        ("hEvent",          _HANDLE),
+    ]
+    _anonymous_ = ("u",)
+
+_LPOVERLAPPED = _POINTER(_OVERLAPPED)
+
 _TRUE = 1
 _FALSE = 0
 _INVALID_HANDLE_VALUE = _HANDLE(-1).value
 _OPEN_EXISTING = 3
 _PIPE_ACCESS_DUPLEX = 0x3
+_FILE_FLAG_OVERLAPPED = 0x40000000
 _PIPE_TYPE_MESSAGE = 0x4
 _PIPE_READMODE_MESSAGE = 0x2
 _PIPE_WAIT = 0
 _kernel32.CreateNamedPipeA.argtypes = [_LPCSTR, _DWORD, _DWORD, _DWORD,
                                        _DWORD, _DWORD, _DWORD, _LPVOID]
 _kernel32.CreateNamedPipeA.restype = _HANDLE
+_kernel32.ConnectNamedPipe.argtypes = [_HANDLE, _LPOVERLAPPED]
+_kernel32.ConnectNamedPipe.restype = _BOOL
 _kernel32.WriteFile.argtypes = [_HANDLE, _LPVOID, _DWORD, _LPDWORD,
                                  _LPVOID]
 _kernel32.WriteFile.restype = _BOOL
 class _pipesocket(object):
     """Use windows named pipe to simulate unix domain socket"""
 
+    @classmethod
+    def _startdaemon(cls):
+        pass
+
     def accept(self):
         pipe = self._conn.get()
         if not pipe:
                     _byref(mode),
                     None,
                     None):
-                    return str(_kernel32.GetLastError()) # todo: should be meaningful text
+                    return str(_kernel32.GetLastError()) # TODO: should be meaningful text
                 return 0
             # failed to connect, see if server isn't ready
             err = _kernel32.GetLastError()
         def run():
             while True:
                 pipe = _kernel32.CreateNamedPipeA(self._path,
-                    _PIPE_ACCESS_DUPLEX,
+                    _PIPE_ACCESS_DUPLEX | _FILE_FLAG_OVERLAPPED,
                     _PIPE_TYPE_MESSAGE | _PIPE_READMODE_MESSAGE |
                     _PIPE_WAIT,
                     _PIPE_UNLIMITED_INSTANCES,
                 if pipe == _INVALID_HANDLE_VALUE:
                     raise socket.error(str(_kernel32.GetLastError()))
 
-                conn = _kernel32.ConnectNamedPipe(pipe, None)
+                ovlp = _OVERLAPPED()
+
+                conn = _kernel32.ConnectNamedPipe(pipe, _byref(ovlp))
                 if not conn:
                     err = _kernel32.GetLastError()
                     if err != _ERROR_PIPE_CONNECTED: