mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-23 12:21:05 -04:00
reduces the danger of race conditions
This commit is contained in:
parent
4a8564198b
commit
1af59a16cf
@ -5,7 +5,7 @@
|
||||
*/
|
||||
package de.neemann.digital.core.io.telnet;
|
||||
|
||||
import de.neemann.digital.core.Observer;
|
||||
import de.neemann.digital.core.SyncAccess;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@ -22,7 +22,8 @@ public class Server {
|
||||
private final ServerThread serverThread;
|
||||
private boolean telnetEscape;
|
||||
private ClientThread client;
|
||||
private Observer notify;
|
||||
private Telnet telnet;
|
||||
private SyncAccess syncAccess;
|
||||
|
||||
Server(int port) throws IOException {
|
||||
buffer = new ByteBuffer(1024);
|
||||
@ -48,8 +49,15 @@ public class Server {
|
||||
buffer.deleteAll();
|
||||
}
|
||||
|
||||
void setNotify(Observer notify) {
|
||||
this.notify = notify;
|
||||
/**
|
||||
* Connects the server with the telnet node
|
||||
*
|
||||
* @param telnet the telnet node
|
||||
* @param syncAccess used to access the model
|
||||
*/
|
||||
public void setTelnetNode(Telnet telnet, SyncAccess syncAccess) {
|
||||
this.telnet = telnet;
|
||||
this.syncAccess = syncAccess;
|
||||
}
|
||||
|
||||
boolean hasData() {
|
||||
@ -65,9 +73,11 @@ public class Server {
|
||||
}
|
||||
|
||||
private void dataReceived(int data) {
|
||||
if (syncAccess != null)
|
||||
syncAccess.modify(() -> {
|
||||
buffer.put((byte) data);
|
||||
if (notify != null)
|
||||
notify.hasChanged();
|
||||
telnet.hasChanged();
|
||||
});
|
||||
}
|
||||
|
||||
boolean isDead() {
|
||||
|
@ -103,7 +103,7 @@ public class Telnet extends Node implements Element {
|
||||
throw new NodeException(Lang.get("err_couldNotCreateServer"), e);
|
||||
}
|
||||
server.setTelnetEscape(telnetEscape);
|
||||
server.setNotify(() -> model.modify(Telnet.this::hasChanged));
|
||||
server.setTelnetNode(this, model);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user