summaryrefslogtreecommitdiff
path: root/doc/curlmultiobject.rst
blob: ab8c40d9ef95239031e18d6a0f2db1acfd739d36 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
.. _curlmultiobject:

CurlMulti Object
================

.. autoclass:: pycurl.CurlMulti

    CurlMulti objects have the following methods:
    
    .. method:: close() -> None

        Corresponds to `curl_multi_cleanup`_ in libcurl. This method is
        automatically called by pycurl when a CurlMulti object no longer has
        any references to it, but can also be called explicitly.

    .. method:: perform() -> tuple of status and the number of active Curl objects

        Corresponds to `curl_multi_perform`_ in libcurl.

    .. method:: add_handle(Curl object)  -> None

        Corresponds to `curl_multi_add_handle`_ in libcurl. This method adds an
        existing and valid Curl object to the CurlMulti object.

        IMPORTANT NOTE: add_handle does not implicitly add a Python reference to the
        Curl object (and thus does not increase the reference count on the Curl
        object).

    .. method:: remove_handle(Curl object) -> None

        Corresponds to `curl_multi_remove_handle`_ in libcurl. This method
        removes an existing and valid Curl object from the CurlMulti object.

        IMPORTANT NOTE: remove_handle does not implicitly remove a Python reference
        from the Curl object (and thus does not decrease the reference count on the
        Curl object).

    .. method:: fdset() -> tuple of lists with active file descriptors, readable, writeable, exceptions

        Corresponds to `curl_multi_fdset`_ in libcurl. This method extracts the
        file descriptor information from a CurlMulti object. The returned lists can
        be used with the ``select`` module to poll for events.

        Example usage:

        ::

            import pycurl
            c = pycurl.Curl()
            c.setopt(pycurl.URL, "http://curl.haxx.se")
            m = pycurl.CurlMulti()
            m.add_handle(c)
            while 1:
                ret, num_handles = m.perform()
                if ret != pycurl.E_CALL_MULTI_PERFORM: break
            while num_handles:
                apply(select.select, m.fdset() + (1,))
                while 1:
                    ret, num_handles = m.perform()
                    if ret != pycurl.E_CALL_MULTI_PERFORM: break

    .. method:: select(timeout) -> number of ready file descriptors or -1 on timeout

        This is a convenience function which simplifies the combined use of
        ``fdset()`` and the ``select`` module.

        Example usage:

        ::

            import pycurl
            c = pycurl.Curl()
            c.setopt(pycurl.URL, "http://curl.haxx.se")
            m = pycurl.CurlMulti()
            m.add_handle(c)
            while 1:
                ret, num_handles = m.perform()
                if ret != pycurl.E_CALL_MULTI_PERFORM: break
            while num_handles:
                ret = m.select(1.0)
                if ret == -1:  continue
                while 1:
                    ret, num_handles = m.perform()
                    if ret != pycurl.E_CALL_MULTI_PERFORM: break

    .. method:: info_read([max]) -> number of queued messages, a list of successful objects, a list of failed objects

        Corresponds to the `curl_multi_info_read`_ function in libcurl. This
        method extracts at most *max* messages from the multi stack and returns them
        in two lists. The first list contains the handles which completed
        successfully and the second list contains a tuple *(curl object, curl error
        number, curl error message)* for each failed curl object. The number of
        queued messages after this method has been called is also returned.

.. _curl_multi_cleanup:
    http://curl.haxx.se/libcurl/c/curl_multi_cleanup.html
.. _curl_multi_perform:
    http://curl.haxx.se/libcurl/c/curl_multi_perform.html
.. _curl_multi_add_handle:
    http://curl.haxx.se/libcurl/c/curl_multi_add_handle.html
.. _curl_multi_remove_handle:
    http://curl.haxx.se/libcurl/c/curl_multi_remove_handle.html
.. _curl_multi_fdset:
    http://curl.haxx.se/libcurl/c/curl_multi_fdset.html
.. _curl_multi_info_read:
    http://curl.haxx.se/libcurl/c/curl_multi_info_read.html