mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-26 14:02:06 +01:00
Changed flushing type of jzlib to fix hang in client.
git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@7613 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
parent
9627fef139
commit
93766ee788
1 changed files with 62 additions and 57 deletions
|
@ -32,9 +32,9 @@ import javax.net.ssl.SSLSocket;
|
|||
import java.io.*;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.InetAddress;
|
||||
import java.net.Socket;
|
||||
import java.net.UnknownHostException;
|
||||
import java.net.InetAddress;
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CopyOnWriteArraySet;
|
||||
|
@ -52,7 +52,7 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|||
* con.login("jsmith", "mypass");
|
||||
* // Start a new conversation with John Doe and send him a message.
|
||||
* Chat chat = connection.getChatManager().createChat("jdoe@igniterealtime.org"</font>, new MessageListener() {
|
||||
*
|
||||
* <p/>
|
||||
* public void processMessage(Chat chat, Message message) {
|
||||
* // Print out any messages we get back to standard out.
|
||||
* System.out.println(<font color="green">"Received message: "</font> + message);
|
||||
|
@ -62,11 +62,11 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|||
* // Disconnect from the server
|
||||
* con.disconnect();
|
||||
* </pre>
|
||||
*
|
||||
* <p/>
|
||||
* XMPPConnections can be reused between connections. This means that an XMPPConnection
|
||||
* may be connected, disconnected and then connected again. Listeners of the XMPPConnection
|
||||
* will be retained accross connections.<p>
|
||||
*
|
||||
* <p/>
|
||||
* If a connected XMPPConnection gets disconnected abruptly then it will try to reconnect
|
||||
* again. To stop the reconnection process, use {@link #disconnect()}. Once stopped
|
||||
* you can use {@link #connect()} to manually connect to the server.
|
||||
|
@ -83,7 +83,7 @@ public class XMPPConnection {
|
|||
* <li> Server Traffic -- raw XML traffic sent by the server to the client.
|
||||
* <li> Interpreted Packets -- shows XML packets from the server as parsed by Smack.
|
||||
* </ul>
|
||||
*
|
||||
* <p/>
|
||||
* Debugging can be enabled by setting this field to true, or by setting the Java system
|
||||
* property <tt>smack.debugEnabled</tt> to true. The system property can be set on the
|
||||
* command line such as "java SomeApp -Dsmack.debugEnabled=true".
|
||||
|
@ -109,6 +109,7 @@ public class XMPPConnection {
|
|||
// Ensure the SmackConfiguration class is loaded by calling a method in it.
|
||||
SmackConfiguration.getVersion();
|
||||
}
|
||||
|
||||
private SmackDebugger debugger = null;
|
||||
|
||||
/**
|
||||
|
@ -174,11 +175,11 @@ public class XMPPConnection {
|
|||
* <tt>serviceName</tt> with the default port of 5222. Encrypted connections (TLS)
|
||||
* will be used if available, stream compression is disabled, and standard SASL
|
||||
* mechanisms will be used for authentication.<p>
|
||||
*
|
||||
* <p/>
|
||||
* This is the simplest constructor for connecting to an XMPP server. Alternatively,
|
||||
* you can get fine-grained control over connection settings using the
|
||||
* {@link #XMPPConnection(ConnectionConfiguration)} constructor.<p>
|
||||
*
|
||||
* <p/>
|
||||
* Note that XMPPConnection constructors do not establish a connection to the server
|
||||
* and you must call {@link #connect()}.
|
||||
*
|
||||
|
@ -195,11 +196,11 @@ public class XMPPConnection {
|
|||
|
||||
/**
|
||||
* Creates a new XMPP connection using the specified connection configuration.<p>
|
||||
*
|
||||
* <p/>
|
||||
* Manually specifying connection configuration information is suitable for
|
||||
* advanced users of the API. In many cases, using the
|
||||
* {@link #XMPPConnection(String)} constructor is a better approach.<p>
|
||||
*
|
||||
* <p/>
|
||||
* Note that XMPPConnection constructors do not establish a connection to the server
|
||||
* and you must call {@link #connect()}.
|
||||
*
|
||||
|
@ -296,8 +297,7 @@ public class XMPPConnection {
|
|||
* to the serrver.
|
||||
*/
|
||||
public synchronized void login(String username, String password, String resource)
|
||||
throws XMPPException
|
||||
{
|
||||
throws XMPPException {
|
||||
login(username, password, resource, true);
|
||||
}
|
||||
|
||||
|
@ -309,7 +309,7 @@ public class XMPPConnection {
|
|||
* is false, a presence packet must be sent manually later. If more than five seconds
|
||||
* (default timeout) elapses in each step of the authentication process without a
|
||||
* response from the server, or if an error occurs, a XMPPException will be thrown.<p>
|
||||
*
|
||||
* <p/>
|
||||
* Before logging in (i.e. authenticate) to the server the connection must be connected.
|
||||
* For compatibility and easiness of use the connection will automatically connect to the
|
||||
* server if not already connected.
|
||||
|
@ -324,8 +324,7 @@ public class XMPPConnection {
|
|||
* to the serrver.
|
||||
*/
|
||||
public synchronized void login(String username, String password, String resource,
|
||||
boolean sendPresence) throws XMPPException
|
||||
{
|
||||
boolean sendPresence) throws XMPPException {
|
||||
if (!isConnected()) {
|
||||
throw new IllegalStateException("Not connected to server.");
|
||||
}
|
||||
|
@ -508,7 +507,7 @@ public class XMPPConnection {
|
|||
* @return a chat manager instance for this connection.
|
||||
*/
|
||||
public synchronized ChatManager getChatManager() {
|
||||
if(this.chatManager == null) {
|
||||
if (this.chatManager == null) {
|
||||
this.chatManager = new ChatManager(this);
|
||||
}
|
||||
return this.chatManager;
|
||||
|
@ -592,14 +591,18 @@ public class XMPPConnection {
|
|||
}
|
||||
|
||||
// Close down the readers and writers.
|
||||
if (reader != null)
|
||||
{
|
||||
try { reader.close(); } catch (Throwable ignore) { /* ignore */ }
|
||||
if (reader != null) {
|
||||
try {
|
||||
reader.close();
|
||||
}
|
||||
catch (Throwable ignore) { /* ignore */ }
|
||||
reader = null;
|
||||
}
|
||||
if (writer != null)
|
||||
{
|
||||
try { writer.close(); } catch (Throwable ignore) { /* ignore */ }
|
||||
if (writer != null) {
|
||||
try {
|
||||
writer.close();
|
||||
}
|
||||
catch (Throwable ignore) { /* ignore */ }
|
||||
writer = null;
|
||||
}
|
||||
|
||||
|
@ -617,7 +620,7 @@ public class XMPPConnection {
|
|||
* Closes the connection by setting presence to unavailable then closing the stream to
|
||||
* the XMPP server. The XMPPConnection can still be used for connecting to the server
|
||||
* again.<p>
|
||||
*
|
||||
* <p/>
|
||||
* This method cleans up all resources used by the connection. Therefore, the roster,
|
||||
* listeners and other stateful objects cannot be re-used by simply calling connect()
|
||||
* on this connection again. This is unlike the behavior during unexpected disconnects
|
||||
|
@ -635,7 +638,7 @@ public class XMPPConnection {
|
|||
* information such as "On vacation". Typically, just the status text of the presence
|
||||
* packet is set with online information, but most XMPP servers will deliver the full
|
||||
* presence packet with whatever data is set.<p>
|
||||
*
|
||||
* <p/>
|
||||
* This method cleans up all resources used by the connection. Therefore, the roster,
|
||||
* listeners and other stateful objects cannot be re-used by simply calling connect()
|
||||
* on this connection again. This is unlike the behavior during unexpected disconnects
|
||||
|
@ -964,7 +967,7 @@ public class XMPPConnection {
|
|||
zoClass.getConstructor(OutputStream.class, Integer.TYPE);
|
||||
Object out = constructor.newInstance(socket.getOutputStream(), 9);
|
||||
Method method = zoClass.getMethod("setFlushMode", Integer.TYPE);
|
||||
method.invoke(out, 1);
|
||||
method.invoke(out, 2);
|
||||
writer =
|
||||
new BufferedWriter(new OutputStreamWriter((OutputStream) out, "UTF-8"));
|
||||
|
||||
|
@ -972,7 +975,7 @@ public class XMPPConnection {
|
|||
constructor = ziClass.getConstructor(InputStream.class);
|
||||
Object in = constructor.newInstance(socket.getInputStream());
|
||||
method = ziClass.getMethod("setFlushMode", Integer.TYPE);
|
||||
method.invoke(in, 1);
|
||||
method.invoke(in, 2);
|
||||
reader = new BufferedReader(new InputStreamReader((InputStream) in, "UTF-8"));
|
||||
}
|
||||
catch (Exception e) {
|
||||
|
@ -1093,8 +1096,7 @@ public class XMPPConnection {
|
|||
*/
|
||||
void startTLSReceived(boolean required) {
|
||||
if (required && configuration.getSecurityMode() ==
|
||||
ConnectionConfiguration.SecurityMode.disabled)
|
||||
{
|
||||
ConnectionConfiguration.SecurityMode.disabled) {
|
||||
packetReader.notifyConnectionError(new IllegalStateException(
|
||||
"TLS required by server but not allowed by connection configuration"));
|
||||
return;
|
||||
|
@ -1170,7 +1172,7 @@ public class XMPPConnection {
|
|||
* traffic can be reduced up to 90%. Therefore, stream compression is ideal when using a slow
|
||||
* speed network connection. However, the server will need to use more CPU time in order to
|
||||
* un/compress network data so under high load the server performance might be affected.<p>
|
||||
*
|
||||
* <p/>
|
||||
* Note: to use stream compression the smackx.jar file has to be present in the classpath.
|
||||
*
|
||||
* @return true if network traffic is being compressed.
|
||||
|
@ -1184,11 +1186,11 @@ public class XMPPConnection {
|
|||
* reduced up to 90%. Therefore, stream compression is ideal when using a slow speed network
|
||||
* connection. However, the server and the client will need to use more CPU time in order to
|
||||
* un/compress network data so under high load the server performance might be affected.<p>
|
||||
*
|
||||
* <p/>
|
||||
* Stream compression has to have been previously offered by the server. Currently only the
|
||||
* zlib method is supported by the client. Stream compression negotiation has to be done
|
||||
* before authentication took place.<p>
|
||||
*
|
||||
* <p/>
|
||||
* Note: to use stream compression the smackx.jar file has to be present in the classpath.
|
||||
*
|
||||
* @return true if stream compression negotiation was successful.
|
||||
|
@ -1267,11 +1269,12 @@ public class XMPPConnection {
|
|||
this.notify();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Establishes a connection to the XMPP server and performs an automatic login
|
||||
* only if the previous connection state was logged (authenticated). It basically
|
||||
* creates and maintains a socket connection to the server.<p>
|
||||
*
|
||||
* <p/>
|
||||
* Listeners will be preserved from a previous connection if the reconnection
|
||||
* occurs after an abrupt termination.
|
||||
*
|
||||
|
@ -1292,11 +1295,13 @@ public class XMPPConnection {
|
|||
if (isAnonymous()) {
|
||||
// Make the anonymous login
|
||||
loginAnonymously();
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
login(getConfiguration().getUsername(), getConfiguration().getPassword(),
|
||||
getConfiguration().getResource(), getConfiguration().isSendPresence());
|
||||
}
|
||||
} catch (XMPPException e) {
|
||||
}
|
||||
catch (XMPPException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue