Example #1
0
 public bool addSocket(Socket s, SocketUpdateFunc update_func, TcpTransport trans)
 {
     s.Info = new SocketInfo { sock = s.FD, func = update_func, transport = trans };
     lock (socks)
         socks.Add(s.FD, s);
     return true;
 }
Example #2
0
        public static bool exists(string service_name, bool print_failure_reason)
        {
            string mapped_name = names.resolve(service_name);

            string host = "";
            int port = 0;

            if (ServiceManager.Instance.lookUpService(mapped_name, ref host, ref port))
            {
                TcpTransport transport = new TcpTransport();

                IDictionary m = new Hashtable
                {
                    {"probe", "1"},
                    {"md5sum", "*"},
                    {"callerid", this_node.Name},
                    {"service", mapped_name}
                };

                byte[] headerbuf = null;
                int size = 0;
                Header h = new Header();
                h.Write(m, ref headerbuf, ref size);

                if (transport.connect(host, port))
                {
                    byte[] sizebuf = BitConverter.GetBytes(size);

                    transport.write(sizebuf, 0, sizebuf.Length);
                    transport.write(headerbuf, 0, size);

                    return true;
                }
                if (print_failure_reason)
                {
                    ROS.Info("waitForService: Service[{0}] could not connect to host [{1}:{2}], waiting...", mapped_name, host, port);
                }
            }
            else if (print_failure_reason)
            {
                ROS.Info("waitForService: Service[{0}] has not been advertised, waiting...", mapped_name);
            }
            return false;
        }
Example #3
0
 private void onDisconnect(TcpTransport trans)
 {
     if (trans != transport) throw new Exception("THAT EVENT IS NOT FOR MEEE!");
     drop(DropReason.TransportDisconnect);
 }
Example #4
0
 private void onWriteable(TcpTransport trans)
 {
     if (trans != transport) throw new Exception("THAT EVENT IS NOT FOR MEEE!");
     writeTransport();
 }
Example #5
0
 private void onReadable(TcpTransport trans)
 {
     if (trans != transport) throw new Exception("THAT EVENT IS NOT FOR MEEE!");
     readTransport();
 }
Example #6
0
        public void initialize(TcpTransport trans, bool is_server, HeaderReceivedFunc header_func)
        {
            if (trans == null) throw new Exception("Connection innitialized with null transport");
            transport = trans;
            this.header_func = header_func;
            this.is_server = is_server;

            transport.read_cb += onReadable;
            transport.write_cb += onWriteable;
            transport.disconnect_cb += onDisconnect;

            if (this.header_func != null)
            {
                read(4, onHeaderLengthRead);
            }
        }
Example #7
0
        public void pendingConnectionDone(PendingConnection conn, IntPtr res)
        {
            XmlRpcValue result = XmlRpcValue.LookUp(res);

            lock (shutdown_mutex)
            {
                if (shutting_down || _dropped)
                {
                    return;
                }
            }
            XmlRpcValue proto = new XmlRpcValue();

            if (!XmlRpcManager.Instance.validateXmlrpcResponse("requestTopic", result, ref proto))
            {
                conn.failures++;
                EDB.WriteLine("Negotiating for " + conn.parent.name + " has failed " + conn.failures + " times");
                return;
            }
            lock (pending_connections_mutex)
            {
                pending_connections.Remove(conn);
            }
            string peer_host  = conn.client.Host;
            int    peer_port  = conn.client.Port;
            string xmlrpc_uri = "http://" + peer_host + ":" + peer_port + "/";

            if (proto.Size == 0)
            {
#if DEBUG
                EDB.WriteLine("Couldn't agree on any common protocols with [" + xmlrpc_uri + "] for topic [" + name +
                              "]");
#endif
                return;
            }
            if (proto.Type != TypeEnum.TypeArray)
            {
                EDB.WriteLine("Available protocol info returned from " + xmlrpc_uri + " is not a list.");
                return;
            }
            string proto_name = proto[0].Get <string>();
            if (proto_name == "UDPROS")
            {
                EDB.WriteLine("OWNED! Only tcpros is supported right now.");
            }
            else if (proto_name == "TCPROS")
            {
                if (proto.Size != 3 || proto[1].Type != TypeEnum.TypeString || proto[2].Type != TypeEnum.TypeInt)
                {
                    EDB.WriteLine("publisher implements TCPROS... BADLY! parameters aren't string,int");
                    return;
                }
                string pub_host = proto[1].Get <string>();
                int    pub_port = proto[2].Get <int>();
#if DEBUG
                EDB.WriteLine("Connecting via tcpros to topic [" + name + "] at host [" + pub_host + ":" + pub_port +
                              "]");
#endif

                TcpTransport transport = new TcpTransport(PollManager.Instance.poll_set)
                {
                    _topic = name
                };
                if (transport.connect(pub_host, pub_port))
                {
                    Connection             connection = new Connection();
                    TransportPublisherLink pub_link   = new TransportPublisherLink(this, xmlrpc_uri);

                    connection.initialize(transport, false, null);
                    pub_link.initialize(connection);

                    ConnectionManager.Instance.addConnection(connection);

                    lock (publisher_links_mutex)
                    {
                        addPublisherLink(pub_link);
                    }


#if DEBUG
                    EDB.WriteLine("Connected to publisher of topic [" + name + "] at  [" + pub_host + ":" + pub_port +
                                  "]");
#endif
                }
                else
                {
                    EDB.WriteLine("Failed to connect to publisher of topic [" + name + "] at  [" + pub_host + ":" +
                                  pub_port + "]");
                }
            }
            else
            {
                EDB.WriteLine("Your xmlrpc server be talking jibber jabber, foo");
            }
        }
Example #8
0
 public TcpTransport accept()
 {
     SocketAsyncEventArgs args = new SocketAsyncEventArgs();
     if (sock == null || !sock.AcceptAsync(args))
         return null;
     if (args.AcceptSocket == null)
     {
         EDB.WriteLine("NOTHING TO ACCEPT SO RETURNING NULL!");
         return null;
     }
     Socket acc = new Socket(args.AcceptSocket);
     TcpTransport transport = new TcpTransport(poll_set, flags);
     if (!transport.setSocket(acc))
     {
         throw new Exception("FAILED TO ADD SOCKET TO TRANSPORT ZOMG!");
     }
     return transport;
 }
Example #9
0
 public bool addSocket(Socket s, SocketUpdateFunc update_func, TcpTransport trans)
 {
     SocketInfo info = new SocketInfo {sock = s.FD, func = update_func, transport = trans};
     lock (socket_info_mutex)
     {
         if (socket_info.ContainsKey(info.sock))
             return false;
         socket_info.Add(info.sock, info);
         sockets_changed = true;
     }
     signal();
     return true;
 }