mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-01-30 16:13:51 +00:00
Special return code for "socket closed"
Blocking recv calls return a special return code (-2) for notifying the socket is closed (this information is useful for MDP socket users). This implementation is unsatisfactory: return code should instead be consistent with recvfrom(), that is always returning the length of received data (0 for socket closed).
This commit is contained in:
parent
927a35d879
commit
6783656179
@ -160,7 +160,7 @@ int overlay_mdp_recv(int mdp_sockfd, overlay_mdp_frame *mdp, int port, int *ttl)
|
|||||||
mdp->packetTypeAndFlags = 0;
|
mdp->packetTypeAndFlags = 0;
|
||||||
len = recvwithttl(mdp_sockfd, (unsigned char *)mdp, sizeof(overlay_mdp_frame), ttl, (struct sockaddr *)&recvaddr, &recvaddrlen);
|
len = recvwithttl(mdp_sockfd, (unsigned char *)mdp, sizeof(overlay_mdp_frame), ttl, (struct sockaddr *)&recvaddr, &recvaddrlen);
|
||||||
if (len <= 0)
|
if (len <= 0)
|
||||||
return -1; // no packet received
|
return -2; // no packet received
|
||||||
|
|
||||||
// If the received address overflowed the buffer, then it cannot have come from the server, whose
|
// If the received address overflowed the buffer, then it cannot have come from the server, whose
|
||||||
// address always fits within a struct sockaddr_un.
|
// address always fits within a struct sockaddr_un.
|
||||||
|
15
mdp_jni.c
15
mdp_jni.c
@ -300,6 +300,8 @@ Java_org_servalproject_servald_mdp_MeshSocket__1receive(JNIEnv * env,
|
|||||||
jbyteArray jbuf, jsid;
|
jbyteArray jbuf, jsid;
|
||||||
jbyte *sid;
|
jbyte *sid;
|
||||||
overlay_mdp_frame mdp;
|
overlay_mdp_frame mdp;
|
||||||
|
int res;
|
||||||
|
char *msg;
|
||||||
|
|
||||||
/* fd = this.fd; */
|
/* fd = this.fd; */
|
||||||
fd = (*env)->GetIntField(env, this, f_meshsocket_fd);
|
fd = (*env)->GetIntField(env, this, f_meshsocket_fd);
|
||||||
@ -311,10 +313,15 @@ Java_org_servalproject_servald_mdp_MeshSocket__1receive(JNIEnv * env,
|
|||||||
length = (*env)->GetIntField(env, mdppack, f_meshpacket_length);
|
length = (*env)->GetIntField(env, mdppack, f_meshpacket_length);
|
||||||
|
|
||||||
/* Receive data. */
|
/* Receive data. */
|
||||||
if (overlay_mdp_recv(fd, &mdp, localport, &ttl)) {
|
if (res = (overlay_mdp_recv(fd, &mdp, localport, &ttl))) {
|
||||||
(*env)->ThrowNew(env, cl_meshsocketexception,
|
if (res == -2) {
|
||||||
"Cannot receive data from servald");
|
/* Socket is closed. */
|
||||||
WHY("Cannot receive data from servald");
|
msg = "Socket closed";
|
||||||
|
} else {
|
||||||
|
msg = "Cannot receive data from servald";
|
||||||
|
}
|
||||||
|
(*env)->ThrowNew(env, cl_meshsocketexception, msg);
|
||||||
|
WHY(msg);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user