fix: 降低超时可能
This commit is contained in:
parent
efa2cacd3b
commit
ec7f1b8ea9
@ -204,17 +204,20 @@ public class RtkClusterService implements ApplicationRunner {
|
||||
private void classifyConnection(Socket s) {
|
||||
exec.submit(() -> {
|
||||
try {
|
||||
// short probe to classify role
|
||||
s.setSoTimeout(300);
|
||||
InputStream in = s.getInputStream();
|
||||
byte[] probe = new byte[64];
|
||||
byte[] probe = new byte[256];
|
||||
int n = 0;
|
||||
try { n = in.read(probe); } catch (IOException ignore) {}
|
||||
// restore to blocking mode for steady-state
|
||||
s.setSoTimeout(0);
|
||||
if (n > 0 && isLikelyText(probe, n)) {
|
||||
// OUT connection (NMEA etc.)
|
||||
closeQuietly(outConn);
|
||||
outConn = s;
|
||||
LOGGER.info("Endpoint {} OUT connected", port);
|
||||
pumpOut(outConn);
|
||||
pumpOut(outConn, probe, n);
|
||||
} else {
|
||||
// IN connection (RTCM sink)
|
||||
closeQuietly(inConn);
|
||||
@ -237,11 +240,16 @@ public class RtkClusterService implements ApplicationRunner {
|
||||
return printable >= Math.max(1, n - 4); // tolerate some non-printables
|
||||
}
|
||||
|
||||
private void pumpOut(Socket s) {
|
||||
private void pumpOut(Socket s, byte[] firstBuf, int firstLen) {
|
||||
exec.submit(() -> {
|
||||
try (InputStream in = s.getInputStream()) {
|
||||
byte[] buf = new byte[2048];
|
||||
int read;
|
||||
// deliver first classified bytes if any
|
||||
if (firstLen > 0) {
|
||||
String preview = new String(firstBuf, 0, Math.min(firstLen, 64), StandardCharsets.US_ASCII).replaceAll("\n", "\\n");
|
||||
LOGGER.info("[OUT:{}] {} bytes: {}...", port, firstLen, preview);
|
||||
}
|
||||
while ((read = in.read(buf)) != -1) {
|
||||
// For now, just log a short preview
|
||||
String preview = new String(buf, 0, Math.min(read, 64), StandardCharsets.US_ASCII).replaceAll("\n", "\\n");
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user