1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-26 16:22: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:
Derek DeMoro 2007-03-20 22:09:15 +00:00 committed by derek
parent 9627fef139
commit 93766ee788

View file

@ -32,9 +32,9 @@ import javax.net.ssl.SSLSocket;
import java.io.*; import java.io.*;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.net.InetAddress;
import java.net.Socket; import java.net.Socket;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.net.InetAddress;
import java.util.Collection; import java.util.Collection;
import java.util.Set; import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet; import java.util.concurrent.CopyOnWriteArraySet;
@ -52,7 +52,7 @@ import java.util.concurrent.atomic.AtomicInteger;
* con.login("jsmith", "mypass"); * con.login("jsmith", "mypass");
* // Start a new conversation with John Doe and send him a message. * // Start a new conversation with John Doe and send him a message.
* Chat chat = connection.getChatManager().createChat("jdoe@igniterealtime.org"</font>, new MessageListener() { * Chat chat = connection.getChatManager().createChat("jdoe@igniterealtime.org"</font>, new MessageListener() {
* * <p/>
* public void processMessage(Chat chat, Message message) { * public void processMessage(Chat chat, Message message) {
* // Print out any messages we get back to standard out. * // Print out any messages we get back to standard out.
* System.out.println(<font color="green">"Received message: "</font> + message); * System.out.println(<font color="green">"Received message: "</font> + message);
@ -62,11 +62,11 @@ import java.util.concurrent.atomic.AtomicInteger;
* // Disconnect from the server * // Disconnect from the server
* con.disconnect(); * con.disconnect();
* </pre> * </pre>
* * <p/>
* XMPPConnections can be reused between connections. This means that an XMPPConnection * XMPPConnections can be reused between connections. This means that an XMPPConnection
* may be connected, disconnected and then connected again. Listeners of the XMPPConnection * may be connected, disconnected and then connected again. Listeners of the XMPPConnection
* will be retained accross connections.<p> * will be retained accross connections.<p>
* * <p/>
* If a connected XMPPConnection gets disconnected abruptly then it will try to reconnect * If a connected XMPPConnection gets disconnected abruptly then it will try to reconnect
* again. To stop the reconnection process, use {@link #disconnect()}. Once stopped * again. To stop the reconnection process, use {@link #disconnect()}. Once stopped
* you can use {@link #connect()} to manually connect to the server. * 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> 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. * <li> Interpreted Packets -- shows XML packets from the server as parsed by Smack.
* </ul> * </ul>
* * <p/>
* Debugging can be enabled by setting this field to true, or by setting the Java system * 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 * property <tt>smack.debugEnabled</tt> to true. The system property can be set on the
* command line such as "java SomeApp -Dsmack.debugEnabled=true". * 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. // Ensure the SmackConfiguration class is loaded by calling a method in it.
SmackConfiguration.getVersion(); SmackConfiguration.getVersion();
} }
private SmackDebugger debugger = null; private SmackDebugger debugger = null;
/** /**
@ -174,11 +175,11 @@ public class XMPPConnection {
* <tt>serviceName</tt> with the default port of 5222. Encrypted connections (TLS) * <tt>serviceName</tt> with the default port of 5222. Encrypted connections (TLS)
* will be used if available, stream compression is disabled, and standard SASL * will be used if available, stream compression is disabled, and standard SASL
* mechanisms will be used for authentication.<p> * mechanisms will be used for authentication.<p>
* * <p/>
* This is the simplest constructor for connecting to an XMPP server. Alternatively, * This is the simplest constructor for connecting to an XMPP server. Alternatively,
* you can get fine-grained control over connection settings using the * you can get fine-grained control over connection settings using the
* {@link #XMPPConnection(ConnectionConfiguration)} constructor.<p> * {@link #XMPPConnection(ConnectionConfiguration)} constructor.<p>
* * <p/>
* Note that XMPPConnection constructors do not establish a connection to the server * Note that XMPPConnection constructors do not establish a connection to the server
* and you must call {@link #connect()}. * and you must call {@link #connect()}.
* *
@ -195,11 +196,11 @@ public class XMPPConnection {
/** /**
* Creates a new XMPP connection using the specified connection configuration.<p> * Creates a new XMPP connection using the specified connection configuration.<p>
* * <p/>
* Manually specifying connection configuration information is suitable for * Manually specifying connection configuration information is suitable for
* advanced users of the API. In many cases, using the * advanced users of the API. In many cases, using the
* {@link #XMPPConnection(String)} constructor is a better approach.<p> * {@link #XMPPConnection(String)} constructor is a better approach.<p>
* * <p/>
* Note that XMPPConnection constructors do not establish a connection to the server * Note that XMPPConnection constructors do not establish a connection to the server
* and you must call {@link #connect()}. * and you must call {@link #connect()}.
* *
@ -296,8 +297,7 @@ public class XMPPConnection {
* to the serrver. * to the serrver.
*/ */
public synchronized void login(String username, String password, String resource) public synchronized void login(String username, String password, String resource)
throws XMPPException throws XMPPException {
{
login(username, password, resource, true); 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 * 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 * (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> * 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. * 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 * For compatibility and easiness of use the connection will automatically connect to the
* server if not already connected. * server if not already connected.
@ -324,8 +324,7 @@ public class XMPPConnection {
* to the serrver. * to the serrver.
*/ */
public synchronized void login(String username, String password, String resource, public synchronized void login(String username, String password, String resource,
boolean sendPresence) throws XMPPException boolean sendPresence) throws XMPPException {
{
if (!isConnected()) { if (!isConnected()) {
throw new IllegalStateException("Not connected to server."); throw new IllegalStateException("Not connected to server.");
} }
@ -592,14 +591,18 @@ public class XMPPConnection {
} }
// Close down the readers and writers. // Close down the readers and writers.
if (reader != null) if (reader != null) {
{ try {
try { reader.close(); } catch (Throwable ignore) { /* ignore */ } reader.close();
}
catch (Throwable ignore) { /* ignore */ }
reader = null; reader = null;
} }
if (writer != null) if (writer != null) {
{ try {
try { writer.close(); } catch (Throwable ignore) { /* ignore */ } writer.close();
}
catch (Throwable ignore) { /* ignore */ }
writer = null; writer = null;
} }
@ -617,7 +620,7 @@ public class XMPPConnection {
* Closes the connection by setting presence to unavailable then closing the stream to * 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 * the XMPP server. The XMPPConnection can still be used for connecting to the server
* again.<p> * again.<p>
* * <p/>
* This method cleans up all resources used by the connection. Therefore, the roster, * 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() * 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 * 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 * 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 * packet is set with online information, but most XMPP servers will deliver the full
* presence packet with whatever data is set.<p> * presence packet with whatever data is set.<p>
* * <p/>
* This method cleans up all resources used by the connection. Therefore, the roster, * 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() * 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 * 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); zoClass.getConstructor(OutputStream.class, Integer.TYPE);
Object out = constructor.newInstance(socket.getOutputStream(), 9); Object out = constructor.newInstance(socket.getOutputStream(), 9);
Method method = zoClass.getMethod("setFlushMode", Integer.TYPE); Method method = zoClass.getMethod("setFlushMode", Integer.TYPE);
method.invoke(out, 1); method.invoke(out, 2);
writer = writer =
new BufferedWriter(new OutputStreamWriter((OutputStream) out, "UTF-8")); new BufferedWriter(new OutputStreamWriter((OutputStream) out, "UTF-8"));
@ -972,7 +975,7 @@ public class XMPPConnection {
constructor = ziClass.getConstructor(InputStream.class); constructor = ziClass.getConstructor(InputStream.class);
Object in = constructor.newInstance(socket.getInputStream()); Object in = constructor.newInstance(socket.getInputStream());
method = ziClass.getMethod("setFlushMode", Integer.TYPE); method = ziClass.getMethod("setFlushMode", Integer.TYPE);
method.invoke(in, 1); method.invoke(in, 2);
reader = new BufferedReader(new InputStreamReader((InputStream) in, "UTF-8")); reader = new BufferedReader(new InputStreamReader((InputStream) in, "UTF-8"));
} }
catch (Exception e) { catch (Exception e) {
@ -1093,8 +1096,7 @@ public class XMPPConnection {
*/ */
void startTLSReceived(boolean required) { void startTLSReceived(boolean required) {
if (required && configuration.getSecurityMode() == if (required && configuration.getSecurityMode() ==
ConnectionConfiguration.SecurityMode.disabled) ConnectionConfiguration.SecurityMode.disabled) {
{
packetReader.notifyConnectionError(new IllegalStateException( packetReader.notifyConnectionError(new IllegalStateException(
"TLS required by server but not allowed by connection configuration")); "TLS required by server but not allowed by connection configuration"));
return; return;
@ -1170,7 +1172,7 @@ public class XMPPConnection {
* traffic can be reduced up to 90%. Therefore, stream compression is ideal when using a slow * 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 * 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> * 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. * Note: to use stream compression the smackx.jar file has to be present in the classpath.
* *
* @return true if network traffic is being compressed. * @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 * 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 * 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> * 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 * 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 * zlib method is supported by the client. Stream compression negotiation has to be done
* before authentication took place.<p> * before authentication took place.<p>
* * <p/>
* Note: to use stream compression the smackx.jar file has to be present in the classpath. * Note: to use stream compression the smackx.jar file has to be present in the classpath.
* *
* @return true if stream compression negotiation was successful. * @return true if stream compression negotiation was successful.
@ -1267,11 +1269,12 @@ public class XMPPConnection {
this.notify(); this.notify();
} }
} }
/** /**
* Establishes a connection to the XMPP server and performs an automatic login * Establishes a connection to the XMPP server and performs an automatic login
* only if the previous connection state was logged (authenticated). It basically * only if the previous connection state was logged (authenticated). It basically
* creates and maintains a socket connection to the server.<p> * creates and maintains a socket connection to the server.<p>
* * <p/>
* Listeners will be preserved from a previous connection if the reconnection * Listeners will be preserved from a previous connection if the reconnection
* occurs after an abrupt termination. * occurs after an abrupt termination.
* *
@ -1292,11 +1295,13 @@ public class XMPPConnection {
if (isAnonymous()) { if (isAnonymous()) {
// Make the anonymous login // Make the anonymous login
loginAnonymously(); loginAnonymously();
} else { }
else {
login(getConfiguration().getUsername(), getConfiguration().getPassword(), login(getConfiguration().getUsername(), getConfiguration().getPassword(),
getConfiguration().getResource(), getConfiguration().isSendPresence()); getConfiguration().getResource(), getConfiguration().isSendPresence());
} }
} catch (XMPPException e) { }
catch (XMPPException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }