use of com.koushikdutta.async.AsyncSSLSocket in project AndroidAsync by koush.
the class SpdyMiddleware method createHandshakeCallback.
@Override
protected AsyncSSLSocketWrapper.HandshakeCallback createHandshakeCallback(final GetSocketData data, final ConnectCallback callback) {
final String key = data.state.get("spdykey");
if (key == null)
return super.createHandshakeCallback(data, callback);
return new AsyncSSLSocketWrapper.HandshakeCallback() {
@Override
public void onHandshakeCompleted(Exception e, AsyncSSLSocket socket) {
data.request.logv("checking spdy handshake");
if (e != null || nativeGetAlpnNegotiatedProtocol == null) {
invokeConnect(key, callback, e, socket);
noSpdy(key);
return;
}
String protoString;
try {
long ptr = (Long) sslNativePointer.get(socket.getSSLEngine());
byte[] proto = (byte[]) nativeGetAlpnNegotiatedProtocol.invoke(null, ptr);
if (proto == null) {
invokeConnect(key, callback, null, socket);
noSpdy(key);
return;
}
protoString = new String(proto);
Protocol p = Protocol.get(protoString);
if (p == null || !p.needsSpdyConnection()) {
invokeConnect(key, callback, null, socket);
noSpdy(key);
return;
}
} catch (Exception ex) {
throw new AssertionError(ex);
}
final AsyncSpdyConnection connection = new AsyncSpdyConnection(socket, Protocol.get(protoString)) {
boolean hasReceivedSettings;
@Override
public void settings(boolean clearPrevious, Settings settings) {
super.settings(clearPrevious, settings);
if (!hasReceivedSettings) {
hasReceivedSettings = true;
SpdyConnectionWaiter waiter = connections.get(key);
if (waiter.originalCancellable.setComplete()) {
data.request.logv("using new spdy connection for host: " + data.request.getUri().getHost());
newSocket(data, this, callback);
}
waiter.setComplete(this);
}
}
};
try {
connection.sendConnectionPreface();
} catch (IOException e1) {
e1.printStackTrace();
}
}
};
}
Aggregations