Added an extra step to the datagram negotation process. Before
the server starts sending datagrams willy-nilly, it must wait for a (reliable) go-ahead from the client. Otherwise, it's possible that the server may be successfully receiving datagrams but not sending them. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5792 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -56,6 +56,7 @@ import com.threerings.presents.net.AuthResponseData;
|
||||
import com.threerings.presents.net.DownstreamMessage;
|
||||
import com.threerings.presents.net.LogoffRequest;
|
||||
import com.threerings.presents.net.PingRequest;
|
||||
import com.threerings.presents.net.TransmitDatagramsRequest;
|
||||
import com.threerings.presents.net.Transport;
|
||||
import com.threerings.presents.net.UpstreamMessage;
|
||||
import com.threerings.presents.util.DatagramSequencer;
|
||||
@@ -766,6 +767,9 @@ public class BlockingCommunicator extends Communicator
|
||||
if (cport > 0) {
|
||||
log.info("Datagram connection established", "port", cport);
|
||||
|
||||
// notify the server
|
||||
postMessage(new TransmitDatagramsRequest());
|
||||
|
||||
// start up the writer thread
|
||||
_datagramWriter = new DatagramWriter();
|
||||
_datagramWriter.start();
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
//
|
||||
// $Id$
|
||||
//
|
||||
// Narya library - tools for developing networked games
|
||||
// Copyright (C) 2002-2007 Three Rings Design, Inc., All Rights Reserved
|
||||
// http://www.threerings.net/code/narya/
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it
|
||||
// under the terms of the GNU Lesser General Public License as published
|
||||
// by the Free Software Foundation; either version 2.1 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package com.threerings.presents.net;
|
||||
|
||||
/**
|
||||
* Notifies the server that we would like it to send us datagrams.
|
||||
*/
|
||||
public class TransmitDatagramsRequest extends UpstreamMessage
|
||||
{
|
||||
@Override
|
||||
public String toString ()
|
||||
{
|
||||
return "[type=TRANSMIT_DATAGRAMS, msgid=" + messageId + "]";
|
||||
}
|
||||
}
|
||||
@@ -63,6 +63,7 @@ import com.threerings.presents.net.PingRequest;
|
||||
import com.threerings.presents.net.PongResponse;
|
||||
import com.threerings.presents.net.SubscribeRequest;
|
||||
import com.threerings.presents.net.ThrottleUpdatedMessage;
|
||||
import com.threerings.presents.net.TransmitDatagramsRequest;
|
||||
import com.threerings.presents.net.UnsubscribeRequest;
|
||||
import com.threerings.presents.net.UnsubscribeResponse;
|
||||
import com.threerings.presents.net.UpdateThrottleMessage;
|
||||
@@ -1085,6 +1086,18 @@ public class PresentsSession
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes datagram transmission requests.
|
||||
*/
|
||||
protected static class TransmitDatagramsDispatcher implements MessageDispatcher
|
||||
{
|
||||
public void dispatch (PresentsSession client, Message msg)
|
||||
{
|
||||
log.debug("Client requested datagram transmission", "client", client);
|
||||
client.getConnection().setTransmitDatagrams(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes throttle updated messages.
|
||||
*/
|
||||
@@ -1158,6 +1171,7 @@ public class PresentsSession
|
||||
_disps.put(UnsubscribeRequest.class, new UnsubscribeDispatcher());
|
||||
_disps.put(ForwardEventRequest.class, new ForwardEventDispatcher());
|
||||
_disps.put(PingRequest.class, new PingDispatcher());
|
||||
_disps.put(TransmitDatagramsRequest.class, new TransmitDatagramsDispatcher());
|
||||
_disps.put(ThrottleUpdatedMessage.class, new ThrottleUpdatedDispatcher());
|
||||
_disps.put(LogoffRequest.class, new LogoffDispatcher());
|
||||
}
|
||||
|
||||
@@ -121,6 +121,22 @@ public class Connection implements NetEventHandler
|
||||
return (_channel == null) ? null : _channel.socket().getInetAddress();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether we should transmit datagrams.
|
||||
*/
|
||||
public void setTransmitDatagrams (boolean transmit)
|
||||
{
|
||||
_transmitDatagrams = transmit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether we should transmit datagrams.
|
||||
*/
|
||||
public boolean getTransmitDatagrams ()
|
||||
{
|
||||
return _transmitDatagrams;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the address to which datagrams should be sent or null if no datagram address has
|
||||
* been established.
|
||||
@@ -435,6 +451,7 @@ public class Connection implements NetEventHandler
|
||||
|
||||
protected InetSocketAddress _datagramAddress;
|
||||
protected byte[] _datagramSecret;
|
||||
protected boolean _transmitDatagrams;
|
||||
|
||||
protected MessageDigest _digest;
|
||||
protected DatagramSequencer _sequencer;
|
||||
|
||||
@@ -61,6 +61,7 @@ import com.threerings.presents.annotation.AuthInvoker;
|
||||
import com.threerings.presents.client.Client;
|
||||
import com.threerings.presents.data.ConMgrStats;
|
||||
import com.threerings.presents.net.Message;
|
||||
import com.threerings.presents.net.PongResponse;
|
||||
import com.threerings.presents.server.Authenticator;
|
||||
import com.threerings.presents.server.ChainedAuthenticator;
|
||||
import com.threerings.presents.server.ClientManager;
|
||||
@@ -902,9 +903,11 @@ public class ConnectionManager extends LoopingThread
|
||||
}
|
||||
|
||||
try {
|
||||
// send it as a datagram if hinted and possible
|
||||
if (!msg.getTransport().isReliable() && conn.getDatagramAddress() != null &&
|
||||
postDatagram(conn, msg)) {
|
||||
// send it as a datagram if hinted and possible (pongs must be sent as part of the
|
||||
// negotation process)
|
||||
if (!msg.getTransport().isReliable() &&
|
||||
(conn.getTransmitDatagrams() || msg instanceof PongResponse) &&
|
||||
postDatagram(conn, msg)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user