tango.net.SocketListener

License:

BSD style: see license.txt

Version:

Initial release: June 2004

Author:

Kris
class SocketListener #
Abstract class to asynchronously listen for incoming data on a socket. This can be used with DatagramSocket & MulticastSocket, and might possibly be useful with a basic SocketConduit also. Note that DatagramSocket must first be bound to a local network address via bind(), and MulticastSocket should first be made a member of a multicast group via its join() method. Note also that the underlying thread is not started by the constructor; you should do that manually via the start() method.
this(Bin buffer) #
Construct a listener with the requisite arguments. The specified buffer is populated via the provided instance of ISocketReader before being passed to the notify() method. All arguments are required.
this(InputStream stream, Bin buffer) #
Construct a listener with the requisite arguments. The specified buffer is populated via the provided instance of ISocketReader before being passed to the notify() method. All arguments are required.
void notify(InputBuffer buffer) [abstract] #
Notification callback invoked whenever the listener has anything to report. The buffer will have whatever content was available from the read() operation
void exception(char[] msg) [abstract] #
Handle error conditions from the listener thread.
void execute() #
Start this listener
void cancel() #
Cancel this listener. The thread will quit only after the current read() request responds, or is interrrupted.
void setErrorLimit(ushort limit) #
Set the maximum contiguous number of exceptions this listener will survive. Setting a limit of zero will not survive any errors at all, whereas a limit of two will survive as long as two consecutive errors don't arrive back to back.
void run() [private] #
Execution of this thread is typically stalled on the read() method belonging to the conduit specified during construction. You can invoke cancel() to indicate execution should not proceed further, but that will not actually interrupt a blocked read() operation.
Note that exceptions are all directed towards the handler implemented by the class instance.