예제 #1
0
def main():
    args = get_args()
    connector = get_connector()
    connection, success = connector.connect_waiting(args.host, args.port)
    if success:
        connector.send(connection, args.filename)
        connector.shutdown()
    else:
        print 'could not connect to host=%s, port=%d' % (args.host, args.port)
예제 #2
0
def main():
    args = get_args()
    connector = get_connector()
    connection, success = connector.connect_waiting(args.host, args.port)
    if success:
        connector.send(connection, args.filename)
        connector.shutdown()
    else:
        print "could not connect to host=%s, port=%d" % (args.host, args.port)
예제 #3
0
  def test_disconnect_finish_queue(self):
    converter = _PausingConverter()
    connector = self._get_connector(listening=True, converter=converter)
    connector.run()

    # Listen for the connector.
    listener = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    listener.bind(('', TestConnector._LISTEN_PORT))
    listener.listen(1)

    # The connector should create a half-open connection to the listening socket.
    connection, success = connector.connect_waiting(
        '', TestConnector._LISTEN_PORT)
    self.assertTrue(success)
    # Accept the connection so now a full connection.
    s, addr = listener.accept()

    # Wait for the first message to be partially serialized.
    connector.send(connection, 'ONE')
    converter._wait_for_callback()
    # Enqueue the second message and disconnect.
    connector.send(connection, 'TWO')
    connector.disconnect(connection, now=True)
    # Continue serializing the first message.
    converter._use_callback()

    # Serialize the second message.
    converter._wait_for_callback()
    converter._use_callback()

    # Both messages are sent completely.
    msg = self.recv()
    self.assertEqual(msg.type(), connector.Event.FINISH_DISCONNECT)
    self.assertIsNone(msg.incomplete())
    self.assertFalse(msg.queued())

    # Both messages are received completely.
    all_recv_bytes = self._read_until_closed(s)
    self.assertEqual(all_recv_bytes, 'abcONE123abcTWO123')

    connector.shutdown()
예제 #4
0
    def test_disconnect_finish_queue(self):
        converter = _PausingConverter()
        connector = self._get_connector(listening=True, converter=converter)
        connector.run()

        # Listen for the connector.
        listener = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        listener.bind(('', TestConnector._LISTEN_PORT))
        listener.listen(1)

        # The connector should create a half-open connection to the listening socket.
        connection, success = connector.connect_waiting(
            '', TestConnector._LISTEN_PORT)
        self.assertTrue(success)
        # Accept the connection so now a full connection.
        s, addr = listener.accept()

        # Wait for the first message to be partially serialized.
        connector.send(connection, 'ONE')
        converter._wait_for_callback()
        # Enqueue the second message and disconnect.
        connector.send(connection, 'TWO')
        connector.disconnect(connection, now=True)
        # Continue serializing the first message.
        converter._use_callback()

        # Serialize the second message.
        converter._wait_for_callback()
        converter._use_callback()

        # Both messages are sent completely.
        msg = self.recv()
        self.assertEqual(msg.type(), connector.Event.FINISH_DISCONNECT)
        self.assertIsNone(msg.incomplete())
        self.assertFalse(msg.queued())

        # Both messages are received completely.
        all_recv_bytes = self._read_until_closed(s)
        self.assertEqual(all_recv_bytes, 'abcONE123abcTWO123')

        connector.shutdown()