Пример #1
0
 public Socket(ns.AddressFamily addressFamily, ns.SocketType socketType, ns.ProtocolType protocolType)
     : base(addressFamily, socketType, protocolType)
 {
     lock (_socklist)
     {
         _socklist.Add(FD, this);
     }
     //EDB.WriteLine("Making socket w/ FD=" + FD);
 }
Пример #2
0
 public Socket(ns.SocketInformation socketInformation)
     : base(socketInformation)
 {
     lock (_socklist)
     {
         _socklist.Add(FD, this);
     }
     //EDB.WriteLine("Making socket w/ FD=" + FD);
 }
Пример #3
0
 public int Send(byte[] arr, int offset, int size, ns.SocketFlags f, out ns.SocketError er)
 {
     return realsocket.Send(arr, offset, size, f, out er);
 }
Пример #4
0
 public int Receive(byte[] arr, int offset, int size, ns.SocketFlags f)
 {
     return realsocket.Receive(arr,offset,size,f);
 }
Пример #5
0
 public int IOControl(ns.IOControlCode code, byte[] inval, byte[] outval)
 {
     return realsocket.IOControl(code, inval, outval);
 }
Пример #6
0
 public byte[] GetSocketOption(ns.SocketOptionLevel lvl, ns.SocketOptionName n, int optionlength)
 {
     return realsocket.GetSocketOption(lvl, n, optionlength);
 }
Пример #7
0
		// Called by the Session class for peers connecting through the server, adds it to a list which can then be added when
		// ProcessWaitingData() is called so we keep it on one thread
		internal void AddPeer( Sockets.Socket socket, Sockets.NetworkStream netStream, PeerInformation peerInformation )
		{
			lock ( mWaitingPeers.SyncRoot )
			{
				mWaitingPeers.Add( new object[] { socket, netStream, peerInformation } );
			}
		}
Пример #8
0
 public Socket(ns.AddressFamily addressFamily, ns.SocketType socketType, ns.ProtocolType protocolType)
     : this(new ns.Socket(addressFamily, socketType, protocolType))
 {
     //EDB.WriteLine("Making socket w/ FD=" + FD);
 }
Пример #9
0
 public bool SafePoll(int timeout, ns.SelectMode sm)
 {
     bool res = false;
     try
     {
         if (!disposed)
             res = realsocket.Poll(timeout, sm);
     }
     catch (ns.SocketException e)
     {
         EDB.WriteLine(e);
         res = !disposed && sm == ns.SelectMode.SelectError;
     }
     return res;
 }
Пример #10
0
 public bool ConnectAsync(ns.SocketAsyncEventArgs e)
 {
     attemptedConnectionEndpoint = e.RemoteEndPoint.ToString();
     return realsocket.ConnectAsync(e);
 }
Пример #11
0
 public Socket(ns.Socket sock)
     : this(sock.DuplicateAndClose(Process.GetCurrentProcess().Id))
 {
 }
Пример #12
0
 public bool SafePoll(int timeout, ns.SelectMode sm)
 {
     lock (this)
     {
         bool res = false;
         try
         {
             res = !disposed && Poll(timeout, sm);
         }
         catch (Exception e)
         {
             Console.WriteLine(e);
             res = !disposed && sm == ns.SelectMode.SelectError;
         }
         return res;
     }
 }
Пример #13
0
		// Called by the Session class for peers connecting through the server and in StartPeerConnectionThread() method for peers
		// connected to directly
		private void AddPeerPrivate(Sockets.Socket socket, Sockets.NetworkStream netStream, PeerInformation peerInformation)
		{
			try
			{
				if ( Config.ActiveConfig.MaxPeersConnected < this.mPeers.Count )
				{
					socket.Close();
					return;
				}

				bool connect = true;

				if (Config.ActiveConfig.OnlyOneConnectionFromEachIP)
				{
					foreach ( Peer connectedPeer in this.mPeers )
					{
						if (connectedPeer.Information.IP.Equals(peerInformation.IP))
						{
							connect = false;
							break;
						}
					}
				}

				if (!connect)
				{
					socket.Close();
					return;
				}

				if (!this.downloadFile.Bitfield.AllFalse)
					PeerProtocol.SendBitfieldMessage(netStream, this.downloadFile);

				Peer peer = new Peer(this.infofile, this.downloadFile, socket, netStream, peerInformation);
				peer.Disconnected += new PeerDisconnectedCallback(peer_Disconnected);

				Config.LogDebugMessage("Connection accepted from: " + peer.ToString());

				// add to download and upload manager
				this.mDownloadStrategy.HookPeerEvents(peer);
				this.uploadManager.AddPeer(peer);
				this.peerManager.AddPeer(peer);

				if (this.PeerConnected != null)
					this.PeerConnected(this, peer, true);

				this.mPeers.Add( peer );
			}
			catch ( System.Exception e )
			{
				Config.LogException( e );
			}
		}
Пример #14
0
 public void SetSocketOption(ns.SocketOptionLevel lvl, ns.SocketOptionName n, object optionvalue)
 {
     realsocket.SetSocketOption(lvl, n, optionvalue);
 }
Пример #15
0
 public bool AcceptAsync(ns.SocketAsyncEventArgs a)
 {
     return realsocket.AcceptAsync(a);
 }
Пример #16
0
 public void Shutdown(ns.SocketShutdown sd)
 {
     realsocket.Shutdown(sd);
 }
Пример #17
0
 public object GetSocketOption(ns.SocketOptionLevel lvl, ns.SocketOptionName n)
 {
     return realsocket.GetSocketOption(lvl, n);
 }
Пример #18
0
 public Socket(ns.Socket sock)
 {
     realsocket = sock;
     disposed = false;
 }
Пример #19
0
 public void GetSocketOption(ns.SocketOptionLevel lvl, ns.SocketOptionName n, byte[] optionvalue)
 {
     realsocket.GetSocketOption(lvl, n, optionvalue);
 }
Пример #20
0
		public Peer(MetainfoFile infofile, DownloadFile downloadFile,
			Sockets.Socket socket, Sockets.NetworkStream netStream, PeerInformation peerInformation)
		{
			this.infofile = infofile;
			this.downloadFile = downloadFile;
			this.socket = socket;
			this.netStream = netStream;
			this.peerInformation = peerInformation;

			this.piecesDownloaded = new BitField(this.infofile.PieceCount);
			this.peerProtocol.UpThrottle.Start();
			this.peerProtocol.DownThrottle.Start();
		}
Пример #21
0
 /// <summary>
 /// Ctor
 /// </summary>
 /// <param name="bufferSize"></param>
 /// <param name="socket"></param>
 public SocketState(int bufferSize, Sockets.Socket socket)
 {
     _BufferSize = bufferSize;
     _WorkBuffer = new byte[bufferSize];
     _WorkSocket = socket;
     _WorkStringBuilder = new StringBuilder();
 }