本文整理了Java中okio.Timeout.timeout()
方法的一些代码示例,展示了Timeout.timeout()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Timeout.timeout()
方法的具体详情如下:
包路径:okio.Timeout
类名称:Timeout
方法名:timeout
[英]Wait at most timeout time before aborting an operation. Using a per-operation timeout means that as long as forward progress is being made, no sequence of operations will fail.
If timeout == 0, operations will run indefinitely. (Operating system timeouts may still apply.)
[中]在中止操作之前,最多等待超时时间。使用每次操作超时意味着,只要向前进行,任何操作序列都不会失败。
如果timeout==0,操作将无限期运行。(操作系统超时可能仍然适用。)
代码示例来源:origin: AsyncHttpClient/async-http-client
@Override
public Timeout timeout() {
return new Timeout().timeout(executeTimeoutMillis, TimeUnit.MILLISECONDS);
}
代码示例来源:origin: square/okhttp
b0 = source.readByte() & 0xff;
} finally {
source.timeout().timeout(timeoutBefore, TimeUnit.NANOSECONDS);
代码示例来源:origin: square/okhttp
public HttpCodec newCodec(OkHttpClient client, Interceptor.Chain chain,
StreamAllocation streamAllocation) throws SocketException {
if (http2Connection != null) {
return new Http2Codec(client, chain, streamAllocation, http2Connection);
} else {
socket.setSoTimeout(chain.readTimeoutMillis());
source.timeout().timeout(chain.readTimeoutMillis(), MILLISECONDS);
sink.timeout().timeout(chain.writeTimeoutMillis(), MILLISECONDS);
return new Http1Codec(client, streamAllocation, source, sink);
}
}
代码示例来源:origin: com.squareup.okhttp3/okhttp
b0 = source.readByte() & 0xff;
} finally {
source.timeout().timeout(timeoutBefore, TimeUnit.NANOSECONDS);
代码示例来源:origin: square/okhttp
@Override public void writeRequestHeaders(Request request) throws IOException {
if (stream != null) return;
boolean hasRequestBody = request.body() != null;
List<Header> requestHeaders = http2HeadersList(request);
stream = connection.newStream(requestHeaders, hasRequestBody);
// We may have been asked to cancel while creating the new stream and sending the request
// headers, but there was still no stream to close.
if (canceled) {
stream.closeLater(ErrorCode.CANCEL);
throw new IOException("Canceled");
}
stream.readTimeout().timeout(chain.readTimeoutMillis(), TimeUnit.MILLISECONDS);
stream.writeTimeout().timeout(chain.writeTimeoutMillis(), TimeUnit.MILLISECONDS);
}
代码示例来源:origin: com.squareup.okhttp3/okhttp
public HttpCodec newCodec(OkHttpClient client, Interceptor.Chain chain,
StreamAllocation streamAllocation) throws SocketException {
if (http2Connection != null) {
return new Http2Codec(client, chain, streamAllocation, http2Connection);
} else {
socket.setSoTimeout(chain.readTimeoutMillis());
source.timeout().timeout(chain.readTimeoutMillis(), MILLISECONDS);
sink.timeout().timeout(chain.writeTimeoutMillis(), MILLISECONDS);
return new Http1Codec(client, streamAllocation, source, sink);
}
}
代码示例来源:origin: com.squareup.okhttp3/okhttp
@Override public void writeRequestHeaders(Request request) throws IOException {
if (stream != null) return;
boolean hasRequestBody = request.body() != null;
List<Header> requestHeaders = http2HeadersList(request);
stream = connection.newStream(requestHeaders, hasRequestBody);
// We may have been asked to cancel while creating the new stream and sending the request
// headers, but there was still no stream to close.
if (canceled) {
stream.closeLater(ErrorCode.CANCEL);
throw new IOException("Canceled");
}
stream.readTimeout().timeout(chain.readTimeoutMillis(), TimeUnit.MILLISECONDS);
stream.writeTimeout().timeout(chain.writeTimeoutMillis(), TimeUnit.MILLISECONDS);
}
代码示例来源:origin: square/okhttp
while (true) {
Http1Codec tunnelConnection = new Http1Codec(null, null, source, sink);
source.timeout().timeout(readTimeout, MILLISECONDS);
sink.timeout().timeout(writeTimeout, MILLISECONDS);
tunnelConnection.writeRequest(tunnelRequest.headers(), requestLine);
tunnelConnection.finishRequest();
代码示例来源:origin: square/okhttp
? new StreamedRequestBody(contentLength)
: new BufferedRequestBody(contentLength);
requestBody.timeout().timeout(client.writeTimeoutMillis(), TimeUnit.MILLISECONDS);
代码示例来源:origin: square/okio
@Test public void readWithoutTimeout() throws Exception {
Socket socket = socket(ONE_MB, 0);
BufferedSource source = Okio.buffer(Okio.source(socket));
source.timeout().timeout(5000, TimeUnit.MILLISECONDS);
source.require(ONE_MB);
socket.close();
}
代码示例来源:origin: square/okio
@Test public void readWithTimeout() throws Exception {
Socket socket = socket(0, 0);
BufferedSource source = Okio.buffer(Okio.source(socket));
source.timeout().timeout(250, TimeUnit.MILLISECONDS);
try {
source.require(ONE_MB);
fail();
} catch (SocketTimeoutException expected) {
}
socket.close();
}
代码示例来源:origin: square/okio
@Test public void writeWithoutTimeout() throws Exception {
Socket socket = socket(0, ONE_MB);
Sink sink = Okio.buffer(Okio.sink(socket));
sink.timeout().timeout(500, TimeUnit.MILLISECONDS);
byte[] data = new byte[ONE_MB];
sink.write(new Buffer().write(data), data.length);
sink.flush();
socket.close();
}
代码示例来源:origin: square/okio
@Test public synchronized void notified() throws InterruptedIOException {
Timeout timeout = new Timeout();
timeout.timeout(5000, TimeUnit.MILLISECONDS);
double start = now();
executorService.schedule(new Runnable() {
@Override public void run() {
synchronized (WaitUntilNotifiedTest.this) {
WaitUntilNotifiedTest.this.notify();
}
}
}, 1000, TimeUnit.MILLISECONDS);
timeout.waitUntilNotified(this);
assertElapsed(1000.0, start);
}
代码示例来源:origin: square/okio
@Test public void writeWithTimeout() throws Exception {
Socket socket = socket(0, 0);
Sink sink = Okio.sink(socket);
sink.timeout().timeout(500, TimeUnit.MILLISECONDS);
byte[] data = new byte[ONE_MB];
long start = System.nanoTime();
try {
sink.write(new Buffer().write(data), data.length);
sink.flush();
fail();
} catch (SocketTimeoutException expected) {
}
long elapsed = System.nanoTime() - start;
socket.close();
assertTrue("elapsed: " + elapsed, TimeUnit.NANOSECONDS.toMillis(elapsed) >= 500);
assertTrue("elapsed: " + elapsed, TimeUnit.NANOSECONDS.toMillis(elapsed) <= 750);
}
代码示例来源:origin: com.squareup.okhttp3/okhttp
while (true) {
Http1Codec tunnelConnection = new Http1Codec(null, null, source, sink);
source.timeout().timeout(readTimeout, MILLISECONDS);
sink.timeout().timeout(writeTimeout, MILLISECONDS);
tunnelConnection.writeRequest(tunnelRequest.headers(), requestLine);
tunnelConnection.finishRequest();
代码示例来源:origin: square/okio
@Test public synchronized void timeout() {
Timeout timeout = new Timeout();
timeout.timeout(1000, TimeUnit.MILLISECONDS);
double start = now();
try {
timeout.waitUntilNotified(this);
fail();
} catch (InterruptedIOException expected) {
assertEquals("timeout", expected.getMessage());
}
assertElapsed(1000.0, start);
}
代码示例来源:origin: square/okio
@Test public synchronized void deadlineBeforeTimeout() {
Timeout timeout = new Timeout();
timeout.timeout(5000, TimeUnit.MILLISECONDS);
timeout.deadline(1000, TimeUnit.MILLISECONDS);
double start = now();
try {
timeout.waitUntilNotified(this);
fail();
} catch (InterruptedIOException expected) {
assertEquals("timeout", expected.getMessage());
}
assertElapsed(1000.0, start);
}
代码示例来源:origin: square/okio
@Test public synchronized void timeoutBeforeDeadline() {
Timeout timeout = new Timeout();
timeout.timeout(1000, TimeUnit.MILLISECONDS);
timeout.deadline(5000, TimeUnit.MILLISECONDS);
double start = now();
try {
timeout.waitUntilNotified(this);
fail();
} catch (InterruptedIOException expected) {
assertEquals("timeout", expected.getMessage());
}
assertElapsed(1000.0, start);
}
代码示例来源:origin: square/okio
@Test public void sourceTimeout() throws Exception {
Pipe pipe = new Pipe(3L);
pipe.source().timeout().timeout(1000, TimeUnit.MILLISECONDS);
double start = now();
Buffer readBuffer = new Buffer();
try {
pipe.source().read(readBuffer, 6L);
fail();
} catch (InterruptedIOException expected) {
assertEquals("timeout", expected.getMessage());
}
assertElapsed(1000.0, start);
assertEquals(0, readBuffer.size());
}
代码示例来源:origin: square/okio
@Test public void sinkTimeout() throws Exception {
Pipe pipe = new Pipe(3);
pipe.sink().timeout().timeout(1000, TimeUnit.MILLISECONDS);
pipe.sink().write(new Buffer().writeUtf8("abc"), 3L);
double start = now();
try {
pipe.sink().write(new Buffer().writeUtf8("def"), 3L);
fail();
} catch (InterruptedIOException expected) {
assertEquals("timeout", expected.getMessage());
}
assertElapsed(1000.0, start);
Buffer readBuffer = new Buffer();
assertEquals(3L, pipe.source().read(readBuffer, 6L));
assertEquals("abc", readBuffer.readUtf8());
}
内容来源于网络,如有侵权,请联系作者删除!