Esempio n. 1
0
		public TChannel(TSocket socket, string host, int port, TService service): base(service)
		{
			this.socket = socket;
			this.service = service;
			this.parser = new PacketParser(this.recvBuffer);
			this.remoteAddress = host + ":" + port;
		}
Esempio n. 2
0
		public TChannel(TSocket socket, TService service): base(service)
		{
			this.isConnected = true;
			this.socket = socket;
			this.service = service;
			this.parser = new PacketParser(this.recvBuffer);
			this.remoteAddress = this.socket.RemoteAddress;
			this.StartRecv();
		}
Esempio n. 3
0
		private void Dispose(bool disposing)
		{
			if (this.acceptor == null)
			{
				return;
			}

			if (disposing)
			{
				foreach (ObjectId id in this.idChannels.Keys.ToArray())
				{
					TChannel channel = this.idChannels[id];
					channel.Dispose();
				}
				this.acceptor.Dispose();
			}

			this.acceptor = null;
		}
Esempio n. 4
0
		private void Dispose(bool disposing)
		{
			if (this.socket == null)
			{
				return;
			}

			this.onDispose(this);

			if (disposing)
			{
				// 释放托管的资源
				this.socket.Dispose();
			}

			// 释放非托管资源
			this.service.Remove(this);
			this.socket = null;
		}
Esempio n. 5
0
		public Task<bool> AcceptAsync(TSocket accpetSocket)
		{
			var tcs = new TaskCompletionSource<bool>();
			this.innArgs.UserToken = tcs;
			this.innArgs.AcceptSocket = accpetSocket.socket;
			if (!this.socket.AcceptAsync(this.innArgs))
			{
				OnAcceptComplete(this.innArgs);
			}
			return tcs.Task;
		}
Esempio n. 6
0
 /// <summary>
 /// 即可做client也可做server
 /// </summary>
 /// <param name="host"></param>
 /// <param name="port"></param>
 public TService(string host, int port)
 {
     this.acceptor = new TSocket(this.poller);
     this.acceptor.Bind(host, port);
     this.acceptor.Listen(100);
 }
Esempio n. 7
0
		public async Task<AChannel> GetChannel()
		{
			if (this.acceptor == null)
			{
				throw new Exception("service construct must use host and port param");
			}
			TSocket socket = new TSocket(this.poller);
			await this.acceptor.AcceptAsync(socket);
			TChannel channel = new TChannel(socket, this);
			this.channels[channel.RemoteAddress] = channel;
			this.idChannels[channel.Id] = channel;
			return channel;
		}
Esempio n. 8
0
		/// <summary>
		/// 即可做client也可做server
		/// </summary>
		/// <param name="host"></param>
		/// <param name="port"></param>
		public TService(string host, int port)
		{
			this.acceptor = new TSocket(this.poller);
			this.acceptor.Bind(host, port);
			this.acceptor.Listen(100);
		}
Esempio n. 9
0
		public AChannel GetChannel(string host, int port)
		{
			TChannel channel = null;
			if (this.channels.TryGetValue(host + ":" + port, out channel))
			{
				return channel;
			}

			TSocket newSocket = new TSocket(this.poller);
			channel = new TChannel(newSocket, host, port, this);
			this.channels[channel.RemoteAddress] = channel;
			this.idChannels[channel.Id] = channel;
			this.SocketConnectAsync(channel);
			return channel;
		}