Skip to content

Commit 856a8cc

Browse files
Abort sending AddName/Refresh requests when the server is shutting down
Registering three names (the same host both as workstation and server, plus the workgroup name) with five retries each at two second intervals takes 30 seconds, and with more names to announce it'd only get worse. Right now, if the server is being shut down shortly after having been started, we have to wait for all those AddName requests to be processes, which seems a bit pointless.
1 parent 92c3c18 commit 856a8cc

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/main/java/org/filesys/netbios/server/NetBIOSNameServer.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ else if (m_hshutdown == true)
198198
boolean txsts = true;
199199
int retry = 0;
200200

201-
while (req.hasErrorStatus() == false && retry++ < reqRetry) {
201+
retryLoop: while (req.hasErrorStatus() == false && retry++ < reqRetry) {
202202

203203
// Debug
204204
if (Debug.EnableInfo && hasDebug())
@@ -210,6 +210,9 @@ else if (m_hshutdown == true)
210210
// Add name request
211211
case ADD_NAME:
212212

213+
// The server is shutting down, we can stop handling ADD_NAME
214+
if (m_shutdown)
215+
break retryLoop;
213216
// Check if a WINS server is configured
214217
if (hasPrimaryWINSServer())
215218
txsts = sendAddName(req, getPrimaryWINSServer(), false);
@@ -230,6 +233,9 @@ else if (m_hshutdown == true)
230233
// Refresh name request
231234
case REFRESH_NAME:
232235

236+
// The server is shutting down, we can stop handling REFRESH_NAME
237+
if (m_shutdown)
238+
break retryLoop;
233239
// Check if a WINS server is configured
234240
if (hasPrimaryWINSServer())
235241
txsts = sendRefreshName(req, getPrimaryWINSServer(), false);
@@ -1617,6 +1623,9 @@ public void shutdownServer(boolean immediate) {
16171623
Debug.println(ex);
16181624
}
16191625

1626+
// Indicate that the server is closing
1627+
m_shutdown = true;
1628+
16201629
// If the shutdown is not immediate then release all of the names registered by this server
16211630
if (isActive() && immediate == false) {
16221631

@@ -1663,9 +1672,6 @@ public void shutdownServer(boolean immediate) {
16631672
Debug.println(ex);
16641673
}
16651674

1666-
// Indicate that the server is closing
1667-
m_shutdown = true;
1668-
16691675
try {
16701676

16711677
// Close the server socket so that any pending receive is cancelled

0 commit comments

Comments
 (0)