() {
69 | // @Override
70 | // public void onCompleted(Exception e, DnsResponse result) {
71 | //// semaphore.release();
72 | // }
73 | // });
74 | //
75 | // semaphore.tryAcquire(1000000, TimeUnit.MILLISECONDS);
76 | }
77 |
78 | public void testNoDomain() throws Exception {
79 | AsyncServer server = new AsyncServer();
80 |
81 | try {
82 | final Semaphore semaphore = new Semaphore(0);
83 | server.connectSocket("www.clockworkmod-notfound.com", 8080, new ConnectCallback() {
84 | @Override
85 | public void onConnectCompleted(Exception ex, AsyncSocket socket) {
86 | assertTrue(ex instanceof UnknownHostException);
87 | semaphore.release();
88 | }
89 | });
90 | assertTrue(semaphore.tryAcquire(5000, TimeUnit.MILLISECONDS));
91 | }
92 | finally {
93 | server.stop();
94 | }
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/AndroidAsync/src/com/koushikdutta/async/http/Protocol.java:
--------------------------------------------------------------------------------
1 | package com.koushikdutta.async.http;
2 |
3 | import java.util.Hashtable;
4 | import java.util.Locale;
5 |
6 | /**
7 | * Protocols that OkHttp implements for NPN and
9 | * ALPN
10 | * selection.
11 | *
12 | * Protocol vs Scheme
13 | * Despite its name, {@link java.net.URL#getProtocol()} returns the
14 | * {@linkplain java.net.URI#getScheme() scheme} (http, https, etc.) of the URL, not
15 | * the protocol (http/1.1, spdy/3.1, etc.). OkHttp uses the word protocol
16 | * to identify how HTTP messages are framed.
17 | */
18 | public enum Protocol {
19 | /**
20 | * An obsolete plaintext framing that does not use persistent sockets by
21 | * default.
22 | */
23 | HTTP_1_0("http/1.0"),
24 |
25 | /**
26 | * A plaintext framing that includes persistent connections.
27 | *
28 | * This version of OkHttp implements RFC 2616, and tracks
30 | * revisions to that spec.
31 | */
32 | HTTP_1_1("http/1.1"),
33 |
34 | /**
35 | * Chromium's binary-framed protocol that includes header compression,
36 | * multiplexing multiple requests on the same socket, and server-push.
37 | * HTTP/1.1 semantics are layered on SPDY/3.
38 | *
39 | * This version of OkHttp implements SPDY 3 draft
41 | * 3.1. Future releases of OkHttp may use this identifier for a newer draft
42 | * of the SPDY spec.
43 | */
44 | SPDY_3("spdy/3.1") {
45 | @Override
46 | public boolean needsSpdyConnection() {
47 | return true;
48 | }
49 | },
50 |
51 | /**
52 | * The IETF's binary-framed protocol that includes header compression,
53 | * multiplexing multiple requests on the same socket, and server-push.
54 | * HTTP/1.1 semantics are layered on HTTP/2.
55 | *
56 | * This version of OkHttp implements HTTP/2 draft 12
58 | * with HPACK draft
60 | * 6. Future releases of OkHttp may use this identifier for a newer draft
61 | * of these specs.
62 | */
63 | HTTP_2("h2-13") {
64 | @Override
65 | public boolean needsSpdyConnection() {
66 | return true;
67 | }
68 | };
69 |
70 | private final String protocol;
71 | private static final Hashtable protocols = new Hashtable();
72 |
73 | static {
74 | protocols.put(HTTP_1_0.toString(), HTTP_1_0);
75 | protocols.put(HTTP_1_1.toString(), HTTP_1_1);
76 | protocols.put(SPDY_3.toString(), SPDY_3);
77 | protocols.put(HTTP_2.toString(), HTTP_2);
78 | }
79 |
80 |
81 | Protocol(String protocol) {
82 | this.protocol = protocol;
83 | }
84 |
85 | /**
86 | * Returns the protocol identified by {@code protocol}.
87 | */
88 | public static Protocol get(String protocol) {
89 | if (protocol == null)
90 | return null;
91 | return protocols.get(protocol.toLowerCase(Locale.US));
92 | }
93 |
94 | /**
95 | * Returns the string used to identify this protocol for ALPN and NPN, like
96 | * "http/1.1", "spdy/3.1" or "h2-13".
97 | */
98 | @Override
99 | public String toString() {
100 | return protocol;
101 | }
102 |
103 | public boolean needsSpdyConnection() {
104 | return false;
105 | }
106 | }
107 |
--------------------------------------------------------------------------------