mirror of
https://github.com/square/okhttp.git
synced 2025-08-08 23:42:08 +03:00
New BufferedSocket class (#8977)
* New BufferedSocket class I'm starting to push Okio's socket throughout OkHttp, and it turns out what I usually want is a BufferedSocket instead. * Flush not emit * Track exception messages * Use flush more
This commit is contained in:
@@ -21,25 +21,13 @@ import java.util.concurrent.FutureTask
|
||||
import java.util.concurrent.LinkedBlockingQueue
|
||||
import java.util.concurrent.TimeUnit
|
||||
import mockwebserver3.SocketHandler
|
||||
import okio.BufferedSink
|
||||
import okio.BufferedSource
|
||||
import okhttp3.internal.connection.BufferedSocket
|
||||
import okhttp3.internal.connection.asBufferedSocket
|
||||
import okio.Socket
|
||||
import okio.buffer
|
||||
import okio.utf8Size
|
||||
|
||||
private typealias Action = (BufferedSocket) -> Unit
|
||||
|
||||
private class BufferedSocket(
|
||||
val socket: Socket,
|
||||
) {
|
||||
val source: BufferedSource = socket.source.buffer()
|
||||
val sink: BufferedSink = socket.sink.buffer()
|
||||
|
||||
fun cancel() {
|
||||
socket.cancel()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A scriptable request/response conversation. Create the script by calling methods like
|
||||
* [receiveRequest] in the sequence they are run.
|
||||
@@ -104,7 +92,7 @@ class MockSocketHandler : SocketHandler {
|
||||
}
|
||||
|
||||
override fun handle(socket: Socket) {
|
||||
val task = serviceSocketTask(BufferedSocket(socket))
|
||||
val task = serviceSocketTask(socket.asBufferedSocket())
|
||||
results.add(task)
|
||||
task.run()
|
||||
}
|
||||
|
Reference in New Issue
Block a user