You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by gh...@apache.org on 2006/06/19 12:21:47 UTC
svn commit: r415279 - in /incubator/harmony/enhanced/classlib/trunk:
modules/nio/src/main/java/org/apache/harmony/nio/internal/
modules/nio/src/test/java/org/apache/harmony/tests/java/nio/channels/
native-src/linux.IA32/luni/ native-src/win.IA32/luni/
Author: gharley
Date: Mon Jun 19 03:21:46 2006
New Revision: 415279
URL: http://svn.apache.org/viewvc?rev=415279&view=rev
Log:
HARMONY-41 : NIO: java.nio.channels.spi and java.nio.channels.Channels, Pipe, Selector have not been implemented
Added:
incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/SelectionKeyImpl.java (with props)
incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/SelectorImpl.java (with props)
incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/channels/SelectionKeyTest.java (with props)
incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/channels/SelectorTest.java (with props)
Modified:
incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/SelectorProviderImpl.java
incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/channels/AllTests.java
incubator/harmony/enhanced/classlib/trunk/native-src/linux.IA32/luni/OSNetworkSystemLinux.c
incubator/harmony/enhanced/classlib/trunk/native-src/win.IA32/luni/OSNetworkSystemWin32.c
Added: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/SelectionKeyImpl.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/SelectionKeyImpl.java?rev=415279&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/SelectionKeyImpl.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/SelectionKeyImpl.java Mon Jun 19 03:21:46 2006
@@ -0,0 +1,93 @@
+/* Copyright 2006 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.harmony.nio.internal;
+
+import java.nio.channels.CancelledKeyException;
+import java.nio.channels.SelectableChannel;
+import java.nio.channels.SelectionKey;
+import java.nio.channels.Selector;
+import java.nio.channels.spi.AbstractSelectableChannel;
+import java.nio.channels.spi.AbstractSelectionKey;
+
+/*
+ * Default implementation of SelectionKey
+ */
+final class SelectionKeyImpl extends AbstractSelectionKey {
+
+ private AbstractSelectableChannel channel;
+
+ int oldInterestOps;
+
+ private int interestOps;
+
+ private int readyOps;
+
+ private SelectorImpl selector;
+
+ public SelectionKeyImpl(AbstractSelectableChannel channel, int operations,
+ Object attachment, SelectorImpl selector) {
+ super();
+ this.channel = channel;
+ interestOps = operations;
+ this.selector = selector;
+ attach(attachment);
+ }
+
+ public SelectableChannel channel() {
+ return channel;
+ }
+
+ public int interestOps() {
+ checkValid();
+ synchronized (selector.keysLock) {
+ return interestOps;
+ }
+ }
+
+ public SelectionKey interestOps(int operations) {
+ checkValid();
+ if ((operations & ~(channel().validOps())) != 0) {
+ throw new IllegalArgumentException();
+ }
+ synchronized (selector.keysLock) {
+ interestOps = operations;
+ }
+ return this;
+ }
+
+ public int readyOps() {
+ checkValid();
+ return readyOps;
+ }
+
+ public Selector selector() {
+ return selector;
+ }
+
+ /*
+ * package private method for setting the ready operation by selector
+ */
+ void setReadyOps(int readyOps) {
+ this.readyOps = readyOps;
+ }
+
+ private void checkValid() {
+ if (!isValid()) {
+ throw new CancelledKeyException();
+ }
+ }
+
+}
\ No newline at end of file
Propchange: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/SelectionKeyImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/SelectorImpl.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/SelectorImpl.java?rev=415279&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/SelectorImpl.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/SelectorImpl.java Mon Jun 19 03:21:46 2006
@@ -0,0 +1,391 @@
+/* Copyright 2006 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.harmony.nio.internal;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.channels.ClosedSelectorException;
+import java.nio.channels.IllegalSelectorException;
+import java.nio.channels.Pipe;
+import java.nio.channels.SelectableChannel;
+import java.nio.channels.SelectionKey;
+import java.nio.channels.Selector;
+import java.nio.channels.SocketChannel;
+import java.nio.channels.spi.AbstractSelectableChannel;
+import java.nio.channels.spi.AbstractSelectionKey;
+import java.nio.channels.spi.AbstractSelector;
+import java.nio.channels.spi.SelectorProvider;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.harmony.luni.platform.INetworkSystem;
+import org.apache.harmony.luni.platform.Platform;
+
+/*
+ * Default implementation of java.nio.channels.Selector
+ *
+ */
+final class SelectorImpl extends AbstractSelector {
+
+ private static final int MOCK_WRITEBUF_SIZE = 1;
+
+ private static final int MOCK_READBUF_SIZE = 8;
+
+ private static final int NA = 0;
+
+ private static final int READABLE = 1;
+
+ private static final int WRITEABLE = 2;
+
+ private static final int SELECT_BLOCK = -1;
+
+ private static final int SELECT_NOW = 0;
+
+ // keysLock is used to brief synchronization when get selectionKeys snapshot
+ // before selection
+ final Object keysLock = new Object();
+
+ private final Set<SelectionKey> keys = new HashSet<SelectionKey>();
+
+ private Set<SelectionKey> unmodifiableKeys = Collections
+ .unmodifiableSet(keys);
+
+ private final Set<SelectionKey> selectedKeys = new HashSet<SelectionKey>();
+
+ private Set<SelectionKey> unaddableSelectedKeys = new UnaddableSet<SelectionKey>(
+ selectedKeys);
+
+ // sink and source are used by wakeup()
+ private Pipe.SinkChannel sink;
+
+ private Pipe.SourceChannel source;
+
+ private List<SelectableChannel> readableChannels = new ArrayList<SelectableChannel>();
+
+ private List<SelectableChannel> writableChannels = new ArrayList<SelectableChannel>();
+
+ private SelectableChannel[] readable;
+
+ private SelectableChannel[] writable;
+
+ public SelectorImpl(SelectorProvider selectorProvider) {
+ super(selectorProvider);
+ try {
+ Pipe mockSelector = selectorProvider.openPipe();
+ sink = mockSelector.sink();
+ source = mockSelector.source();
+ source.configureBlocking(false);
+ } catch (IOException e) {
+ // do nothing
+ }
+ }
+
+ /*
+ * @see java.nio.channels.spi.AbstractSelector#implCloseSelector()
+ */
+ protected void implCloseSelector() throws IOException {
+ doCancel();
+ for (SelectionKey sk : keys) {
+ deregister((AbstractSelectionKey) sk);
+ }
+ wakeup();
+ }
+
+ /*
+ * @see java.nio.channels.spi.AbstractSelector#register(java.nio.channels.spi.AbstractSelectableChannel,
+ * int, java.lang.Object)
+ */
+ protected SelectionKey register(AbstractSelectableChannel channel,
+ int operations, Object attachment) {
+ if (!provider().equals(channel.provider())) {
+ throw new IllegalSelectorException();
+ }
+ synchronized (this) {
+ synchronized (keys) {
+ SelectionKey sk = new SelectionKeyImpl(channel, operations,
+ attachment, this);
+ keys.add(sk);
+ return sk;
+ }
+ }
+ }
+
+ /*
+ * @see java.nio.channels.Selector#keys()
+ */
+ public synchronized Set<SelectionKey> keys() {
+ closeCheck();
+ return unmodifiableKeys;
+ }
+
+ private void closeCheck() {
+ if (!isOpen()) {
+ throw new ClosedSelectorException();
+ }
+ }
+
+ /*
+ * @see java.nio.channels.Selector#select()
+ */
+ public int select() throws IOException {
+ return selectInternal(SELECT_BLOCK);
+ }
+
+ /*
+ * @see java.nio.channels.Selector#select(long)
+ */
+ public int select(long timeout) throws IOException {
+ if (timeout < 0) {
+ throw new IllegalArgumentException();
+ }
+ return selectInternal((0 == timeout) ? SELECT_BLOCK : timeout);
+ }
+
+ /*
+ * @see java.nio.channels.Selector#selectNow()
+ */
+ public int selectNow() throws IOException {
+ return selectInternal(SELECT_NOW);
+ }
+
+ private int selectInternal(long timeout) throws IOException {
+ closeCheck();
+ synchronized (this) {
+ synchronized (keys) {
+ synchronized (selectedKeys) {
+ doCancel();
+ return selectImpl(timeout);
+ }
+ }
+ }
+ }
+
+ private boolean isConnected(SelectionKeyImpl key) {
+ SelectableChannel channel = key.channel();
+ if (channel instanceof SocketChannel) {
+ return ((SocketChannel) channel).isConnected();
+ }
+ return true;
+ }
+
+ // Prepares and adds channels to list for selection
+ private void prepareChannels() {
+ readableChannels.add(source);
+ synchronized (keysLock) {
+ for (Iterator i = keys.iterator(); i.hasNext();) {
+ SelectionKeyImpl key = (SelectionKeyImpl) i.next();
+ key.oldInterestOps = key.interestOps();
+ boolean isReadableChannel = ((SelectionKey.OP_ACCEPT | SelectionKey.OP_READ) & key.oldInterestOps) != 0;
+ boolean isWritableChannel = ((SelectionKey.OP_CONNECT | SelectionKey.OP_WRITE) & key.oldInterestOps) != 0;
+ if (isReadableChannel) {
+ readableChannels.add(key.channel());
+ }
+ if (isWritableChannel) {
+ writableChannels.add(key.channel());
+ }
+ }
+ }
+ readable = (SelectableChannel[]) readableChannels
+ .toArray(new SelectableChannel[0]);
+ writable = (SelectableChannel[]) writableChannels
+ .toArray(new SelectableChannel[0]);
+ readableChannels.clear();
+ writableChannels.clear();
+ }
+
+ // Analyses selected channels and adds keys of ready channels to
+ // selectedKeys list
+ private int processSelectResult(int[] readyChannels) throws IOException {
+ if (0 == readyChannels.length) {
+ return 0;
+ }
+ // if the mock channel is selected, read the content.
+ if (READABLE == readyChannels[0]) {
+ ByteBuffer readbuf = ByteBuffer.allocate(MOCK_READBUF_SIZE);
+ while (source.read(readbuf) > 0) {
+ readbuf.flip();
+ }
+ }
+ int selected = 0;
+ for (int i = 1; i < readyChannels.length; i++) {
+ SelectionKeyImpl key = (SelectionKeyImpl) (i >= readable.length ? writable[i
+ - readable.length].keyFor(this)
+ : readable[i].keyFor(this));
+ if (null == key) {
+ continue;
+ }
+ boolean isOldSelectedKey = selectedKeys.contains(key);
+ int selectedOp = 0;
+ // set ready ops
+ switch (readyChannels[i]) {
+ case NA:
+ selectedOp = 0;
+ break;
+ case READABLE:
+ selectedOp = (SelectionKey.OP_READ | SelectionKey.OP_ACCEPT)
+ & key.oldInterestOps;
+ break;
+ case WRITEABLE:
+ if (isConnected(key)) {
+ selectedOp = SelectionKey.OP_WRITE & key.oldInterestOps;
+ } else {
+ selectedOp = SelectionKey.OP_CONNECT & key.oldInterestOps;
+ }
+ break;
+ }
+
+ if (0 != selectedOp) {
+ if (isOldSelectedKey && key.readyOps() != selectedOp) {
+ key.setReadyOps(key.readyOps() | selectedOp);
+ selected++;
+ } else if (!isOldSelectedKey) {
+ key.setReadyOps(selectedOp);
+ selectedKeys.add(key);
+ selected++;
+ }
+ }
+ }
+ return selected;
+ }
+
+ private int selectImpl(long timeout) throws IOException {
+ INetworkSystem os = Platform.getNetworkSystem();
+ int[] readyChannels = null;
+ boolean isBlock = (SELECT_NOW != timeout);
+ if (keys.size() == 0) {
+ return 0;
+ }
+ prepareChannels();
+ try {
+ if (isBlock) {
+ begin();
+ }
+ readyChannels = os.select(readable, writable, timeout);
+ } finally {
+ if (isBlock) {
+ end();
+ }
+ }
+ return processSelectResult(readyChannels);
+ }
+
+ /*
+ * @see java.nio.channels.Selector#selectedKeys()
+ */
+ public synchronized Set<SelectionKey> selectedKeys() {
+ closeCheck();
+ return unaddableSelectedKeys;
+ }
+
+ private void doCancel() {
+ Set<SelectionKey> cancelledKeys = cancelledKeys();
+ synchronized (cancelledKeys) {
+ if (cancelledKeys.size() > 0) {
+ for (SelectionKey currentkey : cancelledKeys) {
+ deregister((AbstractSelectionKey) currentkey);
+ keys.remove(currentkey);
+ selectedKeys.remove(currentkey);
+ }
+ }
+ cancelledKeys.clear();
+ }
+ }
+
+ /*
+ * @see java.nio.channels.Selector#wakeup()
+ */
+ public Selector wakeup() {
+ try {
+ sink.write(ByteBuffer.allocate(MOCK_WRITEBUF_SIZE));
+ } catch (IOException e) {
+ // do nothing
+ }
+ return this;
+ }
+
+ private static class UnaddableSet<E> implements Set<E> {
+
+ private Set<E> set;
+
+ UnaddableSet(Set<E> set) {
+ this.set = set;
+ }
+
+ public boolean equals(Object object) {
+ return set.equals(object);
+ }
+
+ public int hashCode() {
+ return set.hashCode();
+ }
+
+ public boolean add(Object object) {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean addAll(Collection<? extends E> c) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void clear() {
+ set.clear();
+ }
+
+ public boolean contains(Object object) {
+ return set.contains(object);
+ }
+
+ public boolean containsAll(Collection<?> c) {
+ return set.containsAll(c);
+ }
+
+ public boolean isEmpty() {
+ return set.isEmpty();
+ }
+
+ public Iterator<E> iterator() {
+ return set.iterator();
+ }
+
+ public boolean remove(Object object) {
+ return set.remove(object);
+ }
+
+ public boolean removeAll(Collection<?> c) {
+ return set.removeAll(c);
+ }
+
+ public boolean retainAll(Collection<?> c) {
+ return set.retainAll(c);
+ }
+
+ public int size() {
+ return set.size();
+ }
+
+ public Object[] toArray() {
+ return set.toArray();
+ }
+
+ public <T> T[] toArray(T[] a) {
+ return (T[]) set.toArray(a);
+ }
+ }
+}
Propchange: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/SelectorImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/SelectorProviderImpl.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/SelectorProviderImpl.java?rev=415279&r1=415278&r2=415279&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/SelectorProviderImpl.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/SelectorProviderImpl.java Mon Jun 19 03:21:46 2006
@@ -57,10 +57,8 @@
* @see java.nio.channels.spi.SelectorProvider#openSelector()
*/
public AbstractSelector openSelector() throws IOException {
-// return new SelectorImpl(this);
- //FIXME: wait for JIRA-41
- return null;
- }
+ return new SelectorImpl(this);
+ }
/*
*
Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/channels/AllTests.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/channels/AllTests.java?rev=415279&r1=415278&r2=415279&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/channels/AllTests.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/channels/AllTests.java Mon Jun 19 03:21:46 2006
@@ -33,6 +33,8 @@
suite.addTestSuite(ServerSocketChannelTest.class);
suite.addTestSuite(SocketChannelTest.class);
suite.addTestSuite(SourceChannelTest.class);
+ suite.addTestSuite(SelectionKeyTest.class);
+ suite.addTestSuite(SelectorTest.class);
//$JUnit-END$
return suite;
}
Added: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/channels/SelectionKeyTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/channels/SelectionKeyTest.java?rev=415279&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/channels/SelectionKeyTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/channels/SelectionKeyTest.java Mon Jun 19 03:21:46 2006
@@ -0,0 +1,320 @@
+/* Copyright 2006 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.harmony.tests.java.nio.channels;
+
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.net.ServerSocket;
+import java.nio.channels.CancelledKeyException;
+import java.nio.channels.SelectableChannel;
+import java.nio.channels.SelectionKey;
+import java.nio.channels.Selector;
+import java.nio.channels.SocketChannel;
+
+import junit.framework.TestCase;
+import tests.support.Support_PortManager;
+
+/*
+ * Tests for SelectionKey and its default implemetation
+ */
+public class SelectionKeyTest extends TestCase {
+
+ Selector selector;
+
+ SocketChannel sc;
+
+ SelectionKey selectionKey;
+
+ private static String LOCAL_ADDR = "127.0.0.1";
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ selector = Selector.open();
+ sc = SocketChannel.open();
+ sc.configureBlocking(false);
+ selectionKey = sc.register(selector, SelectionKey.OP_CONNECT);
+ }
+
+ protected void tearDown() throws Exception {
+ selectionKey.cancel();
+ selectionKey = null;
+ selector.close();
+ selector = null;
+ super.tearDown();
+ }
+
+ static class MockSelectionKey extends SelectionKey {
+ private int interestOps;
+
+ MockSelectionKey(int ops) {
+ interestOps = ops;
+ }
+
+ public void cancel() {
+ // do nothing
+ }
+
+ public SelectableChannel channel() {
+ return null;
+ }
+
+ public int interestOps() {
+ return 0;
+ }
+
+ public SelectionKey interestOps(int operations) {
+ return null;
+ }
+
+ public boolean isValid() {
+ return true;
+ }
+
+ public int readyOps() {
+ return interestOps;
+ }
+
+ public Selector selector() {
+ return null;
+ }
+ }
+
+ /**
+ * @tests java.nio.channels.SelectionKey#attach(Object)
+ */
+ public void test_attach() {
+ MockSelectionKey mockSelectionKey = new MockSelectionKey(SelectionKey.OP_ACCEPT);
+ // no previous, return null
+ Object o = new Object();
+ Object check = mockSelectionKey.attach(o);
+ assertNull(check);
+
+ // null parameter is ok
+ check = mockSelectionKey.attach(null);
+ assertSame(o, check);
+
+ check = mockSelectionKey.attach(o);
+ assertNull(check);
+ }
+
+ /**
+ * @tests java.nio.channels.SelectionKey#attachment()
+ */
+ public void test_attachment() {
+ MockSelectionKey mockSelectionKey = new MockSelectionKey(SelectionKey.OP_ACCEPT);
+ assertNull(mockSelectionKey.attachment());
+ Object o = new Object();
+ mockSelectionKey.attach(o);
+ assertSame(o, mockSelectionKey.attachment());
+ }
+
+ /**
+ * @tests java.nio.channels.SelectionKey#channel()
+ */
+ public void test_channel() {
+ assertSame(sc, selectionKey.channel());
+ // can be invoked even canceled
+ selectionKey.cancel();
+ assertSame(sc, selectionKey.channel());
+ }
+
+ /**
+ * @tests java.nio.channels.SelectionKey#interestOps()
+ */
+ public void test_interestOps() {
+ assertEquals(SelectionKey.OP_CONNECT, selectionKey.interestOps());
+ }
+
+ /**
+ * @tests java.nio.channels.SelectionKey#interestOps(int)
+ */
+ public void test_interestOpsI() {
+ selectionKey.interestOps(SelectionKey.OP_WRITE);
+ assertEquals(SelectionKey.OP_WRITE, selectionKey.interestOps());
+
+ try {
+ selectionKey.interestOps(SelectionKey.OP_ACCEPT);
+ fail("should throw IAE.");
+ } catch (IllegalArgumentException ex) {
+ // expected;
+ }
+
+ try {
+ selectionKey.interestOps(~sc.validOps());
+ fail("should throw IAE.");
+ } catch (IllegalArgumentException ex) {
+ // expected;
+ }
+ try {
+ selectionKey.interestOps(-1);
+ fail("should throw IAE.");
+ } catch (IllegalArgumentException ex) {
+ // expected;
+ }
+
+ }
+
+ /**
+ * @tests java.nio.channels.SelectionKey#isValid()
+ */
+ public void test_isValid() {
+ assertTrue(selectionKey.isValid());
+ }
+
+ /**
+ * @tests java.nio.channels.SelectionKey#isValid()
+ */
+ public void test_isValid_KeyCancelled() {
+ selectionKey.cancel();
+ assertFalse(selectionKey.isValid());
+ }
+
+ /**
+ * @tests java.nio.channels.SelectionKey#isValid()
+ */
+ public void test_isValid_ChannelColsed() throws IOException {
+ sc.close();
+ assertFalse(selectionKey.isValid());
+ }
+
+ /**
+ * @tests java.nio.channels.SelectionKey#isValid()
+ */
+ public void test_isValid_SelectorClosed() throws IOException {
+ selector.close();
+ assertFalse(selectionKey.isValid());
+ }
+
+ /**
+ * @tests java.nio.channels.SelectionKey#isAcceptable()
+ */
+ public void test_isAcceptable() throws IOException {
+ MockSelectionKey mockSelectionKey1 = new MockSelectionKey(SelectionKey.OP_ACCEPT);
+ assertTrue(mockSelectionKey1.isAcceptable());
+ MockSelectionKey mockSelectionKey2 = new MockSelectionKey(SelectionKey.OP_CONNECT);
+ assertFalse(mockSelectionKey2.isAcceptable());
+ }
+
+ /**
+ * @tests java.nio.channels.SelectionKey#isConnectable()
+ */
+ public void test_isConnectable() {
+ MockSelectionKey mockSelectionKey1 = new MockSelectionKey(SelectionKey.OP_CONNECT);
+ assertTrue(mockSelectionKey1.isConnectable());
+ MockSelectionKey mockSelectionKey2 = new MockSelectionKey(SelectionKey.OP_ACCEPT);
+ assertFalse(mockSelectionKey2.isConnectable());
+ }
+
+ /**
+ * @tests java.nio.channels.SelectionKey#isReadable()
+ */
+ public void test_isReadable() {
+ MockSelectionKey mockSelectionKey1 = new MockSelectionKey(SelectionKey.OP_READ);
+ assertTrue(mockSelectionKey1.isReadable());
+ MockSelectionKey mockSelectionKey2 = new MockSelectionKey(SelectionKey.OP_ACCEPT);
+ assertFalse(mockSelectionKey2.isReadable());
+ }
+
+ /**
+ * @tests java.nio.channels.SelectionKey#isWritable()
+ */
+ public void test_isWritable() {
+ MockSelectionKey mockSelectionKey1 = new MockSelectionKey(SelectionKey.OP_WRITE);
+ assertTrue(mockSelectionKey1.isWritable());
+ MockSelectionKey mockSelectionKey2 = new MockSelectionKey(SelectionKey.OP_ACCEPT);
+ assertFalse(mockSelectionKey2.isWritable());
+ }
+
+ /**
+ * @tests java.nio.channels.SelectionKey#cancel()
+ */
+ public void test_cancel() {
+ selectionKey.cancel();
+ try {
+ selectionKey.isAcceptable();
+ fail("should throw CancelledKeyException.");
+ } catch (CancelledKeyException ex) {
+ // expected
+ }
+ try {
+ selectionKey.isConnectable();
+ fail("should throw CancelledKeyException.");
+ } catch (CancelledKeyException ex) {
+ // expected
+ }
+ try {
+ selectionKey.isReadable();
+ fail("should throw CancelledKeyException.");
+ } catch (CancelledKeyException ex) {
+ // expected
+ }
+ try {
+ selectionKey.isWritable();
+ fail("should throw CancelledKeyException.");
+ } catch (CancelledKeyException ex) {
+ // expected
+ }
+
+ try {
+ selectionKey.readyOps();
+ fail("should throw CancelledKeyException.");
+ } catch (CancelledKeyException ex) {
+ // expected
+ }
+
+ try {
+ selectionKey.interestOps(SelectionKey.OP_CONNECT);
+ fail("should throw CancelledKeyException.");
+ } catch (CancelledKeyException ex) {
+ // expected
+ }
+
+ try {
+ selectionKey.interestOps();
+ fail("should throw CancelledKeyException.");
+ } catch (CancelledKeyException ex) {
+ // expected
+ }
+ }
+
+ /**
+ * @tests java.nio.channels.SelectionKey#readyOps()
+ */
+ public void test_readyOps() throws IOException {
+ int port = Support_PortManager.getNextPort();
+ ServerSocket ss = new ServerSocket(port);
+ try {
+ sc.connect(new InetSocketAddress(LOCAL_ADDR, port));
+ assertEquals(0, selectionKey.readyOps());
+ assertFalse(selectionKey.isConnectable());
+ selector.selectNow();
+ assertEquals(SelectionKey.OP_CONNECT, selectionKey.readyOps());
+ } finally {
+ ss.close();
+ ss = null;
+ }
+
+ }
+
+ /**
+ * @tests java.nio.channels.SelectionKey#selector()
+ */
+ public void test_selector() {
+ assertSame(selector, selectionKey.selector());
+ selectionKey.cancel();
+ assertSame(selector, selectionKey.selector());
+ }
+}
Propchange: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/channels/SelectionKeyTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/channels/SelectorTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/channels/SelectorTest.java?rev=415279&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/channels/SelectorTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/channels/SelectorTest.java Mon Jun 19 03:21:46 2006
@@ -0,0 +1,543 @@
+/* Copyright 2006 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.harmony.tests.java.nio.channels;
+
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.net.ServerSocket;
+import java.nio.ByteBuffer;
+import java.nio.channels.ClosedChannelException;
+import java.nio.channels.ClosedSelectorException;
+import java.nio.channels.SelectionKey;
+import java.nio.channels.Selector;
+import java.nio.channels.ServerSocketChannel;
+import java.nio.channels.SocketChannel;
+import java.nio.channels.spi.SelectorProvider;
+import java.util.Set;
+
+import junit.framework.TestCase;
+import tests.support.Support_PortManager;
+
+/*
+ * Tests for Selector and its default implemetation
+ */
+public class SelectorTest extends TestCase {
+
+ private static final int WAIT_TIME = 100;
+
+ private static final int PORT = Support_PortManager.getNextPort();
+
+ private static final InetSocketAddress LOCAL_ADDRESS = new InetSocketAddress(
+ "127.0.0.1", PORT);
+
+ Selector selector;
+
+ ServerSocketChannel ssc;
+
+ enum SelectType {
+ NULL, TIMEOUT, NOW
+ };
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ ssc = ServerSocketChannel.open();
+ ssc.configureBlocking(false);
+ ServerSocket ss = ssc.socket();
+ InetSocketAddress address = new InetSocketAddress(PORT);
+ ss.bind(address);
+ selector = Selector.open();
+ }
+
+ protected void tearDown() throws Exception {
+ try {
+ ssc.close();
+ } catch (Exception e) {
+ // do nothing
+ }
+ try {
+ selector.close();
+ } catch (Exception e) {
+ // do nothing
+ }
+ super.tearDown();
+ }
+
+ /**
+ * @tests java.nio.channels.Selector#open()
+ */
+ public void test_open() throws IOException {
+ assertNotNull(selector);
+ }
+
+ /**
+ * @tests Selector#isOpen()
+ */
+ public void test_isOpen() throws IOException {
+ assertTrue(selector.isOpen());
+ selector.close();
+ assertFalse(selector.isOpen());
+ }
+
+ /**
+ * @tests java.nio.channels.Selector#provider()
+ */
+ public void test_provider() throws IOException {
+ // should be system default provider
+ assertNotNull(selector.provider());
+ assertSame(SelectorProvider.provider(), selector.provider());
+ }
+
+ /**
+ * @tests java.nio.channels.Selector#keys()
+ */
+ public void test_keys() throws IOException {
+ SelectionKey key = ssc.register(selector, SelectionKey.OP_ACCEPT);
+
+ Set<SelectionKey> keySet = selector.keys();
+ Set<SelectionKey> keySet2 = selector.keys();
+
+ assertSame(keySet, keySet2);
+ assertEquals(1,keySet.size());
+ SelectionKey key2 = keySet.iterator().next();
+ assertEquals(key,key2);
+
+ // Any attempt to modify keys will cause UnsupportedOperationException
+ SocketChannel sc = SocketChannel.open();
+ sc.configureBlocking(false);
+ SelectionKey key3 = sc.register(selector, SelectionKey.OP_READ);
+ try {
+ keySet2.add(key3);
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ keySet2.remove(key3);
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ keySet2.clear();
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ selector.close();
+ try {
+ selector.keys();
+ fail("should throw ClosedSelectorException");
+ } catch (ClosedSelectorException e) {
+ // expected
+ }
+ }
+
+ /**
+ * @tests java.nio.channels.Selector#keys()
+ */
+ public void test_selectedKeys() throws IOException {
+ SocketChannel sc = SocketChannel.open();
+ ssc.register(selector, SelectionKey.OP_ACCEPT);
+ try {
+ int count = 0;
+ sc.connect(LOCAL_ADDRESS);
+ count = blockingSelect(SelectType.NULL, 0);
+ assertEquals(1, count);
+ Set<SelectionKey> selectedKeys = selector.selectedKeys();
+ Set<SelectionKey> selectedKeys2 = selector.selectedKeys();
+ assertSame(selectedKeys, selectedKeys2);
+
+ assertEquals(1, selectedKeys.size());
+ assertEquals(ssc.keyFor(selector), selectedKeys.iterator().next());
+ // add one key into selectedKeys
+ try {
+ selectedKeys.add(ssc.keyFor(selector));
+ fail("Should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ // no exception should be thrown
+ selectedKeys.clear();
+
+ Set<SelectionKey> selectedKeys3 = selector.selectedKeys();
+ assertSame(selectedKeys, selectedKeys3);
+
+ ssc.keyFor(selector).cancel();
+ assertEquals(0, selectedKeys.size());
+ selector.close();
+ try {
+ selector.selectedKeys();
+ fail("should throw ClosedSelectorException");
+ } catch (ClosedSelectorException e) {
+ // expected
+ }
+ } finally {
+ sc.close();
+ }
+ }
+
+ /**
+ * @tests java.nio.channel.Selector#selectNow()
+ */
+ public void test_selectNow() throws IOException {
+ assert_select_OP_ACCEPT(SelectType.NOW, 0);
+ assert_select_OP_CONNECT(SelectType.NOW, 0);
+ assert_select_OP_READ(SelectType.NOW, 0);
+ assert_select_OP_WRITE(SelectType.NOW, 0);
+ }
+
+ /**
+ * @tests java.nio.channel.Selector#selectNow()
+ */
+ public void test_selectNow_SelectorClosed() throws IOException {
+ assert_select_SelectorClosed(SelectType.NOW, 0);
+ }
+
+ /**
+ * @test java.nio.channels.Selector#selectNow()
+ */
+ public void test_selectNow_Timeout() throws IOException {
+ // make sure selectNow doesn't block
+ selector.selectNow();
+ }
+
+ /**
+ * @tests java.nio.channel.Selector#select()
+ */
+ public void test_select() throws IOException {
+ assert_select_OP_ACCEPT(SelectType.NULL, 0);
+ assert_select_OP_CONNECT(SelectType.NULL, 0);
+ assert_select_OP_READ(SelectType.NULL, 0);
+ assert_select_OP_WRITE(SelectType.NULL, 0);
+ }
+
+ /**
+ * @tests java.nio.channel.Selector#select()
+ */
+ public void test_select_SelectorClosed() throws IOException {
+ assert_select_SelectorClosed(SelectType.NULL, 0);
+ }
+
+ /**
+ * @tests java.nio.channel.Selector#select(long)
+ */
+ public void test_selectJ() throws IOException {
+ assert_select_OP_ACCEPT(SelectType.TIMEOUT, 0);
+ assert_select_OP_CONNECT(SelectType.TIMEOUT, 0);
+ assert_select_OP_READ(SelectType.TIMEOUT, 0);
+ assert_select_OP_WRITE(SelectType.TIMEOUT, 0);
+
+ assert_select_OP_ACCEPT(SelectType.TIMEOUT, WAIT_TIME);
+ assert_select_OP_CONNECT(SelectType.TIMEOUT, WAIT_TIME);
+ assert_select_OP_READ(SelectType.TIMEOUT, WAIT_TIME);
+ assert_select_OP_WRITE(SelectType.TIMEOUT, WAIT_TIME);
+ }
+
+ /**
+ * @tests java.nio.channel.Selector#select(long)
+ */
+ public void test_selectJ_SelectorClosed() throws IOException {
+ assert_select_SelectorClosed(SelectType.TIMEOUT, 0);
+ selector = Selector.open();
+ assert_select_SelectorClosed(SelectType.TIMEOUT, WAIT_TIME);
+ }
+
+ /**
+ * @tests java.nio.channel.Selector#select(long)
+ */
+ public void test_selectJ_Exception() throws IOException {
+ try {
+ selector.select(-1);
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+ }
+
+ /**
+ * @test java.nio.channels.Selector#select(long)
+ */
+ public void test_selectJ_Timeout() throws IOException {
+ // make sure select(timeout) doesn't block
+ selector.select(WAIT_TIME);
+ }
+
+ /**
+ * @tests java.nio.channels.Selector#wakeup()
+ */
+ public void test_wakeup() throws IOException {
+ /*
+ * make sure the test does not block on select
+ */
+ selector.wakeup();
+ selectOnce(SelectType.NULL, 0);
+ selector.wakeup();
+ selectOnce(SelectType.TIMEOUT, 0);
+
+ // try to wakeup select. The invocation sequence of wakeup and select
+ // doesn't affect test result.
+ new Thread() {
+ public void run() {
+
+ try {
+ Thread.sleep(WAIT_TIME);
+ } catch (InterruptedException e) {
+ // ignore
+ }
+ selector.wakeup();
+ }
+ }.start();
+ selectOnce(SelectType.NULL, 0);
+
+ // try to wakeup select. The invocation sequence of wakeup and select
+ // doesn't affect test result.
+ new Thread() {
+ public void run() {
+
+ try {
+ Thread.sleep(WAIT_TIME);
+ } catch (InterruptedException e) {
+ // ignore
+ }
+ selector.wakeup();
+ }
+ }.start();
+ selectOnce(SelectType.TIMEOUT, 0);
+ }
+
+ private void assert_select_SelectorClosed(SelectType type, int timeout)
+ throws IOException {
+ // selector is closed
+ selector.close();
+ try {
+ selectOnce(type, timeout);
+ fail("should throw ClosedSelectorException");
+ } catch (ClosedSelectorException e) {
+ // expected
+ }
+ }
+
+ private void assert_select_OP_ACCEPT(SelectType type, int timeout)
+ throws IOException, ClosedChannelException {
+ SocketChannel sc = SocketChannel.open();
+ SocketChannel client = null;
+ try {
+ ssc.register(selector, SelectionKey.OP_ACCEPT);
+ sc.connect(LOCAL_ADDRESS);
+ int count = blockingSelect(type, timeout);
+ assertEquals(1, count);
+ Set<SelectionKey> selectedKeys = selector.selectedKeys();
+ assertEquals(1, selectedKeys.size());
+ SelectionKey key = selectedKeys.iterator().next();
+ assertEquals(ssc.keyFor(selector), key);
+ assertEquals(SelectionKey.OP_ACCEPT, key.readyOps());
+ // select again, it should return 0
+ count = selectOnce(type, timeout);
+ assertEquals(0,count);
+ // but selectedKeys remains the same as previous
+ assertSame(selectedKeys, selector.selectedKeys());
+ client = ssc.accept();
+ selectedKeys.clear();
+ } finally {
+ try {
+ sc.close();
+ } catch (IOException e) {
+ // do nothing
+ }
+ if (null != client) {
+ client.close();
+ }
+ }
+ ssc.keyFor(selector).cancel();
+ }
+
+ private void assert_select_OP_CONNECT(SelectType type, int timeout)
+ throws IOException, ClosedChannelException {
+ SocketChannel sc = SocketChannel.open();
+ sc.configureBlocking(false);
+ sc.register(selector, SelectionKey.OP_CONNECT);
+ try {
+ sc.connect(LOCAL_ADDRESS);
+ int count = blockingSelect(type, timeout);
+ assertEquals(1, count);
+ Set<SelectionKey> selectedKeys = selector.selectedKeys();
+ assertEquals(1, selectedKeys.size());
+ SelectionKey key = selectedKeys.iterator().next();
+ assertEquals(sc.keyFor(selector), key);
+ assertEquals(SelectionKey.OP_CONNECT, key.readyOps());
+ // select again, it should return 0
+ count = selectOnce(type, timeout);
+ assertEquals(0, count);
+ // but selectedKeys remains the same as previous
+ assertSame(selectedKeys, selector.selectedKeys());
+ sc.finishConnect();
+ selectedKeys.clear();
+ } finally {
+ try {
+ ssc.accept().close();
+ } catch (IOException e) {
+ // do nothing
+ }
+
+ try {
+ sc.close();
+ } catch (IOException e) {
+ // do nothing
+ }
+ }
+ }
+
+ private void assert_select_OP_READ(SelectType type, int timeout)
+ throws IOException {
+ SocketChannel sc = SocketChannel.open();
+ SocketChannel client = null;
+ SocketChannel sc2 = SocketChannel.open();
+ SocketChannel client2 = null;
+ try {
+ ssc.configureBlocking(true);
+ sc.connect(LOCAL_ADDRESS);
+ client = ssc.accept();
+ sc.configureBlocking(false);
+ sc.register(selector, SelectionKey.OP_READ);
+ client.configureBlocking(true);
+
+ sc2.connect(LOCAL_ADDRESS);
+ client2 = ssc.accept();
+ sc2.configureBlocking(false);
+ sc2.register(selector, SelectionKey.OP_READ);
+ client2.configureBlocking(true);
+
+ client.write(ByteBuffer.wrap("a".getBytes()));
+ int count = blockingSelect(type, timeout);
+ assertEquals(1, count);
+ Set<SelectionKey> selectedKeys = selector.selectedKeys();
+ assertEquals(1, selectedKeys.size());
+ SelectionKey key = selectedKeys.iterator().next();
+ assertEquals(sc.keyFor(selector), key);
+ assertEquals(SelectionKey.OP_READ, key.readyOps());
+ // select again, it should return 0
+ count = selectOnce(type, timeout);
+ assertEquals(0, count);
+ // but selectedKeys remains the same as previous
+ assertSame(selectedKeys, selector.selectedKeys());
+
+ sc.read(ByteBuffer.allocate(8));
+
+ // the second SocketChannel should be selected this time
+ client2.write(ByteBuffer.wrap("a".getBytes()));
+ count = blockingSelect(type, timeout);
+ assertEquals(1, count);
+ // selectedKeys still includes the key of sc, because the key of sc
+ // is not removed last time.
+ selectedKeys = selector.selectedKeys();
+ assertEquals(2, selectedKeys.size());
+ } finally {
+ if (null != client) {
+ try {
+ client.close();
+ } catch (Exception e) {
+ // ignore
+ }
+ }
+ if (null != client2) {
+ try {
+ client2.close();
+ } catch (Exception e) {
+ // ignore
+ }
+ }
+ try {
+ sc.close();
+ } catch (Exception e) {
+ // ignore
+ }
+ try {
+ sc2.close();
+ } catch (Exception e) {
+ // ignore
+ }
+ ssc.configureBlocking(false);
+ }
+ }
+
+ private void assert_select_OP_WRITE(SelectType type, int timeout)
+ throws IOException {
+ SocketChannel sc = SocketChannel.open();
+ SocketChannel client = null;
+ try {
+ sc.connect(LOCAL_ADDRESS);
+ ssc.configureBlocking(true);
+ client = ssc.accept();
+ sc.configureBlocking(false);
+ sc.register(selector, SelectionKey.OP_WRITE);
+ int count = blockingSelect(type, timeout);
+ assertEquals(1, count);
+ Set<SelectionKey> selectedKeys = selector.selectedKeys();
+ assertEquals(1, selectedKeys.size());
+ SelectionKey key = selectedKeys.iterator().next();
+ assertEquals(sc.keyFor(selector), key);
+ assertEquals(SelectionKey.OP_WRITE, key.readyOps());
+ // select again, it should return 0
+ count = selectOnce(type, timeout);
+ assertEquals(0, count);
+ // but selectedKeys remains the same as previous
+ assertSame(selectedKeys, selector.selectedKeys());
+ } finally {
+ if (null != client) {
+ client.close();
+ }
+ try {
+ sc.close();
+ } catch (IOException e) {
+ // do nothing
+ }
+ ssc.configureBlocking(false);
+ }
+ }
+
+ private int blockingSelect(SelectType type, int timeout) throws IOException {
+ int ret = 0;
+ do {
+ ret = selectOnce(type, timeout);
+ if (ret > 0) {
+ return ret;
+ }
+ try {
+ Thread.sleep(100);
+ } catch (InterruptedException e) {
+ // ignore
+ }
+ } while (true);
+ }
+
+ private int selectOnce(SelectType type, int timeout) throws IOException {
+ int ret = 0;
+ switch (type) {
+ case NULL:
+ ret = selector.select();
+ break;
+ case TIMEOUT:
+ ret = selector.select(timeout);
+ break;
+ case NOW:
+ ret = selector.selectNow();
+ break;
+ }
+ return ret;
+ }
+
+}
\ No newline at end of file
Propchange: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/channels/SelectorTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/harmony/enhanced/classlib/trunk/native-src/linux.IA32/luni/OSNetworkSystemLinux.c
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/native-src/linux.IA32/luni/OSNetworkSystemLinux.c?rev=415279&r1=415278&r2=415279&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/native-src/linux.IA32/luni/OSNetworkSystemLinux.c (original)
+++ incubator/harmony/enhanced/classlib/trunk/native-src/linux.IA32/luni/OSNetworkSystemLinux.c Mon Jun 19 03:21:46 2006
@@ -191,6 +191,8 @@
jboolean isCopy ;
jint *flagArray;
int val;
+ U_32 time_sec = (U_32)timeout/1000;
+ U_32 time_msec = (U_32)(timeout%1000)*1000;
fdset_read = hymem_allocate_memory(sizeof (struct hyfdset_struct));
fdset_write = hymem_allocate_memory(sizeof (struct hyfdset_struct));
@@ -224,11 +226,11 @@
{
/* only set when timeout >= 0 (non-block)*/
if (0 <= timeout){
- hysock_timeval_init ( 0, (I_32)timeout, &timeP);
- result = hysock_select (size, fdset_read, fdset_write, NULL,&timeP);
+ hysock_timeval_init (time_sec, time_msec, &timeP);
+ result = hysock_select (size, fdset_read, fdset_write, NULL,&timeP);
}
else{
- result = hysock_select (size, fdset_read, fdset_write, NULL,NULL);
+ result = hysock_select (size, fdset_read, fdset_write, NULL,NULL);
}
}
Modified: incubator/harmony/enhanced/classlib/trunk/native-src/win.IA32/luni/OSNetworkSystemWin32.c
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/native-src/win.IA32/luni/OSNetworkSystemWin32.c?rev=415279&r1=415278&r2=415279&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/native-src/win.IA32/luni/OSNetworkSystemWin32.c (original)
+++ incubator/harmony/enhanced/classlib/trunk/native-src/win.IA32/luni/OSNetworkSystemWin32.c Mon Jun 19 03:21:46 2006
@@ -47,6 +47,8 @@
jboolean isCopy ;
jint *flagArray;
int val;
+ U_32 time_sec = (U_32)timeout/1000;
+ U_32 time_msec = (U_32)(timeout%1000)*1000;
fdset_read = hymem_allocate_memory(sizeof (struct hyfdset_struct));
fdset_write = hymem_allocate_memory(sizeof (struct hyfdset_struct));
@@ -102,11 +104,11 @@
{
/* only set when timeout >= 0 (non-block)*/
if (0 <= timeout){
- hysock_timeval_init ( 0, (I_32)timeout, &timeP);
- result = hysock_select (size, fdset_read, fdset_write, NULL,&timeP);
+ hysock_timeval_init ( time_sec, time_msec, &timeP);
+ result = hysock_select (size, fdset_read, fdset_write, NULL,&timeP);
}
else{
- result = hysock_select (size, fdset_read, fdset_write, NULL,NULL);
+ result = hysock_select (size, fdset_read, fdset_write, NULL,NULL);
}
}