Compare commits

..
6 Commits
4 changed files with 32 additions and 9 deletions

No files matched your search

+2 -2
View File
@@ -11,8 +11,8 @@ android {
minSdkVersion 16 minSdkVersion 16
targetSdkVersion 23 targetSdkVersion 23
versionName "4.5.4" versionName "4.5.5"
versionCode = 91 versionCode = 93
} }
productFlavors { productFlavors {
Binary file not shown.
+29 -6
View File
@@ -15,9 +15,21 @@ Java_com_limelight_nvstream_enet_EnetConnection_initializeEnet(JNIEnv *env, jobj
} }
JNIEXPORT jlong JNICALL JNIEXPORT jlong JNICALL
Java_com_limelight_nvstream_enet_EnetConnection_createClient(JNIEnv *env, jobject class) { Java_com_limelight_nvstream_enet_EnetConnection_createClient(JNIEnv *env, jobject class, jstring address) {
ENetAddress enetAddress;
const char *addrStr;
int err;
// Perform a lookup on the address to determine the address family
addrStr = (*env)->GetStringUTFChars(env, address, 0);
err = enet_address_set_host(&enetAddress, addrStr);
(*env)->ReleaseStringUTFChars(env, address, addrStr);
if (err < 0) {
return CLIENT_TO_LONG(NULL);
}
// Create a client that can use 1 outgoing connection and 1 channel // Create a client that can use 1 outgoing connection and 1 channel
return CLIENT_TO_LONG(enet_host_create(NULL, 1, 1, 0, 0)); return CLIENT_TO_LONG(enet_host_create(enetAddress.address.ss_family, NULL, 1, 1, 0, 0));
} }
JNIEXPORT jlong JNICALL JNIEXPORT jlong JNICALL
@@ -26,12 +38,16 @@ Java_com_limelight_nvstream_enet_EnetConnection_connectToPeer(JNIEnv *env, jobje
ENetAddress enetAddress; ENetAddress enetAddress;
ENetEvent event; ENetEvent event;
const char *addrStr; const char *addrStr;
int err;
// Initialize the ENet address // Initialize the ENet address
addrStr = (*env)->GetStringUTFChars(env, address, 0); addrStr = (*env)->GetStringUTFChars(env, address, 0);
enet_address_set_host(&enetAddress, addrStr); err = enet_address_set_host(&enetAddress, addrStr);
enet_address_set_port(&enetAddress, port); enet_address_set_port(&enetAddress, port);
(*env)->ReleaseStringUTFChars(env, address, addrStr); (*env)->ReleaseStringUTFChars(env, address, addrStr);
if (err < 0) {
return PEER_TO_LONG(NULL);
}
// Start the connection // Start the connection
peer = enet_host_connect(LONG_TO_CLIENT(client), &enetAddress, 1, 0); peer = enet_host_connect(LONG_TO_CLIENT(client), &enetAddress, 1, 0);
@@ -99,9 +115,16 @@ Java_com_limelight_nvstream_enet_EnetConnection_writePacket(JNIEnv *env, jobject
packet = enet_packet_create(dataPtr, length, packetFlags); packet = enet_packet_create(dataPtr, length, packetFlags);
if (packet != NULL) { if (packet != NULL) {
// Send the message to the peer // Send the message to the peer
enet_peer_send(LONG_TO_PEER(peer), 0, packet); if (enet_peer_send(LONG_TO_PEER(peer), 0, packet) < 0) {
enet_host_flush(LONG_TO_CLIENT(client)); // This can fail if the peer has been disconnected
ret = JNI_TRUE; enet_packet_destroy(packet);
ret = JNI_FALSE;
}
else {
// Force the client to send the packet now
enet_host_flush(LONG_TO_CLIENT(client));
ret = JNI_TRUE;
}
} }
else { else {
ret = JNI_FALSE; ret = JNI_FALSE;