예제 #1
0
		void SendQuery (SimpleResolverEventArgs args, DnsQuery query, bool add_it)
		{
			// TODO: not sure about reusing IDs when add_it == false
			int count = 0;
			if (add_it) {
				do {
					query.Header.ID = (ushort)new Random().Next(1, 65534);
					if (count > 500)
						throw new InvalidOperationException ("Too many pending queries (or really bad luck)");
				} while (AddQuery (query, args) == false);
				args.QueryID = query.Header.ID;
			} else {
				query.Header.ID = args.QueryID;
			}
			if (args.Timer == null)
				args.Timer = new Timer (timeout_cb, args, 5000, Timeout.Infinite);
			else
				args.Timer.Change (5000, Timeout.Infinite);
			client.BeginSend (query.Packet, 0, query.Length, SocketFlags.None, null, null);
		}
예제 #2
0
		bool AddQuery (DnsQuery query, SimpleResolverEventArgs args)
		{
			lock (queries) {
				if (queries.ContainsKey (query.Header.ID))
					return false;
				queries [query.Header.ID] = args;
			}
			return true;
		}