mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-24 04:42:51 -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;
|
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.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
@ -22,7 +22,8 @@ public class Server {
|
|||||||
private final ServerThread serverThread;
|
private final ServerThread serverThread;
|
||||||
private boolean telnetEscape;
|
private boolean telnetEscape;
|
||||||
private ClientThread client;
|
private ClientThread client;
|
||||||
private Observer notify;
|
private Telnet telnet;
|
||||||
|
private SyncAccess syncAccess;
|
||||||
|
|
||||||
Server(int port) throws IOException {
|
Server(int port) throws IOException {
|
||||||
buffer = new ByteBuffer(1024);
|
buffer = new ByteBuffer(1024);
|
||||||
@ -48,8 +49,15 @@ public class Server {
|
|||||||
buffer.deleteAll();
|
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() {
|
boolean hasData() {
|
||||||
@ -65,9 +73,11 @@ public class Server {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void dataReceived(int data) {
|
private void dataReceived(int data) {
|
||||||
|
if (syncAccess != null)
|
||||||
|
syncAccess.modify(() -> {
|
||||||
buffer.put((byte) data);
|
buffer.put((byte) data);
|
||||||
if (notify != null)
|
telnet.hasChanged();
|
||||||
notify.hasChanged();
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isDead() {
|
boolean isDead() {
|
||||||
|
@ -103,7 +103,7 @@ public class Telnet extends Node implements Element {
|
|||||||
throw new NodeException(Lang.get("err_couldNotCreateServer"), e);
|
throw new NodeException(Lang.get("err_couldNotCreateServer"), e);
|
||||||
}
|
}
|
||||||
server.setTelnetEscape(telnetEscape);
|
server.setTelnetEscape(telnetEscape);
|
||||||
server.setNotify(() -> model.modify(Telnet.this::hasChanged));
|
server.setTelnetNode(this, model);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user