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.sentrysoftware.wbem.sblim.slp.internal.sa;
23
24 /*-
25 * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲
26 * WBEM Java Client
27 * ჻჻჻჻჻჻
28 * Copyright (C) 2023 Sentry Software
29 * ჻჻჻჻჻჻
30 * This program is free software: you can redistribute it and/or modify
31 * it under the terms of the GNU Lesser General Public License as
32 * published by the Free Software Foundation, either version 3 of the
33 * License, or (at your option) any later version.
34 *
35 * This program is distributed in the hope that it will be useful,
36 * but WITHOUT ANY WARRANTY; without even the implied warranty of
37 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
38 * GNU General Lesser Public License for more details.
39 *
40 * You should have received a copy of the GNU General Lesser Public
41 * License along with this program. If not, see
42 * <http://www.gnu.org/licenses/lgpl-3.0.html>.
43 * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱
44 */
45
46 import java.io.IOException;
47 import java.net.ServerSocket;
48 import java.net.Socket;
49 import java.net.SocketTimeoutException;
50
51 import org.sentrysoftware.wbem.sblim.slp.internal.SLPConfig;
52 import org.sentrysoftware.wbem.sblim.slp.internal.TRC;
53
54 /**
55 * TCPThread
56 *
57 */
58 public class TCPThread extends RecieverThread {
59
60 private ServerSocket iListenerSocket;
61
62 /**
63 * Ctor.
64 *
65 * @param pSrvAgent
66 */
67 public TCPThread(ServiceAgent pSrvAgent) {
68 super("TCP receiver", pSrvAgent);
69 }
70
71 @Override
72 protected void init() throws IOException {
73 this.iListenerSocket = new ServerSocket(SLPConfig.getGlobalCfg().getPort());
74 this.iListenerSocket.setReuseAddress(true);
75 this.iListenerSocket.setSoTimeout(100);
76 }
77
78 @Override
79 protected void mainLoop() throws IOException {
80 try {
81 new ConnectionThread(this.iListenerSocket.accept());
82 } catch (SocketTimeoutException e) {
83 // superclass will execute the mainLoop again
84 }
85 }
86
87 private class ConnectionThread implements Runnable {
88
89 private Socket iSock;
90
91 /**
92 * Ctor.
93 *
94 * @param pSock
95 */
96 public ConnectionThread(Socket pSock) {
97 this.iSock = pSock;
98 new Thread(this).start();
99 }
100
101 public void run() {
102 TCPThread.this.iSrvAgent.processMessage(this.iSock);
103 }
104
105 }
106
107 @Override
108 protected void close() {
109 if (this.iListenerSocket == null) return;
110 try {
111 this.iListenerSocket.close();
112 } catch (IOException e) {
113 TRC.error(e);
114 }
115 }
116
117 }