Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoreutarass2010-08-24 13:35:54 -0400
committereutarass2010-08-24 13:35:54 -0400
commitc70fa1fb1f27200ccbc0d340c378bc9c84172a93 (patch)
treeb0b2ab5fad93a07b4712d60199977f3c510c568f /plugins/org.eclipse.tm.tcf.core
parente94b846cfb7f6e19d5b9fa33dc1f0764581ef1ea (diff)
downloadorg.eclipse.tcf-c70fa1fb1f27200ccbc0d340c378bc9c84172a93.tar.gz
org.eclipse.tcf-c70fa1fb1f27200ccbc0d340c378bc9c84172a93.tar.xz
org.eclipse.tcf-c70fa1fb1f27200ccbc0d340c378bc9c84172a93.zip
Added support for new communication channel transport: named pipes.
Diffstat (limited to 'plugins/org.eclipse.tm.tcf.core')
-rw-r--r--plugins/org.eclipse.tm.tcf.core/src/org/eclipse/tm/internal/tcf/core/TransportManager.java15
-rw-r--r--plugins/org.eclipse.tm.tcf.core/src/org/eclipse/tm/internal/tcf/services/local/LocatorService.java17
-rw-r--r--plugins/org.eclipse.tm.tcf.core/src/org/eclipse/tm/tcf/core/ChannelPIPE.java113
3 files changed, 139 insertions, 6 deletions
diff --git a/plugins/org.eclipse.tm.tcf.core/src/org/eclipse/tm/internal/tcf/core/TransportManager.java b/plugins/org.eclipse.tm.tcf.core/src/org/eclipse/tm/internal/tcf/core/TransportManager.java
index cda2376b6..58ed4a497 100644
--- a/plugins/org.eclipse.tm.tcf.core/src/org/eclipse/tm/internal/tcf/core/TransportManager.java
+++ b/plugins/org.eclipse.tm.tcf.core/src/org/eclipse/tm/internal/tcf/core/TransportManager.java
@@ -18,6 +18,7 @@ import java.util.Map;
import java.util.Set;
import org.eclipse.tm.tcf.core.AbstractChannel;
+import org.eclipse.tm.tcf.core.ChannelPIPE;
import org.eclipse.tm.tcf.core.ChannelTCP;
import org.eclipse.tm.tcf.protocol.IChannel;
import org.eclipse.tm.tcf.protocol.IPeer;
@@ -73,6 +74,20 @@ public class TransportManager {
addTransportProvider(new ITransportProvider() {
public String getName() {
+ return "PIPE";
+ }
+
+ public IChannel openChannel(IPeer peer) {
+ assert getName().equals(peer.getTransportName());
+ String name = peer.getAttributes().get("PipeName");
+ if (name == null) name = "//./pipe/TCF-Agent";
+ return new ChannelPIPE(peer, name);
+ }
+ });
+
+ addTransportProvider(new ITransportProvider() {
+
+ public String getName() {
return "Loop";
}
diff --git a/plugins/org.eclipse.tm.tcf.core/src/org/eclipse/tm/internal/tcf/services/local/LocatorService.java b/plugins/org.eclipse.tm.tcf.core/src/org/eclipse/tm/internal/tcf/services/local/LocatorService.java
index 5d1ddce00..2ef7d82fa 100644
--- a/plugins/org.eclipse.tm.tcf.core/src/org/eclipse/tm/internal/tcf/services/local/LocatorService.java
+++ b/plugins/org.eclipse.tm.tcf.core/src/org/eclipse/tm/internal/tcf/services/local/LocatorService.java
@@ -976,15 +976,21 @@ public class LocatorService implements ILocator {
private void handlePeerInfoPacket(InputPacket p) {
try {
Map<String,String> map = parsePeerAtrributes(p.getData(), p.getLength());
+ if (TRACE_DISCOVERY) traceDiscoveryPacket(true, "CONF_PEER_INFO", map, p);
String id = map.get(IPeer.ATTR_ID);
if (id == null) throw new Exception("Invalid peer info: no ID");
+ boolean ok = true;
InetAddress peer_addr = getInetAddress(map.get(IPeer.ATTR_IP_HOST));
- if (peer_addr == null) return;
- if (TRACE_DISCOVERY) {
- traceDiscoveryPacket(true, "CONF_PEER_INFO", map, p);
+ if (peer_addr != null) {
+ ok = false;
+ for (SubNet subnet : subnets) {
+ if (subnet.contains(peer_addr)) {
+ ok = true;
+ break;
+ }
+ }
}
- for (SubNet subnet : subnets) {
- if (!subnet.contains(peer_addr)) continue;
+ if (ok) {
IPeer peer = peers.get(id);
if (peer instanceof RemotePeer) {
((RemotePeer)peer).updateAttributes(map);
@@ -992,7 +998,6 @@ public class LocatorService implements ILocator {
else if (peer == null) {
new RemotePeer(map);
}
- break;
}
}
catch (Exception x) {
diff --git a/plugins/org.eclipse.tm.tcf.core/src/org/eclipse/tm/tcf/core/ChannelPIPE.java b/plugins/org.eclipse.tm.tcf.core/src/org/eclipse/tm/tcf/core/ChannelPIPE.java
new file mode 100644
index 000000000..b758f28e7
--- /dev/null
+++ b/plugins/org.eclipse.tm.tcf.core/src/org/eclipse/tm/tcf/core/ChannelPIPE.java
@@ -0,0 +1,113 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Wind River Systems, Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Wind River Systems - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.tm.tcf.core;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.SocketException;
+
+import org.eclipse.tm.tcf.protocol.IPeer;
+import org.eclipse.tm.tcf.protocol.Protocol;
+
+/**
+ * ChannelPIPE is a IChannel implementation that works on top of named pipes as a transport.
+ */
+public class ChannelPIPE extends StreamChannel {
+
+ private InputStream inp;
+ private OutputStream out;
+ private boolean started;
+ private boolean closed;
+
+ public ChannelPIPE(IPeer remote_peer, String name) {
+ super(remote_peer);
+ try {
+ inp = new BufferedInputStream(new FileInputStream(name));
+ byte[] buf = new byte[0x400];
+ int rd = inp.read(buf);
+ if (rd <= 0 || buf[rd - 1] != 0) throw new Exception("Invalid remote peer responce");
+ out = new BufferedOutputStream(new FileOutputStream(new String(buf, 0, rd - 1, "UTF-8")));
+ onConnected(null);
+ }
+ catch (Exception x) {
+ onConnected(x);
+ }
+ }
+
+ private void onConnected(final Throwable x) {
+ Protocol.invokeLater(new Runnable() {
+ public void run() {
+ if (x != null) {
+ terminate(x);
+ closed = true;
+ }
+ if (closed) {
+ try {
+ if (out != null) out.close();
+ if (inp != null) inp.close();
+ }
+ catch (IOException y) {
+ Protocol.log("Cannot close pipe", y);
+ }
+ }
+ else {
+ started = true;
+ start();
+ }
+ }
+ });
+ }
+
+ @Override
+ protected int get() throws IOException {
+ try {
+ if (closed) return -1;
+ return inp.read();
+ }
+ catch (SocketException x) {
+ if (closed) return -1;
+ throw x;
+ }
+ }
+
+ @Override
+ protected void put(int b) throws IOException {
+ assert b >= 0 && b <= 0xff;
+ if (closed) return;
+ out.write(b);
+ }
+
+ @Override
+ protected final void put(byte[] buf) throws IOException {
+ if (closed) return;
+ out.write(buf);
+ }
+
+ @Override
+ protected void flush() throws IOException {
+ if (closed) return;
+ out.flush();
+ }
+
+ @Override
+ protected void stop() throws IOException {
+ closed = true;
+ if (started) {
+ out.close();
+ inp.close();
+ }
+ }
+}

Back to the top