Skip to content

Commit 9b62fa3

Browse files
committed
Add buffer size setting to the Telnet component, closes #1114
1 parent 220e551 commit 9b62fa3

File tree

5 files changed

+29
-4
lines changed

5 files changed

+29
-4
lines changed

src/main/java/de/neemann/digital/core/element/Keys.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import de.neemann.digital.core.IntFormat;
1010
import de.neemann.digital.core.arithmetic.BarrelShifterMode;
1111
import de.neemann.digital.core.arithmetic.LeftRightFormat;
12+
import de.neemann.digital.core.element.Key.KeyInteger;
1213
import de.neemann.digital.core.extern.Application;
1314
import de.neemann.digital.core.io.CommonConnectionType;
1415
import de.neemann.digital.core.io.InValue;
@@ -1016,4 +1017,13 @@ private static File getATMISPPath() {
10161017
*/
10171018
public static final Key<Boolean> SKIP_HDL =
10181019
new Key<>("skipHDL", false).setSecondary();
1020+
1021+
/**
1022+
* Telnet buffer size
1023+
*/
1024+
public static final Key<Integer> TELNET_BUFFER_SIZE =
1025+
new KeyInteger("telnetBufferSize", 1024)
1026+
.setMin(1)
1027+
.setMax(1 << 20)
1028+
.allowGroupEdit();
10191029
}

src/main/java/de/neemann/digital/core/io/telnet/Server.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,14 @@
1818
*/
1919
public class Server {
2020
private final ServerSocket serverSocket;
21-
private final ByteBuffer buffer;
21+
private ByteBuffer buffer;
2222
private final ServerThread serverThread;
2323
private boolean telnetEscape;
2424
private ClientThread client;
2525
private Telnet telnet;
2626
private SyncAccess syncAccess;
2727

2828
Server(int port) throws IOException {
29-
buffer = new ByteBuffer(1024);
3029
serverSocket = new ServerSocket(port);
3130
serverThread = new ServerThread();
3231
serverThread.start();
@@ -72,6 +71,10 @@ void setTelnetEscape(boolean telnetEscape) {
7271
this.telnetEscape = telnetEscape;
7372
}
7473

74+
void setBufferSize(int bufferSize) {
75+
buffer = new ByteBuffer(bufferSize);
76+
}
77+
7578
private void dataReceived(int data) {
7679
if (syncAccess != null)
7780
syncAccess.modify(() -> {

src/main/java/de/neemann/digital/core/io/telnet/Telnet.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,14 @@ public class Telnet extends Node implements Element {
3030
.addAttribute(Keys.ROTATE)
3131
.addAttribute(Keys.LABEL)
3232
.addAttribute(Keys.TELNET_ESCAPE)
33-
.addAttribute(Keys.PORT);
33+
.addAttribute(Keys.PORT)
34+
.addAttribute(Keys.TELNET_BUFFER_SIZE);
3435

3536
private final ObservableValue dataOut;
3637
private final ObservableValue dataAvail;
3738
private final int port;
3839
private final boolean telnetEscape;
40+
private final int bufferSize;
3941
private ObservableValue dataIn;
4042
private ObservableValue clockValue;
4143
private ObservableValue writeEnable;
@@ -57,6 +59,7 @@ public Telnet(ElementAttributes attributes) {
5759
.setPinDescription(DESCRIPTION);
5860
port = attributes.get(Keys.PORT);
5961
telnetEscape = attributes.get(Keys.TELNET_ESCAPE);
62+
bufferSize = attributes.get(Keys.TELNET_BUFFER_SIZE);
6063
}
6164

6265
@Override
@@ -103,6 +106,7 @@ public void init(Model model) throws NodeException {
103106
throw new NodeException(Lang.get("err_couldNotCreateServer"), e);
104107
}
105108
server.setTelnetEscape(telnetEscape);
109+
server.setBufferSize(bufferSize);
106110
server.setTelnetNode(this, model);
107111
}
108112

src/main/resources/lang/lang_en.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1673,6 +1673,10 @@
16731673
the server is a simple TCP server.</string>
16741674
<string name="key_port">Port</string>
16751675
<string name="key_port_tt">The port to be opened by the server.</string>
1676+
<string name="key_telnetBufferSize">Buffer size</string>
1677+
<string name="key_telnetBufferSize_tt">The size (in bytes) of the buffer for the received data.
1678+
If data is received faster than it can be processed, the buffer can become full.
1679+
If the buffer is full, incoming data can be lost.</string>
16761680

16771681
<string name="key_openRemotePort">Allow remote connection</string>
16781682
<string name="key_openRemotePort_tt">If set, a TCP/IP port is opened, through which the control of the

src/main/resources/lang/lang_fr.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2689,7 +2689,11 @@ ligne d'en-tête utilisée pour spécifier les signaux testés.&lt;/p&gt;
26892689
De plus, le serveur envoie les commandes SGA et ECHO. Si cette option est désactivée,
26902690
le serveur est un simple serveur TCP.</string>
26912691
<string name="key_port">Port</string>
2692-
<string name="key_port_tt">Le port ouvert par le serveur.</string>
2692+
<string name="key_port_tt">Le port d'écoute du serveur.</string>
2693+
<string name="key_telnetBufferSize">Taille du tampon</string>
2694+
<string name="key_telnetBufferSize_tt">La taille (en octets) du tampon pour les données reçues.
2695+
Si les données sont reçues plus rapidement qu'elles ne sont traitées, le tampon se remplira.
2696+
Si le tampon est plein, les données reçues peuvent être perdues.</string>
26932697
<string name="key_skipHDL">Ignorer lors de l'exportation en Verilog/VHDL</string>
26942698
<string name="key_skipHDL_tt">Ignore la génération des composants internes au circuit lors de l'exportation en
26952699
Verilog ou VHDL. Les références au circuit sont gardées, permettant de fournir une

0 commit comments

Comments
 (0)