コード例 #1
0
ファイル: Connection.cs プロジェクト: wiwing/ROS.NET
        public async Task <IDictionary <string, string> > ReadHeader(CancellationToken cancel)
        {
            int length = await this.ReadInt32(cancel);

            if (length > MESSAGE_SIZE_LIMIT)
            {
                throw new ConnectionError("Invalid header length received");
            }

            byte[] headerBuffer = await this.ReadBlock(length, cancel);

            if (!Header.Parse(headerBuffer, length, out string errorMessage))
            {
                throw new ConnectionError(errorMessage);
            }

            if (Header.Values.ContainsKey("error"))
            {
                string error = Header.Values["error"];
                logger.LogInformation("Received error message in header for connection to [{0}]: [{1}]",
                                      "TCPROS connection to [" + this.Socket.RemoteEndPoint + "]", error);
                throw new ConnectionError(error);
            }

            if (topic == null && Header.Values.ContainsKey("topic"))
            {
                topic = Header.Values["topic"];
            }

            if (Header.Values.ContainsKey("tcp_nodelay"))
            {
                if (Header.Values["tcp_nodelay"] == "1")
                {
                    this.Socket.NoDelay = true;
                }
            }

            return(Header.Values);
        }
コード例 #2
0
        private bool onHeaderRead(Connection conn, byte[] data, int size, bool success)
        {
            Debug.Assert(conn == this);

            if (!success)
            {
                return(false);
            }

            string error_msg = "";

            if (!header.Parse(data, (int)size, ref error_msg))
            {
                drop(DropReason.HeaderError);
                return(false);
            }
            else
            {
                string error_val = "";
                if (header.Values.ContainsKey("error"))
                {
                    error_val = (string)header.Values["error"];
                    ROS.Info()($"[{ThisNode.Name}] Received error message in header for connection to [TCPROS connection to [{transport.cachedRemoteHost}]]: [{error_val}]");
                    drop(DropReason.HeaderError);
                    return(false);
                }
                else
                {
                    if (header_func == null)
                    {
                        throw new InvalidOperationException("`header_func` callback was not registered");
                    }

                    transport.parseHeader(header);
                    header_func(conn, header);
                }
            }
            return(true);
        }