Merge "Switch LocalSocketImpl.accept() over to using Os.accept()"
This commit is contained in:
@@ -205,16 +205,6 @@ class LocalSocketImpl
|
|||||||
private native Credentials getPeerCredentials_native(
|
private native Credentials getPeerCredentials_native(
|
||||||
FileDescriptor fd) throws IOException;
|
FileDescriptor fd) throws IOException;
|
||||||
|
|
||||||
/**
|
|
||||||
* Accepts a connection on a server socket.
|
|
||||||
*
|
|
||||||
* @param fd file descriptor of server socket
|
|
||||||
* @param s socket implementation that will become the new socket
|
|
||||||
* @return file descriptor of new socket
|
|
||||||
*/
|
|
||||||
private native FileDescriptor accept
|
|
||||||
(FileDescriptor fd, LocalSocketImpl s) throws IOException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new instance.
|
* Create a new instance.
|
||||||
*/
|
*/
|
||||||
@@ -338,14 +328,17 @@ class LocalSocketImpl
|
|||||||
* @param s a socket that will be used to represent the new connection.
|
* @param s a socket that will be used to represent the new connection.
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
protected void accept(LocalSocketImpl s) throws IOException
|
protected void accept(LocalSocketImpl s) throws IOException {
|
||||||
{
|
|
||||||
if (fd == null) {
|
if (fd == null) {
|
||||||
throw new IOException("socket not created");
|
throw new IOException("socket not created");
|
||||||
}
|
}
|
||||||
|
|
||||||
s.fd = accept(fd, s);
|
try {
|
||||||
s.mFdCreatedInternally = true;
|
s.fd = Os.accept(fd, null /* address */);
|
||||||
|
s.mFdCreatedInternally = true;
|
||||||
|
} catch (ErrnoException e) {
|
||||||
|
throw e.rethrowAsIOException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -112,49 +112,6 @@ socket_bind_local (JNIEnv *env, jobject object, jobject fileDescriptor,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* private native FileDescriptor
|
|
||||||
** accept (FileDescriptor fd, LocalSocketImpl s)
|
|
||||||
** throws IOException;
|
|
||||||
*/
|
|
||||||
static jobject
|
|
||||||
socket_accept (JNIEnv *env, jobject object, jobject fileDescriptor, jobject s)
|
|
||||||
{
|
|
||||||
union {
|
|
||||||
struct sockaddr address;
|
|
||||||
struct sockaddr_un un_address;
|
|
||||||
} sa;
|
|
||||||
|
|
||||||
int ret;
|
|
||||||
int retFD;
|
|
||||||
int fd;
|
|
||||||
socklen_t addrlen;
|
|
||||||
|
|
||||||
if (s == NULL) {
|
|
||||||
jniThrowNullPointerException(env, NULL);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
fd = jniGetFDFromFileDescriptor(env, fileDescriptor);
|
|
||||||
|
|
||||||
if (env->ExceptionCheck()) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
do {
|
|
||||||
addrlen = sizeof(sa);
|
|
||||||
ret = accept(fd, &(sa.address), &addrlen);
|
|
||||||
} while (ret < 0 && errno == EINTR);
|
|
||||||
|
|
||||||
if (ret < 0) {
|
|
||||||
jniThrowIOException(env, errno);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
retFD = ret;
|
|
||||||
|
|
||||||
return jniCreateFileDescriptor(env, retFD);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* private native void shutdown(FileDescriptor fd, boolean shutdownInput) */
|
/* private native void shutdown(FileDescriptor fd, boolean shutdownInput) */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -566,7 +523,6 @@ static JNINativeMethod gMethods[] = {
|
|||||||
{"connectLocal", "(Ljava/io/FileDescriptor;Ljava/lang/String;I)V",
|
{"connectLocal", "(Ljava/io/FileDescriptor;Ljava/lang/String;I)V",
|
||||||
(void*)socket_connect_local},
|
(void*)socket_connect_local},
|
||||||
{"bindLocal", "(Ljava/io/FileDescriptor;Ljava/lang/String;I)V", (void*)socket_bind_local},
|
{"bindLocal", "(Ljava/io/FileDescriptor;Ljava/lang/String;I)V", (void*)socket_bind_local},
|
||||||
{"accept", "(Ljava/io/FileDescriptor;Landroid/net/LocalSocketImpl;)Ljava/io/FileDescriptor;", (void*)socket_accept},
|
|
||||||
{"shutdown", "(Ljava/io/FileDescriptor;Z)V", (void*)socket_shutdown},
|
{"shutdown", "(Ljava/io/FileDescriptor;Z)V", (void*)socket_shutdown},
|
||||||
{"read_native", "(Ljava/io/FileDescriptor;)I", (void*) socket_read},
|
{"read_native", "(Ljava/io/FileDescriptor;)I", (void*) socket_read},
|
||||||
{"readba_native", "([BIILjava/io/FileDescriptor;)I", (void*) socket_readba},
|
{"readba_native", "([BIILjava/io/FileDescriptor;)I", (void*) socket_readba},
|
||||||
|
|||||||
Reference in New Issue
Block a user