Merge "Set isConnected, isBound, implCreated on server-side LocalSockets"
This commit is contained in:
@@ -87,9 +87,9 @@ public class LocalServerSocket {
|
||||
{
|
||||
LocalSocketImpl acceptedImpl = new LocalSocketImpl();
|
||||
|
||||
impl.accept (acceptedImpl);
|
||||
impl.accept(acceptedImpl);
|
||||
|
||||
return new LocalSocket(acceptedImpl, LocalSocket.SOCKET_UNKNOWN);
|
||||
return LocalSocket.createLocalSocketForAccept(acceptedImpl, LocalSocket.SOCKET_UNKNOWN);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -75,17 +75,24 @@ public class LocalSocket implements Closeable {
|
||||
isConnected = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* for use with AndroidServerSocket
|
||||
* @param impl a SocketImpl
|
||||
*/
|
||||
/*package*/ LocalSocket(LocalSocketImpl impl, int sockType) {
|
||||
private LocalSocket(LocalSocketImpl impl, int sockType) {
|
||||
this.impl = impl;
|
||||
this.sockType = sockType;
|
||||
this.isConnected = false;
|
||||
this.isBound = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* for use with LocalServerSocket.accept()
|
||||
*/
|
||||
static LocalSocket createLocalSocketForAccept(LocalSocketImpl impl, int sockType) {
|
||||
LocalSocket socket = new LocalSocket(impl, sockType);
|
||||
socket.isConnected = true;
|
||||
socket.isBound = true;
|
||||
socket.implCreated = true;
|
||||
return socket;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
@@ -235,29 +235,29 @@ class LocalSocketImpl
|
||||
* @throws IOException
|
||||
*/
|
||||
public void create(int sockType) throws IOException {
|
||||
// no error if socket already created
|
||||
// need this for LocalServerSocket.accept()
|
||||
if (fd == null) {
|
||||
int osType;
|
||||
switch (sockType) {
|
||||
case LocalSocket.SOCKET_DGRAM:
|
||||
osType = OsConstants.SOCK_DGRAM;
|
||||
break;
|
||||
case LocalSocket.SOCKET_STREAM:
|
||||
osType = OsConstants.SOCK_STREAM;
|
||||
break;
|
||||
case LocalSocket.SOCKET_SEQPACKET:
|
||||
osType = OsConstants.SOCK_SEQPACKET;
|
||||
break;
|
||||
default:
|
||||
throw new IllegalStateException("unknown sockType");
|
||||
}
|
||||
try {
|
||||
fd = Os.socket(OsConstants.AF_UNIX, osType, 0);
|
||||
mFdCreatedInternally = true;
|
||||
} catch (ErrnoException e) {
|
||||
e.rethrowAsIOException();
|
||||
}
|
||||
if (fd != null) {
|
||||
throw new IOException("LocalSocketImpl already has an fd");
|
||||
}
|
||||
|
||||
int osType;
|
||||
switch (sockType) {
|
||||
case LocalSocket.SOCKET_DGRAM:
|
||||
osType = OsConstants.SOCK_DGRAM;
|
||||
break;
|
||||
case LocalSocket.SOCKET_STREAM:
|
||||
osType = OsConstants.SOCK_STREAM;
|
||||
break;
|
||||
case LocalSocket.SOCKET_SEQPACKET:
|
||||
osType = OsConstants.SOCK_SEQPACKET;
|
||||
break;
|
||||
default:
|
||||
throw new IllegalStateException("unknown sockType");
|
||||
}
|
||||
try {
|
||||
fd = Os.socket(OsConstants.AF_UNIX, osType, 0);
|
||||
mFdCreatedInternally = true;
|
||||
} catch (ErrnoException e) {
|
||||
e.rethrowAsIOException();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user