• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# PooledSocket类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中PooledSocket的典型用法代码示例。如果您正苦于以下问题:C# PooledSocket类的具体用法?C# PooledSocket怎么用?C# PooledSocket使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



PooledSocket类属于命名空间,在下文中一共展示了PooledSocket类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: ReadResponse

		protected internal override IOperationResult ReadResponse(PooledSocket socket)
		{
			var response = new BinaryResponse();
			var serverData = new Dictionary<string, string>();
			var retval = false;

			while (response.Read(socket) && response.KeyLength > 0)
			{
				retval = true;

				var data = response.Data;
				var key = BinaryConverter.DecodeKey(data.Array, data.Offset, response.KeyLength);
				var value = BinaryConverter.DecodeKey(data.Array, data.Offset + response.KeyLength, data.Count - response.KeyLength);

				serverData[key] = value;
			}

			this.result = serverData;
			this.StatusCode = response.StatusCode;

			var result = new BinaryOperationResult()
			{
				StatusCode = StatusCode
			};

			result.PassOrFail(retval, "Failed to read response");
			return result;
		}
开发者ID:javithalion,项目名称:NCache,代码行数:28,代码来源:StatsOperation.cs


示例2: ReadResponse

		protected internal override IOperationResult ReadResponse(PooledSocket socket)
		{
			var retval = new Dictionary<string, CacheItem>();
			var cas = new Dictionary<string, ulong>();

			try
			{
				GetResponse r;

				while ((r = GetHelper.ReadItem(socket)) != null)
				{
					var key = r.Key;

					retval[key] = r.Item;
					cas[key] = r.CasValue;
				}
			}
			catch (NotSupportedException)
			{
				throw;
			}
			catch (Exception e)
			{
				log.Error(e);
			}

			this.result = retval;
			this.Cas = cas;

			return new TextOperationResult().Pass();
		}
开发者ID:javithalion,项目名称:NCache,代码行数:31,代码来源:MultiGetOperation.cs


示例3: FinishCurrent

		public static void FinishCurrent(PooledSocket socket)
		{
			string response = TextSocketHelper.ReadResponse(socket);

			if (String.Compare(response, "END", StringComparison.Ordinal) != 0)
				throw new MemcachedClientException("No END was received.");
		}
开发者ID:89sos98,项目名称:EnyimMemcached,代码行数:7,代码来源:GetHelper.cs


示例4: Auth

		/// <summary>
		/// Implements memcached's SASL auth sequence. (See the protocol docs for more details.)
		/// </summary>
		/// <param name="socket"></param>
		/// <returns></returns>
		private bool Auth(PooledSocket socket)
		{
			SaslStep currentStep = new SaslStart(this.authenticationProvider);

			socket.Write(currentStep.GetBuffer());

			while (!currentStep.ReadResponse(socket))
			{
				// challenge-response authentication
				if (currentStep.StatusCode == 0x21)
				{
					currentStep = new SaslContinue(this.authenticationProvider, currentStep.Data);
					socket.Write(currentStep.GetBuffer());
				}
				else
				{
					if (log.IsWarnEnabled)
						log.WarnFormat("Authentication failed, return code: 0x{0:x}", currentStep.StatusCode);

					// invalid credentials or other error
					return false;
				}
			}

			return true;
		}
开发者ID:xianrendzw,项目名称:LightFramework.Net,代码行数:31,代码来源:BinaryNode.cs


示例5: ReadResponse

        protected internal override bool ReadResponse(PooledSocket socket)
        {
            this.result = new Dictionary<string, CacheItem>();
            this.Cas = new Dictionary<string, ulong>();

            var response = new BinaryResponse();

            while (response.Read(socket))
            {
                // found the noop, quit
                if (response.CorrelationId == this.noopId)
                    return true;

                string key;

                // find the key to the response
                if (!this.idToKey.TryGetValue(response.CorrelationId, out key))
                {
                    // we're not supposed to get here tho
                    log.WarnFormat("Found response with CorrelationId {0}, but no key is matching it.", response.CorrelationId);
                    continue;
                }

                if (log.IsDebugEnabled) log.DebugFormat("Reading item {0}", key);

                // deserialize the response
                int flags = BinaryConverter.DecodeInt32(response.Extra, 0);

                this.result[key] = new CacheItem((ushort)flags, response.Data);
                this.Cas[key] = response.CAS;
            }

            // finished reading but we did not find the NOOP
            return false;
        }
