using new send-noconn proc is too expensive if it's only going to fail

(return false) so add new iface comms can call once to get flags to
tell it whether to use that proc.  One implementation of
TransportProcs returns one flag; the other, the other.
This commit is contained in:
Andy2 2011-08-16 19:31:08 -07:00
parent dfab747504
commit 066cef0306
4 changed files with 53 additions and 6 deletions

View file

@ -49,6 +49,21 @@ makeJAddr( JNIEnv* env, const CommsAddrRec* addr )
return jaddr;
}
static XP_U32
and_xport_getFlags( void* closure )
{
jint result = 0;
AndTransportProcs* aprocs = (AndTransportProcs*)closure;
if ( NULL != aprocs->jxport ) {
JNIEnv* env = *aprocs->envp;
const char* sig = "()I";
jmethodID mid = getMethodID( env, aprocs->jxport, "getFlags", sig );
result = (*env)->CallIntMethod( env, aprocs->jxport, mid );
}
return result;
}
static XP_S16
and_xport_send( const XP_U8* buf, XP_U16 len, const CommsAddrRec* addr,
void* closure )
@ -166,6 +181,9 @@ makeXportProcs( MPFORMAL JNIEnv** envp, jobject jxport )
aprocs->envp = envp;
MPASSIGN( aprocs->mpool, mpool );
#ifdef COMMS_XPORT_FLAGSPROC
aprocs->tp.getFlags = and_xport_getFlags;
#endif
aprocs->tp.send = and_xport_send;
aprocs->tp.rstatus = and_xport_relayStatus;
aprocs->tp.rconnd = and_xport_relayConnd;

View file

@ -325,6 +325,9 @@ public class CommsTransport implements TransportProcs,
}
// TransportProcs interface
public int getFlags() { return COMMS_XPORT_FLAGS_NONE; }
public int transportSend( byte[] buf, final CommsAddrRec faddr )
{
//Utils.logf( "CommsTransport::transportSend(nbytes=%d)", buf.length );
@ -418,7 +421,7 @@ public class CommsTransport implements TransportProcs,
public boolean relayNoConnProc( byte[] buf, String relayID )
{
Utils.logf( "CommsTransport.relayNoConnProc()=>false" );
Assert.fail();
return false;
}

View file

@ -20,12 +20,27 @@
package org.eehouse.android.xw4;
import android.content.Context;
import java.util.HashMap;
import java.util.ArrayList;
import junit.framework.Assert;
import org.eehouse.android.xw4.jni.*;
public class RelayMsgSink implements TransportProcs {
private HashMap<String,ArrayList<byte[]>> m_msgLists = null;
public void send( Context context )
{
NetUtils.sendToRelay( context, m_msgLists );
}
/***** TransportProcs interface *****/
public int getFlags() { return COMMS_XPORT_FLAGS_HASNOCONN; }
public int transportSend( byte[] buf, final CommsAddrRec addr )
{
Assert.fail();
@ -34,24 +49,30 @@ public class RelayMsgSink implements TransportProcs {
public void relayStatus( CommsRelayState newState )
{
Assert.fail();
}
public void relayErrorProc( XWRELAY_ERROR relayErr )
{
Assert.fail();
}
public void relayConnd( String room, int devOrder, boolean allHere,
int nMissing )
{
Assert.fail();
}
public boolean relayNoConnProc( byte[] buf, String relayID )
{
Utils.logf( "relayNoConnProc got %d bytes for %s; send 'em!!!",
buf.length, relayID );
if ( null == m_msgLists ) {
m_msgLists = new HashMap<String,ArrayList<byte[]>>();
}
ArrayList<byte[]> list = m_msgLists.get( relayID );
if ( list == null ) {
list = new ArrayList<byte[]>();
m_msgLists.put( relayID, list );
}
list.add( buf );
return true;
}
}

View file

@ -21,6 +21,11 @@
package org.eehouse.android.xw4.jni;
public interface TransportProcs {
public static final int COMMS_XPORT_FLAGS_NONE = 0;
public static final int COMMS_XPORT_FLAGS_HASNOCONN = 1;
int getFlags();
int transportSend( byte[] buf, final CommsAddrRec addr );
enum CommsRelayState { COMMS_RELAYSTATE_UNCONNECTED