mirror of
				https://github.com/nadoo/glider.git
				synced 2025-11-04 07:42:38 +08:00 
			
		
		
		
	The proxy can't actively disconnect, you need to use socket shutdown instead of directly close
This commit is contained in:
		
							parent
							
								
									c477d48cbc
								
							
						
					
					
						commit
						8fd20daa95
					
				@ -45,14 +45,41 @@ func Relay(left, right net.Conn) (int64, int64, error) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	go func() {
 | 
						go func() {
 | 
				
			||||||
		n, err := io.Copy(right, left)
 | 
							n, err := io.Copy(right, left)
 | 
				
			||||||
		right.SetDeadline(time.Now()) // wake up the other goroutine blocking on right
 | 
					
 | 
				
			||||||
		left.SetDeadline(time.Now())  // wake up the other goroutine blocking on left
 | 
							switch src := left.(type) {
 | 
				
			||||||
 | 
							case *net.TCPConn:
 | 
				
			||||||
 | 
								src.CloseRead()
 | 
				
			||||||
 | 
							default:
 | 
				
			||||||
 | 
								src.SetDeadline(time.Now())
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							switch dst := right.(type) {
 | 
				
			||||||
 | 
							case *net.TCPConn:
 | 
				
			||||||
 | 
								dst.CloseWrite()
 | 
				
			||||||
 | 
								dst.SetDeadline(time.Now().Add(time.Second * 60))
 | 
				
			||||||
 | 
							default:
 | 
				
			||||||
 | 
								dst.SetDeadline(time.Now())
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		ch <- res{n, err}
 | 
							ch <- res{n, err}
 | 
				
			||||||
	}()
 | 
						}()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	n, err := io.Copy(left, right)
 | 
						n, err := io.Copy(left, right)
 | 
				
			||||||
	right.SetDeadline(time.Now()) // wake up the other goroutine blocking on right
 | 
						switch src := left.(type) {
 | 
				
			||||||
	left.SetDeadline(time.Now())  // wake up the other goroutine blocking on left
 | 
						case *net.TCPConn:
 | 
				
			||||||
 | 
							src.CloseWrite()
 | 
				
			||||||
 | 
							src.SetDeadline(time.Now().Add(time.Second * 60))
 | 
				
			||||||
 | 
						default:
 | 
				
			||||||
 | 
							src.SetDeadline(time.Now())
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						switch dst := right.(type) {
 | 
				
			||||||
 | 
						case *net.TCPConn:
 | 
				
			||||||
 | 
							dst.CloseRead()
 | 
				
			||||||
 | 
						default:
 | 
				
			||||||
 | 
							dst.SetDeadline(time.Now())
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	rs := <-ch
 | 
						rs := <-ch
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if err == nil {
 | 
						if err == nil {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user