开发者ID:jocull,项目名称:EnyimMemcached,代码行数:35,代码来源:MultiGetOperation.cs


示例6: Read

        public unsafe bool Read(PooledSocket socket)
        {
            this.StatusCode = -1;

            if (!socket.IsAlive)
                return false;

            var header = new byte[HeaderLength];
            socket.Read(header, 0, header.Length);

            int dataLength, extraLength;

            DeserializeHeader(header, out dataLength, out extraLength);

            if (dataLength > 0)
            {
                var data = new byte[dataLength];
                socket.Read(data, 0, dataLength);

                this.Extra = new ArraySegment<byte>(data, 0, extraLength);
                this.Data = new ArraySegment<byte>(data, extraLength, data.Length - extraLength);
            }

            return this.StatusCode == 0;
        }
开发者ID:yorkart,项目名称:CachingClient,代码行数:25,代码来源:BinaryResponse.cs


示例7: ReadResponse

        /// <summary>
        /// Reads the response of the server.
        /// </summary>
        /// <returns>The data sent by the memcached server.</returns>
        /// <exception cref="T:System.InvalidOperationException">The server did not sent a response or an empty line was returned.</exception>
        /// <exception cref="T:Enyim.Caching.Memcached.MemcachedException">The server did not specified any reason just returned the string ERROR. - or - The server returned a SERVER_ERROR, in this case the Message of the exception is the message returned by the server.</exception>
        /// <exception cref="T:Enyim.Caching.Memcached.MemcachedClientException">The server did not recognize the request sent by the client. The Message of the exception is the message returned by the server.</exception>
        public static string ReadResponse(PooledSocket socket)
        {
            string response = TextSocketHelper.ReadLine(socket);

            if (log.IsDebugEnabled)
                log.Debug("Received response: " + response);

            if (String.IsNullOrEmpty(response))
                throw new MemcachedClientException("Empty response received.");

            if (String.Compare(response, GenericErrorResponse, StringComparison.Ordinal) == 0)
                throw new NotSupportedException("Operation is not supported by the server or the request was malformed. If the latter please report the bug to the developers.");

            if (response.Length >= ErrorResponseLength)
            {
                if (String.Compare(response, 0, ClientErrorResponse, 0, ErrorResponseLength, StringComparison.Ordinal) == 0)
                {
                    throw new MemcachedClientException(response.Remove(0, ErrorResponseLength));
                }
                else if (String.Compare(response, 0, ServerErrorResponse, 0, ErrorResponseLength, StringComparison.Ordinal) == 0)
                {
                    throw new MemcachedException(response.Remove(0, ErrorResponseLength));
                }
            }

            return response;
        }
开发者ID:yorkart,项目名称:CachingClient,代码行数:34,代码来源:TextSocketHelper.cs


示例8: ReadResponse

		protected internal override IOperationResult ReadResponse(PooledSocket socket)
		{
			return new TextOperationResult
			{
				Success = String.Compare(TextSocketHelper.ReadResponse(socket), "STORED", StringComparison.Ordinal) == 0
			};
		}
开发者ID:ZhaoYngTest01,项目名称:EnyimMemcached,代码行数:7,代码来源:StoreOperationBase.cs


示例9: ReadFrom

        public override void ReadFrom(PooledSocket socket)
        {
            var replies = new List<RedisValue>();
            if (Transactional)
            {
                _multi.ReadFrom(socket);  // OK

                for (int i = 0; i < _commands.Count; i++)
                {
                    // read "QUEUED"
                    var status = socket.ExpectSingleLineReply();
                }
                // The result is a multi-bulk, so
                // consume the count of returned items
                var count = socket.ExpectMultiBulkCount();
                if (count != _commands.Count)
                    throw new RedisClientException(
                        String.Format("Invalid number of bulk responses. Expected {0}, Got {1}", _commands.Count, count));
            }

            foreach (var command in _commands)
            {
                command.ReadFrom(socket);
                replies.Add(command.Value);
            }
            this.Value = new RedisValue(){Type = RedisValueType.MultiBulk, MultiBulkValues =replies.ToArray()};   
        }
