typo
[mdref/mdref-pq] / pq / Connection / resetAsync.md
1 # void pq\Connection::resetAsync()
2
3 [Asynchronously](pq/Connection/: Asynchronous Usage) reset a possibly broken connection to a working state.
4
5 ## Params:
6
7 None.
8
9 ## Throws:
10
11 * pq\Exception\InvalidArgumentException
12 * pq\Exception\BadMethodCallException
13 * pq\Exception\RuntimeException
14
15
16 ## Example:
17
18 <?php
19
20 $c->resetAsync();
21
22 // wait until the stream becomes writable
23 $w = array($c->socket);
24 $r = $e = null;
25
26 if (stream_select($r, $w, $e, null)) {
27
28 // loop until the connection is established
29 while (true) {
30
31 switch ($c->poll()) {
32
33 case pq\Connection::POLLING_READING:
34 // we should wait for the stream to be read-ready
35 $r = array($c->socket);
36 stream_select($r, $w, $e, NULL);
37 break;
38
39 case pq\Connection::POLLING_WRITING:
40 // we should wait for the stream to be write-ready
41 $w = array($c->socket);
42 $r = $e = null;
43 stream_select($r, $w, $e, null);
44 break;
45
46 case pq\Connection::POLLING_FAILED:
47 printf("Connection failed: %s\n", $c->errorMessage);
48 break 2;
49
50 case pq\Connection::POLLING_OK:
51 printf("Connection completed\n");
52 break 2;
53 }
54 }
55
56 ?>
57