mirror of
				https://github.com/yggdrasil-network/yggdrasil-go.git
				synced 2025-11-04 11:15:07 +03:00 
			
		
		
		
	fix some races and GetBytes/PutBytes usage, but this still seems to deadlock somewhere in iperf tests
This commit is contained in:
		
							parent
							
								
									5f66c4c95c
								
							
						
					
					
						commit
						efdaea1b5e
					
				
					 2 changed files with 7 additions and 3 deletions
				
			
		| 
						 | 
					@ -3,6 +3,7 @@ package tuntap
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"errors"
 | 
						"errors"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/yggdrasil-network/yggdrasil-go/src/util"
 | 
				
			||||||
	"github.com/yggdrasil-network/yggdrasil-go/src/yggdrasil"
 | 
						"github.com/yggdrasil-network/yggdrasil-go/src/yggdrasil"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -40,7 +41,7 @@ func (s *tunConn) reader() error {
 | 
				
			||||||
		select {
 | 
							select {
 | 
				
			||||||
		case <-read:
 | 
							case <-read:
 | 
				
			||||||
			if n > 0 {
 | 
								if n > 0 {
 | 
				
			||||||
				s.tun.send <- b[:n]
 | 
									s.tun.send <- append(util.GetBytes(), b[:n]...)
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		case <-s.stop:
 | 
							case <-s.stop:
 | 
				
			||||||
			s.tun.log.Debugln("Stopping conn reader for", s)
 | 
								s.tun.log.Debugln("Stopping conn reader for", s)
 | 
				
			||||||
| 
						 | 
					@ -68,8 +69,8 @@ func (s *tunConn) writer() error {
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			if _, err := s.conn.Write(b); err != nil {
 | 
								if _, err := s.conn.Write(b); err != nil {
 | 
				
			||||||
				s.tun.log.Errorln(s.conn.String(), "TUN/TAP conn write error:", err)
 | 
									s.tun.log.Errorln(s.conn.String(), "TUN/TAP conn write error:", err)
 | 
				
			||||||
				continue
 | 
					 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
								util.PutBytes(b)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -95,6 +95,7 @@ func (tun *TunAdapter) writer() error {
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			w, err = tun.iface.Write(b[:n])
 | 
								w, err = tun.iface.Write(b[:n])
 | 
				
			||||||
 | 
								util.PutBytes(b)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			tun.log.Errorln("TUN/TAP iface write error:", err)
 | 
								tun.log.Errorln("TUN/TAP iface write error:", err)
 | 
				
			||||||
| 
						 | 
					@ -219,9 +220,11 @@ func (tun *TunAdapter) reader() error {
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		// If we have a connection now, try writing to it
 | 
							// If we have a connection now, try writing to it
 | 
				
			||||||
		if isIn && session != nil {
 | 
							if isIn && session != nil {
 | 
				
			||||||
 | 
								packet := append(util.GetBytes(), bs[:n]...)
 | 
				
			||||||
			select {
 | 
								select {
 | 
				
			||||||
			case session.send <- bs[:n]:
 | 
								case session.send <- packet:
 | 
				
			||||||
			default:
 | 
								default:
 | 
				
			||||||
 | 
									util.PutBytes(packet)
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue