/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright (c) 2001 by Sun Microsystems, Inc.
* All rights reserved.
*
*/
// Listener.java: Organize basic listening for slpd and specifically
// support datagram listening.
// Author: James Kempf
// Created On: Mon May 18 12:43:50 1998
// Last Modified By: James Kempf
// Last Modified On: Thu Jan 7 08:39:19 1999
// Update Count: 54
//
/**
* This class supplies the basic listening function for the DA
* and SA. On creation, a StreamListener is created to listen for
* clients that need to initiate unicast connections. The main object
* listens on the SLP multicast address for SLP multicasts, and
* passes the results off to the RequestHandler for direction to
* the proper table. The RequestHandler object is executed in a different
* thread to maximize throughput. Note that unicast datagram requests
* may also enter through this class, since many systems don't distinguish
* between the multicast and datagram queues for a port.
*
* @author James Kempf, Erik Guttman
*/
new Hashtable(); // Listeners keyed by interface.
// This includes a datagram listener, a DAAdvertiser (which shares
// the same socket as the datagram listener) if a DA, and a
// stream listener.
throws ServiceLocationException {
// If we've done the intializtion, forget it.
return;
}
// Get config object.
}
// Create a listener object for this interface.
// Start thread to listen for incoming datagram request.
// Create a stream listener object for this interface.
// We wait until this point to advertise ourselves as DAs. At
// this point, we have the listeners up to handle any messages
// that might come in as a result.
}
// Return the socket for the listener on the designated interface.
// DAAdvertisers and the SLPv1 codes uses this to share the
// same socket as the main datagram listener.
}
return null;
}
// Add the listener on the interface to the multicast group.
static void
throws ServiceLocationException {
// Ignore if we haven't got it.
return;
}
// Only add if we're multicast.
if (dss instanceof MulticastSocket) {
try {
// Record the groups monitored.
} catch (IOException ex) {
"socket_initializtion_failure",
}
}
}
// Refresh the listener socket on the interface. If there is no
// listener, then simply return a new send socket.
static DatagramSocket
}
}
// Create a Listener for the interface.
// Get packet size.
// Get a socket for this interface.
// Record here so we can use standard utility to add to multicast
// group.
// If we're multicasting, add to the default SLP group.
}
// Listen on multicast for incoming requests, spawn a RequestHandler
// to process the datagram.
public void run() {
boolean retry = true;
if (config.isBroadcastOnly()) {
castName = "Broadcast";
}
dss.getLocalPort());
// Loop forever, receiving datagrams and spawning a request handler
// to handle it.
while (true) {
// Block on datagram receive.
try {
interfac});
}
} catch (IOException ex) {
// Die if we can't retry.
"datagram_io_error",
ex.getMessage()});
retry = false;
ex.getMessage()});
// Close cast socket, get a new one and try again.
groups);
}
}
}
}