HDFS-347: style cleanups. Contributed by Colin Patrick McCabe.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/HDFS-347@1446830 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Aaron Myers 2013-02-16 00:59:01 +00:00
parent 27e158362c
commit 3a417cbf1d
7 changed files with 195 additions and 141 deletions

View File

@ -51,7 +51,7 @@ public class DomainSocket implements Closeable {
} else if (!NativeCodeLoader.isNativeCodeLoaded()) { } else if (!NativeCodeLoader.isNativeCodeLoaded()) {
loadingFailureReason = "libhadoop cannot be loaded."; loadingFailureReason = "libhadoop cannot be loaded.";
} else { } else {
String problem = "DomainSocket#anchorNative got error: unknown"; String problem;
try { try {
anchorNative(); anchorNative();
problem = null; problem = null;
@ -132,17 +132,99 @@ public class DomainSocket implements Closeable {
} }
/** /**
* Status bits * Tracks the reference count of the file descriptor, and also whether it is
* * open or closed.
* Bit 30: 0 = DomainSocket open, 1 = DomainSocket closed
* Bits 29 to 0: the reference count.
*/ */
private final AtomicInteger status; private static class Status {
/**
* Bit mask representing a closed domain socket.
*/
private static final int STATUS_CLOSED_MASK = 1 << 30;
/**
* Status bits
*
* Bit 30: 0 = DomainSocket open, 1 = DomainSocket closed
* Bits 29 to 0: the reference count.
*/
private final AtomicInteger bits = new AtomicInteger(0);
Status() { }
/**
* Increment the reference count of the underlying file descriptor.
*
* @throws ClosedChannelException If the file descriptor is closed.
*/
void reference() throws ClosedChannelException {
int curBits = bits.incrementAndGet();
if ((curBits & STATUS_CLOSED_MASK) != 0) {
bits.decrementAndGet();
throw new ClosedChannelException();
}
}
/**
* Decrement the reference count of the underlying file descriptor.
*
* @param checkClosed Whether to throw an exception if the file
* descriptor is closed.
*
* @throws AsynchronousCloseException If the file descriptor is closed and
* checkClosed is set.
*/
void unreference(boolean checkClosed) throws AsynchronousCloseException {
int newCount = bits.decrementAndGet();
assert (newCount & ~STATUS_CLOSED_MASK) >= 0;
if (checkClosed && ((newCount & STATUS_CLOSED_MASK) != 0)) {
throw new AsynchronousCloseException();
}
}
/**
* Return true if the file descriptor is currently open.
*
* @return True if the file descriptor is currently open.
*/
boolean isOpen() {
return ((bits.get() & STATUS_CLOSED_MASK) == 0);
}
/**
* Mark the file descriptor as closed.
*
* Once the file descriptor is closed, it cannot be reopened.
*
* @return The current reference count.
* @throws ClosedChannelException If someone else closes the file
* descriptor before we do.
*/
int setClosed() throws ClosedChannelException {
while (true) {
int curBits = bits.get();
if ((curBits & STATUS_CLOSED_MASK) != 0) {
throw new ClosedChannelException();
}
if (bits.compareAndSet(curBits, curBits | STATUS_CLOSED_MASK)) {
return curBits & (~STATUS_CLOSED_MASK);
}
}
}
/**
* Get the current reference count.
*
* @return The current reference count.
*/
int getReferenceCount() {
return bits.get() & (~STATUS_CLOSED_MASK);
}
}
/** /**
* Bit mask representing a closed domain socket. * The socket status.
*/ */
private static final int STATUS_CLOSED_MASK = 1 << 30; private final Status status;
/** /**
* The file descriptor associated with this UNIX domain socket. * The file descriptor associated with this UNIX domain socket.
@ -170,7 +252,7 @@ public class DomainSocket implements Closeable {
private final DomainChannel channel = new DomainChannel(); private final DomainChannel channel = new DomainChannel();
private DomainSocket(String path, int fd) { private DomainSocket(String path, int fd) {
this.status = new AtomicInteger(0); this.status = new Status();
this.fd = fd; this.fd = fd;
this.path = path; this.path = path;
} }
@ -208,14 +290,14 @@ public class DomainSocket implements Closeable {
* @throws SocketTimeoutException If the accept timed out. * @throws SocketTimeoutException If the accept timed out.
*/ */
public DomainSocket accept() throws IOException { public DomainSocket accept() throws IOException {
fdRef(); status.reference();
boolean exc = true; boolean exc = true;
try { try {
DomainSocket ret = new DomainSocket(path, accept0(fd)); DomainSocket ret = new DomainSocket(path, accept0(fd));
exc = false; exc = false;
return ret; return ret;
} finally { } finally {
fdUnref(exc); status.unreference(exc);
} }
} }
@ -235,38 +317,14 @@ public class DomainSocket implements Closeable {
return new DomainSocket(path, fd); return new DomainSocket(path, fd);
} }
/** /**
* Increment the reference count of the underlying file descriptor. * Return true if the file descriptor is currently open.
* *
* @throws SocketException If the file descriptor is closed. * @return True if the file descriptor is currently open.
*/ */
private void fdRef() throws ClosedChannelException { public boolean isOpen() {
int bits = status.incrementAndGet(); return status.isOpen();
if ((bits & STATUS_CLOSED_MASK) != 0) { }
status.decrementAndGet();
throw new ClosedChannelException();
}
}
/**
* Decrement the reference count of the underlying file descriptor.
*/
private void fdUnref(boolean checkClosed) throws AsynchronousCloseException {
int newCount = status.decrementAndGet();
assert (newCount & ~STATUS_CLOSED_MASK) >= 0;
if (checkClosed && ((newCount & STATUS_CLOSED_MASK) != 0)) {
throw new AsynchronousCloseException();
}
}
/**
* Return true if the file descriptor is currently open.
*
* @return True if the file descriptor is currently open.
*/
public boolean isOpen() {
return ((status.get() & STATUS_CLOSED_MASK) == 0);
}
/** /**
* @return The socket path. * @return The socket path.
@ -296,29 +354,29 @@ public class DomainSocket implements Closeable {
return channel; return channel;
} }
public static final int SND_BUF_SIZE = 1; public static final int SEND_BUFFER_SIZE = 1;
public static final int RCV_BUF_SIZE = 2; public static final int RECEIVE_BUFFER_SIZE = 2;
public static final int SND_TIMEO = 3; public static final int SEND_TIMEOUT = 3;
public static final int RCV_TIMEO = 4; public static final int RECEIVE_TIMEOUT = 4;
private static native void setAttribute0(int fd, int type, int val) private static native void setAttribute0(int fd, int type, int val)
throws IOException; throws IOException;
public void setAttribute(int type, int size) throws IOException { public void setAttribute(int type, int size) throws IOException {
fdRef(); status.reference();
boolean exc = true; boolean exc = true;
try { try {
setAttribute0(fd, type, size); setAttribute0(fd, type, size);
exc = false; exc = false;
} finally { } finally {
fdUnref(exc); status.unreference(exc);
} }
} }
private native int getAttribute0(int fd, int type) throws IOException; private native int getAttribute0(int fd, int type) throws IOException;
public int getAttribute(int type) throws IOException { public int getAttribute(int type) throws IOException {
fdRef(); status.reference();
int attribute; int attribute;
boolean exc = true; boolean exc = true;
try { try {
@ -326,7 +384,7 @@ public class DomainSocket implements Closeable {
exc = false; exc = false;
return attribute; return attribute;
} finally { } finally {
fdUnref(exc); status.unreference(exc);
} }
} }
@ -343,20 +401,17 @@ public class DomainSocket implements Closeable {
@Override @Override
public void close() throws IOException { public void close() throws IOException {
// Set the closed bit on this DomainSocket // Set the closed bit on this DomainSocket
int bits; int refCount;
while (true) { try {
bits = status.get(); refCount = status.setClosed();
if ((bits & STATUS_CLOSED_MASK) != 0) { } catch (ClosedChannelException e) {
return; // already closed // Someone else already closed the DomainSocket.
} return;
if (status.compareAndSet(bits, bits | STATUS_CLOSED_MASK)) {
break;
}
} }
// Wait for all references to go away // Wait for all references to go away
boolean didShutdown = false; boolean didShutdown = false;
boolean interrupted = false; boolean interrupted = false;
while ((bits & (~STATUS_CLOSED_MASK)) > 0) { while (refCount > 0) {
if (!didShutdown) { if (!didShutdown) {
try { try {
// Calling shutdown on the socket will interrupt blocking system // Calling shutdown on the socket will interrupt blocking system
@ -373,60 +428,57 @@ public class DomainSocket implements Closeable {
} catch (InterruptedException e) { } catch (InterruptedException e) {
interrupted = true; interrupted = true;
} }
bits = status.get(); refCount = status.getReferenceCount();
} }
// Close the file descriptor. After this point, the file descriptor // At this point, nobody has a reference to the file descriptor,
// number will be reused by something else. Although this DomainSocket // and nobody will be able to get one in the future either.
// object continues to hold the old file descriptor number (it's a final // We now call close(2) on the file descriptor.
// field), we never use it again because we look at the closed bit and // After this point, the file descriptor number will be reused by
// realize that this DomainSocket is not usable. // something else. Although this DomainSocket object continues to hold
// the old file descriptor number (it's a final field), we never use it
// again because this DomainSocket is closed.
close0(fd); close0(fd);
if (interrupted) { if (interrupted) {
Thread.currentThread().interrupt(); Thread.currentThread().interrupt();
} }
} }
/* private native static void sendFileDescriptors0(int fd,
* Clean up if the user forgets to close the socket. FileDescriptor descriptors[],
*/
protected void finalize() throws IOException {
close();
}
private native static void sendFileDescriptors0(int fd, FileDescriptor jfds[],
byte jbuf[], int offset, int length) throws IOException; byte jbuf[], int offset, int length) throws IOException;
/** /**
* Send some FileDescriptor objects to the process on the other side of this * Send some FileDescriptor objects to the process on the other side of this
* socket. * socket.
* *
* @param jfds The file descriptors to send. * @param descriptors The file descriptors to send.
* @param jbuf Some bytes to send. You must send at least * @param jbuf Some bytes to send. You must send at least
* one byte. * one byte.
* @param offset The offset in the jbuf array to start at. * @param offset The offset in the jbuf array to start at.
* @param length Length of the jbuf array to use. * @param length Length of the jbuf array to use.
*/ */
public void sendFileDescriptors(FileDescriptor jfds[], public void sendFileDescriptors(FileDescriptor descriptors[],
byte jbuf[], int offset, int length) throws IOException { byte jbuf[], int offset, int length) throws IOException {
fdRef(); status.reference();
boolean exc = true; boolean exc = true;
try { try {
sendFileDescriptors0(fd, jfds, jbuf, offset, length); sendFileDescriptors0(fd, descriptors, jbuf, offset, length);
exc = false; exc = false;
} finally { } finally {
fdUnref(exc); status.unreference(exc);
} }
} }
private static native int receiveFileDescriptors0(int fd, FileDescriptor[] jfds, private static native int receiveFileDescriptors0(int fd,
FileDescriptor[] descriptors,
byte jbuf[], int offset, int length) throws IOException; byte jbuf[], int offset, int length) throws IOException;
/** /**
* Receive some FileDescriptor objects from the process on the other side of * Receive some FileDescriptor objects from the process on the other side of
* this socket. * this socket.
* *
* @param jfds (output parameter) Array of FileDescriptors. * @param descriptors (output parameter) Array of FileDescriptors.
* We will fill as many slots as possible with file * We will fill as many slots as possible with file
* descriptors passed from the remote process. The * descriptors passed from the remote process. The
* other slots will contain NULL. * other slots will contain NULL.
@ -443,16 +495,16 @@ public class DomainSocket implements Closeable {
* otherwise, it will be positive. * otherwise, it will be positive.
* @throws IOException if there was an I/O error. * @throws IOException if there was an I/O error.
*/ */
public int receiveFileDescriptors(FileDescriptor[] jfds, public int receiveFileDescriptors(FileDescriptor[] descriptors,
byte jbuf[], int offset, int length) throws IOException { byte jbuf[], int offset, int length) throws IOException {
fdRef(); status.reference();
boolean exc = true; boolean exc = true;
try { try {
int nBytes = receiveFileDescriptors0(fd, jfds, jbuf, offset, length); int nBytes = receiveFileDescriptors0(fd, descriptors, jbuf, offset, length);
exc = false; exc = false;
return nBytes; return nBytes;
} finally { } finally {
fdUnref(exc); status.unreference(exc);
} }
} }
@ -462,44 +514,44 @@ public class DomainSocket implements Closeable {
* *
* See {@link DomainSocket#recvFileInputStreams(ByteBuffer)} * See {@link DomainSocket#recvFileInputStreams(ByteBuffer)}
*/ */
public int recvFileInputStreams(FileInputStream[] fis, byte buf[], public int recvFileInputStreams(FileInputStream[] streams, byte buf[],
int offset, int length) throws IOException { int offset, int length) throws IOException {
FileDescriptor fds[] = new FileDescriptor[fis.length]; FileDescriptor descriptors[] = new FileDescriptor[streams.length];
boolean success = false; boolean success = false;
for (int i = 0; i < fis.length; i++) { for (int i = 0; i < streams.length; i++) {
fis[i] = null; streams[i] = null;
} }
fdRef(); status.reference();
try { try {
int ret = receiveFileDescriptors0(fd, fds, buf, offset, length); int ret = receiveFileDescriptors0(fd, descriptors, buf, offset, length);
for (int i = 0, j = 0; i < fds.length; i++) { for (int i = 0, j = 0; i < descriptors.length; i++) {
if (fds[i] != null) { if (descriptors[i] != null) {
fis[j++] = new FileInputStream(fds[i]); streams[j++] = new FileInputStream(descriptors[i]);
fds[i] = null; descriptors[i] = null;
} }
} }
success = true; success = true;
return ret; return ret;
} finally { } finally {
if (!success) { if (!success) {
for (int i = 0; i < fds.length; i++) { for (int i = 0; i < descriptors.length; i++) {
if (fds[i] != null) { if (descriptors[i] != null) {
try { try {
closeFileDescriptor0(fds[i]); closeFileDescriptor0(descriptors[i]);
} catch (Throwable t) { } catch (Throwable t) {
LOG.warn(t); LOG.warn(t);
} }
} else if (fis[i] != null) { } else if (streams[i] != null) {
try { try {
fis[i].close(); streams[i].close();
} catch (Throwable t) { } catch (Throwable t) {
LOG.warn(t); LOG.warn(t);
} finally { } finally {
fis[i] = null; } streams[i] = null; }
} }
} }
} }
fdUnref(!success); status.unreference(!success);
} }
} }
@ -523,7 +575,7 @@ public class DomainSocket implements Closeable {
public class DomainInputStream extends InputStream { public class DomainInputStream extends InputStream {
@Override @Override
public int read() throws IOException { public int read() throws IOException {
fdRef(); status.reference();
boolean exc = true; boolean exc = true;
try { try {
byte b[] = new byte[1]; byte b[] = new byte[1];
@ -531,33 +583,33 @@ public class DomainSocket implements Closeable {
exc = false; exc = false;
return (ret >= 0) ? b[0] : -1; return (ret >= 0) ? b[0] : -1;
} finally { } finally {
fdUnref(exc); status.unreference(exc);
} }
} }
@Override @Override
public int read(byte b[], int off, int len) throws IOException { public int read(byte b[], int off, int len) throws IOException {
fdRef(); status.reference();
boolean exc = true; boolean exc = true;
try { try {
int nRead = DomainSocket.readArray0(DomainSocket.this.fd, b, off, len); int nRead = DomainSocket.readArray0(DomainSocket.this.fd, b, off, len);
exc = false; exc = false;
return nRead; return nRead;
} finally { } finally {
fdUnref(exc); status.unreference(exc);
} }
} }
@Override @Override
public int available() throws IOException { public int available() throws IOException {
fdRef(); status.reference();
boolean exc = true; boolean exc = true;
try { try {
int nAvailable = DomainSocket.available0(DomainSocket.this.fd); int nAvailable = DomainSocket.available0(DomainSocket.this.fd);
exc = false; exc = false;
return nAvailable; return nAvailable;
} finally { } finally {
fdUnref(exc); status.unreference(exc);
} }
} }
@ -579,7 +631,7 @@ public class DomainSocket implements Closeable {
@Override @Override
public void write(int val) throws IOException { public void write(int val) throws IOException {
fdRef(); status.reference();
boolean exc = true; boolean exc = true;
try { try {
byte b[] = new byte[1]; byte b[] = new byte[1];
@ -587,19 +639,19 @@ public class DomainSocket implements Closeable {
DomainSocket.writeArray0(DomainSocket.this.fd, b, 0, 1); DomainSocket.writeArray0(DomainSocket.this.fd, b, 0, 1);
exc = false; exc = false;
} finally { } finally {
fdUnref(exc); status.unreference(exc);
} }
} }
@Override @Override
public void write(byte[] b, int off, int len) throws IOException { public void write(byte[] b, int off, int len) throws IOException {
fdRef(); status.reference();
boolean exc = true; boolean exc = true;
try { try {
DomainSocket.writeArray0(DomainSocket.this.fd, b, off, len); DomainSocket.writeArray0(DomainSocket.this.fd, b, off, len);
exc = false; exc = false;
} finally { } finally {
fdUnref(exc); status.unreference(exc);
} }
} }
} }
@ -618,7 +670,7 @@ public class DomainSocket implements Closeable {
@Override @Override
public int read(ByteBuffer dst) throws IOException { public int read(ByteBuffer dst) throws IOException {
fdRef(); status.reference();
boolean exc = true; boolean exc = true;
try { try {
int nread = 0; int nread = 0;
@ -640,7 +692,7 @@ public class DomainSocket implements Closeable {
exc = false; exc = false;
return nread; return nread;
} finally { } finally {
fdUnref(exc); status.unreference(exc);
} }
} }
} }

View File

@ -38,13 +38,13 @@
#include <sys/un.h> #include <sys/un.h>
#include <unistd.h> #include <unistd.h>
#define SND_BUF_SIZE org_apache_hadoop_net_unix_DomainSocket_SND_BUF_SIZE #define SEND_BUFFER_SIZE org_apache_hadoop_net_unix_DomainSocket_SEND_BUFFER_SIZE
#define RCV_BUF_SIZE org_apache_hadoop_net_unix_DomainSocket_RCV_BUF_SIZE #define RECEIVE_BUFFER_SIZE org_apache_hadoop_net_unix_DomainSocket_RECEIVE_BUFFER_SIZE
#define SND_TIMEO org_apache_hadoop_net_unix_DomainSocket_SND_TIMEO #define SEND_TIMEOUT org_apache_hadoop_net_unix_DomainSocket_SEND_TIMEOUT
#define RCV_TIMEO org_apache_hadoop_net_unix_DomainSocket_RCV_TIMEO #define RECEIVE_TIMEOUT org_apache_hadoop_net_unix_DomainSocket_RECEIVE_TIMEOUT
#define DEFAULT_RCV_TIMEO 120000 #define DEFAULT_RECEIVE_TIMEOUT 120000
#define DEFAULT_SND_TIMEO 120000 #define DEFAULT_SEND_TIMEOUT 120000
#define LISTEN_BACKLOG 128 #define LISTEN_BACKLOG 128
/** /**
@ -391,8 +391,8 @@ JNIEnv *env, jclass clazz, jstring path)
(*env)->Throw(env, jthr); (*env)->Throw(env, jthr);
return -1; return -1;
} }
if (((jthr = setAttribute0(env, fd, SND_TIMEO, DEFAULT_SND_TIMEO))) || if (((jthr = setAttribute0(env, fd, SEND_TIMEOUT, DEFAULT_SEND_TIMEOUT))) ||
((jthr = setAttribute0(env, fd, RCV_TIMEO, DEFAULT_RCV_TIMEO)))) { ((jthr = setAttribute0(env, fd, RECEIVE_TIMEOUT, DEFAULT_RECEIVE_TIMEOUT)))) {
RETRY_ON_EINTR(ret, close(fd)); RETRY_ON_EINTR(ret, close(fd));
(*env)->Throw(env, jthr); (*env)->Throw(env, jthr);
return -1; return -1;
@ -412,7 +412,7 @@ static jthrowable setAttribute0(JNIEnv *env, jint fd, jint type, jint val)
int ret, buf; int ret, buf;
switch (type) { switch (type) {
case SND_BUF_SIZE: case SEND_BUFFER_SIZE:
buf = val; buf = val;
if (setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &buf, sizeof(buf))) { if (setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &buf, sizeof(buf))) {
ret = errno; ret = errno;
@ -420,7 +420,7 @@ static jthrowable setAttribute0(JNIEnv *env, jint fd, jint type, jint val)
"setsockopt(SO_SNDBUF) error: %s", terror(ret)); "setsockopt(SO_SNDBUF) error: %s", terror(ret));
} }
return NULL; return NULL;
case RCV_BUF_SIZE: case RECEIVE_BUFFER_SIZE:
buf = val; buf = val;
if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &buf, sizeof(buf))) { if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &buf, sizeof(buf))) {
ret = errno; ret = errno;
@ -428,7 +428,7 @@ static jthrowable setAttribute0(JNIEnv *env, jint fd, jint type, jint val)
"setsockopt(SO_RCVBUF) error: %s", terror(ret)); "setsockopt(SO_RCVBUF) error: %s", terror(ret));
} }
return NULL; return NULL;
case SND_TIMEO: case SEND_TIMEOUT:
javaMillisToTimeVal(val, &tv); javaMillisToTimeVal(val, &tv);
if (setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, (struct timeval *)&tv, if (setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, (struct timeval *)&tv,
sizeof(tv))) { sizeof(tv))) {
@ -437,7 +437,7 @@ static jthrowable setAttribute0(JNIEnv *env, jint fd, jint type, jint val)
"setsockopt(SO_SNDTIMEO) error: %s", terror(ret)); "setsockopt(SO_SNDTIMEO) error: %s", terror(ret));
} }
return NULL; return NULL;
case RCV_TIMEO: case RECEIVE_TIMEOUT:
javaMillisToTimeVal(val, &tv); javaMillisToTimeVal(val, &tv);
if (setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, (struct timeval *)&tv, if (setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, (struct timeval *)&tv,
sizeof(tv))) { sizeof(tv))) {
@ -487,7 +487,7 @@ JNIEnv *env, jclass clazz, jint fd, jint type)
int ret, rval = 0; int ret, rval = 0;
switch (type) { switch (type) {
case SND_BUF_SIZE: case SEND_BUFFER_SIZE:
len = sizeof(rval); len = sizeof(rval);
if (getsockopt(fd, SOL_SOCKET, SO_SNDBUF, &rval, &len)) { if (getsockopt(fd, SOL_SOCKET, SO_SNDBUF, &rval, &len)) {
ret = errno; ret = errno;
@ -496,7 +496,7 @@ JNIEnv *env, jclass clazz, jint fd, jint type)
return -1; return -1;
} }
return getSockOptBufSizeToJavaBufSize(rval); return getSockOptBufSizeToJavaBufSize(rval);
case RCV_BUF_SIZE: case RECEIVE_BUFFER_SIZE:
len = sizeof(rval); len = sizeof(rval);
if (getsockopt(fd, SOL_SOCKET, SO_RCVBUF, &rval, &len)) { if (getsockopt(fd, SOL_SOCKET, SO_RCVBUF, &rval, &len)) {
ret = errno; ret = errno;
@ -505,7 +505,7 @@ JNIEnv *env, jclass clazz, jint fd, jint type)
return -1; return -1;
} }
return getSockOptBufSizeToJavaBufSize(rval); return getSockOptBufSizeToJavaBufSize(rval);
case SND_TIMEO: case SEND_TIMEOUT:
memset(&tv, 0, sizeof(tv)); memset(&tv, 0, sizeof(tv));
len = sizeof(struct timeval); len = sizeof(struct timeval);
if (getsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, &tv, &len)) { if (getsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, &tv, &len)) {
@ -515,7 +515,7 @@ JNIEnv *env, jclass clazz, jint fd, jint type)
return -1; return -1;
} }
return timeValToJavaMillis(&tv); return timeValToJavaMillis(&tv);
case RCV_TIMEO: case RECEIVE_TIMEOUT:
memset(&tv, 0, sizeof(tv)); memset(&tv, 0, sizeof(tv));
len = sizeof(struct timeval); len = sizeof(struct timeval);
if (getsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &tv, &len)) { if (getsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &tv, &len)) {

View File

@ -282,15 +282,15 @@ public class TestDomainSocket {
DomainSocket serv = DomainSocket.bindAndListen(TEST_PATH); DomainSocket serv = DomainSocket.bindAndListen(TEST_PATH);
try { try {
// Let's set a new receive buffer size // Let's set a new receive buffer size
int bufSize = serv.getAttribute(DomainSocket.RCV_BUF_SIZE); int bufSize = serv.getAttribute(DomainSocket.RECEIVE_BUFFER_SIZE);
int newBufSize = bufSize / 2; int newBufSize = bufSize / 2;
serv.setAttribute(DomainSocket.RCV_BUF_SIZE, newBufSize); serv.setAttribute(DomainSocket.RECEIVE_BUFFER_SIZE, newBufSize);
int nextBufSize = serv.getAttribute(DomainSocket.RCV_BUF_SIZE); int nextBufSize = serv.getAttribute(DomainSocket.RECEIVE_BUFFER_SIZE);
Assert.assertEquals(newBufSize, nextBufSize); Assert.assertEquals(newBufSize, nextBufSize);
// Let's set a server timeout // Let's set a server timeout
int newTimeout = 1000; int newTimeout = 1000;
serv.setAttribute(DomainSocket.RCV_TIMEO, newTimeout); serv.setAttribute(DomainSocket.RECEIVE_TIMEOUT, newTimeout);
int nextTimeout = serv.getAttribute(DomainSocket.RCV_TIMEO); int nextTimeout = serv.getAttribute(DomainSocket.RECEIVE_TIMEOUT);
Assert.assertEquals(newTimeout, nextTimeout); Assert.assertEquals(newTimeout, nextTimeout);
try { try {
serv.accept(); serv.accept();

View File

@ -47,3 +47,5 @@ HDFS-4485. DN should chmod socket path a+w. (Colin Patrick McCabe via atm)
HDFS-4453. Make a simple doc to describe the usage and design of the shortcircuit read feature. (Colin Patrick McCabe via atm) HDFS-4453. Make a simple doc to describe the usage and design of the shortcircuit read feature. (Colin Patrick McCabe via atm)
HDFS-4496. DFSClient: don't create a domain socket unless we need it (Colin Patrick McCabe via todd) HDFS-4496. DFSClient: don't create a domain socket unless we need it (Colin Patrick McCabe via todd)
HDFS-347: style cleanups (Colin Patrick McCabe via atm)

View File

@ -114,7 +114,7 @@ class DomainSocketFactory {
DomainSocket sock = null; DomainSocket sock = null;
try { try {
sock = DomainSocket.connect(escapedPath); sock = DomainSocket.connect(escapedPath);
sock.setAttribute(DomainSocket.RCV_TIMEO, conf.socketTimeout); sock.setAttribute(DomainSocket.RECEIVE_TIMEOUT, conf.socketTimeout);
success = true; success = true;
} catch (IOException e) { } catch (IOException e) {
LOG.warn("error creating DomainSocket", e); LOG.warn("error creating DomainSocket", e);

View File

@ -50,12 +50,12 @@ public class DomainPeer implements Peer {
@Override @Override
public void setReadTimeout(int timeoutMs) throws IOException { public void setReadTimeout(int timeoutMs) throws IOException {
socket.setAttribute(DomainSocket.RCV_TIMEO, timeoutMs); socket.setAttribute(DomainSocket.RECEIVE_TIMEOUT, timeoutMs);
} }
@Override @Override
public int getReceiveBufferSize() throws IOException { public int getReceiveBufferSize() throws IOException {
return socket.getAttribute(DomainSocket.RCV_BUF_SIZE); return socket.getAttribute(DomainSocket.RECEIVE_BUFFER_SIZE);
} }
@Override @Override
@ -66,7 +66,7 @@ public class DomainPeer implements Peer {
@Override @Override
public void setWriteTimeout(int timeoutMs) throws IOException { public void setWriteTimeout(int timeoutMs) throws IOException {
socket.setAttribute(DomainSocket.SND_TIMEO, timeoutMs); socket.setAttribute(DomainSocket.SEND_TIMEOUT, timeoutMs);
} }
@Override @Override

View File

@ -48,7 +48,7 @@ public class DomainPeerServer implements PeerServer {
@Override @Override
public void setReceiveBufferSize(int size) throws IOException { public void setReceiveBufferSize(int size) throws IOException {
sock.setAttribute(DomainSocket.RCV_BUF_SIZE, size); sock.setAttribute(DomainSocket.RECEIVE_BUFFER_SIZE, size);
} }
@Override @Override