Changed connection timeout from millis -> nanos
This commit is contained in:
parent
7f823bc2e7
commit
0c7202d00c
|
@ -29,6 +29,7 @@ import kotlinx.coroutines.delay
|
||||||
import mu.KLogger
|
import mu.KLogger
|
||||||
import java.net.Inet4Address
|
import java.net.Inet4Address
|
||||||
import java.net.InetAddress
|
import java.net.InetAddress
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
interface MediaDriverConnection : AutoCloseable {
|
interface MediaDriverConnection : AutoCloseable {
|
||||||
val address: InetAddress?
|
val address: InetAddress?
|
||||||
|
@ -52,7 +53,8 @@ interface MediaDriverConnection : AutoCloseable {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* For a client, the ports specified here MUST be manually flipped because they are in the perspective of the SERVER
|
* For a client, the ports specified here MUST be manually flipped because they are in the perspective of the SERVER.
|
||||||
|
* A connection timeout of 0, means to wait forever
|
||||||
*/
|
*/
|
||||||
class UdpMediaDriverConnection(override val address: InetAddress,
|
class UdpMediaDriverConnection(override val address: InetAddress,
|
||||||
override val publicationPort: Int,
|
override val publicationPort: Int,
|
||||||
|
@ -122,8 +124,9 @@ class UdpMediaDriverConnection(override val address: InetAddress,
|
||||||
var success = false
|
var success = false
|
||||||
|
|
||||||
// this will wait for the server to acknowledge the connection (all via aeron)
|
// this will wait for the server to acknowledge the connection (all via aeron)
|
||||||
var startTime = System.currentTimeMillis()
|
val timoutInNanos = TimeUnit.MILLISECONDS.toNanos(connectionTimeoutMS)
|
||||||
while (System.currentTimeMillis() - startTime < connectionTimeoutMS) {
|
var startTime = System.nanoTime()
|
||||||
|
while (timoutInNanos == 0L || System.nanoTime() - startTime < timoutInNanos) {
|
||||||
if (subscription.isConnected && subscription.imageCount() > 0) {
|
if (subscription.isConnected && subscription.imageCount() > 0) {
|
||||||
success = true
|
success = true
|
||||||
break
|
break
|
||||||
|
@ -141,8 +144,8 @@ class UdpMediaDriverConnection(override val address: InetAddress,
|
||||||
success = false
|
success = false
|
||||||
|
|
||||||
// this will wait for the server to acknowledge the connection (all via aeron)
|
// this will wait for the server to acknowledge the connection (all via aeron)
|
||||||
startTime = System.currentTimeMillis()
|
startTime = System.nanoTime()
|
||||||
while (System.currentTimeMillis() - startTime < connectionTimeoutMS) {
|
while (timoutInNanos == 0L || System.nanoTime() - startTime < timoutInNanos) {
|
||||||
if (publication.isConnected) {
|
if (publication.isConnected) {
|
||||||
success = true
|
success = true
|
||||||
break
|
break
|
||||||
|
|
Loading…
Reference in New Issue
Block a user