开发者ID:vebin,项目名称:Guanima.Redis,代码行数:27,代码来源:PipelineCommand.cs


示例10: ReadAsync

		/// <summary>
		/// Reads the response from the socket asynchronously.
		/// </summary>
		/// <param name="socket">The socket to read from.</param>
		/// <param name="next">The delegate whihc will continue processing the response. This is only called if the read completes asynchronoulsy.</param>
		/// <param name="ioPending">Set totrue if the read is still pending when ReadASync returns. In this case 'next' will be called when the read is finished.</param>
		/// <returns>
		/// If the socket is already dead, ReadAsync returns false, next is not called, ioPending = false
		/// If the read completes synchronously (e.g. data is received from the buffer), it returns true/false depending on the StatusCode, and ioPending is set to true, 'next' will not be called.
		/// It returns true if it has to read from the socket, so the operation will complate asynchronously at a later time. ioPending will be true, and 'next' will be called to handle the data
		/// </returns>
		public bool ReadAsync(PooledSocket socket, Action<bool> next, out bool ioPending)
		{
			this.StatusCode = -1;
			this.currentSocket = socket;
			this.next = next;

			var asyncEvent = new AsyncIOArgs();

			asyncEvent.Count = HeaderLength;
			asyncEvent.Next = this.DoDecodeHeaderAsync;

			this.shouldCallNext = true;

			if (socket.ReceiveAsync(asyncEvent))
			{
				ioPending = true;
				return true;
			}

			ioPending = false;
			this.shouldCallNext = false;

			return asyncEvent.Fail
					? false
					: this.DoDecodeHeader(asyncEvent, out ioPending);
		}
开发者ID:623442733,项目名称:EnyimMemcached,代码行数:37,代码来源:BinaryResponse.cs


示例11: ReadResponse

        protected internal override bool ReadResponse(PooledSocket socket)
        {
            var response = new BinaryResponse();
            var retval = response.Read(socket);
            this.Cas = response.CAS;

            return retval & this.ProcessResponse(response);
        }
开发者ID:couchbaselabs,项目名称:EnyimMemcached,代码行数:8,代码来源:BinarySingleItemOperation.cs


示例12: ReadResponse

        protected internal override bool ReadResponse(PooledSocket socket)
        {
            var response = new BinaryResponse();
            var retval = response.Read(socket);

            this.StatusCode = StatusCode;

            return retval;
        }
开发者ID:yorkart,项目名称:CachingClient,代码行数:9,代码来源:FlushOperation.cs


示例13: WriteTo

        public override void WriteTo(PooledSocket socket)
        {
            new MultiCommand().WriteTo(socket);

            foreach (var command in _commands)
            {
                command.WriteTo(socket);
            }
            new ExecCommand().WriteTo(socket);                    
        }
开发者ID:vebin,项目名称:Guanima.Redis,代码行数:10,代码来源:MultiExecCommand.cs


示例14: ReadResponse

        protected internal override bool ReadResponse(PooledSocket socket)
        {
            string response = TextSocketHelper.ReadResponse(socket);

            //maybe we should throw an exception when the item is not found?
            if (String.Compare(response, "NOT_FOUND", StringComparison.Ordinal) == 0)
                return false;

            return UInt64.TryParse(response, NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite, CultureInfo.InvariantCulture, out this.result);
        }
开发者ID:yorkart,项目名称:CachingClient,代码行数:10,代码来源:MutatorOperation.cs


