Subversion Repositories qbpwcf-lib(archive)

Rev

Rev 915 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 liveuser 1
<?php
2
 
3
namespace React\Socket;
4
 
5
/**
6
 * The `ConnectorInterface` is responsible for providing an interface for
7
 * establishing streaming connections, such as a normal TCP/IP connection.
8
 *
9
 * This is the main interface defined in this package and it is used throughout
10
 * React's vast ecosystem.
11
 *
12
 * Most higher-level components (such as HTTP, database or other networking
13
 * service clients) accept an instance implementing this interface to create their
14
 * TCP/IP connection to the underlying networking service.
15
 * This is usually done via dependency injection, so it's fairly simple to actually
16
 * swap this implementation against any other implementation of this interface.
17
 *
18
 * The interface only offers a single `connect()` method.
19
 *
20
 * @see ConnectionInterface
21
 */
22
interface ConnectorInterface
23
{
24
    /**
25
     * Creates a streaming connection to the given remote address
26
     *
27
     * If returns a Promise which either fulfills with a stream implementing
28
     * `ConnectionInterface` on success or rejects with an `Exception` if the
29
     * connection is not successful.
30
     *
31
     * ```php
32
     * $connector->connect('google.com:443')->then(
33
     *     function (React\Socket\ConnectionInterface $connection) {
34
     *         // connection successfully established
35
     *     },
36
     *     function (Exception $error) {
37
     *         // failed to connect due to $error
38
     *     }
39
     * );
40
     * ```
41
     *
42
     * The returned Promise MUST be implemented in such a way that it can be
43
     * cancelled when it is still pending. Cancelling a pending promise MUST
44
     * reject its value with an Exception. It SHOULD clean up any underlying
45
     * resources and references as applicable.
46
     *
47
     * ```php
48
     * $promise = $connector->connect($uri);
49
     *
50
     * $promise->cancel();
51
     * ```
52
     *
53
     * @param string $uri
54
     * @return \React\Promise\PromiseInterface resolves with a stream implementing ConnectionInterface on success or rejects with an Exception on error
55
     * @see ConnectionInterface
56
     */
57
    public function connect($uri);
58
}