am 2ca4f73e: Merge "Switch LocalSocketImpl.accept() over to using Os.accept()"
* commit '2ca4f73e8036b35085f12cdbcff3350812c42ff6': Switch LocalSocketImpl.accept() over to using Os.accept()
This commit is contained in:
@@ -205,16 +205,6 @@ class LocalSocketImpl
|
||||
private native Credentials getPeerCredentials_native(
|
||||
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.
|
||||
*/
|
||||
@@ -338,14 +328,17 @@ class LocalSocketImpl
|
||||
* @param s a socket that will be used to represent the new connection.
|
||||
* @throws IOException
|
||||
*/
|
||||
protected void accept(LocalSocketImpl s) throws IOException
|
||||
{
|
||||
protected void accept(LocalSocketImpl s) throws IOException {
|
||||
if (fd == null) {
|
||||
throw new IOException("socket not created");
|
||||
}
|
||||
|
||||
s.fd = accept(fd, s);
|
||||
s.mFdCreatedInternally = true;
|
||||
try {
|
||||
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) */
|
||||
|
||||
static void
|
||||
@@ -566,7 +523,6 @@ static JNINativeMethod gMethods[] = {
|
||||
{"connectLocal", "(Ljava/io/FileDescriptor;Ljava/lang/String;I)V",
|
||||
(void*)socket_connect_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},
|
||||
{"read_native", "(Ljava/io/FileDescriptor;)I", (void*) socket_read},
|
||||
{"readba_native", "([BIILjava/io/FileDescriptor;)I", (void*) socket_readba},
|
||||
|
||||
Reference in New Issue
Block a user