示例15: Read

		public unsafe bool Read(PooledSocket socket)
		{
			if (!socket.IsAlive)
			{
				this.StatusCode = -1;
				return false;
			}

			byte[] header = new byte[24];
			socket.Read(header, 0, 24);
#if DEBUG_PROTOCOL
			if (log.IsDebugEnabled)
			{
				log.Debug("Received binary response");

				StringBuilder sb = new StringBuilder(128).AppendLine();

				for (int i = 0; i < header.Length; i++)
				{
					byte value = header[i];
					sb.Append(value < 16 ? "0x0" : "0x").Append(value.ToString("X"));

					if (i % 4 == 3) sb.AppendLine(); else sb.Append(" ");
				}

				log.Debug(sb.ToString());
			}
#endif

			fixed (byte* buffer = header)
			{
				if (buffer[0] != MAGIC_VALUE)
					throw new InvalidOperationException("Expected magic value " + MAGIC_VALUE + ", received: " + buffer[0]);

				int remaining = BinaryConverter.DecodeInt32(buffer, HEADER_BODY);
				int extraLength = buffer[HEADER_EXTRA];

				byte[] data = new byte[remaining];
				socket.Read(data, 0, remaining);

				this.Extra = new ArraySegment<byte>(data, 0, extraLength);
				this.Data = new ArraySegment<byte>(data, extraLength, data.Length - extraLength);

				this.DataType = buffer[HEADER_DATATYPE];
				this.Opcode = buffer[HEADER_OPCODE];
				this.StatusCode = BinaryConverter.DecodeInt16(buffer, HEADER_STATUS);

				this.KeyLength = BinaryConverter.DecodeInt16(buffer, HEADER_KEY);
				this.CorrelationId = BinaryConverter.DecodeInt32(buffer, HEADER_OPAQUE);
				this.CAS = BinaryConverter.DecodeUInt64(buffer, HEADER_CAS);
			}

			return this.StatusCode == 0;
		}
开发者ID:xianrendzw,项目名称:LightFramework.Net,代码行数:54,代码来源:BinaryResponse.cs


示例16: ReadResponseAsync

		protected internal override bool ReadResponseAsync(PooledSocket socket, Action<bool> next)
		{
			this.result = new Dictionary<string, CacheItem>();
			this.Cas = new Dictionary<string, ulong>();

			this.currentSocket = socket;
			this.asyncReader = new BinaryResponse();
			this.asyncLoopState = null;
			this.afterAsyncRead = next;

			return this.DoReadAsync();
		}
开发者ID:623442733,项目名称:EnyimMemcached,代码行数:12,代码来源:MultiGetOperation.cs


示例17: WriteTo

        public override void WriteTo(PooledSocket socket)
        {
            if (Transactional)
                _multi.WriteTo(socket);

            foreach (var command in _commands)
            {
                // todo: if transactional, ignore MULTI or EXEC, if any
                command.WriteTo(socket);
            }
            if (Transactional)
                _exec.WriteTo(socket);
        }
开发者ID:vebin,项目名称:Guanima.Redis,代码行数:13,代码来源:PipelineCommand.cs


示例18: ReadResponse

		protected internal override IOperationResult ReadResponse(PooledSocket socket)
		{
			string response = TextSocketHelper.ReadResponse(socket);
			var result = new TextOperationResult();

			//maybe we should throw an exception when the item is not found?
			if (String.Compare(response, "NOT_FOUND", StringComparison.Ordinal) == 0)
				return result.Fail("Failed to read response.  Item not found");

			result.Success = 
				UInt64.TryParse(response, NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite, CultureInfo.InvariantCulture, out this.result);
			return result;
		}
开发者ID:javithalion,项目名称:NCache,代码行数:13,代码来源:MutatorOperation.cs


示例19: ReadResponse

        protected internal override bool ReadResponse(PooledSocket socket)
        {
            GetResponse r = GetHelper.ReadItem(socket);

            if (r == null) return false;

            this.result = r.Item;
            this.Cas = r.CasValue;

            GetHelper.FinishCurrent(socket);

            return true;
        }
开发者ID:yorkart,项目名称:CachingClient,代码行数:13,代码来源:GetOperation.cs


示例20: ReadResponse

		protected internal override IOperationResult ReadResponse(PooledSocket socket)
		{
			GetResponse r = GetHelper.ReadItem(socket);
			var result = new TextOperationResult();

			if (r == null) return result.Fail("Failed to read response");

			this.result = r.Item;
			this.Cas = r.CasValue;

			GetHelper.FinishCurrent(socket);

			return result.Pass();
		}
开发者ID:ZhaoYngTest01,项目名称:EnyimMemcached,代码行数:14,代码来源:GetOperation.cs



注:本文中的PooledSocket类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Population类代码示例发布时间:2022-05-24
下一篇:
C# Pool类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap