1 /*
2 (C) Copyright IBM Corp. 2007, 2009
3
4 THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE
5 ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE
6 CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT.
7
8 You can obtain a current copy of the Eclipse Public License from
9 http://www.opensource.org/licenses/eclipse-1.0.php
10
11 @author : Endre Bak, IBM, ebak@de.ibm.com
12 *
13 * Change History
14 * Flag Date Prog Description
15 *-------------------------------------------------------------------------------
16 * 1804402 2007-09-28 ebak IPv6 ready SLP
17 * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL
18 * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1)
19 * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors
20 */
21
22 package org.metricshub.wbem.sblim.slp.internal.sa;
23
24 /*-
25 * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲
26 * WBEM Java Client
27 * ჻჻჻჻჻჻
28 * Copyright 2023 - 2025 MetricsHub
29 * ჻჻჻჻჻჻
30 * Licensed under the Apache License, Version 2.0 (the "License");
31 * you may not use this file except in compliance with the License.
32 * You may obtain a copy of the License at
33 *
34 * http://www.apache.org/licenses/LICENSE-2.0
35 *
36 * Unless required by applicable law or agreed to in writing, software
37 * distributed under the License is distributed on an "AS IS" BASIS,
38 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
39 * See the License for the specific language governing permissions and
40 * limitations under the License.
41 * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱
42 */
43
44 import java.io.IOException;
45 import java.net.ServerSocket;
46 import java.net.Socket;
47 import java.net.SocketTimeoutException;
48 import org.metricshub.wbem.sblim.slp.internal.SLPConfig;
49 import org.metricshub.wbem.sblim.slp.internal.TRC;
50
51 /**
52 * TCPThread
53 *
54 */
55 public class TCPThread extends RecieverThread {
56 private ServerSocket iListenerSocket;
57
58 /**
59 * Ctor.
60 *
61 * @param pSrvAgent
62 */
63 public TCPThread(ServiceAgent pSrvAgent) {
64 super("TCP receiver", pSrvAgent);
65 }
66
67 @Override
68 protected void init() throws IOException {
69 this.iListenerSocket = new ServerSocket(SLPConfig.getGlobalCfg().getPort());
70 this.iListenerSocket.setReuseAddress(true);
71 this.iListenerSocket.setSoTimeout(100);
72 }
73
74 @Override
75 protected void mainLoop() throws IOException {
76 try {
77 new ConnectionThread(this.iListenerSocket.accept());
78 } catch (SocketTimeoutException e) {
79 // superclass will execute the mainLoop again
80 }
81 }
82
83 private class ConnectionThread implements Runnable {
84 private Socket iSock;
85
86 /**
87 * Ctor.
88 *
89 * @param pSock
90 */
91 public ConnectionThread(Socket pSock) {
92 this.iSock = pSock;
93 new Thread(this).start();
94 }
95
96 public void run() {
97 TCPThread.this.iSrvAgent.processMessage(this.iSock);
98 }
99 }
100
101 @Override
102 protected void close() {
103 if (this.iListenerSocket == null) return;
104 try {
105 this.iListenerSocket.close();
106 } catch (IOException e) {
107 TRC.error(e);
108 }
109 }
110 }