File tree Expand file tree Collapse file tree
core/src/main/java/xyz/gianlu/librespot/core Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1212
1313import java .io .IOException ;
1414import java .net .InetAddress ;
15+ import java .net .SocketTimeoutException ;
1516import java .nio .ByteBuffer ;
17+ import java .util .concurrent .TimeUnit ;
1618import java .util .concurrent .atomic .AtomicLong ;
1719
1820/**
@@ -61,14 +63,19 @@ public static long currentTimeMillis() {
6163 }
6264
6365 private static void updateWithNtp () throws IOException {
64- synchronized (offset ) {
65- NTPUDPClient client = new NTPUDPClient ();
66- client .open ();
67- TimeInfo info = client .getTime (InetAddress .getByName ("time.google.com" ));
68- info .computeDetails ();
69- Long offsetValue = info .getOffset ();
70- LOGGER .debug (String .format ("Loaded time offset from NTP: %dms" , offsetValue ));
71- offset .set (offsetValue == null ? 0 : offsetValue );
66+ try {
67+ synchronized (offset ) {
68+ NTPUDPClient client = new NTPUDPClient ();
69+ client .open ();
70+ client .setSoTimeout ((int ) TimeUnit .SECONDS .toMillis (10 ));
71+ TimeInfo info = client .getTime (InetAddress .getByName ("time.google.com" ));
72+ info .computeDetails ();
73+ Long offsetValue = info .getOffset ();
74+ LOGGER .debug (String .format ("Loaded time offset from NTP: %dms" , offsetValue ));
75+ offset .set (offsetValue == null ? 0 : offsetValue );
76+ }
77+ } catch (SocketTimeoutException ex ) {
78+ updateWithNtp ();
7279 }
7380 }
7481
You can’t perform that action at this time.
0 commit comments