mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 02:20:39 +00:00
Align receive timeout behavior for dbus client with cli and JSON-RPC
Timeout is reset by every incoming message
This commit is contained in:
parent
5cccf52103
commit
8e773d92c1
1 changed files with 19 additions and 6 deletions
|
@ -3,7 +3,6 @@ package org.asamk.signal.dbus;
|
||||||
import org.asamk.Signal;
|
import org.asamk.Signal;
|
||||||
import org.asamk.signal.DbusConfig;
|
import org.asamk.signal.DbusConfig;
|
||||||
import org.asamk.signal.manager.Manager;
|
import org.asamk.signal.manager.Manager;
|
||||||
import org.asamk.signal.manager.api.StickerPackInvalidException;
|
|
||||||
import org.asamk.signal.manager.api.AttachmentInvalidException;
|
import org.asamk.signal.manager.api.AttachmentInvalidException;
|
||||||
import org.asamk.signal.manager.api.Configuration;
|
import org.asamk.signal.manager.api.Configuration;
|
||||||
import org.asamk.signal.manager.api.Device;
|
import org.asamk.signal.manager.api.Device;
|
||||||
|
@ -19,6 +18,7 @@ import org.asamk.signal.manager.api.RecipientIdentifier;
|
||||||
import org.asamk.signal.manager.api.SendGroupMessageResults;
|
import org.asamk.signal.manager.api.SendGroupMessageResults;
|
||||||
import org.asamk.signal.manager.api.SendMessageResults;
|
import org.asamk.signal.manager.api.SendMessageResults;
|
||||||
import org.asamk.signal.manager.api.StickerPack;
|
import org.asamk.signal.manager.api.StickerPack;
|
||||||
|
import org.asamk.signal.manager.api.StickerPackInvalidException;
|
||||||
import org.asamk.signal.manager.api.StickerPackUrl;
|
import org.asamk.signal.manager.api.StickerPackUrl;
|
||||||
import org.asamk.signal.manager.api.TypingAction;
|
import org.asamk.signal.manager.api.TypingAction;
|
||||||
import org.asamk.signal.manager.api.UpdateGroup;
|
import org.asamk.signal.manager.api.UpdateGroup;
|
||||||
|
@ -53,6 +53,7 @@ import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
@ -498,12 +499,24 @@ public class DbusManagerImpl implements Manager {
|
||||||
public void receiveMessages(
|
public void receiveMessages(
|
||||||
final Duration timeout, final ReceiveMessageHandler handler
|
final Duration timeout, final ReceiveMessageHandler handler
|
||||||
) throws IOException {
|
) throws IOException {
|
||||||
addReceiveHandler(handler);
|
final var lastMessage = new AtomicLong(System.currentTimeMillis());
|
||||||
try {
|
|
||||||
Thread.sleep(timeout.toMillis());
|
final ReceiveMessageHandler receiveHandler = (envelope, e) -> {
|
||||||
} catch (InterruptedException ignored) {
|
lastMessage.set(System.currentTimeMillis());
|
||||||
|
handler.handleMessage(envelope, e);
|
||||||
|
};
|
||||||
|
addReceiveHandler(receiveHandler);
|
||||||
|
while (true) {
|
||||||
|
try {
|
||||||
|
final var sleepTimeRemaining = timeout.toMillis() - (System.currentTimeMillis() - lastMessage.get());
|
||||||
|
if (sleepTimeRemaining < 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
Thread.sleep(sleepTimeRemaining);
|
||||||
|
} catch (InterruptedException ignored) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
removeReceiveHandler(handler);
|
removeReceiveHandler(receiveHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue