def testCompletionPortsNonQueued(self, test_overlapped_death = 0):
        # In 204 we had a reference count bug when OVERLAPPED objects were
        # associated with a completion port other than via
        # PostQueuedCompletionStatus.  This test is based on the reproduction
        # reported with that bug.
        # Create the pipe.
        BUFSIZE = 512
        pipe_name = r"\\.\pipe\pywin32_test_pipe"
        handle = win32pipe.CreateNamedPipe(pipe_name,
                          win32pipe.PIPE_ACCESS_DUPLEX|
                          win32file.FILE_FLAG_OVERLAPPED,
                          win32pipe.PIPE_TYPE_MESSAGE|
                          win32pipe.PIPE_READMODE_MESSAGE|
                          win32pipe.PIPE_WAIT,
                          1, BUFSIZE, BUFSIZE,
                          win32pipe.NMPWAIT_WAIT_FOREVER,
                          None)
        # Create an IOCP and associate it with the handle.        
        port = win32file.CreateIoCompletionPort(-1, 0, 0, 0)
        win32file.CreateIoCompletionPort(handle, port, 1, 0)

        thread = threading.Thread(target=self._IOCPServerThread, args=(handle,port, test_overlapped_death))
        thread.start()
        try:
            time.sleep(0.1) # let thread do its thing.
            try:
                win32pipe.CallNamedPipe(r"\\.\pipe\pywin32_test_pipe", "Hello there", BUFSIZE, 0)
            except win32pipe.error:
                # Testing for overlapped death causes this
                if not test_overlapped_death:
                    raise
        finally:
            handle.Close()
            thread.join()
Esempio n. 2
0
 def login(self, credentials):
     PIPE_NAME = "\\\\.\\pipe\\VDSMDPipe"
     BUFSIZE = 1024
     RETIRES = 3
     try:
         self._performSAS()
     except Exception:
         logging.warning("Failed to perform SAS", exc_info=True)
     try:
         retries = 1
         while retries <= RETIRES:
             try:
                 time.sleep(1)
                 win32pipe.CallNamedPipe(PIPE_NAME, credentials, BUFSIZE,
                                         win32pipe.NMPWAIT_WAIT_FOREVER)
                 logging.debug("Credentials were written to pipe.")
                 break
             except:
                 error = windll.kernel32.GetLastError()
                 logging.error(
                     "Error writing credentials to pipe [%d/%d] "
                     "(error = %d)", retries, RETIRES, error)
                 retries += 1
     except:
         logging.exception("Error occurred during user login.")
Esempio n. 3
0
    def testCallNamedPipe(self):
        event = threading.Event()
        self.startPipeServer(event)

        got = win32pipe.CallNamedPipe(self.pipename, str2bytes("foo\0bar"), 1024, win32pipe.NMPWAIT_WAIT_FOREVER)
        self.failUnlessEqual(got, str2bytes("bar\0foo"))
        event.wait(5)
        self.failUnless(event.isSet(), "Pipe server thread didn't terminate")
Esempio n. 4
0
 def login(self, credentials):
     PIPE_NAME = "\\\\.\\pipe\\VDSMDPipe"
     BUFSIZE = 1024
     RETIRES = 3
     try:
         if find_library('sas') is not None:
             logging.debug("Simulating a secure attention sequence (SAS).")
             windll.sas.SendSAS(0)
         retries = 1
         while retries <= RETIRES:
             try:
                 time.sleep(1)
                 win32pipe.CallNamedPipe(PIPE_NAME, credentials, BUFSIZE,
                                         win32pipe.NMPWAIT_WAIT_FOREVER)
                 logging.debug("Credentials were written to pipe.")
                 break
             except:
                 error = windll.kernel32.GetLastError()
                 logging.error(
                     "Error writing credentials to pipe [%d/%d] "
                     "(error = %d)", retries, RETIRES, error)
                 retries += 1
     except:
         logging.exception("Error occurred during user login.")
Esempio n. 5
0
# sell copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.

import winerror
import win32pipe
import win32file
import win32api
import sys
import pywintypes
import time

if len(sys.argv) != 2:
    print("Usage: %s message" % sys.argv[0])
    sys.exit(1)

message = "[%05.3f %s]: %s" % (time.time() % 100000, sys.argv[0], sys.argv[1])

win32pipe.CallNamedPipe("\\\\.\\pipe\\DebugServer", message.encode(), 16,
                        win32pipe.NMPWAIT_WAIT_FOREVER)
Esempio n. 6
0
# PipeServiceClient.py
#
# A client for testing the PipeService.
#
# Usage:
#
#   PipeServiceClient.py message

import win32pipe
import sys
import string

if __name__ == '__main__':
    message = string.join(sys.argv[1:])
    pipeName = "\\\\.\\pipe\\PyPipeService"
    data = win32pipe.CallNamedPipe(pipeName, message, 512, 0)
    print "The service sent back:"
    print data
Esempio n. 7
0
    def serve(self):
        print "Got connection"
        win32file.WriteFile(self.handle, 'Hello!\n')
        while 1:
            data = win32file.ReadFile(self.handle, BUFSIZE)[1]
            print "Got data: %r" % data
            if not data[:4] == 'tran':
                win32file.WriteFile(self.handle, data)
            print "Sent data"
            if data[:4] == 'quit':
                break

    def __del__(self):
        win32pipe.DisconnectNamedPipe(self.handle)

if __name__ == '__main__':
    import sys
    if 's' in sys.argv:
        svc = PipeService()
        iocp = Iocp(svc)
        if 'bug' in sys.argv:
            iocp.wait_buggy()
        else:
            iocp.wait_good()
        svc.serve()
    elif 'c' in sys.argv:
        print win32pipe.CallNamedPipe(PIPE, "Hello there", BUFSIZE, 0)

        
Esempio n. 8
0
 def call(cls, name, data, inBufferSize, timeOut = win32pipe.NMPWAIT_USE_DEFAULT_WAIT, \
          path = '', host = PIPE_LOCALHOST):
     pipeName = cls.getCanoicalName(host, path, name)
     result = win32pipe.CallNamedPipe(pipeName, data, inBufferSize, timeOut)
     return result