protected Socket OpenAbstractUnix(string path) { AbstractUnixEndPoint ep = new AbstractUnixEndPoint (path); Socket client = new Socket (AddressFamily.Unix, SocketType.Stream, 0); client.Connect (ep); return client; }
public override bool Equals(object o) { AbstractUnixEndPoint abstractUnixEndPoint = o as AbstractUnixEndPoint; if (abstractUnixEndPoint == null) { return(false); } return(abstractUnixEndPoint.path == this.path); }
public override bool Equals(object o) { AbstractUnixEndPoint other = o as AbstractUnixEndPoint; if (other == null) { return(false); } return(other.path == path); }
public override void Open(AddressEntry entry) { string path; bool isAbstract; if (entry.Properties.TryGetValue("path", out path)) isAbstract = false; else if (entry.Properties.TryGetValue("abstract", out path)) isAbstract = true; else throw new ArgumentException("No path specified for UNIX transport"); EndPoint ep; if (isAbstract) ep = new AbstractUnixEndPoint(path); else ep = new UnixEndPoint(path); var client = new Socket(AddressFamily.Unix, SocketType.Stream, 0); client.Connect(ep); Stream = new NetworkStream(client); }
public WvUnix(string path) : base(null) { EndPoint ep; if (path.StartsWith("@")) ep = new AbstractUnixEndPoint(path.Substring(1)); else ep = new UnixEndPoint(path); Socket sock = new Socket(AddressFamily.Unix, SocketType.Stream, 0); sock.Connect(ep); this.sock = sock; }
//TODO: complete this test daemon/server example, and a client //TODO: maybe generalise it and integrate it into the core public static void Main (string[] args) { bool isServer; if (args.Length == 1 && args[0] == "server") isServer = true; else if (args.Length == 1 && args[0] == "client") isServer = false; else { Console.Error.WriteLine ("Usage: test-server [server|client]"); return; } string addr = "unix:abstract=/tmp/dbus-ABCDEFGHIJ"; Connection conn; ObjectPath myOpath = new ObjectPath ("/org/ndesk/test"); string myNameReq = "org.ndesk.test"; if (!isServer) { conn = new Connection (addr); DemoObject demo = conn.GetObject<DemoObject> (myNameReq, myOpath); demo.GiveNoReply (); //float ret = demo.Hello ("hi from test client", 21); float ret = 200; while (ret > 5) { ret = demo.Hello ("hi from test client", (int)ret); Console.WriteLine ("Returned float: " + ret); System.Threading.Thread.Sleep (1000); } } else { string path; bool abstr; Address.Parse (addr, out path, out abstr); AbstractUnixEndPoint ep = new AbstractUnixEndPoint (path); Socket server = new Socket (AddressFamily.Unix, SocketType.Stream, 0); server.Bind (ep); //server.Listen (1); server.Listen (5); while (true) { Console.WriteLine ("Waiting for client on " + addr); Socket client = server.Accept (); Console.WriteLine ("Client accepted"); client.Blocking = true; PeerCred pc = new PeerCred (client); Console.WriteLine ("PeerCred: pid={0}, uid={1}, gid={2}", pc.ProcessID, pc.UserID, pc.GroupID); conn = new Connection (null); conn.ns = new NetworkStream (client); conn.SocketHandle = (long)client.Handle; //ConnectionHandler.Handle (conn); //in reality a thread per connection is of course too expensive ConnectionHandler hnd = new ConnectionHandler (conn); new Thread (new ThreadStart (hnd.Handle)).Start (); Console.WriteLine (); } } }